Free RTOS heap memory changed from SRAM0 to DTCM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Free RTOS heap memory changed from SRAM0 to DTCM

1,071 Views
Omkar9903
Contributor III

Hi,

I am using FreeRTOS with heap_1.c, and the configuration
configAPPLICATION_ALLOCATED_HEAP = 1 is enabled.

I have allocated the FreeRTOS heap in DTCM RAM from main.c as shown below:

uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]
__attribute__((section(".my_heap")));

 

In the linker script, I have mapped the heap section to DTCM memory as follows:
/* Heap section */

 

/* Data tightly coupled memory (D-TCM) */

dtcm (rw) : ORIGIN = 0x20000000, LENGTH = 0x1F000 /* 124KB Data RAM */

stack_dtcm (rw) : ORIGIN = 0x2001F000, LENGTH = 0x1000 /* 4KB */

 

.bss_tcm_data (NOLOAD) :

{

. = ALIGN(4);

__dtcm_bss_start__ = .;

*(.dtcm_bss*)

. = ALIGN(4);

__dtcm_bss_end__ = .;

*(.my_heap)

} > dtcm

 

.heap (NOLOAD) :
{
    . = ALIGN(4);
    _end = .;
    end = .;
    _heap_start = .;
    . += HEAP_SIZE;
    _heap_end = .;
} > dtcm

 

.my_heap (NOLOAD) :
{
    *(.my_heap)
} > dtcm

 

The .map file confirms that the heap memory has been placed in DTCM.
However, after this change, FreeRTOS is not functioning correctly.

Could you please help review this setup and advise on what might be missing or incorrect?

Tags (1)
0 Kudos
Reply
3 Replies

984 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @Omkar9903,

Could you please clarify what you mean by “FreeRTOS is not functioning correctly”?
For example, does the scheduler fail to start, do tasks not run, or are you encountering a HardFault?
Also, can you ensure that the .my_heap section is aligned in the same way as the default .heap section.

Finally, please provide the following details so the issue can be analyzed accurately:

  • MCU variant
  • RTD version
  • FreeRTOS RTD extension version

 

BR, Daniel

 

0 Kudos
Reply

977 Views
Omkar9903
Contributor III

Hi @danielmartynek ,


I am using s32k341 microcontroller with RTD version 5.0.0 and RTOS version FreeRTOS Kernel V10.5.0.

The issue is observed that we are getting hard fault from clock init function i.e "Clock_Ip_SetWaitStates"


I have declared the heap array in main.c as follows:

UNSIGNED8 ucHeap[8712] __attribute__((section(".dtcm_bss")));
 

I have verified in the MAP file that ucHeap is correctly allocated in DTCM memory.

I am attaching my linker file for review.
Please let me know if anything is missing or incorrectly configured.

snapshot of map file :

note main.c is renamed as sid.c

Omkar9903_0-1776686466120.pngOmkar9903_0-1776686466120.png

 

Thanks.

Tags (1)
0 Kudos
Reply

