micropython-mpu9x50 on custom 1.18. firmware

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

micropython-mpu9x50 on custom 1.18. firmware

Post by mekanixms » Tue Mar 29, 2022 8:10 am

Hi,

I need to have some libraries frozen into the firmware (ESP32) for a project I work on. Using the standard compiling approach, I build the latest 1.18 firmware with IDF 4.4
Looks like a build/configuration problem because now I get the bellow exception when trying to load the MPU6050 library (https://github.com/micropython-IMU/micropython-mpu9x50)

Must say that I tested on the standard firmware, downloaded from micropython website, and works well.

How should I compile the firmware so I get rid of this issue?

Code: Select all

>>> from machine import Pin,I2C
>>> from imu import MPU6050
>>> i2c = I2C(0)
>>> imu = MPU6050(i2c)
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4008c8b4  PS      : 0x00060031  A0      : 0x8008ca49  A1      : 0x3ffbeed0  
A2      : 0x3ffd9a7c  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x00000800  
A6      : 0x3ffbd680  A7      : 0x80000002  A8      : 0x3ffd8408  A9      : 0x00000901  
A10     : 0x00000003  A11     : 0x00060023  A12     : 0x00000001  A13     : 0x3ffd840c  
A14     : 0x00000000  A15     : 0x3ff53000  SAR     : 0x0000001d  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000008  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  


Backtrace:0x4008c8b1:0x3ffbeed00x4008ca46:0x3ffbef10 0x40082c71:0x3ffbef40 0x401d9d17:0x3ffca6d0 0x400d2d87:0x3ffca6f0 0x400963dc:0x3ffca710 

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by pythoncoder » Tue Mar 29, 2022 9:43 am

Does the import fail only when the module is frozen? If the module imports OK when not frozen, I'd try cross compiling it. Delete the .py file from the target and replace with the .mpy. If that fails you may need to rebuild the cross compiler. (Frozen byte code is cross-compiled at build time).
Peter Hinch
Index to my micropython libraries.

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by mekanixms » Tue Mar 29, 2022 1:13 pm

The module imports ok. In this specific case I have it compiled to mpy and included in ports/esp32/modules.
Anyway, it works well both compiled or simple .py when is not frozen, on any firmware

After further testing (In repl, as you can see in the code posted) it seems the crash appears when creating an instance for the mpu, MPU6050(I2C(0)) and only when the mpu9x50 libs are frozen

All the other modules I have, working with ADC or digital inputs, i2c displays,... work well frozen in the firmware.
I suspect is something inside MPU9x50 library causing the crash

Thanks

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by pythoncoder » Wed Mar 30, 2022 12:40 pm

If you can import it and use it as an mpy file I'm baffled as to why it fails when frozen. The module is standard Python throughout.

Totally clutching at straws here, but it might be interesting to see if soft I2C makes any difference.
Peter Hinch
Index to my micropython libraries.

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by mekanixms » Thu Mar 31, 2022 7:24 am

After further testing I notice that:
  1. with the standard 1.17 firmware, I can create an instance of MPU6050

Code: Select all

MicroPython v1.17 on 2021-09-02; ESP32 module with ESP32
Type "help()" for more information.
>>> 
>>> from imu import MPU6050
>>> from machine import I2C
>>> imu=MPU6050(I2C(0))
>>> 
  • with the standard 1.18 firmware, I can create an instance of MPU6050

Code: Select all

MicroPython v1.18 on 2022-01-17; ESP32 module with ESP32
Type "help()" for more information.
>>> 
>>> from imu import MPU6050
>>> from machine import I2C
>>> imu=MPU6050(I2C(0))
>>> 
  • with the compiled 1.18 firmware, I get the error when instancing MPU6050
this compilation did not had the modules frozen in the firmware

Code: Select all

MicroPython v1.18-257-g35dbde163 on 2022-03-31; ESP32 module with ESP32
Type "help()" for more information.
>>> from machine import I2C
>>> from imu import MPU6050
>>> imu=MPU6050(I2C(0))
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
Given above I think is something related to the way I compile firmware. Even if I folow the standard procedure it may be that the configuration/optimization is different in the github nightly from the micropython standard releases.
Any suggestion what configuration/optimizations to use for compilation?

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by mekanixms » Thu Mar 31, 2022 8:02 am

pythoncoder wrote:
Wed Mar 30, 2022 12:40 pm
Totally clutching at straws here, but it might be interesting to see if soft I2C makes any difference.



Micropython 1.18 standard, no issues both on I2C and SoftI2c

Code: Select all

MicroPython v1.18 on 2022-01-17; ESP32 module with ESP32
imu=MPU6050(I2C(0))
imu=MPU6050(SoftI2C(scl=Pin(18),sda=Pin(19)))
Surprise, current 1.8, reboots on I2C but not on SoftI2c!

Code: Select all

MicroPython v1.18-257-g35dbde163 on 2022-03-31; ESP32 module with ESP32
Type "help()" for more information.
>>> 
>>> from machine import SoftI2C,Pin
>>> from imu import MPU6050
>>> imu=MPU6050(SoftI2C(scl=Pin(18),sda=Pin(19)))
>>> from machine import I2C
>>> imu=MPU6050(SoftI2C(scl=Pin(18),sda=Pin(19)))
>>> imu=MPU6050(I2C(0))
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Many thanks @pythoncoder for pointing this out to me!
Looks like I2C is indeed gone in the next stable and SoftI2C is the way to go

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by pythoncoder » Thu Mar 31, 2022 8:18 am

Out of interest could you please try hard I2C, but this time specifying the pins to the constructor:

Code: Select all

imu=MPU6050(I2C(0, scl=Pin(18),sda=Pin(19)))
Peter Hinch
Index to my micropython libraries.

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by mekanixms » Thu Mar 31, 2022 8:31 am

pythoncoder wrote:
Thu Mar 31, 2022 8:18 am
Out of interest could you please try hard I2C, but this time specifying the pins to the constructor:

Code: Select all

imu=MPU6050(I2C(0, scl=Pin(18),sda=Pin(19)))
Of Course, find below please

Code: Select all

>>> from imu import MPU6050
>>> from machine import Pin,I2C
>>> imu=MPU6050(I2C(0, scl=Pin(18),sda=Pin(19)))
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by mekanixms » Thu Mar 31, 2022 8:32 am

just FYI, above tested with the modules frozen in 1.18 build

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: micropython-mpu9x50 on custom 1.18. firmware

Post by pythoncoder » Fri Apr 01, 2022 9:46 am

There does seem to be a firmware bug here but I'm unsure how to report it as the maintainers are unlikely to have a suitable IMU.
Peter Hinch
Index to my micropython libraries.

Post Reply