Memory allocation failed issue on Portenta

Starting this new thread based on question asked on another one:

Okay that’s good, thanks for clarifying!

I’m on Portenta H7 Vision Shield (LoRa)

Right, that’s what I’d like to avoid too. When I wasn’t using sleep to save power, this wasn’t happening so my initial hypothesis was that the Portenta is probably losing the pointer to the loaded model or maybe the gc.collect() or (as used during testing) gc.enable() deems it inactive in some random allocation and deletes it.

UPDATE

Tried invoking model only once upon boot again. Works fine for a few iterations but then when it goes to sleep and wakes up for iteration, throws an Invoke failed.

PC

Hi,

This sounds like memory corruption caused by light sleep.

If you only use deep sleep does it work correctly? It should be fine without any sleep too. It sounds like light sleep corrupts memory. We don’t edit the code from MicroPython upstream here so this may be a general bug with the STM32 HAL from MicroPython.

Let me test this and get back to you. None of my recent tests are on deepsleep since I realised for my application lightsleep is sufficient.

I see. Maybe I’ll reach out to Micropython through their forum for this. Meanwhile, please let me know if you have any other suggestion or contacts to reach the right person from STM or Micropython.

PC

Verify first that everything is good without the sleeping and then add deep sleep and then switch that too light sleep. This will give you a pretty straight up smoking gun here.

After that, a minimal example of the least amount of lines of code to generate the error will help. Particularly, if you are able to make it happen using standard non OpenMV libraries only.

1 Like

Just simulated without machine.lightsleep() for 1 hour and there’s no memory issue. I have been working on this approach for a few months now and all that testing confirms the same thing.

I’m not sure if I can test this using machine.deepsleep() 'cause everytime the Portenta wakes up, the program starts executing again from the beginning as expected since RAM is not retained during deepsleep.

I opened a query on Micropython’s STM discussion page a few days ago after our discussion here. I just posted a minimal program there Memory allocation failed when using machine.lightsleep on Arduino Portenta (STM32H747) · micropython · Discussion #16832

PC

@prithulc - MicroPython folks aren’t going to debug anything related to our firmware. You need to reduce the example down to something that breaks purely on off the shelf Python code without any of our library components and make an extremely minimal example.

… anyway, as for what to do next. Please push Arduino to assign debugging lightsleep() to use and Ibrahim can take a look at this as part of our service contract. Otherwise, please remove lightsleep() from your code.

As for the way to report this to MicroPython: Waking machine.lightsleep(): timer and external interruption · Issue #2621 · openmv/openmv · GitHub

You need to overwrite our firmware with Pure MicroPython code and then test to see if the machine.lightsleep() method is failing.

See also: Installing MicroPython | Arduino Documentation

Hi @kwagyeman, thanks for your response.

My bad! I thought I was using pure MicroPython libraries there. Well, I did start off like that by compartmentalising each component of the program to see what’s breaking and until I use sensor and ml, lightsleep works fine, and I lost focus on using only MP libs.

Sorry but there’s no clarity on how to push issues to Arduino. I already tried raising through the contact form (arduino.cc/en/contact-us) when you suggested this last time but have had no response. I’ll try again this way.

I posted this query. Are you saying this is the right way to raise issue and that I should be raising this memory corruption issue that we are discussing in such manner?

Thank you for your patience, truly.

PC

Hi Prithulc,

They should be monitoring the contact form.

Thanks for this: machine.lightsleep() won’t wake using ExtInt() when timer wakeup is used in the same program · Issue #16862 · micropython/micropython

It’s not our firmware issue. In this case Arduino assigning us to fix it would be the best. Otherwise… you need to wait for MP folks to fix.

As for what you should do now. Please comment out lightsleep from your code in the meantime. I’ll get back to you if you need to do anything other than contacting Arduino.

1 Like

Perhaps it’s the SDRAM that gets corrupted on STOP mode entry/exit. Maybe it’s the self-refresh mode, PLLs or something else.
There might be a way to try reproduce this issue with pure MicroPython, without messing with any GC or ML models, if you use uctypes.bytearray_at to create a buffer at say the last MB of SDRAM and fill it with data and check it after wakeup.

1 Like