Skip to content

These module docs are in beta and may be incomplete.

modm:platform:core

Options

stack_execution_guard

Fill the stack with relative jumps to fault handler to prevent accidental execution.: False{ True, False }

allocator

Dynamic memory allocation strategy: tlsf{ block, newlib, tlsf }

By default, the arm-none-eabi toolchain ships with the newlib libc, which uses dlmalloc as the underlying allocator algorithm and only requires the implementation of the void * sbrk(ptrdiff_t size) hook. However, this limits the allocator to use just one memory region, which must then also be of continuous extend, since sbrk can only grow and shrink, but not jump. Therefore, when using the newlib strategy, only the largest memory region is used as heap! Depending on the device memory architecture this can leave large memory regions unused.

For devices with very small memories, we recommend using the block allocator strategy, which uses a very light-weight and simple algorithm. This also only operates on one continuous memory region as heap.

Note

Memories can have different traits, such as DMA-ability or access time. The default memory allocator functions (malloc, new, etc) only return DMA-able memories, ordered by fastest access time. Similarly the search for the largest memory region only considers DMA-able memory.

Warning

For devices which contain separate memories laid out in a continuous way (often called SRAM1, SRAM2, etc.) the newlib and block strategies choose the largest continuous memory region, even though unaligned accesses across memory regions may not be supported in hardware and lead to a bus fault! Consider using the TLSF implementation, which does not suffer from this issue.

To use all non-statically allocated memory for heap, use the TLSF strategy, which natively supports multiple memory regions. Our implementation treats all internal memories as separate regions, so unaligned accesses across memory boundaries are not an issue. To request heap memory of different traits, see modm::MemoryTraits.

Note

The TLSF implementation has a static overhead of about 1kB per memory trait group, however, these can then contain multiple non-continuous memory regions. The upside of this large static allocation is very fast allocation times of O(1), but we recommend using TLSF only for devices with multiple memory regions.

vector_table_location

Vector table location in ROM or RAM: fastest{ fastest, ram, rom }

The vector table is always stored in ROM and copied to RAM by the startup script if required. You can modify the RAM vector table using the CMSIS NVIC functions:

  • void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
  • uint32_t NVIC_GetVector(IRQn_Type IRQn)

For applications that do not modify the vector table at runtime, relocation to RAM is not necessary and can save a few hundred bytes of static memory.

By default, the fastest option is chosen depending on the target memory architecture. This does not always mean the table is copied into RAM, and therefore may not be modifiable with this option!

From the ARM Cortex-M4 Technical Reference Manual on exception handling:

  • Processor state is automatically stored to the stack on an exception, and automatically restored from the stack at the end of the Interrupt Service Routine.
  • The vector is fetched in parallel to the state saving, enabling efficient interrupt entry.

Warning

Placing main stack and vector table into the same memory can significantly slow down interrupt latency, since both I-Code and D-Code memory interface need to fetch from the same access port.

main_stack_size

Minimum size of the application main stack: 3040{ 256 ... 65536 }

The ARM Cortex-M uses a descending stack mechanism which is placed so that it grows towards the beginning of RAM. In case of a stack overflow the hardware then attempts to stack into invalid memory which triggers a HardFault. A stack overflow will therefore never overwrite any static or heap memory and this protection works without the MPU and therefore also on ARM Cortex-M0 devices.

If you enable either the LED or the logging HardFault option, a smaller stack is added above the main stack. This stack is only used by the HardFault handler when not enough memory remains in the main stack to preserve GDB backtrace behavior. This memory also acts as a small safety buffer against main stack underflow, which is not detected however.

If the vector table is relocated into RAM, the start address needs to be aligned to the next highest power-of-two word depending on the total number of device interrupts. On devices where the table is relocated into the same memory as the main stack, an alignment buffer up to 1kB is added to the main stack.

|              ...                |
|---------------------------------|
|    Interrupt Vectors (in RAM)   |
|        (if re-mapped)           | <-- vector table origin
|---------------------------------| <-- HardFault stack top
|        HardFault Stack          |
|       (grows downwards)         |
|               |                 |
|               v                 |
|---------------------------------| <-- main stack top
|           Main Stack            |
|       (grows downwards)         |
|               |                 |
|               v                 |
|---------------------------------|
|  Alignment buffer for vectors   |
|   (overwritten by main stack!)  |
'---------------------------------' <-- RAM origin

Warning

The main stack size you provide is a minimum and may be enlarged to satisfy alignment requirements. Be aware that these requirements operate on the sum of HardFault and main stack. Disabling HardFault options may therefore decrease the alignment buffer added to the main stack size, which may make your application overflow stack. You need to increase your minimum main stack size in that case.

Note

The main stack is watermarked and you can get the maximum stack usage using the uint32_t modm::cortex::getMaximumStackUsage() function.

linkerscript.memory

Default: SDRAM (rwx) : ORIGIN = 0xC0000000, LENGTH = 16M{ String }

linkerscript.sections

Default: ` .sdramdata : { __sdramdata_load = LOADADDR (.sdramdata); /* address in FLASH / __sdramdata_start = .; / address in RAM */

        KEEP(*(.sdramdata))

        . = ALIGN(4);
        __sdramdata_end = .;
    } >SDRAM AT >FLASH

    .heap_extern (NOLOAD) : ALIGN(4)
    {
        __heap_extern_start = .;
        . = ORIGIN(SDRAM) + LENGTH(SDRAM);
        __heap_extern_end = .;
    } >SDRAM
` ∈ `{ String }`

linkerscript.table_extern.zero

Values: { String }

linkerscript.table_extern.copy

Default: LONG (__sdramdata_load) LONG (__sdramdata_start) LONG (__sdramdata_end){ String }

linkerscript.table_extern.heap

Default: LONG (0x801f) LONG (__heap_extern_start) LONG (__heap_extern_end){ String }

Content

// Struct
struct modm::FlashReader< typename T , std::size_t size >;

// Define
#define EXTERN_FLASH_STORAGE(var)
#define EXTERN_FLASH_STORAGE_STRING(s)
#define FLASH_STORAGE(var)
#define FLASH_STORAGE_STRING(s)
#define INLINE_FLASH_STORAGE_STRING(s)
#define PSTR(s)

Dependencies

modm:platform:core modm_platform_core modm: platform: core modm_architecture_accessor modm: architecture: accessor modm_platform_core->modm_architecture_accessor modm_architecture_assert modm: architecture: assert modm_platform_core->modm_architecture_assert modm_architecture_atomic modm: architecture: atomic modm_platform_core->modm_architecture_atomic modm_architecture_clock modm: architecture: clock modm_platform_core->modm_architecture_clock modm_architecture_delay modm: architecture: delay modm_platform_core->modm_architecture_delay modm_architecture_heap modm: architecture: heap modm_platform_core->modm_architecture_heap modm_architecture_interrupt modm: architecture: interrupt modm_platform_core->modm_architecture_interrupt modm_architecture_memory modm: architecture: memory modm_platform_core->modm_architecture_memory modm_architecture_unaligned modm: architecture: unaligned modm_platform_core->modm_architecture_unaligned modm_cmsis_device modm: cmsis: device modm_platform_core->modm_cmsis_device modm_platform modm: platform modm_platform_core->modm_platform modm_platform_clock_cortex modm: platform: clock.cortex modm_platform_core->modm_platform_clock_cortex modm_board_disco-f469ni modm: board: disco-f469ni modm_board_disco-f469ni->modm_platform_core