cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WLE5CCU6 – Bootloader jumps to second slot but app hangs in HAL_Delay (ROPI, IAR)

Rylus
Visitor

Hello everyone,

I’m working with an STM32WLE5CCU6 and I have implemented a bootloader that should be able to start applications stored in two flash regions (“slots”).

  • Bootloader at 0x08000000

  • Slot 1 (FW1) at 0x08005000

  • Slot 2 (FW2) at 0x08015000

  • Applications are built with IAR EWARM using ROPI (Read-Only Position Independent).

The bootloader uses the following jump code:

__attribute__((naked)) static void jump_to_app(uint32_t pc, uint32_t sp) {
  __asm volatile("msr msp, r1 \n" /* load r1 into MSP */
                 "bx  r0      \n" /* branch to the address at r0 */
  );
}

#define VECTOR_TABLE_SIZE 0x138
static void start_app(uint32_t *fw_addr) {
 // Remap 0x0000 (NVIC table location) to SRAM1
      SYSCFG->MEMRMP = 0b011;
  const uint32_t *app_code = fw_addr;
  volatile uint32_t *sram = (uint32_t *)0x00000000;

// Copy SP (no offset)
      sram[0] = app_code[0];

// Copy PC (with offset)
      sram[1] = app_code[1] + (uint32_t)fw_addr;

// Copy the rest of the vector table
      for (int i = 2; i < VECTOR_TABLE_SIZE / 4; ++i) {
    if (app_code[i] == 0) {
      sram[i] = 0;
    } else {
      sram[i] = app_code[i] + (uint32_t)fw_addr;
    }
  }
  uint32_t app_sp = app_code[0];
  uint32_t app_pc = app_code[1] + (uint32_t)fw_addr;
  jump_to_app(app_pc | 1, app_sp);
}

 

  • FW1 in slot 1: starts and runs fine, SysTick increments and HAL_Delay() works.

  • FW2 copied into slot 1: also works fine, which indicates the binary itself is correct.

  • FW2 executed directly from slot 2: the CPU enters the Reset_Handler, but then gets stuck in HAL_Delay() because HAL_GetTick() never increments. Sometimes I also see a HardFault PRECISERR with an invalid data address.

It looks like the vector table is not handled correctly when running from the second slot:

  • Is it enough to use SYSCFG->MEMRMP = SRAM or should I also update SCB->VTOR?

  • With ROPI, can it happen that some entries in the vector table are already absolute addresses (0x080…), so adding fw_addr makes them invalid?

  • What is the recommended way to manage the vector table so that SysTick and interrupts work correctly when starting an app from different slots?

Any advice or shared experience with STM32WL + IAR ROPI + multi-slot applications would be greatly appreciated

 

0 REPLIES 0