Loading...
 
Skip to main content

System Workbench for STM32


Moving ISRs to ITCM RAM

Thanks MSchultz and dautrevaux. I had indeed made a typo - corrected that now, and my test function does now show up in the .itcm_text section of my output.map file. With a few more changes to the linker script I was able to get my function successfully moved into ITCM RAM and verified with the debugger that it was running from that location.

I changed my memory sections definition a bit as well to make sure that the code doesn't clobber the ISR vector table, which is loaded into the start of ITCM RAM by the startup script. I allocated 1kB for that table and started my section after:

/* Specify the memory areas */
MEMORY
{
ITCM_ISR (rx) : ORIGIN = 0x00000000, LENGTH = 1K
ITCM_RAM (rx) : ORIGIN = 0x00000400, LENGTH = 15K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
FLASH (rx) : ORIGIN = 0x00200000, LENGTH = 1024K
}

I also added the symbol definitions as suggested so that I can memcpy the right section into that portion of memory later on. But it took an additional symbol in order to actually find the function data in Flash, to know where to copy from.

I based this on how the .data section is handled. There's an extra symbol before that section is defined:

/* used by the startup to initialize data */
_sidata = LOADADDR(.data);

That gets picked up by the startup script to know where to load initialization data from to populate the .data section of ram. So my linker script ends up looking like:

/* Copy specific fast-executing code to ITCM RAM */
itcm_data = LOADADDR(.itcm_text);
.itcm_text :
{
. = ALIGN(4);
itcm_text_start = .;
*(.itcm_text)
*(.itcm_text*)
. = ALIGN(4);
itcm_text_end = .;
} >ITCM_RAM AT> FLASH

Then at the start of main() I have the following:

/* Load functions into ITCM RAM */
extern const unsigned char itcm_text_start;
extern const unsigned char itcm_text_end;
extern const unsigned char itcm_data;
memcpy(&itcm_text_start, &itcm_data, (int) (&itcm_text_end - &itcm_text_start));

And with that I'm good to go! Thanks again for the help.