DFU to MSP Auto Switch, Arduino IDE?
DFU to MSP Comms over USB
- How does betaflight work? How can it flash but also receive live data via usb?
Normal Mode (MSP Communication over USB Serial):
- Implement MSP protocol over USB CDC to send telemetry and receive commands.
- Use
Serial
for communication.DFU Mode (Firmware Update via USB Bootloader):
- STM32: Use the built-in DFU bootloader and jump to DFU via software.
Switching Between Modes:
- Listen for an MSP command to trigger DFU mode.
- Reboot into the bootloader when DFU is requested.
Jump to DFU Mode from Firmware
void enterDFU() { void (*boot_jump)(void) = (void (*)(void)) (*((uint32_t*) 0x1FFF0004)); __set_MSP(*(uint32_t*) 0x1FFF0000); boot_jump(); }
Enter DFU when a specific command is recieved
void processMSP(uint8_t command) { if (command == 150) { // MSP_FC_VERSION Serial.write(36); // Start Byte Serial.write('M'); // MSP Header Serial.write('<'); Serial.write(2); Serial.write(150); Serial.write(4); Serial.write(2); Serial.write(150); } else if (command == 255) { // Custom command to enter DFU enterDFU(); // Function to reboot into DFU mode } }
When
255
is received, the FC switches to DFU mode.
- I might try configuring a board in the arduino ide using the stm32duino github I was looking at yesterday. I feel like PlatformIO is just adding unnecessary complexity. Maybe once I get it working in Arduino IDE I can bring it over to PlatformIO?