AnsweredAssumed Answered

Leave DFU while boot0 is high (STM32F4)

Question asked by Mike on Mar 12, 2013
Latest reply on Mar 13, 2013 by Clive One
I'm having trouble leaving DFU mode (following instructions on pp 18 ~21 of AN3156) and entering my application while boot0 is high.  My application is loaded at 0x08000000 and I'm using STM32F4's system memory bootloader (reset with boot0 high). 

Here's my C# "Leave DFU" code for verifying the algorithm.
//Open device
STDFUFunction.Call(() => STDFU.API.Open(_path, out _handle));

//Set Start Address.  See pp 18 (section 5.2 of application note AN3156)
byte[] address = new byte[] { 0x21, 0x00, 0x00, 0x00, 0x08 };
STDFUFunction.Call(() => STDFU.API.Dnload(ref _handle, address, (uint)address.Length, 0));

//Make start address active my issuing a GetStatus
STDFU.DFUSTATUS status = new STDFU.DFUSTATUS();
STDFUFunction.Call(() => STDFU.API.GetStatus(ref _handle, ref status));

//A second Get Status to ensure address is accepted
status = new STDFU.DFUSTATUS();
STDFUFunction.Call(() => STDFU.API.GetStatus(ref _handle, ref status));

//Command to leave DFU mode see pp 21 (section 5.5 of application note AN3156)
byte[] dummy = new byte[] {};
STDFUFunction.Call(() => STDFU.API.Dnload(ref _handle, dummy, 0, 0));

//Get status to activate the command
status = new STDFU.DFUSTATUS();
STDFUFunction.Call(() => STDFU.API.GetStatus(ref _handle, ref status));

//Close device
STDFUFunction.Call(() => STDFU.API.Close(ref _handle));

Although I'm not checking the statuses in the code above, I've verified they all return the values expected as documented in AN3156.

If I leave boot0 high, I hear the Windows USB disconnect "ding", but it appears that the my application doesn't run.  However, it doesn't seem to be in the DFU mode either, as I can't re-download with resetting the processor again. 

If I pull boot0 low before the "leave DFU mode" code runs, and leave it low, it enters the application fine.

I'm fairly certain my linker script and startup scripts properly place the code and vector table where they should be, at 0x08000000.  You can find the full source code attached, but here's the relevant parts.

Linker script (edited for brevity, see attachment for full code):
CCRAM    (rxw) : ORIGIN = 0x10000000, LENGTH =  64k
FLASH    (rx)  : ORIGIN = 0x08000000, LENGTH = 512k

_estack = ORIGIN(CCRAM) + LENGTH(CCRAM);

.isr_vector :                    
    {
    . = ALIGN(4);
        KEEP(*(.isr_vector))  
    . = ALIGN(4);
    } >FLASH


Startup (edited for brevity, see attachment for full source code):
    .section  .isr_vector,"a",%progbits
    .type     __Vectors, %object
    .size     __Vectors, .-__Vectors

__Vectors:
    .word  _estack       /* Top of the stack */
    .word  Reset_Handler /* System Reset Handler */


My SystemInit is stock from the STM32F4 peripheral library.

Does anyone see what I'm doing wrong?

Outcomes