cancel
Showing results for 
Search instead for 
Did you mean: 

Jump to System bootloader: does not stay inside

Led
Senior

It has been asked several times, however I can not find a working solution for me.

With STM32L486RGT6 I achieved to implement jump to bootloader, entering DFU mode successfully. All fine!

Doing it similar for STM32L071CZY6TR and STM32F469VE it does not remain in bootloader, but starts the application from flash.

 

Environment: Boot0 = 0 fixed. Application is stored in Bank1.

Debugging STM32L071 I see the jump to 0x1ff0’0510. Stepping forward ends up in a small loop. Disconnecting the debugger, the application starts from flash. I don’t see any Hardfault message.

 

Do I miss something to reset or should this anyway not be used to update the FW in Flash?
Below the code I use.

 

 

void Jump2StInternalBootloader(void)
{
  volatile uint32_t addr = 0x1FF00000;

  HAL_UART_DeInit(&huart1);
  HAL_UART_DeInit(&huart5);
  HAL_ADC_DeInit(&hadc);
  HAL_I2C_DeInit(&hi2c1);
  HAL_TIM_Base_DeInit(&htim2);
  HAL_LPTIM_DeInit(&hlptim1);

  HAL_StatusTypeDef s = HAL_RCC_DeInit();
  if (s != HAL_OK){
    while(1){;}
  }
  HAL_SuspendTick();

  SysTick->CTRL = 0;
  SysTick->LOAD = 0;
  SysTick->VAL  = 0;

  HAL_DeInit();
  __disable_irq();

  HAL_RCCEx_DisableLSECSS();

  __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();

  /* Clear Interrupt Enable Register & Interrupt Pending Register. TODO check code */
  for (uint8_t i = 0; i < (MCU_IRQS + 31u) / 32; i++) {
    NVIC->ICER[i] = 0xFFFFFFFF;
    NVIC->ICPR[i] = 0xFFFFFFFF;
  }
  for (IRQn_Type i = WWDG_IRQn; i <= LPUART1_IRQn; i++) {
    HAL_NVIC_DisableIRQ(i);
  }

  void (*jumpFuncPtr)(void);
  jumpFuncPtr = (void (*)(void))(*((uint32_t *)(addr + 4)));
  __set_MSP(*(uint32_t *)addr);
  jumpFuncPtr();
}

 

Thanks in advance.
Led

11 REPLIES 11
Elatewendy
Associate III

Hello,

Is the address right? You can get the address at AN2606.

Elatewendy_0-1708675458794.png

I did the same function at STM32F429 with the stdlib.It works sucessfully.

#define BootloaderAddress    0x1FFF0000
void JumptoBoot(void)
{
    unsigned char i;

    /* Test if user code is programmed starting from address "BootloaderAddress" */
    if (((*(__IO uint32_t*)BootloaderAddress) & 0x2FFE0000 ) == 0x20000000)
    { 
       #if defined(STM32F429_439xx)
       SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SystemFlash);
       #endif
       GPIO_DeInit(GPIOF);
       GPIO_DeInit(GPIOE);
       GPIO_DeInit(GPIOD);
       GPIO_DeInit(GPIOC);
       GPIO_DeInit(GPIOB);
       GPIO_DeInit(GPIOA);

       TIM_DeInit(TIM4);
       USART_DeInit(USART1);
       INTX_DISABLE();

       SysTick->CTRL = 0;
       SysTick->LOAD = 0;
       SysTick->VAL = 0;
       RCC_DeInit();
       for (i = 0; i < 8; i++)
       {
         NVIC->ICER[i]=0xFFFFFFFF;
         NVIC->ICPR[i]=0xFFFFFFFF;
       }    
       //INTX_ENABLE();
       INTX_DISABLE();

      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (BootloaderAddress + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) BootloaderAddress);
      Jump_To_Application();
    }
}

  

Can you show the full code you're using for the STM32F4? Not sure what "first reply in this chat" refers to.

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