Flashing the Crazyflie in DFU update mode

Firmware/software/electronics/mechanics
Post Reply
sAz
Beginner
Posts: 27
Joined: Wed Jun 10, 2020 5:35 pm

Flashing the Crazyflie in DFU update mode

Post by sAz »

Hi everybody,

I am trying to understand how flashing in DFU mode works. I looked at the documentation here https://wiki.bitcraze.io/projects:crazy ... %5B%5D=dfu and in forum threads.

If I am not wrong, flashing this way might break the bootloader, if something goes wrong. So in case something goes wrong, how is it possible to flash back the bootloader?

Is there something else that can go wrong when flashing in DFU mode? Are there issues that might be irreversible?

I have multiple Crazyradios, but flashing the Crazyflies without Crazyradios might help a lot.

Thanks
kimberly
Bitcraze
Posts: 1024
Joined: Fri Jul 06, 2018 11:13 am

Re: Flashing the Crazyflie in DFU update mode

Post by kimberly »

Hi!

Just some background info here. We put this warning on the dfu there, since many users just assumed this was a standard, overflashed the bootloader and spend weeks to figure out what's wrong with their crazyflie afterwards. So DFU flashing is only for people that understand what they are doing.

So yes, if you by accident flash over the bootloader, you can recover this by dfu flashing (or a programmer). The addresses on the memory for both the bootloader and the main program are listed on that page. Just make sure you do not mix those addresses!

In general, flashing the crazyflie overair is quite an ease (especially if you use warmboot with cfloader flash cf2.bin stm32-fw -w URI directly) and that will never break the bootloader. So it is hard to imagine that anybody would prefer the dfu flashing over that, at least we don't here at bitcraze.
sAz
Beginner
Posts: 27
Joined: Wed Jun 10, 2020 5:35 pm

Re: Flashing the Crazyflie in DFU update mode

Post by sAz »

I am working in a lab that is equipped with >25 quadcopters and multiple radio dongles. During the pandemic it is impossible for most of the students to come to the lab (due to the regulation), therefore they borrow a Crazyradio and a Crazyflie, so they can work on their project from home.

At home, they only develop the code for the Crazyflies, which means that the Crazyradio is needed only for flashing.
I decided to look for another convenient way to flash the Crazyflies, to make it possible for more students to work from home, and to use the Crazyradios for bigger tasks (Controlling multiple Crazyflies, flashing multiple Crazyflies etc.). To be clear, I find flashing with the Crazyradio very easy and convenient, but flashing with an usb cable might help a lot.

Is there another option for flashing the drones? Or are these the only options?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Flashing the Crazyflie in DFU update mode

Post by arnaud »

Hi,
This is an interesting new requirement, the pandemic tends to change assumptions...

Technically speaking, if you are only interested by flashing the STM32 firmware, the DFU mode could be used for development.

In the Crazyflie firmware project you can type "make flash_dfu" which will flash the firmware using DFU over USB and it does not overwrite the bootloader.

The dificulty though, is that dfu was only intended as a last chance recovery mode in the Crazyflie, so getting to it is a bit convoluted. On my Crazyflie 2.1 I have to:
- Disconnect the battery (no idea why this is needed, but DFU does not start otherwise ...)
- Press the ON/OFF switch on the Crazyflie
- Plug the usb port while the button is pressed
- Wait for the blue led to blink fast and then release the button
- The STM32 is now in usb DFU mode, "make flash_dfu" works. The only way to get out of it is to cut and re-apply the power to the Crazyflie (ie. disconnect and reconnect the USB cable in this case)

If you do not care about flying you can leave the battery disconnected all the time and connect/disconnect the USB cable on the PC side which makes the procedure a bit more bearable but it is still not great.

I think the only piece missing to make it work better would be to be able to restart the STM32 in DFU mode from the USB port, this would allow to reboot, flash, reboot in a single make command. Rebooting an STM32 in bootloader mode is possible and has been done in this PR for the lps-node-firmware: https://github.com/bitcraze/lps-node-fi ... 6R392-R411. In the case of the Crazyflie, the easiest might be to add this as a USB setup request: https://github.com/bitcraze/crazyflie-f ... usb.c#L167. The only one for now is to enable/disable the usb link (used from the lib https://github.com/bitcraze/crazyflie-l ... #L137-L141). This would allow to make a script that reboots from firmware to DFU and the dfu-utils tool already has a flag to reboot from DFU to firmware.

If you (or your students) are interested in looking into this I would gladly help with guidance and merge a pull request. Otherwise we can open a ticket on the firmware project in GitHub and I could look at it when I have time.
sAz
Beginner
Posts: 27
Joined: Wed Jun 10, 2020 5:35 pm

Re: Flashing the Crazyflie in DFU update mode

Post by sAz »

I can try to improve flashing in DFU mode further, the same way you suggest. I have sent you a pm.
crglick
Beginner
Posts: 2
Joined: Fri Jan 21, 2022 5:30 pm

Re: Flashing the Crazyflie in DFU update mode

Post by crglick »

Has there been any development to streamline flashing in DFU mode? I too am an instructor and it would be very helpful to be able to flash the Crazyflie 2.1 over USB. I have verified that my method will work to flash the Crazyflie once it's in DFU mode but as stated earlier it is quite tedious to put it in DFU mode. Has there been any method created to command the Crazyflie to reboot directly into DFU mode?

Any help would be greatly appreciated.

Thanks!
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Flashing the Crazyflie in DFU update mode

Post by arnaud »

Hi,

As far as I know there has been no progress yet.

The description I did in my previous message still stands: it should be a mater of a small modification in the firmware and a python script sending the right restart command to the Crazyflie.

I created an issue on the firmware github project: https://github.com/bitcraze/crazyflie-f ... issues/923. We might get to it but we will also gladly merge a PR with this functionality. If anyone is interested and has questions about design/implementation lets discuss it in the github issue.
crglick
Beginner
Posts: 2
Joined: Fri Jan 21, 2022 5:30 pm

Re: Flashing the Crazyflie in DFU update mode

Post by crglick »

For any others finding this thread, here is the PR to add this feature to the Crazyflie firmware. https://github.com/bitcraze/crazyflie-firmware/pull/939
Post Reply