cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding custom bootloader for STM32f412g-discovery board which can support USB DFU class

SSure
Associate II

I have a requirement for implementing firmware upgrade feature for one of our products which is based on STM32F412ZG microcontroller. I know that ST provides a system memory bootloader which already supports firmware upgrade using USB DFU class.

But the requirement is to add additional user interactions(Blink LED, buzzer, etc) during the upgrade process, or to indicate that the device is in bootloader mode. Since I cannot change the on-chip bootloader I'm trying to develop a custom bootloader which is based on the USB DFU device application (generated from STMCubeMX). After flashing this sample project on STM32F412g-discovery and plugging the device into PC using, I get the following error in Device Manager

STM Device in DFU mode (with an exclamation mark) and under details it says, This device cannot start. (Code 10)

However if I jump to system memory bootloader, the PC is able to load the correct driver and it gets detected as STM Device in DFU mode correctly and I'm also able to successfully upgrade the firmware using DfuseDemo.exe

I have installed DfuseDemo package from ST along with the corresponding drivers provided in the same package.

I'm failing to understand why the project created using STMCubeMX is not working and I'm also not able to find an example project for UDB DFU device for STM32F412g-discovery.

Please help me in understanding what could be wrong or direct me to where I can find a working sample project.

PS: PC is running windows 10. I'm also not sure if it's completely windows 10 problem whatever I'm facing.

6 REPLIES 6
Evgeny Popov
Associate III

you have to change

#define CDC_DATA_HS_MAX_PACKET_SIZE                512  /* Endpoint IN & OUT Packet size */

#define CDC_DATA_HS_MAX_PACKET_SIZE                64/* Endpoint IN & OUT Packet size */

in usbd_cdc.h

But I'm using DFU class, not CDC.

i never used DFU. but code 10 error occurs cuz of wrong packet size. SO i think it must smh simillar to this

Okay, I'll look into it. Thanks a lot for your support.

Ben K
Senior III

Take a look at https://github.com/IntergatedCircuits/DfuBootloader

There is no direct support for STM32F412ZG, but you can just use stm32f405 target for the purposes of USB, GPIOs and timers, the basic peripherals are all mapped to the same address and interrupt lines. (Remember to increase the flash size to 16k in the linker script.) Or just start off with the USBDevice library.

The nice feature of the library and the DFU class implementation, that the interface implements both bootloader and application side operation, and it can be mounted on the USB device of the application. Therefore the DFU interface can be used to manage the transition from application mode to bootloader, as it is defined by the DFU class specification.

Watch also stack size on Keil builds

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..