cancel
Showing results for 
Search instead for 
Did you mean: 

jump to internal boot loader from user application

karan
Associate III
Posted on June 12, 2015 at 15:59

I want to develop product using stm32f030cc controller.for that product i want to develop boot loader which can jump to internal boot loader in system memory with out altering boot pin.right now my board is not ready so try to implement this on discovery kit stm32f0308 rev a.so which is the best way to jump on boot loader in system memory from user application????? and which are the change when i migrate to my board with stm32f030cc????

i am useng MDK-Arm 5 and stm32cubemx 

#stm32-bootloader-flash-loader
6 REPLIES 6
Posted on June 12, 2015 at 16:13

Posted several examples of how this might be done for F0/Cortex-M0 parts.

https://community.st.com/0D50X00009Xkg1VSAR

 

Edit: Fixed DEAD LINK, Original post from 12-June-2015

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
karan
Associate III
Posted on June 13, 2015 at 11:19

i made following change in startup_stm32f030x8.s file

Reset_Handler    PROC

                 EXPORT  Reset_Handler                 [WEAK]

LDR        R0, =0x2000FFF0

                LDR        R1, =0xDEADBEEF

                LDR        R2, [R0, #0]

                STR        R0, [R0, #0] ; Invalidate

                CMP        R2, R1

                BEQ        Reboot_Loader

        IMPORT  __main

        IMPORT  SystemInit  

                 LDR     R0, =SystemInit

                 BLX     R0

                 LDR     R0, =__main

                 BX      R0

                 ENDP

Reboot_Loader   PROC

                EXPORT  Reboot_Loader

                LDR     R0, =0x40021018 ; RCC_APB2ENR (+0x18)

                LDR     R1, =0x00000001 ; ENABLE SYSCFG CLOCK

                STR     R1, [R0, #0]

               LDR     R0, =0x40010000 ; SYSCFG_CFGR1 (+0x00)

                LDR     R1, =0x00000001 ; MAP ROM AT ZERO

                STR     R1, [R0, #0]

               LDR     R0, =0x1FFFEC00 ; ROM BASE (STM32F03x)

 ;               LDR     R0, =0x1FFFC400 ; ROM BASE (STM32F04x)

;                LDR     R0, =0x1FFFEC00 ; ROM BASE (STM32F05x)

;                LDR     R0, =0x1FFFC800 ; ROM BASE (STM32F07x)

;                LDR     R0, =0x1FFFD800 ; ROM BASE (STM32F09x)

                LDR     R1, [R0, #0]    ; SP @ +0

                MOV     SP, R1

                LDR     R0, [R0, #4]    ; PC @ +4

                BX      R0

                ENDP ; 

but code got stuck on some hard fault handler and not even user application started

in step debug after executing ldr or str with resister as addres base instruction got in hardware fault( LDR        R2, [R0, #0]

                STR        R0, [R0, #0] ; Invalidate)

Posted on June 13, 2015 at 19:01

Probably because the part only has 32 KB of SRAM?

Consider 0x20007FF0

With

  *((unsigned long *)0x20007FF0) = 0xDEADBEEF;

on the C side before you reset the part.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
karan
Associate III
Posted on June 15, 2015 at 07:39

thank you its my fault.I not check how much ram i has now its working fine.i can able to upgrade firmware 

Posted on July 13, 2017 at 15:12

 ,

 ,

Hi Patel,

My Environment:

STM32F042 Nucleo-32 dev board which has STM32F042K6T6 MCU of 32pin QFP

KEIL ARM MDK v5

Host Windows 10 OS ,

The ,BOOT0 pin PB8 is not available on the CN3 or CN4 connector.  ,

I've used the same code posted above in this thread as it is and in fact the user flash application is handing over the control to system memory bootloader successfully. However the bootloader code ,hands over the control to the user flash application within few mSecs. According to the datasheet of MCU, the bootloader code looks for the BOOT0 pin if the BOOTSEL option bit is not explicitly set to don't check for BOOT0 pin.  ,This presents two solutions. First one is programming the BOOTSEL to skip checking the  ,BOOT0 pin in the bootloader start routine.This will allow the BOOT0 pin to be used as normal GPIO pin for any other operations. The other one is setting the BOOT0 pin thru code using the internal pullup and to HIGH. I've used the second solution in the below posted code

So then I've created a new function that explicitly sets the BOOT0 pin to HIGH before making the jump to the system memory. This change fixed the loop of moving from bootloader to user flash application. The MCU stays in bootloader code. ,

//File : main.c

void SetBoot0Pin(void)

 ,

{

 ,

__HAL_RCC_GPIOB_CLK_ENABLE(),

 ,

GPIO_InitTypeDef gp,

 ,

gp.Pin = GPIO_PIN_8, //BOOT0 pin

 ,

gp.Mode = GPIO_MODE_OUTPUT_PP,

 ,

gp.Speed = GPIO_SPEED_FREQ_LOW,

 ,

HAL_GPIO_Init(GPIOB, &,gp),

 ,

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, (GPIO_PinState) 1),

 ,

}

//File : startup_stm32f042x6.s

, Reset handler routine

 ,

Reset_Handler PROC

 ,

EXPORT Reset_Handler [WEAK]

 ,

LDR R0, =0x200017F0

 ,

LDR R1, =0xDEADDEAD

 ,

LDR R2, [R0, ♯ 0]

 ,

STR R0, [R0, ♯ 0] , Invalidate

 ,

CMP R2, R1

 ,

BEQ Reboot_Loader

 ,

IMPORT __main

 ,

IMPORT SystemInit

 ,

LDR R0, =SystemInit

 ,

BLX R0

 ,

LDR R0, =__main

 ,

BX R0

 ,

ENDP

 ,

 ,

Reboot_Loader PROC

 ,

EXPORT Reboot_Loader

 ,

IMPORT SetBoot0Pin

 ,

LDR R0, =SetBoot0Pin

 ,

BLX R0

 ,

LDR R0, =0x40021018 , RCC_APB2ENR (+0x18)

 ,

LDR R1, =0x00000001 , ENABLE SYSCFG CLOCK

 ,

STR R1, [R0, ♯ 0]

 ,

LDR R0, =0x40010000 , SYSCFG_CFGR1 (+0x00)

 ,

LDR R1, =0x00000001 , MAP ROM AT ZERO

 ,

STR R1, [R0, ♯ 0]

 ,

LDR R0, =0x1FFFC400 , ROM BASE (STM32F04x)

 ,

LDR R1, [R0, ♯ 0] , SP @ +0

 ,

MOV SP, R1

 ,

LDR R0, [R0, ♯ 4] , PC @ +4

 ,

BX R0

 ,

ENDP ,

Snapshot when the code is jumped to system memory bootloader. Notice the jump to the code location 0x1FFFCB45 as per the memory window showing the value at the reset vector address.

0690X00000607aPQAQ.png

Allowed the code to run for some time. Notice the change in PC register shown in the registers window

0690X00000607aUQAQ.png

Hold on. The story is not ended.Next is to ensure that the device is available/detected as USB DFU device in device manager. This is where my setup is not working. The device is not re-enumerated and no entries of USB DFU device in device manager and so the Dfuse demo tool is not listing the device. what could be the problem?  ,

I've used FTDI usb to serial cable and connected it to the nucleo board ,

PA9 -USART1 Tx

PA10 -USART1 RX

and ground of course

Also I've tried using the test app that was posted in other thread to find the device is in DFU mode. That application is not receiving any data that confirms that the USB DFU is not running. Notice that it is for STM32F072 but I hope that this should work for STM32F042 as well.

https://stackoverflow.com/questions/28288453/how-do-you-jump-to-the-bootloader-dfu-mode-in-software-on-the-stm32-f072

 ,

The test app is not receiving any characters back from the device. Someone please guide me on what could be the problem?

Posted on April 02, 2018 at 18:31

Hi Clive,

I am using STM32F207.

My Boot0 pin is tied to ground. I am setting up my boot loader with internal SRAM. I am trying at address 0x2000 0000 or 0x4002 4000. but none of them works. I am suspecting I am not using the right address?

I am trying to access internal SRAM for my boot loader. In my case, could I use 0x20007FF0? if I need more than 32KB of SRAM, says 128KB of SRAM, what address should I use?

Your insight is greatly appreciated.

Best,

Henry Trinh

Cymer/ASML