RT1062 Hangs Importing Modules from SD

My application has a number of modules that are imported from the SD card. Sometimes the RT1062 loads all of the modules and runs fine while other times it hangs when importing these modules. The hangup happens on different modules. I’ve checked the free memory and there is more than enough memory to load the module where the hangup occurs.

memAllocPrev = gc.mem_alloc()
def memoryUsage ():
global memAllocPrev
print(‘Mem free: {} allocated: {}’.format(gc.mem_free(), gc.mem_alloc()))
print("Addl Mem Used = ", gc.mem_alloc() - memAllocPrev)
gc.collect()
memAllocPrev = gc.mem_alloc()
print()

import SystemTests
Mem free: 8421408 allocated: 91104
Addl Mem Used = 4896

import DisplayPages
Mem free: 8396688 allocated: 115824
Addl Mem Used = 24832

Hi, I’m not exactly sure how to help here. You need to provide a way to reproduce the issue.

However, for a professional project, I would suggest building your modules into the firmware: 8. Releasing your OpenMV Cam Scripts for Production — MicroPython 1.24 documentation

Other customers who pay for consulting time do this. Generally they prefer having more control over the system.

The code is still being developed and not ready to freeze. Hanging without any error code makes it difficult to debug. Is there a way to turn on more debugging messages to figure out why it’s hanging?

You can enable MICROPY_DEBUG_VERBOSE.

Question: Do you have executable code in the modules you are importing that’s not under a definition/class? All of that code will run when the module is imported.

Otherwise, the way to debug this is to get a segger jtagger, compile the firmware, load it via the jtagger, and step through the program. The bug you are seeing, though, is part of the MicroPython core, which is pretty well debugged… so, the error is more likely with something in the module you are importing being executed.

How do I enable MICROPY_DEBUG_VERBOSE?

This is a compile option when you build the firmware; you’d need to define it when you build. However, instead of debugging the firmware, it may be better to try to narrow down which module you are importing that is causing the hang. Do you have something that can reproduce it generically?

FYI … Upgrade to Firmware 4.6.20 solved the problem, without changing the modules being imported.