cancel
Showing results for 
Search instead for 
Did you mean: 

Running a function on ITCMRAM

mazotcu16
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4
SofLit
ST Employee

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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
SofLit
ST Employee

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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

>>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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

AN4296 was definitely very helpful. Thank you have a nice day.