Skip to content

Request support for standard (ST) DFU bootloader upload #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
edogaldo opened this issue Sep 19, 2018 · 11 comments · Fixed by #514
Closed

Request support for standard (ST) DFU bootloader upload #330

edogaldo opened this issue Sep 19, 2018 · 11 comments · Fixed by #514
Labels
enhancement New feature or request
Milestone

Comments

@edogaldo
Copy link
Contributor

As per title, it would be useful to allow uploading via the standard ST DFU bootloader (where available).
This could be a good compromise for boards like the Black F407VE which else would require an external tool for initial load..

@fpistm fpistm added the enhancement New feature or request label Sep 19, 2018
@ppescher
Copy link
Contributor

I have done this in our OpenTracker fork.

See board/platform configuration files:
https://github.com/RoboTech-srl/opentracker-stm32-core/blob/7fbe63f592d32d0f7aac16dd4e6d4949937ddf4e/boards.txt#L46 (and below)
https://github.com/RoboTech-srl/opentracker-stm32-core/blob/7fbe63f592d32d0f7aac16dd4e6d4949937ddf4e/platform.txt#L150 (and below)

I am using STM32CubeProgrammer in DFU mode. I'm using this on Windows, there is still an issue with the wrong driver being loaded because the new one does not have a digital signature, however it can be manually switched in the Device Manager. I also briefly tested it on linux. Not sure about MacOSX, but I think I got the application path right.

The implementation of the boot call in this commit:
fortebit@61d98b5
Later modified in:
fortebit@83ca6ee

In the first attempt I reserved a variable (boot flag) in the newly created ".noinit" section, otherwise it would have been zero-initialized by the reset handler.
In the second one I moved the checkBoot() call inside the reset handler, before zero-init. I left the ".noinit" section in the modified linker script, even if no longer required.
I thought it was less invasive change to not requiring all the linker scripts to be modified. Even if kind of hacking or hijacking the reset handler (I count on the fact that all reset handlers are equal and have defined the label LoopCopyDataInit).

And the "1200 baud trick" is in my USB CDC attempt:
https://github.com/RoboTech-srl/opentracker-stm32-core/blob/b6f0b430c4049bd801d27be074034f58cb5de6b7/cores/arduino/stm32/usbd_cdc_if.cpp#L171

If you think this is a proper solution I might prepare a pull request.

@edogaldo
Copy link
Contributor Author

edogaldo commented Sep 21, 2018 via email

@ppescher
Copy link
Contributor

Cool, thanks Edoardo!
It would have been nice to let us know in the same post where we both wrote on the ST Community forum.
This is good news anyway.

@edogaldo
Copy link
Contributor Author

edogaldo commented Sep 22, 2018 via email

@fpistm
Copy link
Member

fpistm commented Oct 10, 2018

This will be handled thanks #351 thanks @chrissbarr

@ppescher
Copy link
Contributor

It seems that #351 only handles loading a new image via DFU after the bootloader has been activated somehow. I would still need a method to reset the board in boot mode automatically.

Since you have DFU you also have USB and probably that's the main communication interface with a PC anyway, so it makes sense to have some method to update the firmware without any human intervention, just like other arduinos do, and the 1200 baud trick does exactly that.

Given that there is no official CDC yet, maybe I should have a look at #344 and compare it with my implementation (when I find some time).

@fpistm
Copy link
Member

fpistm commented Oct 10, 2018

Yes, this only handle DFU upload, that's the request.
I agrred, the management of the bootmode is a nice thing to have but I think this could be done in a second step as it depends on CDC.

@chrissbarr
Copy link
Contributor

I think the 1200 baud rate trick is a great idea @ppescher.

Yeah, the dfu-util implementation will only handle the upload part, and needs the board to be in the right state - so a way to reset the board first would be needed. Boards with custom bootloaders should then be able to accept an upload after being reset (assuming they enter DFU mode for a short time, which is I think common behaviour a la Maple). Boards with only the built-in DFU bootloader will still need the BOOT0 pin set accordingly - I don't know that there's an easy way to use that bootloader without the user interacting with the hardware (though it looks like it is possible, but probably hard to generalise to all chips).

I think ideally the reset and upload methods should be separate - it's likely there are upload methods besides DFU that could be used on reset.

@edogaldo
Copy link
Contributor Author

edogaldo commented Oct 10, 2018

Just a tip for sw jump to standard STM bootloader: https://stm32f4-discovery.net/2017/04/tutorial-jump-system-memory-software-stm32/
this could work around the need to set boot0=1..

@ppescher
Copy link
Contributor

Hi @chrissbarr
Yes it is definitely possible to call into the ROM bootloader to activate DFU. That's what I did (see my #330 (comment)).

I used a similar approach to what micropython does (see https://github.com/micropython/micropython/blob/338635ccc64204b6f388cfaafca00e120090c622/ports/stm32/modmachine.c#L260) even though I jump to the bootloader after resetting the system (to make sure hardware is in the same state as if you used the BOOT0 pin).

@fpistm fpistm added this to the 1.5.0 milestone Oct 21, 2018
@fpistm fpistm modified the milestones: 1.5.0, 1.5.1/1.6.0 Dec 12, 2018
@fpistm
Copy link
Member

fpistm commented May 3, 2019

Closed thanks #514

@fpistm fpistm closed this as completed May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants