malloc mp_task_heap_size problem in main.c

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
timer
Posts: 3
Joined: Fri Feb 07, 2020 1:31 pm

malloc mp_task_heap_size problem in main.c

Post by timer » Mon Feb 17, 2020 3:20 pm

hello everyone,
I have hardware: TTGO Camera Plus 8M spi ram. camera:ov2640 display:st7789
software:the newest Micropython
ESPIDF_SUPHASH_V3 := 143d26aa49df524e10fb8e41a71d12e731b9b71d
esp32-camera: https://github.com/tsaarni/esp32-camera-for-micropython (can not use newest esp32-camera from Espressif)

I encountered a strange problemI encountered a strange problem:

if I compile ov2640 module alone and use webrepl, sometimes it will hard to connect to the device. it will be halt when I enter the password in the webrepl gui.
if I compile ov2640 module and st7789 module together.when I use the webrepl ,it always say that password is wrong.but I sure the password is correct,i saw it from webrepl_cfg.py.
both of them sometimes show that SyntaxError: invalid syntax.

and I try to changed the mp_task_heap_size,it help a little bit.but it seems that have the same problem.

anyone know that pls help. thanks.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: malloc mp_task_heap_size problem in main.c

Post by jimmo » Tue Feb 18, 2020 1:55 am

My guess is that you're enabling PSRAM / SPIRAM for MicroPython? Which means that MicroPython will use the entire PSRAM for its heap, conflicting with the camera driver. (For historical bug workaround reasons, it uses the PSRAM directly via it's memory address, rather than via malloc).

I'm a little bit confused how they intend https://github.com/tsaarni/esp32-camera-for-micropython to be used with MicroPython, but basically you'll need to enable PSRAM, but tell MicroPython not to use it for the heap. (i.e. in main.c mp_task(), make sure the heap is allocated using malloc rather than directly using the PSRAM directly via 0x3f800000).

timer
Posts: 3
Joined: Fri Feb 07, 2020 1:31 pm

Re: malloc mp_task_heap_size problem in main.c

Post by timer » Tue Feb 18, 2020 11:49 am

jimmo wrote:
Tue Feb 18, 2020 1:55 am
My guess is that you're enabling PSRAM / SPIRAM for MicroPython? Which means that MicroPython will use the entire PSRAM for its heap, conflicting with the camera driver. (For historical bug workaround reasons, it uses the PSRAM directly via it's memory address, rather than via malloc).

I'm a little bit confused how they intend https://github.com/tsaarni/esp32-camera-for-micropython to be used with MicroPython, but basically you'll need to enable PSRAM, but tell MicroPython not to use it for the heap. (i.e. in main.c mp_task(), make sure the heap is allocated using malloc rather than directly using the PSRAM directly via 0x3f800000).
do you mean that i should not use spi for micropython?just like that?
// No SPIRAM, fallback to normal allocation
mp_task_heap_size = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
mp_task_heap = malloc(mp_task_heap_size);
break;

i also think there are some conflict between them.but donot know how to solve.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: malloc mp_task_heap_size problem in main.c

Post by jimmo » Tue Feb 18, 2020 12:59 pm

timer wrote:
Tue Feb 18, 2020 11:49 am
do you mean that i should not use spi for micropython?just like that?
Yep.

You still need PSRAM enabled, you just want to make sure it isn't used by the heap so it's available for the camera.

You might need to play around with setting mp_task_heap_size smaller than the largest free block (otherwise I imagine malloc will also just use the entire PSRAM). So perhaps try hard-coding mp_task_heap_size to something small like 256k, otherwise also pass MALLOC_CAP_INTERNAL to heap_caps_get_largest_free_block to force it not to use the PSRAM.

Post Reply