I am facing heap memory issues in my code. I am using dynamic memory allocation for saving microphone data into sd card. Along with this I am using wifi also.
Updated_home_with_wifi.zip
I am facing heap memory issues in my code. I am using dynamic memory allocation for saving microphone data into sd card. Along with this I am using wifi also.
Before we dive into your code, Can you please describe what the issues are exactly using the heap? Are you getting heap memory corruption?
Which companion chip with RAM are you using to control the nRF7002? seems like 153600 is huge chunk of allocation for heap. Have you checked in the memory map if you had that much free space in RAM?
So I am using MS12SF1 module (nrf5340+nrf7002). In my application I need to enable wifi as well as collect audio data through pdm microphone and save it into the sd card. When the wifi was not enabled the application was working smoothly but as the wifi configurations was enabled the memory was not getting allocated for microphone.
Also I am using dynamic allocation because when I tried using static memory I need to take it large enough as the microphone data is coming with speed and is also very large. With small static array it was either facing loses or the generated audio was fast forwarded. Also on using static memory my ram gets increased to 88% but if I use dynamic it stays till 57% around but the issue is in allocation of memory during runtime
Also I changed something in my code, previously I was allocating memory using k_malloc inside the audio_callback(), but later on I created a separate function for allocating memory by calling the function in main() but nothing changed
So I am using MS12SF1 module (nrf5340+nrf7002). In my application I need to enable wifi as well as collect audio data through pdm microphone and save it into the sd card. When the wifi was not enabled the application was working smoothly but as the wifi configurations was enabled the memory was not getting allocated for microphone.
Also I am using dynamic allocation because when I tried using static memory I need to take it large enough as the microphone data is coming with speed and is also very large. With small static array it was either facing loses or the generated audio was fast forwarded. Also on using static memory my ram gets increased to 88% but if I use dynamic it stays till 57% around but the issue is in allocation of memory during runtime
Also I changed something in my code, previously I was allocating memory using k_malloc inside the audio_callback(), but later on I created a separate function for allocating memory by calling the function in main() but nothing changed
After checking the heap stats, the below logs were printed before network got connected
[00:00:00.186,523] <inf> home_demo: INFO: Allocated Heap = 88452
[00:00:00.186,523] <inf> home_demo: INFO: Free Heap = 64368
[00:00:00.186,553] <inf> home_demo: INFO: Max Allocated Heap = 88452
But when I called the heap stats after network got connected, I got
[00:00:26.442,382] <inf> home_demo: INFO: Allocated Heap = 122120
[00:00:26.442,382] <inf> home_demo: INFO: Free Heap = 30652
[00:00:26.442,382] <inf> home_demo: INFO: Max Allocated Heap = 127404
There seems to be some additional heap allocated somehwhere after the connection. Try to enable CONFIG_SYS_HEAP_RUNTIME_STATS=y in your prj.conf to get some dynamic heap stats to see if we get to understand where the difference in memory after connection is happening.
Also is that the memory issue you are talking about, the difference in max allocated heap and allocated heap or are you seeing any other side effects of this in the functioning of your app?
After enabling the above configuration you mentioned and adding
When I don't place the breakpoint in the faults.c, I get
[00:00:37.674,804] <err> os: ***** USAGE FAULT *****
[00:00:37.674,804] <err> os: Illegal load of EXC_RETURN into PC
[00:00:37.674,835] <err> os: r0/a1: 0x0cdb1640 r1/a2: 0x0cd4162e r2/a3: 0x0cca162c
[00:00:37.674,835] <err> os: r3/a4: 0x0cc11630 r12/ip: 0x0cbc162a r14/lr: 0x0cc21630
[00:00:37.674,865] <err> os: xpsr: 0x0ce01600
[00:00:37.674,865] <err> os: Faulting instruction address (r15/pc): 0x0ccd1635
[00:00:37.674,896] <err> os: >>> ZEPHYR FATAL ERROR 34: Unknown error on CPU 0
[00:00:37.674,926] <err> os: Current thread: 0x2000a720 (unknown)
[00:00:38.072,448] <err> os: Halting system
So I already made a addr2line.sh file in which I am executing arm-none-eabi-addr2line -e build/zephyr/zephyr.elf pc address
So I run ./addr2line.sh 0x0ccd1635 but I get ??:0
U got anything?