We're currently making lots of efforts to support Arduino boards and microcontrollers. The Arduino Leonardo is next.
Problem
When uploading firmware to the Arduino Leonardo, I noticed something strange. My Leonardo board was detected by the Arduino IDE on port COM9. Also the Windows Device Manager detects the board there:
However, when flashing the firmware, I see the following output in the Arduino IDE:
It looks like the Leonardo board first displays itself as COM10 (after a reset), and then switches to COM9 after a few seconds. In my understanding, the Arduino IDE forces a reset and then polls the COM-ports to detect the Leonardo board at COM10. As soon as this detection happened, the Arduino IDE proceeds with the actual firmware upload.
My question is: how can we do this in our IDE? In case we'd use Python for this, what Python commands could be used?
PS: Parts of our IDE are coded in Python, other parts in C++
That does not look like a Leonardo. A real Leonardo identifies itself after a power cycle as an Arduino Leonardo and after a reset as a Arduino Leonardo (bootloader). Reset is either achieved by pressing and releasing the reset button or by opening and closing the port at 1200 baud. Once the boot loader times out or a sketch is uploaded, control goes back to the sketch and the Leonardo identifies itself as that.
After you force the reset, you have to retrieve a listing of the com ports and next try to determine which one is the Leonardo bootloader. I have no idea how it's done but the IDE source code is open source so you can check that.
The Leonardo board must be genuine, because I bought it directly from the Arduino store. However, as soon as I had it in my hands, I played with the bootloader. Today I burned the default bootloader with an Atmel ICE - so I thought it should now be in its initial state (the way it left the Arduino factory). I checked, and the burned bootloader seems to be this one: bootloaders/caterina/Caterina-Leonardo.hex
What could be the reason that it identifies itself merely as USB Serial Device (COM9), not as an Arduino Leonardo?
So that's why the port is opened at 1200 baud. I didn't know it's a trick to reset the chip. Thanks for this info.
What are the timing constraints? I mean, how many milliseconds do I have to wait after the reset before I can start looking for the new COM-port and launch avrdude?
You have, if memory serves me well, about 8 seconds to start the actual download. You can check in Windows device manager how long it takes to go from COM10 back to COM9.