Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
I dont know about other firmwares, but this one resets AXP192 settings to the state when it does not switch power on at all. So, it works only till manual power off.
Flashing to one of the original(e.g. factory test) firmwares restores operation.
Flashing to one of the original(e.g. factory test) firmwares restores operation.
- cicciocb
- Site Admin
- Posts: 2795
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 594 times
- Been thanked: 2006 times
- Contact:
Re: Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
Thanks for your feedback but the AXP192 is not fully integrated and this module (the M5Core2) is not supported.
Re: Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
Did I missed something? I allmost did the correction program. It launches AXP192.[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Mon Jan 20, 2025 1:31 pm module (the M5Core2) is not supported.
The only problem thing is to enable LDO2 3.3V output for SD Card.
I obtain only 1.8V.
You do not have the required permissions to view the files attached to this post.
- cicciocb
- Site Admin
- Posts: 2795
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 594 times
- Been thanked: 2006 times
- Contact:
Re: Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
I even forgot that it was supported. 
I'm becoming old and I'm starting to forget... I probably did it while sleeping.
Yes, you are right, it seems to be supported but not completely.
This is the code I implemented to support the AXP2101 (the chip that replace the AXP192 on that module)
Probably something is missing to support the 3.3V on the SDCARD
Edit :
The SDCARD seems to be supplied by the output ALDO4, the same of the LCD and the touchscreen so it should work
I'm becoming old and I'm starting to forget... I probably did it while sleeping.
Yes, you are right, it seems to be supported but not completely.
This is the code I implemented to support the AXP2101 (the chip that replace the AXP192 on that module)
Code: [Local Link Removed for Guests]
#define AXP2101_ADDR 0x34
#define AXP2101_LDO_CTRL_REG 0x90
#define AXP2101_BLDO1_VOLTAGE_REG 0x96
void init_AXP2102() {
Wire.begin(21, 22); // set SDA=21 and SCL=22
//Switch Ldo on
Wire.beginTransmission(AXP2101_ADDR);
Wire.write(AXP2101_LDO_CTRL_REG);
Wire.endTransmission();
Wire.requestFrom(AXP2101_ADDR, 1);
uint8_t data = Wire.read();
Wire.endTransmission();
data |= 0x00011010; // ALD2, ALD4, BLD1
Wire.beginTransmission(AXP2101_ADDR);
Wire.write(AXP2101_LDO_CTRL_REG);
Wire.write(data);
Wire.endTransmission();
//Display Background Led Voltage 0-30 -> (500-3500mV)
Wire.beginTransmission(AXP2101_ADDR);
Wire.write(AXP2101_BLDO1_VOLTAGE_REG);
Wire.write(23);
Wire.endTransmission();
}
Edit :
The SDCARD seems to be supplied by the output ALDO4, the same of the LCD and the touchscreen so it should work
Re: Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
I have an older version of M5Core2 HW. It builded around AXP192
Re: Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
Finelly draft & dirty but works I used as example AXP192.cpp from M5Core2 Arduino library.
Code: [Local Link Removed for Guests]
I2C.SETUP 21, 22 ' set I2C port on pins 21 and 22
wlog "Startup"
true = 1: false = 0
dat = 0
axp192_LDO2_3=0x28
axp192_VBUS_IPSOUT=0x30
axp192_GPIO2_Control=0x93
axp192_Backup_Battery=0x35
axp192_GPIO43_CTR=0x95
axp192_GPIO43_STA=0x96
axp192_PEK=0x36
axp192_ADC=0x82
'Slave_addr:
AXP192_ADDR=0x34
AXP192_LDO_CTRL_REG=0x28
hbyte = i2C.ReadRegByte(AXP192_ADDR, 0x03)
wlog "0x03= "; hex$(hbyte)
'// AXP192 30H
i2C.WriteRegByte AXP192_ADDR, 0x30, (i2C.ReadRegByte(AXP192_ADDR, 0x30) and 0x04) or 0x02
wlog "axp: vbus limit off"
'' AXP192 GPIO1:OD OUTPUT
i2C.WriteRegByte AXP192_ADDR, 0x92, i2C.ReadRegByte(AXP192_ADDR, 0x30) and 0xf8
wlog "axp: gpio1 init"
' // AXP192 GPIO2:OD OUTPUT
i2C.WriteRegByte AXP192_ADDR, 0x93, i2C.ReadRegByte(AXP192_ADDR, 0x93) and 0xf8
wlog "axp: gpio2 init"
' // AXP192 RTC CHG
i2C.WriteRegByte AXP192_ADDR, 0x35, (i2C.ReadRegByte(AXP192_ADDR, 0x35) and 0x1c) or 0xa2
wlog "axp: rtc battery charging enabled"
SetESPVoltage 3350
wlog "axp: esp32 power voltage was set to 3.35v"
SetLcdVoltage 2800
wlog "axp: lcd backlight voltage was set to 2.80v"
SetLDOVoltage 2, 3300 ' // Periph power voltage preset (LCD_logic, SD card)
wlog "axp: lcd logic and sdcard voltage preset to 3.3v"
SetLDOVoltage 3, 2000 ' // Vibrator power voltage preset
wlog "axp: vibrator voltage preset to 2v"
'// Select source for BUS_5V
'// 0 : use internal boost
'// 1 : powered externally
SetBusPowerMode 0
SetLDOEnable 2, true
SetDCDC3 true '// LCD backlight
'SetLed true
SetCHGCurrent 2 'kCHG_200mA
'SetAxpPriphPower 1
'wlog "axp: lcd_logic and sdcard power enabled"
'// AXP192 GPIO4
i2C.WriteRegByte AXP192_ADDR, 0X95, (i2C.ReadRegByte(AXP192_ADDR, 0x95) and 0x72) or 0X84
i2C.WriteRegByte AXP192_ADDR, 0X36, 0X4C
i2C.WriteRegByte AXP192_ADDR, 0x82, 0xff
'SetLCDRSet 0
'pause 100
'SetLCDRSet 1
'pause 100
wlog "END"
end
'========================= SUBS ==================
'// Select source for BUS_5V
'// 0 : use internal boost
'// 1 : powered externally
sub SetBusPowerMode(state)
' uint8_t data;
if (state = 0) then
' // Set GPIO to 3.3V (LDO OUTPUT mode)
dat = i2C.ReadRegByte(AXP192_ADDR, 0x91)
i2C.WriteRegByte AXP192_ADDR, 0x91, (dat and 0x0F) or 0xF0
' // Set GPIO0 to LDO OUTPUT, pullup N_VBUSEN to disable VBUS supply from
' // BUS_5V
dat = i2C.ReadRegByte(AXP192_ADDR, 0x90)
i2C.WriteRegByte AXP192_ADDR, 0x90, (dat and 0xF8) or 0x02
' // Set EXTEN to enable 5v boost
dat = i2C.ReadRegByte(AXP192_ADDR, 0x10)
i2C.WriteRegByte AXP192_ADDR, 0x10, dat or 0x04
else
' // Set EXTEN to disable 5v boost
dat = i2C.ReadRegByte(AXP192_ADDR, 0x10)
i2C.WriteRegByte AXP192_ADDR, 0x10, dat and not 0x04
' // Set GPIO0 to float, using enternal pulldown resistor to enable VBUS
' // supply from BUS_5V
dat = i2C.ReadRegByte(AXP192_ADDR, 0x90)
i2C.WriteRegByte AXP192_ADDR, 0x90, (dat and 0xF8) or 0x07
end if
end sub
sub SetLCDRSet(state)
reg_addr = 0x96
gpio_bit = 0x02
dat = i2C.ReadRegByte(AXP192_ADDR, reg_addr)
if (state) then
dat = dat or gpio_bit
else
dat = dat and not gpio_bit
end if
i2C.WriteRegByte AXP192_ADDR, reg_addr, dat
end sub
sub SetLDOEnable(number, state)
mark = 0x01
if ((number < 2) or (number > 3)) then return
mark = mark << number
if (state = true) then
i2C.WriteRegByte AXP192_ADDR, 0x12, i2C.ReadRegByte(AXP192_ADDR, 0x12) or mark
else
i2C.WriteRegByte AXP192_ADDR, 0x12, i2C.ReadRegByte(AXP192_ADDR, 0x12) and not mark
end if
end sub
sub SetDCDC3(State) {
' buf = i2C.ReadRegByte(AXP192_ADDR, 0x12)
' if (State = true) then
' buf = (1 << 1) or buf
' else
' buf = not (1 << 1) and buf
' end if
'
' i2C.WriteRegByte AXP192_ADDR, 0x12, buf
i2C.WriteRegByte AXP192_ADDR, 0x12, 0x57
end sub
sub SetLed(state)
reg_addr = 0x94
' dat = i2C.ReadRegByte(AXP192_ADDR, reg_addr)
'
' if state=true then
' dat = dat and 0XFD
' else
' dat = dat or 0X02
' end if
' i2C.WriteRegByte AXP192_ADDR, reg_addr, dat
i2C.WriteRegByte AXP192_ADDR, reg_addr, 0x00
end sub
sub SetCHGCurrent(state)
dat = i2C.ReadRegByte(AXP192_ADDR, 0x33)
dat = dat and 0xf0
dat = dat or (state and 0x0f)
i2C.WriteRegByte AXP192_ADDR, 0x33, dat
end sub
sub SetLcdVoltage(voltage)
if (voltage >= 2500) and (voltage <= 3300) SetDCVoltage 2, voltage
end sub
sub SetESPVoltage(voltage)
if (voltage >= 3000) and (voltage <= 3400) then SetDCVoltage 0, voltage
end sub
sub SetLDOVoltage(number, voltage)
' calcVoltageData voltage, 3300, 1800, 100
' vdata = dat and 0x0F
'
' rdata = i2C.ReadRegByte(AXP192_ADDR, 0x28) AND 0x0F
' wlog "0x28= "; hex$(rdata)
' select case number
' case 2:
' rdata = rdata OR (vdata << 4)
' wlog "2write= "; hex$(rdata)
' i2c.WriteRegByte AXP192_ADDR, 0x28, rdata
' case 3:
' rdata = (rdata AND 0x0F) OR vdata
' i2c.WriteRegByte AXP192_ADDR, 0x28, rdata
' end select
i2c.WriteRegByte AXP192_ADDR, 0x28, 0xFF
end sub
'/// @param number 0=DCDC1 / 1=DCDC2 / 2=DCDC3
sub SetDCVoltage(number, voltage)
if (number > 2) then return
select case number
case 0:
addr = 0x26
calcVoltageData voltage, 3500, 700, 25
vdata = dat and 0x7F
case 1:
addr = 0x25
calcVoltageData voltage, 2275, 700, 25
vdata = dat and 0x3F
case 2:
addr = 0x27
calcVoltageData voltage, 3500, 700, 25
vdata = dat and 0x7F
end select
' // Serial.printf("result:%hhu\n", (Read8bit(addr) & 0X80) | (voltage &
' // 0X7F)); Serial.printf("result:%d\n", (Read8bit(addr) & 0X80) | (voltage &
' // 0X7F)); Serial.printf("result:%x\n", (Read8bit(addr) & 0X80) | (voltage &
' // 0X7F));
i2c.WriteRegByte AXP192_ADDR, addr, (i2C.ReadRegByte(AXP192_ADDR, addr) and 0x80) or vdata
end sub
sub calcVoltageData (value, maxv, minv, ste)
dat = 0
if (value > maxv) then value = maxv
if (value > minv) then dat = (value - minv) / ste
end sub
You do not have the required permissions to view the files attached to this post.
- cicciocb
- Site Admin
- Posts: 2795
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 594 times
- Been thanked: 2006 times
- Contact:
Re: Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
Very good.
After all is not so complicate to use the I2C and implement a kind of "driver"
After all is not so complicate to use the I2C and implement a kind of "driver"
Re: Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
One more solution:
ReadRegsAXP192.bas - backups AXP192 registers in a file axp192.bin
use it to save good Axp192 configuration.
WriteRegsAXP192.bas - restores configuration to axp192 from axp192.bin
ReadRegsAXP192.bas - backups AXP192 registers in a file axp192.bin
use it to save good Axp192 configuration.
WriteRegsAXP192.bas - restores configuration to axp192 from axp192.bin
You do not have the required permissions to view the files attached to this post.
Re: Flashing M5Core2 with Annex32 BLE CAN 1.70.5 LFS disturbs AXP192 settings
AXP192 does not stores it's settings after reboot and if you turn it off by long power btn press, you return to unconfigured device.
With no 5V, 3.3V LDO, no speaker power, etc. and have to write all setting again.
To solve it I set WriteRegsAXP192.bas as AutoRun File and launch desired program from it by executing e.g:
With no 5V, 3.3V LDO, no speaker power, etc. and have to write all setting again.
To solve it I set WriteRegsAXP192.bas as AutoRun File and launch desired program from it by executing e.g:
Code: [Local Link Removed for Guests]
f$ = "/mp3_demo/gui_radio3.bas"
COMMAND "print BAS.LOAD f$"