Page 1 of 1

mutexes in noinit-externa RAM

Posted: Mon Feb 20, 2023 5:26 pm
by mhammer3
Dear all
I am trying to use the esp_ring component to store logs beyond SW-restarts or crashes (no power-resets).

defined are;
EXT_RAM_NOINIT_ATTR static StaticRingbuffer_t staticRingbuffer = {0};
EXT_RAM_NOINIT_ATTR static uint8_t buffer[RING_BUFFER_POOL_SIZE]; // 1 MB

The issue is when staticRingbuffer is defined in external none-initialized RAM, the software crashes in "xRingbufferSend",when trying to access a mutex.
When staticRingbuffer is defined in internal initialized RAM, this issue doesn't occur.
But, in this case I cannot save the logs beyond SW-restarts.

What am I missing in order to have and use "staticRingbuffer" in external none-initialized RAM, please?
Your help is much appreciated.
Thanks
Marko


assert failed: xQueueSemaphoreTake queue.c:1556 (pxQueue->uxItemSize == 0)


Backtrace: 0x40084d39:0x3ffbc380 0x400928a5:0x3ffbc3a0 0x400988c5:0x3ffbc3c0 0x400938dd:0x3ffbc4e0 0x401a5d31:0x3ffbc520 0x401a6313:0x3ffbc570 0x400da016:0x3ffbc5b0 0x401a6989:0x3ffbc6f0 0x40098647:0x3ffbc720 0x40190659:0x3ffbc770 0x400d404e:0x3ffbc7b0 0x400d3da4:0x3ffbc7d0 0x401a66ed:0x3ffbc7f0

#0 0x40084d39:0x3ffbc380 in panic_abort at /home/mhammer3/.platformio/packages/framework-espidf/components/esp_system/panic.c:412
#1 0x400928a5:0x3ffbc3a0 in esp_system_abort at /home/mhammer3/.platformio/packages/framework-espidf/components/esp_system/esp_system.c:135
#2 0x400988c5:0x3ffbc3c0 in __assert_func at /home/mhammer3/.platformio/packages/framework-espidf/components/newlib/assert.c:78
#3 0x400938dd:0x3ffbc4e0 in xQueueSemaphoreTake at /home/mhammer3/.platformio/packages/framework-espidf/components/freertos/FreeRTOS-Kernel/queue.c:1556 (discriminator 1)
#4 0x401a5d31:0x3ffbc520 in prvReceiveGeneric at /home/mhammer3/.platformio/packages/framework-espidf/components/esp_ringbuf/ringbuf.c:776
#5 0x401a6313:0x3ffbc570 in xRingbufferReceive at /home/mhammer3/.platformio/packages/framework-espidf/components/esp_ringbuf/ringbuf.c:1132

Re: mutexes in noinit-externa RAM

Posted: Tue Feb 21, 2023 12:38 am
by ESP_Sprite
I don't think that is possible. The ringbuffer memory contains semaphores, which in turn contain pointers to internal FreeRTOS structures. Those structures are not guaranteed to be the same or at the same position after every reboot, so the pointers probably point to wrong data.

Re: mutexes in noinit-externa RAM

Posted: Wed Feb 22, 2023 12:27 am
by MicroController
The solution would be to use a simple, non-threadsafe ringbuffer from the internet and put it into external RAM. Guard accesses via a seperate mutex residing in internal RAM.
However, also consider the edge case of uninitialized RAM acutally being uninitialized, e.g. after power loss. Check if your external RAM goes to a defined state upon power-up.