Skip to content

Flash a swarm by broadcast where the bootloaders take it - #53

Merged
evoggy merged 5 commits into
mainfrom
evoggy/swarm-broadcast
Oct 15, 2026
Merged

evoggy merged 5 commits into
mainfrom
evoggy/swarm-broadcast

Conversation

@evoggy

@evoggy evoggy commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

swarm bootload flash now sends the STM32 and nRF51 firmware by broadcast to the Crazyflies whose bootloaders take it (bootloader protocol 0x11 on both chips, see swarm bootload info). They all receive each image at the same time, so flashing a swarm takes about as long as one broadcast instead of about 20 s per Crazyflie.

How it runs

  1. Every Crazyflie with STM32 or nRF51 firmware to flash is restarted into its bootloader, 2 at a time per Crazyradio (the same limit as swarm bootload info since Restart Crazyflies back into firmware after reading bootloader info #51).
  2. Its bootloader info is read there. In the bootloader every Crazyflie listens on channel 0, so from here on everything runs on one Crazyradio.
  3. The nRF51 bootloader+softdevice from Upgrade the nRF51 bootloader and softdevice when flashing #24 is flashed first where a Crazyflie needs it, one at a time.
  4. The Crazyflies of one platform (the same images) whose bootloaders take broadcast and have the same flash layout form a group. The group is armed, and each image is broadcast once, with a progress bar per image. Then each Crazyflie is checked by CRC, with a bar counting the Crazyflies checked, and pages that didn't make it are flashed again to that Crazyflie alone (up to 3 rounds).
  5. The others are flashed one after another from their bootloader, checked by CRC where their bootloader can do it.
  6. Every Crazyflie sent back into its firmware is checked to have left its bootloader, and restarted again if not (as in Restart Crazyflies back into firmware after reading bootloader info #51). One that fails is reported with the address its bootloader is at.
  7. Deck firmware is flashed last, one Crazyflie per Crazyradio at a time, all Crazyradios at once. The Crazyflies are spread over the Crazyradios as for the other swarm commands, so the ones on one channel share a Crazyradio. The decks of several Crazyflies share one set of progress bars (DeckOutput in bootloader.rs). Each bar is labelled with the Crazyflie's name, and lines are printed above the bars with the name in front. Single-Crazyflie bootload flash is unchanged.

Details:

  • A broadcast is only used for 2 or more Crazyflies: for a single one it is slower than unicast.
  • Each broadcast group gets its own broadcast address. A Crazyflie that fails is left in its bootloader, still armed, and must not receive the images of a later group, which is for another platform.
  • --unicast keeps the old way: every Crazyflie one after another, the same as cfcli bootload flash.
  • The summary says how each Crazyflie was flashed (flashed (broadcast), flashed (broadcast, 2 pages flashed again), flashed (unicast)), followed by how long the whole command took.

The engine follows the one in Swarmkeeper, on cfloader 0.2. bootloader.rs gets enter_bootloader_for_cfloader(), left_bootloader(), start_address() and flash_decks() split out of flash(), and Runner::each_of() runs on some of the targets. docs/swarm.md describes it, and the README now lists swarms, including broadcast flashing, among the features.

Testing

On 3 Crazyflie 2.1 Brushless (both bootloaders 0x11) and one Crazyradio:

  • --release 2026.08: all 3 flashed by broadcast, then the Color LED decks one at a time, in 1:27. With the 3 Crazyflies moved to channels 90, 80 and 70, and 2 Crazyradios, the decks of CF-02 and CF-03 were flashed at the same time, and CF-04 after CF-02 on the same radio: 23 s for the decks, 1:15 in all. The release's nRF51 bootloader (2024.10) was correctly left alone, since these bootloaders report 2024.10.0.
  • --release 2026.08 --targets stm32-fw,nrf51-fw: broadcast took 0:45 (STM32 34 s, nRF51 10 s, then CRC checks). The same flash with --unicast took 1:06. A second round gave the same times.
  • All 3 ran the new firmware afterwards and swarm bootload info read them fine.
  • Unit tests pass.

Not tested yet:

  • A Crazyflie that loses pages during the broadcast (fix-up path). It ran 0 times here, but the same cfloader code was tested in the cfloader-rs examples.
  • A second platform group (its own broadcast address).
  • More than 3 Crazyflies, more than one Crazyradio, and old bootloaders mixed in, which go to unicast.

During the timing runs a --unicast run once hung before printing anything; that is filed as #52 and is not specific to this PR.

swarm bootload flash now restarts every Crazyflie with STM32 or nRF51
firmware to flash into its bootloader (2 at a time per Crazyradio, as for
swarm bootload info), and sends each image once to all the Crazyflies of a
platform whose bootloaders both take broadcast (protocol 0x11). Each one is
then checked by CRC and the pages that didn't make it are flashed again
over unicast. The others are flashed one at a time from their bootloader,
checked by CRC where the bootloader can. Every Crazyflie sent back into its
firmware is checked to have left its bootloader, and restarted again if
not. Deck firmware is flashed last, one Crazyflie at a time.

A broadcast is only used for 2 or more Crazyflies, and every broadcast
group gets its own broadcast address, so a Crazyflie left armed in its
bootloader after a failure can't receive another platform's images.
--unicast keeps the old one-after-another flashing.

The engine follows Swarmkeeper's. bootloader.rs gets
enter_bootloader_for_cfloader(), left_bootloader(), start_address() and
flash_decks() for it.
swarm bootload flash flashed the decks one Crazyflie after another. They
now run one Crazyflie per Crazyradio at a time, with the Crazyflies spread
over the Crazyradios as for the other swarm commands, so Crazyflies on one
channel still share one Crazyradio.

Several Crazyflies printing progress bars at the same time would garble
the output, so flash_decks takes a DeckOutput: progress bars as before for
one Crazyflie, or a line per step with the Crazyflie's name in front for a
swarm. The "flashed successfully" line now names the deck.
The decks of several Crazyflies now share an indicatif MultiProgress: each
deck gets its own bar labelled with the Crazyflie's name, and lines are
printed above the bars. Checking the Crazyflies after a broadcast gets a
bar counting them, which stays like the bars of the images.
@evoggy
evoggy marked this pull request as ready for review October 15, 2026 20:46
@evoggy
evoggy merged commit c5c7395 into main Oct 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant