Skip to content
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

Add USB DFU upload method #27

Open
maxgerhardt opened this issue Jun 21, 2021 · 2 comments
Open

Add USB DFU upload method #27

maxgerhardt opened this issue Jun 21, 2021 · 2 comments
Labels
Arduino IDE Regarding things specific to the Arduino IDE PlatformIO uploader

Comments

@maxgerhardt
Copy link
Member

maxgerhardt commented Jun 21, 2021

Flashing a GD32F303CC board with the popular STM32Duino USB DFU bootloader, e.g. https://github.com/rogerclarkmelbourne/STM32duino-bootloader/blob/master/binaries/generic_boot20_pc13_fastboot.bin, shows that this exact binary works without problems on the board, although it's meant for a STM32F103C8 (which seems to be register-compatible for the USB and GPIO side)

grafik

The device is being recognized via USB and opens the Maple serial as expected.

This should make it possible to add USB DFU uploads for those chips having USB but no built-in USB bootloader, that is for F30x series the 303 chips.

grafik

Important logic in PlatformIO

https://github.com/platformio/platform-ststm32/blob/38e325b59c165c954f6f69c70e0299d36f3b9225/builder/main.py#L206-L265

probably also needs LDScript changes to respect the offset.

Also needs to be implemented for the Arduino IDE.

It should also be investigated what other boards can make use of this USB bootloader.

@maxgerhardt maxgerhardt added Arduino IDE Regarding things specific to the Arduino IDE PlatformIO uploader labels Jun 21, 2021
@maxgerhardt
Copy link
Member Author

maxgerhardt commented Jun 21, 2021

The first DFU upload with the pre-flashed bootloader was possible with PlatformIO, implemented in 7a0c2b1, 448be25 and CommunityGD32Cores/platform-gd32@35265fc.

CURRENT: upload_protocol = dfu
MethodWrapper(["upload"], [".pio\build\genericGD32F303CC\firmware.bin"])
Auto-detected: COM4
maple_upload COM4 2 1EAF:0003 "C:\Users\Max\Desktop\gd32_dev\gd32-pio-projects\gd32-arduino-pwm-out\.pio\build\genericGD32F303CC\firmware.bin"
maple_loader v0.1
Resetting to bootloader via DTR pulse
Searching for DFU device [1EAF:0003]...
Reset via USB Serial Failed! Did you select the right serial port?
Assuming the board is in perpetual bootloader mode and continuing to attempt dfu programming...

Found it!

Opening USB Device 0x1eaf:0x0003...
Found Runtime: [0x1eaf:0x0003] devnum=3, cfg=0, intf=0, alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000"
Setting Configuration 1...
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x0800
bytes_per_hash=264
Starting download: [##################################################] finished!
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
error resetting after download: usb_reset: could not reset device, win error: Ein nicht vorhandenes Gerät wurde angegeben.
Done!

Resetting USB to switch back to runtime mode

However, to sensibly do continuous USB DFU uploads, the core needs to have a USB serial functionality for the Auto-reset into bootloader mode, just like the maple core does (https://github.com/stm32duino/Arduino_Core_STM32/). Since we don't have that yet, it does not make a lot of sense to work on that now (first #5). But some groundwork has been laid now.

@obra
Copy link
Contributor

obra commented Jul 16, 2021

#28 implements dfu upload to an 8k bootloader, including setting the offset of the linked code correctly for builds from within the Arduino IDE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arduino IDE Regarding things specific to the Arduino IDE PlatformIO uploader
Projects
None yet
Development

No branches or pull requests

2 participants