-
I am testing SPIRAM on the ESP32-S3 and while trying to track down the cause of memory exceptions when using external SPIRAM, I have gotten a bit confused in regards to the SPIRAM address range. The DT shows the SPIRAM starting at 0x3c000000 and growing up (which matches the TRM for external memory). zephyr/dts/xtensa/espressif/esp32s3/esp32s3_wroom_n16r8.dtsi Lines 14 to 18 in 32bd3aa However, the linker script is showing that the SPIRAM ends at 0x3E000000 and starts at 0x3E000000 minus the length. This does match a quick read/write test, so I suspect that the DT is wrong in this case (or only correct when the SPIRAM is 32MB). zephyr/soc/xtensa/espressif_esp32/esp32s3/default.ld Lines 79 to 81 in 32bd3aa Also, how can I check the MMU configuration? I haven't been able to track that down yet and could use some pointers. Adding @sylvioalves and @LucasTambor since they have done some support/changes related to this. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
@EricNRS, The correct starting address of the external data memory for the |
Beta Was this translation helpful? Give feedback.
-
Thanks Marek, that clarifies why the mapping PSRAM mapping is done towards the end. The issue I am trying to debug is a networking crash when sending large packets. I did some test code to to allocate from the SPIRAM And the failure is in heap.h. A10 looks like the correct beginning of the SPIRAM (0x3E000000 - 8MB), so not sure why it is crashing. Line 114 in 32bd3aa
The coredump doesn't have the register values, just the heap.h line 114 in the backtrace. SPIRAM itself seems to be fine as I can read and write values from 0x3d800000 to 0x3e000000 which is the correct 8 MB value. Unfortunately, I haven't been able to debug this successfully yet as GDB ends up switching to core 1 every time I step through the code. I wonder if I can disable core 1 for this test as I don't need WiFi. Any tips on how best to debug this? The tests Here is the heap configuration from zephyr/build/.config:
|
Beta Was this translation helpful? Give feedback.
-
I'm seeing what looked like memory corruption that was causing the crash. However, checking the map file, the issue is caused by the SPIRAM heap and the WiFi heaps being allocated on top of each other when Here is part of the map file showing the overlap of the system heap (heap_caps.c): .ext_ram.bss.1
0x000000003d800000 0x4 zephyr/libzephyr.a(heap_caps.c.obj)
0x000000003d800000 _spiram_data_start
0x000000003d800004 . = ALIGN (0x4)
0x000000003d800004 _ext_ram_bss_end = ABSOLUTE (.)
.ext_ram_noinit
0x000000003d800010 0x4c5e4
*libdrivers__wifi.a:(SORT_BY_ALIGNMENT(.noinit) SORT_BY_ALIGNMENT(.noinit.*))
.noinit."WEST_TOPDIR/zephyr/drivers/wifi/esp32/src/esp_wifi_drv.c".3
0x000000003d800010 0x1000 zephyr/drivers/wifi/libdrivers__wifi.a(esp_wifi_drv.c.obj)
0x000000003d800010 esp_wifi_event_stack
.noinit."WEST_TOPDIR/zephyr/drivers/wifi/esp32/src/esp_wifi_drv.c".2
0x000000003d801010 0xb90 zephyr/drivers/wifi/libdrivers__wifi.a(esp_wifi_drv.c.obj)
*libsubsys__net__l2__ethernet.a:(SORT_BY_ALIGNMENT(.noinit) SORT_BY_ALIGNMENT(.noinit.*))
*libsubsys__net__lib__config.a:(SORT_BY_ALIGNMENT(.noinit) SORT_BY_ALIGNMENT(.noinit.*))
*libsubsys__net__ip.a:(SORT_BY_ALIGNMENT(.noinit) SORT_BY_ALIGNMENT(.noinit.*))
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_mgmt.c".0
0x000000003d801ba0 0x800 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_mgmt.c.obj)
0x000000003d801ba0 mgmt_stack
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_tc.c".1
0x000000003d8023a0 0x1000 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_tc.c.obj)
0x000000003d8023a0 rx_stack
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/tcp.c".0
0x000000003d8033a0 0x800 zephyr/subsys/net/ip/libsubsys__net__ip.a(tcp.c.obj)
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_mgmt.c".1
0x000000003d803ba0 0x154 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_mgmt.c.obj)
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c".3
0x000000003d803cf4 0x20000 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c".2
0x000000003d823cf4 0xe00 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c".1
0x000000003d824af4 0x20000 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c".0
0x000000003d844af4 0xe00 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c".k_mem_slab_buf_tx_pkts
0x000000003d8458f4 0x2000 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
0x000000003d8458f4 _k_mem_slab_buf_tx_pkts
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c".k_mem_slab_buf_rx_pkts
0x000000003d8478f4 0x2000 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
0x000000003d8478f4 _k_mem_slab_buf_rx_pkts
.noinit."WEST_TOPDIR/zephyr/subsys/net/ip/tcp.c".k_mem_slab_buf_tcp_conns_slab
0x000000003d8498f4 0x2d00 zephyr/subsys/net/ip/libsubsys__net__ip.a(tcp.c.obj)
*libsubsys__net.a:(SORT_BY_ALIGNMENT(.noinit) SORT_BY_ALIGNMENT(.noinit.*)) And here is the system heap definition from hal_espressif/zephyr/esp_shared/src/common/heap_caps.c #if defined(CONFIG_ESP_SPIRAM)
EXT_RAM_ATTR int _spiram_data_start;
STRUCT_SECTION_ITERABLE(k_heap, _spiram_heap) = {
.heap = {
.init_mem = &_spiram_data_start,
#if (CONFIG_ESP_SPIRAM_SIZE <= 0x400000)
.init_bytes = CONFIG_ESP_SPIRAM_SIZE,
#else
.init_bytes = 0x400000,
#endif
},
}; This is looking like a bug or at least a conflict between the SPIRAM heap and CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM. Also, what is the rational of only initialising the first 0x4000000 byes (4 MB) of memory? I need to get this fixed to get back on track with the project (and also get back to PRs that I have been ignoring while getting this fixed). Any ideas on a quick workaround? Maybe move the heap to later in the map file and reduce the size? Will probably need to do the same for the network heap. |
Beta Was this translation helpful? Give feedback.
-
Opened #61359 for this. |
Beta Was this translation helpful? Give feedback.
-
Issued fixed. |
Beta Was this translation helpful? Give feedback.
Opened #61359 for this.