cancel
Showing results for 
Search instead for 
Did you mean: 

Jump to Bootloader in STM32 through User Flash Memory i.e using Boot 0 and Boot 1 Pins in Boot mode from User Flash memory

jasdeepsingh
Associate
Posted on November 13, 2014 at 08:13

I have a requirement for firmware upgrade. I am planning to use USB DFU class. But command for firmware upgrade will come from PC application in my case . so i need to switch to bootloader which is there in System Memory. As initially i am running application so it is getting booted from User flash i.e i have Boot0 and Boot 1 pins configured for User flash. As DFU bootloader is there in System flash ,now for that Boot0 and Boot1 pins settings need to be changed . is there a way like Boot 0 and Boot 1 settings remain same as User Flash memory and in the application we jump to System Memory and use DFU for upgrading the firmware?

#stm3220g-eval #stm32f207-flash
8 REPLIES 8
ivani
Associate II
Posted on November 13, 2014 at 08:44

You could remap the system memory to address 0x00000000 via MEM_MODE bits in SYSCFG_MEMRMP register then load the SP with the value residing @ 0x00000000 and jump on the address pointed by 0x00000004.
jasdeepsingh
Associate
Posted on November 13, 2014 at 10:51

By referring to the video Calling the STM32 SystemMemory Bootloader from your application i am using the below mentioned code. This code gets executed but still Dfuse application does not detects the STM device in DFM mode.

Even PC does not detects USB.

void BootLoaderinit(uint32_t BootLoaderStatus)

{

  

   

        JumpAddress = *(__IO uint32_t*) (0x1fff0004);

      JumpToBoot = (SysMemBootJump) JumpAddress;

  if(BootLoaderStatus == 1)

  {

      HAL_RCC_DeInit();

    SysTick->CTRL =0;

    SysTick->LOAD=0;

    SysTick->VAL=0;

    

   __set_PRIMASK(1);

     /* Initialize user application's Stack Pointer */

      __set_MSP(*(__IO uint32_t*) 0x20001000);

      JumpToBoot();

      

  }

  while(1);

  

}

ivani
Associate II
Posted on November 14, 2014 at 08:43

It seems that the system memory resides on a different address for different chips:

- 0x1fff0000 for F4xx & F2xx devices

- 0x1fffb000 for F1xx connectivity line

- 0x1ffff000 for other F1xx devices

- 0x1fffd800 for F3xx devices

If you are using a direct call to system memory you need to check the exact address from the datasheet for the particular chip.
Posted on November 14, 2014 at 13:37

Probably because you're not entering in reset conditions. But rather than rehash this all over again.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/jumping%20to%20the%20bootloader%20via%20software%20does%20not%20permit%20dfu%20mode&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=232]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Java%2Fjumping%20to%20the%20bootloader%20via%20software%20does%20not%20permit%20dfu%20mode&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21¤tviews=232
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Stig Hornang
Associate II
Posted on February 22, 2016 at 08:34

This works for me on a STM32F4 device. Must be called in the beginning of main() based your ''enter bootloader condition'' (magic constant in RAM etc.):

#define BOOTLOADER_START_ADDR 0x1FFF0000

void JumpToBootLoader()

{

    __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();

    __set_MSP(*(__IO uint32_t*) 0x2001FFFF);

    void (*bootloader)(void) = (void(*)(void)) *((uint32_t *) (BOOTLOADER_START_ADDR + 4));

    bootloader();

}
Posted on February 22, 2016 at 17:29

__set_MSP((__IO uint32_t*) 0x20020000); // 32-bit aligned preferred, will predecrement, pretty sure you want the address, not the data that's at the address

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Stig Hornang
Associate II
Posted on March 01, 2016 at 15:56

Oops, your statement makes sense.

I noticed that the jump works without  the __set_MSP call at all.

Is it really needed?
Posted on March 01, 2016 at 17:26

Is it really needed?

It is more apt to succeed. This isn't how I transfer control. Several of the ROMs set the stack up again as part of the start up code. Keil also uses __initial_sp

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..