Cortex M0 Vector Table Reallocation Problem
In my embedded software project, I need to write a bootloader. I wrote an application code for the bootloader and testing, and everything is fine so far, but the delay function in the application code is not working. I think the reason for this is the Vector Table. I wrote the vector table to the RAM address, but it didn't work at all. It jumps to the application code, turns on the LED, but does not toggle. I would really appreciate your help. (STM32f030c8t6 board)
#define APP_START_ADDRESS 0x08006000 // User application start address
#define APP_START_ADDR 0x08006000
#define SRAM_BASE_u 0x20000000
#define VECT_TABLE_SIZE 0xC0 // 48 vectors * 4 bytes
void JumpToApplication(void)
{
// 1. Dsiable all interrupts
__disable_irq();
// 2. Deinit HAL and RCC (optional if bootloader did init)
HAL_DeInit();
HAL_RCC_DeInit();
// 3. Copy vector table
memcpy((void*)SRAM_BASE_u, (void*)APP_START_ADDR, VECT_TABLE_SIZE);
// 4. Remap SRAM to 0x00000000
SYSCFG->CFGR1 &= ~SYSCFG_CFGR1_MEM_MODE; //Clear MEM_MODE bits
SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE_1; // SRAM -> 0x00000000
// 5. Load MSP and Reset Handler from RAM
uint32_t app_sp = *(volatile uint32_t*)SRAM_BASE_u;
uint32_t app_reset = *(volatile uint32_t*)(SRAM_BASE_u + 4);
// 6. Set MSP and jump
__set_MSP(app_sp);
pFunction app_entry = (pFunction)app_reset;
app_entry();
while(1); // Should never return
}Edited to apply source code formatting - please see How to insert source code for future reference.
