Part Number: MSPM0L1306
Hello,
I implemented a custom bootloader for the MSPM0L1306. The bootloader loads the main application into flash and then jumps to it. So the processor starts at 0x0000 inside the bootloader and the bootloader jumps on valid application code into the application.
The jump itself appears to work, but the application immediately ends up in the Default_Handler.
According to the map file of the main application, the vector table is located at 0x00003100.
Bootloader jump code:
#define APP_START_ADDRESS 0x00003100
#define SRAM_START 0x20000000
#define SRAM_END 0x20000F00
#define SHARED_RAM_START 0x20000F00
#define SHARED_RAM_SIZE 0x100
typedef void (*pFunction)(void);
void jumpToApplication(void)
{
uint32_t appStack = *(volatile uint32_t *)APP_START_ADDRESS;
uint32_t appReset = *(volatile uint32_t *)(APP_START_ADDRESS + 4);
// Check if stack pointer is in RAM
if ((appStack < SRAM_START) || (appStack > SRAM_END))
return;
// Check if ResetHandler is valid
if (appReset == 0xFFFFFFFF)
return;
__disable_irq();
// Disable all interrupts
for (int i = 0; i < 8; i++) {
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
// Stop SysTick
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/* Clear pending system interrupts */
SCB->ICSR |= SCB_ICSR_PENDSVCLR_Msk;
SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;
// Switch vector table
SCB->VTOR = APP_START_ADDRESS;
__DSB();
__ISB();
// Set stack pointer
__set_MSP(appStack);
// Jump to reset handler
((void (*)(void))appReset)();
}
Linker configuration of the main application:
FLASH_CODE (RX) : origin = 0x00003100, length = 0x0000CB00
Vector table placement:
.intvecs : > 0x00003100
Map file excerpt:
.intvecs 0 00003100 000000c0
00003100 000000c0 startup_mspm0l130x_ticlang.o (.intvecs)
Additional debugging information:
Before executing the jump I inspected the values in the debugger.
- appStack = 0x20000F00
- appReset = address of the application's Reset_Handler
Both values appear to be valid and match the expected values from the application image.
So the vector table appears to be correctly placed at 0x3100.
However, after jumping to the application, the program ends up in Default_Handler.
My questions:
- Is this the correct procedure to jump from a bootloader to an application on MSPM0 devices?
- Are there additional steps required when switching the vector table (SCB->VTOR)?
- Could this behavior be related to the linker configuration or the startup code of the application?
Any suggestions or hints would be greatly appreciated.
Thank you!
