DFU Mode from running code?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: barthess, RoccoMarco

Rick Burnett
Posts: 144
Joined: Tue Jan 08, 2013 2:20 pm

DFU Mode from running code?

Postby Rick Burnett » Mon Jan 15, 2018 8:18 am

Is it possible to exit out of my application into DFU mode once I am executing my code?

Right now I have a button on my circuit that you have to hold down when powering up. I'd rather just make an option through my UI while running to go into DFU mode.

Am I am able to do this? Using the STM32F427 chip.

User avatar
Giovanni
Site Admin
Posts: 10571
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 267 times
Been thanked: 228 times
Contact:

Re: DFU Mode from running code?

Postby Giovanni » Mon Jan 15, 2018 8:25 am

Hi,

I don't know, the question should be directed to ST I think.

Giovanni

rew
Posts: 222
Joined: Sat Jul 19, 2014 12:59 pm
Been thanked: 1 time

Re: DFU Mode from running code?

Postby rew » Sat Jan 20, 2018 8:47 pm

The DFU firmware is quite "primitive" in that it expects almost everything in fresh-from-reset state. So I would imagine that you disable interrupts and then use RCC to reset most modules. Then configure system memory into boot-space, load stack pointer from 0x0000 and then PC from 0x0004. That should do it. But things are likely to have a few snags....

Rick Burnett
Posts: 144
Joined: Tue Jan 08, 2013 2:20 pm

Re: DFU Mode from running code?

Postby Rick Burnett » Sun Jan 21, 2018 10:31 pm

Thanks for the information, only reason I asked here was if anyone had done this. Makes sense that the way it is probably written is to have a small footprint as well, so expectations of the processor state make sense.

If I decide to proceed on further, I will shoot a question over to the ST boards.

MarkusS
Posts: 11
Joined: Tue Mar 13, 2012 6:52 pm

Re: DFU Mode from running code?

Postby MarkusS » Tue Jan 30, 2018 10:36 pm

I tried this before and failed. I am not sure what I did wrong, but I was not able to get the DFU mode running after ChibiOS initialized the uC.
My solution was a combination of hard and software. I used a 1 MOhm pull-down resistor for the BOOT0 pin and added a 2.2uF cap in parallel. And I also connected another GPIO pin (PB7) to the BOOT0 pin. Now, if I want to jump into the DFU mode, I set the GPIO pin high, wait a few ms until the cap is charged and then do a reset...

Code:

Code: Select all

palSetPadMode(GPIOB, 7, PAL_MODE_OUTPUT_PUSHPULL);
palSetPad(GPIOB, 7);
chThdSleepMilliseconds(500); // charge cap up so that BOOT0 stays high during reset...

palSetPadMode(GPIOB, 7, PAL_MODE_INPUT_PULLUP); // so that we don't discharge the cap on reset
NVIC_SystemReset();


I had some issues with USB re-enumeration, so my full code for jumping into DFU is:

Code: Select all

palSetPadMode(GPIOB, 7, PAL_MODE_OUTPUT_PUSHPULL);
palSetPad(GPIOB, 7);
chThdSleepMilliseconds(500); // charge C20 up so that BOOT0 stays high during reset...

usbStop(serusbcfg.usbp);
palSetPadMode(GPIOA, GPIOA_OTG_FS_DP, PAL_MODE_OUTPUT_OPENDRAIN); //GPIOA_OTG_FS_DP is PA12 = USB DP
usbDisconnectBus(serusbcfg.usbp); // this calls usb_lld_disconnect_bus(usbp), which expands to
                                                     // palClearPad(GPIOA, GPIOA_OTG_FS_DP); ((usbp)->otg->GCCFG &= ~GCCFG_VBUSBSEN)
chThdSleepMilliseconds(1000); // disconnect USB

palSetPadMode(GPIOB, 7, PAL_MODE_INPUT_PULLUP); // so that we don't discharge the cap on reset
NVIC_SystemReset();


Hope this helps,

Markus


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 3 guests