Using SPI RAM from C++ programs

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Using SPI RAM from C++ programs

Postby markwj » Fri Jan 12, 2018 1:03 am

Any suggestions for the best way to use SPI RAM from C++ programs?

I tried setting the "SPI RAM access method" to "Make RAM allocatable using malloc() as well", and reducing "Maximum malloc() size, in bytes, to always put in internal memory" to 32 bytes, but get this crash on startup:

Code: Select all

#0  0x4008dfbc in invoke_abort () at /Users/mark/esp3o/esp-idf/components/esp32/./panic.c:139
#1  0x4008e0b2 in abort () at /Users/mark/esp3o/esp-idf/components/esp32/./panic.c:148
#2  0x4008975e in vPortCPUInitializeMutex (mux=0x3f800238) at /Users/mark/esp3o/esp-idf/components/freertos/./port.c:303
#3  0x400899fc in xQueueGenericReset (xQueue=0x3f8001e8, xNewQueue=1) at /Users/mark/esp3o/esp-idf/components/freertos/./queue.c:270
#4  0x40089a78 in prvInitialiseNewQueue (uxQueueLength=32, uxItemSize=48, pucQueueStorage=0x3f800240 '\376' <repeats 200 times>..., ucQueueType=0 '\000', pxNewQueue=0x3f8001e8)
    at /Users/mark/esp3o/esp-idf/components/freertos/./queue.c:441
#5  0x40089ac9 in xQueueGenericCreate (uxQueueLength=32, uxItemSize=48, ucQueueType=0 '\000') at /Users/mark/esp3o/esp-idf/components/freertos/./queue.c:408
#6  0x40162490 in esp_event_loop_init (cb=<optimized out>, ctx=0x3ffb4980 <MyEvents>) at /Users/mark/esp3o/esp-idf/components/esp32/./event_loop.c:103

(gdb) frame 2
#2  0x4008975e in vPortCPUInitializeMutex (mux=0x3f800238) at /Users/mark/esp3o/esp-idf/components/freertos/./port.c:303
303	    configASSERT(esp_ptr_internal((const void *) mux));
Presumably that is esp_event_loop_init trying to create a FreeRTOS queue, and then objecting because it is not in internal RAM? It seems that the ESP IDF framework is not fully working with SPI RAM yet (due to inherent limitations). It would be better if the memory to be allocated must be internal, it is specifically allocated as internal (rather than just rely on a generic malloc). I understand that this will take some time to work the kinks out. https://github.com/espressif/esp-idf/issues/1492

Anyway, for my application, it would be fine if the C++ new() operator allocated from SPI RAM. If I had a case where I needed that data for a flash write, or DMA access, I'd add a specific malloc to allocate from internal RAM.

Has anybody here done this, or worked with this? I know that the template allocators in C++ have some options for things like this, but none seem to have been provided for SPI RAM in the ESP IDF framework.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Using SPI RAM from C++ programs

Postby ESP_Sprite » Fri Jan 12, 2018 6:53 am

There's a bug we're working on where a structure containing a spinlock can sometimes be allocated in SPI RAM, and as such will not work correctly. We're at the moment working on a solution for that; a fix should appear in esp-idf master soon.

yafra7
Posts: 3
Joined: Fri Apr 23, 2021 1:44 pm

Re: Using SPI RAM from C++ programs

Postby yafra7 » Tue May 25, 2021 10:16 am

Hello,

Did you find a solution to make the new() operator allocate from the SPI RAM ?

Thanks

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: Using SPI RAM from C++ programs

Postby markwj » Thu May 27, 2021 3:03 am

yafra7 wrote:
Tue May 25, 2021 10:16 am
Did you find a solution to make the new() operator allocate from the SPI RAM ?
A few. You can checkout our code at:

https://github.com/openvehicles/Open-Ve ... g-System-3

In particular:

https://github.com/openvehicles/Open-Ve ... ain/ovms.h
https://github.com/openvehicles/Open-Ve ... n/ovms.cpp

That said, several years into this and we are still fighting bugs in the Espressif support for SPI RAM. Very frustrating.

Regards, Mark.

Who is online

Users browsing this forum: No registered users and 71 guests