Go Down

Topic: cannot use avrdude in command line: com port changed during sketch upload  (Read 559 times) previous topic - next topic

softysoft

Hi,

I would like to upload sketch from command line, but I am not able to execute the avrdude command, because the com port is changed by Arduino IDE just during the sketch upload, and I don't know how to change the com port from the command line.

For example: when I connect my device, COM26 is shown in the device manager. When I use the Arduino IDE to upload the sketch, Arduino IDE force COM26 to close, then open COM27: I can see that Arduino IDE runs avrdude with COM27, then force COM27 to close, and reopens COM26.

pert

The way uploads to the boards with native USB work is:
  • Arduino IDE opens a 1200 baud serial connection to the port selected in the Tools > Port menu.
  • There is some background code running on the Arduino board that sees this 1200 baud connection as a signal to reset the microcontroller, which activates the bootloader.
  • The bootloader has its own CDC serial port, which is enumerated to a different port by Windows than the one presented while the sketch is running.
  • After making the 1200 baud connection, the Arduino IDE waits for a new port to be enumerated. It assumes this is the port of the Arduino board's bootloader and runs the avrdude command to upload to that port.


To achieve the same thing from the command line, you could use the Arduino IDE's command line:
https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc
Or arduino-cli:
https://github.com/arduino/arduino-cli

If you prefer to use avrdude directly from the command line then you can determine the port assigned to the board's bootloader (it will be the same port every time) and set up your avrdude command accordingly, manually reset the board, and then immediately run command.



Go Up