The startup file defines device exceptions and interrupts, and provides their initial (weak) handler functions. The file has a naming convention startup_<Device>.c
where <Device>
corresponds to the device name.
Specifically, following functionalities are provided in the startup file:
- The reset handler
Reset_Handler
which is executed upon CPU reset and typically calls the SystemInit()
function. After the system init the control is transferred to the C/C++ run-time library which performs initialization and calls the main
function in the user code.
- The setup values for the Main Stack Pointer (MSP).
- Exception vectors of the Cortex-M Processor with weak functions that implement default routines.
- Interrupt vectors that are device specific with weak functions that implement default routines.
To adapt the file to a specific device only the interrupt vector table needs to be extended with the device-specific interrupt handlers. The naming convention for the interrupt handler names is <interrupt_name>_IRQHandler
. This table needs to be consistent with IRQn_Type that defines all the IRQ numbers for each interrupt.
Additional application-specific adaptations may be required in the startup code and therefore so the startup file shall be located in the application project. Delivery in CMSIS-Packs explains how this can be achieved when device support is provided in CMSIS pack format.
Example:
The following example shows the extension of the interrupt vector table for the LPC1100 device family.
void WAKEUP0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
void WAKEUP1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
void WAKEUP2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
void EINT1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
void EINT2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
Reset_Handler,
NMI_Handler,
HardFault_Handler,
MemManage_Handler,
BusFault_Handler,
UsageFault_Handler,
0,
0,
0,
0,
SVC_Handler,
DebugMon_Handler,
0,
PendSV_Handler,
SysTick_Handler,
WAKEUP0_IRQHandler,
WAKEUP1_IRQHandler,
WAKEUP2_IRQHandler,
EINT1_IRQHandler,
EINT2_IRQHandler,
};
#define __INITIAL_SP
Compiler/linker symbol specifying the location of the main stack (MSP).
Definition: ref_compiler_ctrl.txt:484
#define __VECTOR_TABLE_ATTRIBUTE
Additional decl specs to be used when defining the (static) interrupt vector table.
Definition: ref_compiler_ctrl.txt:533
#define __VECTOR_TABLE
Symbol name used for the (static) interrupt vector table.
Definition: ref_compiler_ctrl.txt:520
startup_Device.c Template File
CMSIS-Core Device Template Files include a startup_Device.c
file that can be used as a starting point for chip vendors to implement own device-specific startup file.
The C startup file relys on certain compiler specific preprocessor defines specified in CMSIS compiler headers:
The stack sealing and the initialization for the Stack Limit register is done in function Reset_Handler(void)
:
{
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
#endif
}
void __set_PSPLIM(uint32_t ProcStackPtrLimit)
Set Process Stack Pointer Limit Devices without Armv8-M Main Extensions (i.e. Cortex-M23) lack the no...
void __set_PSP(uint32_t topOfProcStack)
Set the PSP register.
__set_MSPLIM(uint32_t MainStackPtrLimit)
Set Main Stack Pointer Limit Devices without Armv8-M Main Extensions (i.e. Cortex-M23) lack the non-s...
#define __NO_RETURN
Inform the compiler that a function does not return.
Definition: ref_compiler_ctrl.txt:182
#define __PROGRAM_START
Entry function into the user application or library startup.
Definition: ref_compiler_ctrl.txt:472
#define __STACK_LIMIT
Compiler/linker symbol specifying the limit of the main stack (MSP).
Definition: ref_compiler_ctrl.txt:507
void __TZ_set_STACKSEAL_S(uint32_t *stackTop)
Set stack seal at given address (secure)
#define __STACK_SEAL
Compiler/linker symbol specifying the location of the stack seal.
Definition: ref_trustzone.txt:411
void SystemInit(void)
Function to Initialize the system.
Note
- Stack Sealing also requires the application project to use a scatter file (or a linker script) as explained in Stack Sealing section.