cancel
Showing results for 
Search instead for 
Did you mean: 

stm32: entering DFU Program Mode

sgiessl
Associate
Posted on February 19, 2010 at 16:15

stm32: entering DFU Program Mode

3 REPLIES 3
Posted on May 17, 2011 at 13:40

Use a location in RAM.

-Clive

On a 64KB RAM part I use the following sequence to restart the system and get it into the system loader. I use different keys to perform other critical functions prior to enabling other features, or dropping into the main application. ie Instead of disabling features on a running system, I reboot and do the work in a very controlled set of conditions with no interrupts or anything else. I would do this in assembler, and avoid using library code, again to control the conditions, and limit the code called outside my control.

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

NVIC_GenerateSystemReset();

Then very early in the restart in STM32F10x.s

Reset_Handler PROC

EXPORT Reset_Handler [WEAK]

IMPORT __main

LDR R0, =0x2000FFF0

LDR R1, =0xDEADBEEF

LDR R2, [R0, #0]

STR R0, [R0, #0] ; Invalidate

CMP R2, R1

BEQ Reboot_Loader

; ldr r1, =0xDEADxxxx

; cmp r2, r1

; beq Function_xxxx

LDR R0, =__initial_sp

LDR R1, =0x20010000

LDR R2, =0xE5E5E5E5

Clear_Heap

STR R2, [R0, #0]

ADD R0, #4

CMP R0, R1

BNE Clear_Heap

LDR R0, =__main

BX R0

ENDP

ALIGN

Reboot_Loader PROC

EXPORT Reboot_Loader

LDR R0, =0x1FFFF000 ; System Loader ROM

LDR SP,[R0, #0] ; Initial Stack

LDR R0,[R0, #4] ; Initial Program Counter

BX R0

ENDP

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chikos332
Associate II
Posted on May 17, 2011 at 13:40

Hi Sandro,

You could use the ''User Option Byte'' ? I think it is a simple and safe way to select running ''normal'' code or ''programming code''.

You just have to write a certain value at address:

 ''0x1FFF F802'' (and optionnally its complement at address 0x1FFF F803)

Then, after reset check this value... It is simple like ... hello :)

For more details please refer to Programming Manual PM0042 at

http://www.st.com/stonline/products/literature/pm/13259.pdf

, page 21.

Hope it suites your needs .

sgiessl
Associate
Posted on May 17, 2011 at 13:40

hi chikos and clive1

thanks for your help guys!

I'm going to use the option byte method. Doing it clive1's way was what I've been wanting to do initially. But since I want to use another persistent flag...

By the way, in case anyone wants to use option bytes method:

- the user option byte 0x1FFFF802 is reserved for a few hardware configuration flags, while the Data0 and Data1 bytes at 0x1FFFF804 can freely be used

- don't forget to erase the option bytes before programming them

- the inverse option byte will be computed by the FPEC automatically