cancel
Showing results for 
Search instead for 
Did you mean: 

local bootloader

Snm.1
Associate III

I want to use local bootloader of mcu. First i used to sm32f407vg mcu, than i would to use stm32l052 mcu but i didn't this wit mcu. my tryed code is under of question. i am waiting the advice.

void JumpToBootloader(void) {

  void (*SysMemBootJump)(void);

  /**

   * Step: Set system memory address.

   */

  volatile uint32_t addr = 0x1FFF0000;

  /**

   * Step: Disable RCC, set it to default (after reset) settings

   *    Internal clock, no PLL, etc.

   */

#if defined(USE_HAL_DRIVER)

  HAL_RCC_DeInit();

  HAL_DeInit(); // add by ctien

#endif /* defined(USE_HAL_DRIVER) */

#if defined(USE_STDPERIPH_DRIVER)

  RCC_DeInit();

#endif /* defined(USE_STDPERIPH_DRIVER) */

  /**

   * Step: Disable systick timer and reset it to default values

   */

  SysTick->CTRL = 0;

  SysTick->LOAD = 0;

  SysTick->VAL = 0;

  /**

   * Step: Disable all interrupts

   */

  __disable_irq(); // changed by ctien

  /**

   * Step: Remap system memory to address 0x0000 0000 in address space

   *    For each family registers may be different.

   *    Check reference manual for each family.

   *

   */

  //Remap by hand... {

  //} ...or if you use HAL drivers

  __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();  //Call HAL macro to do this for you

  /**

   * Step: Set jump memory location for system memory

   *    Use address with 4 bytes offset which specifies jump location where program starts

   */

  SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));

  /**

   * Step: Set main stack pointer.

   *    This step must be done last otherwise local variables in this function

   *    don't have proper value since stack pointer is located on different position

   *

   *    Set direct address location which specifies stack pointer in SRAM location

   */

  __set_MSP(*(uint32_t *)addr);

  /**

   * Step: Actually call our function to jump to set location

   *    This will start system memory execution

   */

  SysMemBootJump();

  /**

   * Step: Connect USB<->UART converter to dedicated USART pins and test

   *    and test with bootloader works with STM32 STM32 Cube Programmer

   */

}

0 REPLIES 0