AN4296 · Application noteUse STM32F3/STM32G4 CCM SRAM with IAR Embedded Workbench®, Keil® MDK-ARM, STMicroelectronics STM32CubeIDE, and other GNU-based toolchains
Download .pdfOpen in the full document

Execute application code from CCM SRAM using the IAR Systems IAR Embedded Workbench toolchain

Execute a simple code from CCM SRAM (except for interrupt handler)

A simple code can be composed of one or more functions that are not referenced from an interrupt handler. If the code is referenced from an interrupt handler, follow the steps described in Execute an interrupt handler from CCM SRAM.

IAR Embedded Workbench® provides the possibility to place one or more functions or a whole source file in CCM SRAM. This operation requires a new section to be defined in the linker file (.icf) to host the code to be placed in CCM SRAM. This section is copied to CCM SRAM at startup. The required steps are listed below:

  1. Define the address area for the CCM SRAM by indicating the start and end addresses.
  2. Tell the linker to copy at startup the section named .ccmram from the flash memory to the CCM SRAM.
  3. Indicate to the linker that the code section .ccmram must be placed in the CCM SRAM region.

The figure below shows an example of code implementing these operations.

Figure 3. IAR Embedded Workbench® linker update
Note:

This procedure is not valid for interrupt handlers.

Execute a source file from CCM SRAM

Execute a source file from CCM SRAM means that all functions declared in this file are executed from this memory area.

To place and execute a source file from CCM SRAM, use the IAR Embedded Workbench® file Options window as follows:

  1. Add the section .ccmram (for example) in the linker file as defined in Execute a simple code from CCM SRAM (except for interrupt handler).
  2. Right click on the file name from the workspace window.
  3. Select Options from the displayed menu.
  4. Check Override inherited settings from the displayed window.
  5. Select the Output tab and type the name of the section already defined in the linker file (.ccmram in this example) in the Code section name field (see the figure below).
    Figure 4. IAR Embedded Workbench® file placement

Executing one or more functions from CCM SRAM

The steps required to execute a function from CCM SRAM are the following:

  1. Add the section .ccmram in the linker file as described in Execute a simple code from CCM SRAM (except for interrupt handler).
  2. Using keyword pragma location, specify the function to be executed from CCM SRAM (see the figure below).
Figure 5. IAR Embedded Workbench® function placement
Note:

To execute more than one function from CCM SRAM, the pragma location keyword must be placed above each function declaration.

Execute an interrupt handler from CCM SRAM

The vector table is implemented as an array named __vector_table and referenced in the startup code.

The IAR Embedded Workbench® linker protects the sections that are referenced from the startup code from being affected by an 'initialize by copy' directive. The symbol __vector_table must not be used to allow copying interrupt handler sections via the 'initialize by copy' directive. A second vector table must be created and placed in CCM SRAM.

The steps required to execute an interrupt handler from CCM SRAM are listed below and described in the next sub-sections:

  1. Update the linker file (.icf).
  2. Update the startup file.
  3. Place the interrupt handler in CCM SRAM.
  4. Remap the vector table to CCM SRAM.

Updating the linker file (.icf)

The following steps are needed to update the linker file .icf (see the figure below):

  1. Define the address where the second vector table is located: 0x1000 0000.
  2. Define the memory address area for the CCM SRAM by specifying the start and end addresses.
  3. Tell the linker to copy at startup the section named .ccmram and the second vector table section .intvec_CCMRAM from flash memory to CCM SRAM.
  4. Tell the linker that the second vector table must be placed in the .intvec_CCMRAM section.
  5. Indicate that the .ccmram code section must be placed in CCM SRAM.
Figure 6. IAR Embedded Workbench® linker update for interrupt handler

Updating the startup file

The following steps are needed to update the startup file:

  1. Make a second vector table to be stored in CCM SRAM. For example, the startup_stm32f30x.s file must be modified by removing all entries except sfe(CSTACK) and Reset_Handler from the original vector table __vector_table.
  2. Add a second vector table to be placed in CCM SRAM. It must contain all entries. As an example this table can be called __vector_table_CCMRAM. This vector table must be placed in the .intvec_CCMRAM section defined in the linker file.
Figure 7. IAR Embedded Workbench® startup file update for interrupt handler

Remap the vector table to CCM SRAM

In the SystemInit function, remap the vector table to CCM SRAM by modifying the VTOR register as follows:

SCB->VTOR = 0x10000000 | VECT_TAB_OFFSET;

Execute a library (.a) from CCM SRAM

IAR Embedded Workbench® allows the execution of a library or a library module from CCM SRAM. The required steps are listed below:

  1. Define the memory address area corresponding to the CCM SRAM by specifying the start and end addresses.
    Figure 8. CCM SRAM area definition
  2. Update the linker to copy at startup the library or the library module in CCM SRAM using the 'initialize by copy' directive.
    Figure 9. IAR Embedded Workbench® section initialization
  3. Indicate to the linker that the library must be placed in CCM SRAM.
    Figure 10. IAR Embedded Workbench® library placement

To execute a library module from CCM SRAM, follow steps 1, 2 and 3 using the library module name.

The example in the figure below shows how to place arm_abs_f32.o (a module of iar_cortexM4l_math.a library) in CCM SRAM.

Figure 11. IAR Embedded Workbench® library module placement