868 Views
danielmartynek
NXP TechSupport
NXP TechSupport
0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2353011%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EFree%20RTOS%20heap%20memory%20changed%20from%20SRAM0%20to%20DTCM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2353011%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20am%20using%20%3CSTRONG%3EFreeRTOS%20with%20heap_1.c%3C%2FSTRONG%3E%2C%20and%20the%20configuration%3CBR%20%2F%3EconfigAPPLICATION_ALLOCATED_HEAP%20%3D%201%20is%20enabled.%3C%2FP%3E%3CP%3EI%20have%20allocated%20the%20FreeRTOS%20heap%20in%20%3CSTRONG%3EDTCM%20RAM%3C%2FSTRONG%3E%20from%20main.c%20as%20shown%20below%3A%3C%2FP%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3Euint8_t%20ucHeap%5B%20configTOTAL_HEAP_SIZE%20%5D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E__attribute__((section(%22.my_heap%22)))%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3EIn%20the%20linker%20script%2C%20I%20have%20mapped%20the%20heap%20section%20to%20DTCM%20memory%20as%20follows%3A%3C%2FDIV%3E%3CDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%2F*%20Heap%20section%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CP%3E%3CSPAN%3E%2F*%20Data%20tightly%20coupled%20memory%20(D-TCM)%20*%2F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Edtcm%20(rw)%20%3A%20%3CSPAN%3EORIGIN%3C%2FSPAN%3E%20%3D%200x20000000%2C%20%3CSPAN%3ELENGTH%3C%2FSPAN%3E%20%3D%200x1F000%20%3CSPAN%3E%2F*%20124KB%20Data%20RAM%20*%2F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Estack_dtcm%20(rw)%20%3A%20%3CSPAN%3EORIGIN%3C%2FSPAN%3E%20%3D%200x2001F000%2C%20%3CSPAN%3ELENGTH%3C%2FSPAN%3E%20%3D%200x1000%20%3CSPAN%3E%2F*%204KB%20*%2F%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CP%3E.bss_tcm_data%20(NOLOAD)%20%3A%3C%2FP%3E%3CP%3E%7B%3C%2FP%3E%3CP%3E.%20%3D%20%3CSPAN%3EALIGN%3C%2FSPAN%3E(4)%3B%3C%2FP%3E%3CP%3E__dtcm_bss_start__%20%3D%20.%3B%3C%2FP%3E%3CP%3E*(.dtcm_bss*)%3C%2FP%3E%3CP%3E.%20%3D%20%3CSPAN%3EALIGN%3C%2FSPAN%3E(4)%3B%3C%2FP%3E%3CP%3E__dtcm_bss_end__%20%3D%20.%3B%3C%2FP%3E%3CP%3E*(.my_heap)%3C%2FP%3E%3CP%3E%7D%20%26gt%3B%20dtcm%3C%2FP%3E%3CBR%20%2F%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E.heap%20(NOLOAD)%20%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.%20%3D%20ALIGN(4)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20_end%20%3D%20.%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20end%20%3D%20.%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20_heap_start%20%3D%20.%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.%20%2B%3D%20HEAP_SIZE%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20_heap_end%20%3D%20.%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%7D%20%26gt%3B%20dtcm%3C%2FSPAN%3E%3C%2FDIV%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E.my_heap%20(NOLOAD)%20%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20*(.my_heap)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3E%7D%20%26gt%3B%20dtcm%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CP%3EThe%20.map%20file%20confirms%20that%20the%20heap%20memory%20has%20been%20placed%20in%20DTCM.%3CBR%20%2F%3EHowever%2C%20after%20this%20change%2C%20%3CSTRONG%3EFreeRTOS%20is%20not%20functioning%20correctly%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3ECould%20you%20please%20help%20review%20this%20setup%20and%20advise%20on%20what%20might%20be%20missing%20or%20incorrect%3F%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2354544%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Free%20RTOS%20heap%20memory%20changed%20from%20SRAM0%20to%20DTCM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2354544%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F238723%22%20target%3D%22_blank%22%3E%40Omkar9903%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EHow%20is%26nbsp%3B%3CSPAN%3EportBYTE_ALIGNMENT%3C%2FSPAN%3E%26nbsp%3Bdefined%20in%20portmacro.h%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fforums.freertos.org%2Ft%2Fmemory-alignment-in-heap-1-c-file%2F13355%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fforums.freertos.org%2Ft%2Fmemory-alignment-in-heap-1-c-file%2F13355%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EThe%20heap%20should%20be%20aligned%20to%20that%20number%20of%20bytes.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ERegarding%20the%20fault%20exception%2C%20try%20to%20find%20more%20information%20about%20it%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FExample-S32K312-HARDFAULT-Handling-Interrupt-DS3-5-RTD300%2Fta-p%2F1806259%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FExample-S32K312-HARDFAULT-Handling-Interrupt-DS3-5-RTD300%2Fta-p%2F1806259%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FHow-To-Debug-A-Fault-Exception-On-ARM-Cortex-M-V7M-MCU-S32K3XX%2Fta-p%2F1595570%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FHow-To-Debug-A-Fault-Exception-On-ARM-Cortex-M-V7M-MCU-S32K3XX%2Fta-p%2F1595570%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FFault-handling-on-S32K14x%2Fta-p%2F1114447%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FFault-handling-on-S32K14x%2Fta-p%2F1114447%3C%2FA%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBR%2C%20Daniel%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2353696%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Free%20RTOS%20heap%20memory%20changed%20from%20SRAM0%20to%20DTCM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2353696%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F160001%22%20target%3D%22_blank%22%3E%40danielmartynek%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EI%20am%20using%20s32k341%20microcontroller%20with%20RTD%20version%205.0.0%20and%20RTOS%20version%26nbsp%3B%3CSPAN%3EFreeRTOS%20Kernel%20V10.5.0.%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20issue%20is%20observed%20that%20we%20are%20getting%20hard%20fault%20from%20clock%20init%20function%20i.e%20%22Clock_Ip_SetWaitStates%22%3C%2FSPAN%3E%3CSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%3E%3CP%3EI%20have%20declared%20the%20heap%20array%20in%20main.c%20as%20follows%3A%3C%2FP%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3EUNSIGNED8%20ucHeap%5B8712%5D%20__attribute__((section(%22.dtcm_bss%22)))%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EI%20have%20verified%20in%20the%20%3CSTRONG%3EMAP%20file%3C%2FSTRONG%3E%20that%20ucHeap%20is%20correctly%20allocated%20in%20%3CSTRONG%3EDTCM%20memory%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3EI%20am%20attaching%20my%20%3CSTRONG%3Elinker%20file%3C%2FSTRONG%3E%20for%20review.%3CBR%20%2F%3EPlease%20let%20me%20know%20if%20anything%20is%20missing%20or%20incorrectly%20configured.%3C%2FP%3E%3CP%3Esnapshot%20of%20map%20file%20%3A%3C%2FP%3E%3CP%3Enote%20main.c%20is%20renamed%20as%20sid.c%3C%2FP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Omkar9903_0-1776686466120.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Omkar9903_0-1776686466120.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Omkar9903_0-1776686466120.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F382969i92772C887B750BA6%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Omkar9903_0-1776686466120.png%22%20alt%3D%22Omkar9903_0-1776686466120.png%22%20%2F%3E%3Cspan%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EOmkar9903_0-1776686466120.png%3C%2Fspan%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CP%3EThanks.%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2353647%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Free%20RTOS%20heap%20memory%20changed%20from%20SRAM0%20to%20DTCM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2353647%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F238723%22%20target%3D%22_blank%22%3E%40Omkar9903%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3ECould%20you%20please%20clarify%20what%20you%20mean%20by%20%E2%80%9CFreeRTOS%20is%20not%20functioning%20correctly%E2%80%9D%3F%3CBR%20%2F%3EFor%20example%2C%20does%20the%20scheduler%20fail%20to%20start%2C%20do%20tasks%20not%20run%2C%20or%20are%20you%20encountering%20a%20HardFault%3F%3CBR%20%2F%3EAlso%2C%20can%20you%20ensure%20that%20the%20.my_heap%20section%20is%20aligned%20in%20the%20same%20way%20as%20the%20default%20.heap%20section.%3C%2FP%3E%0A%3CP%3EFinally%2C%20please%20provide%20the%20following%20details%20so%20the%20issue%20can%20be%20analyzed%20accurately%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EMCU%20variant%3C%2FLI%3E%0A%3CLI%3ERTD%20version%3C%2FLI%3E%0A%3CLI%3EFreeRTOS%20RTD%20extension%20version%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBR%2C%20Daniel%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E