Added option to just use dfu tool without issuing reboot command
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dreaded_X 2021-06-08 23:29:08 +02:00
parent 2ecdbf6d1f
commit 6a0da17d54

View File

@ -130,17 +130,19 @@ void read_data(std::unique_ptr<serial::Serial>& 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<serial::Serial>& ser, std::string filename) {
ser->flushInput();
ser->flushOutput();
ser->flush();
void program_dfu(std::unique_ptr<serial::Serial>& 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<serial::Serial> 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);