2024-09-30 07:08 AM
Hello, ı want to run a function in ITCMRAM area. But as long as i call the function i enter HardFault
I added code snippet below(just the ITCMSection part) to the linker script.
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
_siITCM = LOADADDR(.ITCMSection);
.ITCMSection :
{
. = ALIGN(4);
_sITCM = .; /* create a global symbol at ITCM start */
*(.ITCMSection)
. = ALIGN(4);
_eITCM = .; /* create a global symbol at ITCM end */
} >ITCMRAM AT> FLASH
/* The program code and other data goes into FLASH */
.text :
I have a simple function below that is causing hardfault that i declare in my main.c file.
__attribute__((section(".ITCMSection"))) uint8_t my_function(uint8_t a)
{
return 2*a;
}
I can also see that i put 26Bytes in the ITCMRAM area from build analyzer. What might be the reason for HardFault?
Solved! Go to Solution.
2024-09-30 09:12 AM
You can also refer to the AN4296 "Use STM32F3/STM32G4 CCM SRAM with IAR Embedded Workbench®, Keil®
MDK-ARM, STMicroelectronics STM32CubeIDE and other GNU-based toolchains" , especially the section:
4.1 Execute a function or an interrupt handler from CCM SRAM.
I propose this implementation inspired from the application note:
MEMORY
{
...
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 16K
}
/*--- New ITCMMRAM linker section definition ---*/
_siitcmram = LOADADDR(.itcmram);
/* ITCMRAM section */
.itcmram :
{
. = ALIGN(4);
_sitcmram = .; /* define a global symbols at itcmram start */
*(.itcmram)
*(.itcmram*)
. = ALIGN(4);
_eitcmram = .; /* define a global symbols at itcmram end */
} >ITCMRAM AT> FLASH
/*--- End of ITCMRAM linker section definition ---*/
Hope it helps.
2024-09-30 07:34 AM
Hello @mazotcu16 ,
Look at 1 - D1_ITCM - D1_DTCM.ld linker file in X-CUBE-PERF-H7 in the path Projects\STM32H743I_EVAL\stm32h7x3_cpu_perf\SW4STM32\1 - D1_ITCM - D1_DTCM and how objects were defined to be located in ITCM/DTCM memories.
It doesn't use __attribute__ to relocate the objects but to relocate files.
So with this method, declare your function in a file and relocate the file in the section you want.
2024-09-30 09:12 AM
You can also refer to the AN4296 "Use STM32F3/STM32G4 CCM SRAM with IAR Embedded Workbench®, Keil®
MDK-ARM, STMicroelectronics STM32CubeIDE and other GNU-based toolchains" , especially the section:
4.1 Execute a function or an interrupt handler from CCM SRAM.
I propose this implementation inspired from the application note:
MEMORY
{
...
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 16K
}
/*--- New ITCMMRAM linker section definition ---*/
_siitcmram = LOADADDR(.itcmram);
/* ITCMRAM section */
.itcmram :
{
. = ALIGN(4);
_sitcmram = .; /* define a global symbols at itcmram start */
*(.itcmram)
*(.itcmram*)
. = ALIGN(4);
_eitcmram = .; /* define a global symbols at itcmram end */
} >ITCMRAM AT> FLASH
/*--- End of ITCMRAM linker section definition ---*/
Hope it helps.
2024-09-30 01:05 PM
>>What might be the reason for HardFault?
Placement in the .LD
Failure to copy the code into ITCMRAM in startup.s
You could perhaps DEBUG the situation, and see what the processor is actually objecting too, and confirm the code you expect is situated in ITCMRAM
2024-09-30 09:45 PM
AN4296 was definitely very helpful. Thank you have a nice day.