NXP S32K312 chip,configTOTAL_HEAP_SIZE configuration problem

I downloaded the FreeRTOS demo based on K3 series chips from the official website of NXP, and made two modifications on the demo. The first modification is to add the initialization of Usart port, and there are three lighted tasks, the size of each task is 10244 bytes. If configTOTAL_HEAP_SIZE is larger than 301024, the code will compile but will not run and the main function is not enter. If configtotal_heap_size is smaller than 301024, the code will run ok. The second change is that there are six tasks with a total size of 16KB, but configTOTAL_HEAP_SIZE is normal when it is larger than 601024. If it is smaller than 60*1024, the code will compile, but not run. The memory allocation of the chip is shown in the following figure. Attached is the map file compiled and generated in case of an exception.

MEMORY
{
int_flash : ORIGIN = 0x00400000, LENGTH = 0x001D4000 /* 2048K - 176K (sBAF + HSE)/
int_itcm : ORIGIN = 0x00000000, LENGTH = 0x00008000 /
32K /
int_dtcm : ORIGIN = 0x20000000, LENGTH = 0x00010000 /
64K */

int_sram                : ORIGIN = 0x20400000, LENGTH = 0x00014F00    /* 83 KB */
int_sram_fls_rsv        : ORIGIN = 0x20414F00, LENGTH = 0x00000100    
int_sram_stack_c0       : ORIGIN = 0x20415000, LENGTH = 0x00001000    
int_sram_no_cacheable   : ORIGIN = 0x20416000, LENGTH = 0x00000F00    /* 5kb , needs to include int_results  */
int_sram_results        : ORIGIN = 0x20416F00, LENGTH = 0x00000100    
int_sram_shareable      : ORIGIN = 0x20417000, LENGTH = 0x00001000    /* 4KB */
ram_rsvd2               : ORIGIN = 0x20418000, LENGTH = 0             /* End of SRAM */

}

.bss 0x20400080 0x0 ./FreeRTOS/Source/croutine.o
.bss 0x20400080 0x0 ./FreeRTOS/Source/event_groups.o
.bss 0x20400080 0x0 ./FreeRTOS/Source/list.o
.bss 0x20400080 0x40 ./FreeRTOS/Source/queue.o
0x20400080 xQueueRegistry
.bss 0x204000c0 0x0 ./FreeRTOS/Source/stream_buffer.o
.bss 0x204000c0 0x104 ./FreeRTOS/Source/tasks.o
0x204000c4 pxCurrentTCB
.bss 0x204001c4 0x3c ./FreeRTOS/Source/timers.o
.bss 0x20400200 0x8 ./FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1/port.o
.bss 0x20400208 0x8420 ./FreeRTOS/Source/portable/MemMang/heap_4.o
.bss 0x20408628 0x0 ./Project_Settings/Startup_Code/Vector_Table.o
.bss 0x20408628 0x0 ./Project_Settings/Startup_Code/exceptions.o
.bss 0x20408628 0x0 ./Project_Settings/Startup_Code/nvic.o
.bss 0x20408628 0x0 ./Project_Settings/Startup_Code/startup.o
.bss 0x20408628 0x0 ./Project_Settings/Startup_Code/startup_cm7.o
.bss 0x20408628 0x78 ./Project_Settings/Startup_Code/system.o

What is this size - Code size (i.e. text size) or stack size for this task? Are you trying to write 1024*4 or 10244?

Can you elaborate on what you mean by “configTOTAL_HEAP_SIZE is normal when it is larger than 60*1024”?

Can you break the code in debugger and see what it is doing when it appears “not running”?

I want to write stack size 1024*4

when it is large than 65*1024

If i definef configTOTAL_HEAP_SIZE from 301024(30KB) to 651024(65KB) the code will compile, but not run

It is a little unclear what you actual problem is, saying “Won’t Run” is not very descriptive. IF things fail because you assign too much heap, likely you are getting a linker problem, and not getting an actual working image.

If the program enters main, but FreeRTOS doesn’t start, then likely the cause is not enough memory to start up the idle and (if needed) timer task. That will cause the call to start the scheduler to return.

One important thing to remember is that stack size and heap are specified in different units, stack is in WORDS (likely 4 bytes each), and a task will need more than the specified stack, for things like the TCB, and memory for your queues and the like.

One thing I find very helpful is to use the CreateStatic version of the function s and manually allocate as static memory all the major memory blocks, (and possibly not need a heap at all) so I can see on my linker map directly what my memory usage is.

1 Like