Part Number: MSPM0G3519
Hello,
I am implementing a CSC → application jump on MSPM0G3519, 9, based on the example reported in the Application Note "Flash Multi Bank Feature in MSPM0 Family":
static void start_app(uint32_t *vector_table)
{
/* Reset the SP with the value stored at vector_table[0] */
__asm volatile(
"LDR R3,[%[vectab],#0x0] \n"
"MOV SP, R3 \n" ::[vectab] "r"(vector_table));
/* Set the Reset Vector to the new vector table (Resets to 0x000) */
SCB->VTOR = (uint32_t) vector_table;
/* Jump to the Reset Handler address at vector_table[1] */
((void (*)(void))(*(vector_table + 1)))();
}
However, this implementation does not work correctly: after setting VTOR, the MCU gets stuck in the CSC Default_Handler.
I tried to improve the code like this:
void start_app(uint32_t *vector_table)
{
uint32_t sp = vector_table[0];
uint32_t reset = vector_table[1];
// Check if reset handler is valid (not empty flash)
if (reset == 0xFFFFFFFF)
mcubootFail();
// Disable all interrupts globally
__disable_irq();
// Fully stop SysTick to avoid interrupts
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
// Disable all NVIC interrupts
NVIC->ICER[0] = 0xFFFFFFFF;
// Clear all pending NVIC interrupts
NVIC->ICPR[0] = 0xFFFFFFFF;
// Clear pending system exceptions (PendSV and SysTick)
SCB->ICSR |= SCB_ICSR_PENDSVCLR_Msk;
SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;
// Relocate vector table to applicat
SCB->VTOR = (uint32_t)vector_table;
__DSB();
__ISB();
// Set Main Stack Pointer to application's initial SP
__set_MSP(sp);
__DSB();
__ISB();
// Branch to application Reset_Handler
((void (*)(void))(reset))();
}
With this version, the jump to the application seems to occur, but the application does not behave correctly, it seems it doesn't reach the main() because the breakpoints are not hit and if I restart the debug the target is disconnected.
If I load and run the application alone (without CSC), everything works as expected.
I also tried placing CSC in a dedicated flash region and separating RAM between CSC and application but without improvement.
can someone help me?
thank you