diff --git a/src/main.cpp b/src/main.cpp index bdc8467..6690274 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -130,17 +130,19 @@ void read_data(std::unique_ptr& ser, uint8_t* data, uint16_t len } // @todo We need to check if we are already in the bootloader -void program_dfu(std::unique_ptr& ser, std::string filename) { - ser->flushInput(); - ser->flushOutput(); - ser->flush(); +void program_dfu(std::unique_ptr& ser, std::string filename, bool no_reboot) { + if (!no_reboot) { + ser->flushInput(); + ser->flushOutput(); + ser->flush(); - write_command(ser, 0xFF); - write_command(ser, 'b'); + write_command(ser, 0xFF); + write_command(ser, 'b'); - // @todo Can we somehow check if the device is present - std::cout << "Waiting for device to reboot...\n"; - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // @todo Can we somehow check if the device is present + std::cout << "Waiting for device to reboot...\n"; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } // @todo We need some sort of dfu library because this is terrible std::string cmd = "dfu-util -a 0 -D " + filename + " -s 0x08000000:leave"; @@ -283,13 +285,15 @@ int main(int argc, const char** argv) { std::string device; uint16_t address; std::unique_ptr ser = nullptr; + bool no_reboot; app.add_option("filename", filename, "File to upload")->required(); app.add_option("--dev,-d", device, "Serial device to use")->default_val("/dev/ttyUSB0"); - app.add_subcommand("dfu", "Program STM32 mcu using dfu mode")->callback([&] { - program_dfu(ser, filename); + CLI::App* dfu = app.add_subcommand("dfu", "Program STM32 mcu using dfu mode")->callback([&] { + program_dfu(ser, filename, no_reboot); }); + dfu->add_option("--no-reboot,-r", no_reboot, "Base address")->default_val(false); CLI::App* rom = app.add_subcommand("rom", "Program ROM/RAM")->callback([&] { program_rom(ser, filename, address);