cancel
Showing results for 
Search instead for 
Did you mean: 

Cortex M0 Vector Table Reallocation Problem

Morpheuss01
Associate II

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.

2 REPLIES 2
TDK
Super User

> the delay function in the application code is not working

The code presented looks okay to me. Maybe the delay function is bad?

Debugging the code and stepping through should show the issue.

If you feel a post has answered your question, please click "Accept as Solution".
Morpheuss01
Associate II

It cannot return from this while loop. I am thiking that because of vector table at the begining of flash memory. Because when I loaded the code to the begining of flash, it workes as should be. Delay funtion can't get the tick value.
Ekran görüntüsü 2025-12-03 143504.pngEkran görüntüsü 2025-12-03 143544.png