CMSIS-Core (Cortex-M)  
CMSIS-Core support for Cortex-M processor-based devices
 
Loading...
Searching...
No Matches
Startup File startup_<device>.c

The Startup File startup_<device>.c contains:

  • The reset handler which is executed after CPU reset and typically calls the SystemInit function.
  • 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.

The file exists for each supported toolchain and is the only tool-chain specific CMSIS file.

To adapt the file to a new device only the interrupt vector table needs to be extended with the device-specific interrupt handlers. The naming convention for the interrupt handler names are <interrupt_name>_IRQHandler. This table needs to be consistent with IRQn_Type that defines all the IRQ numbers for each interrupt.

Example:

The following example shows the extension of the interrupt vector table for the LPC1100 device family.

/*----------------------------------------------------------------------------
Exception / Interrupt Handler
*----------------------------------------------------------------------------*/
/* Exceptions */
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")));
// :
// :
/*----------------------------------------------------------------------------
Exception / Interrupt Vector table
*----------------------------------------------------------------------------*/
extern const pFunc __VECTOR_TABLE[240];
(pFunc)(&__INITIAL_SP), /* Initial Stack Pointer */
Reset_Handler, /* Reset Handler */
NMI_Handler, /* -14 NMI Handler */
HardFault_Handler, /* -13 Hard Fault Handler */
MemManage_Handler, /* -12 MPU Fault Handler */
BusFault_Handler, /* -11 Bus Fault Handler */
UsageFault_Handler, /* -10 Usage Fault Handler */
0, /* Reserved */
0, /* Reserved */
0, /* Reserved */
0, /* Reserved */
SVC_Handler, /* -5 SVC Handler */
DebugMon_Handler, /* -4 Debug Monitor Handler */
0, /* Reserved */
PendSV_Handler, /* -2 PendSV Handler */
SysTick_Handler, /* -1 SysTick Handler */
/* Interrupts */
WAKEUP0_IRQHandler, /* 0 Wakeup PIO0.0 */
WAKEUP1_IRQHandler, /* 1 Wakeup PIO0.1 */
WAKEUP2_IRQHandler, /* 2 Wakeup PIO0.2 */
// :
// :
EINT1_IRQHandler, /* 30 PIO INT1 */
EINT2_IRQHandler, /* 31 PIO INT2 */
// :
// :
};
#define __INITIAL_SP
Compiler/linker symbol specifying the location of the main stack (MSP).
Definition: Ref_CompilerControl.txt:495
#define __VECTOR_TABLE_ATTRIBUTE
Additional decl specs to be used when defining the (static) interrupt vector table.
Definition: Ref_CompilerControl.txt:544
#define __VECTOR_TABLE
Symbol name used for the (static) interrupt vector table.
Definition: Ref_CompilerControl.txt:531

startup_Device.c Template File

A compiler agnostic startup_Device.c Template File for an Armv7-M processor like Cortex-M3 is shown below. The C startup file relys on certain compiler specific preprocessor defines specified in CMSIS compiler headers:

 

startup_Device.c Template File (Armv8-M/v8.1-M)

The C-startup file for an Armv8-M/v8.1-M processor is similar to the one for an Armv7-M processor except that it offers the possibility of stack sealing for the Main Stack Pointer (MSP). The following preprocessor defines and CMSIS functions are used:

The stack sealing and the initialization fof the Stack Limit register is done in function void Reset_Handler(void):

/*----------------------------------------------------------------------------
Reset Handler called on controller reset
*----------------------------------------------------------------------------*/
__NO_RETURN void Reset_Handler(void)
{
__set_PSP((uint32_t)(&__INITIAL_SP));
__set_MSPLIM((uint32_t)(&__STACK_LIMIT));
__set_PSPLIM((uint32_t)(&__STACK_LIMIT));
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
#endif
SystemInit(); /* CMSIS System Initialization */
__PROGRAM_START(); /* Enter PreMain (C library entry point) */
}
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_CompilerControl.txt:171
#define __PROGRAM_START
Entry function into the user application or library startup.
Definition: Ref_CompilerControl.txt:483
#define __STACK_LIMIT
Compiler/linker symbol specifying the limit of the main stack (MSP).
Definition: Ref_CompilerControl.txt:518
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.