-
Notifications
You must be signed in to change notification settings - Fork 165
Description
The ATmega32u4
microcontroller is present on a couple of Arduino boards, such as the Arduino Leonardo and Arduino Micro. The flash procedure for these boards is quite complicated. I'll first review how it works precisely, then I'll explain why this is a problem for many users of AVRDUDE. Finally we can look into potential solutions.
1. The flash procedure explained
Unlike others, the Arduino Leonardo and Arduino Micro boards identify themselves through one port (eg. COM9
) while you need to flash them through another (eg. COM10
) which is only available for a couple of seconds just after a reset. I observed how the Arduino IDE deals with this case:
-
Open the serial port through which the board has identified itself (eg.
COM9
) at baudrate 1200 and close it immediately thereafter. This basically triggers a board reset. -
Observe the serial ports from the OS (Windows/Linux). As soon as the board has completed the reset, it should present itself with the serial port for flashing (eg.
COM10
). Store that port name and go on to the next step. -
Flash the firmware through the new port (eg.
COM10
) with AVRDUDE. Do it quickly, because this serial port is only active for a couple of seconds.
Arduino IDE does it this way. PlatformIO also.
2. What is the problem?
The flash procedure explained above consists of three steps. I know how to put the third step in a makefile, but I have no idea how to implement the first two.
I could just hardcode the first two steps in Embeetle IDE and run them behind the scenes before launching the third step. I actually just did that, and it works. But it feels wrong. At Embeetle, we have the desire to keep our users informed and free. In other words: if one of our users decides to work on a project outside Embeetle IDE, he/she is free to do so. We achieve that in two ways:
-
All Embeetle projects are makefile-based. The user simply needs to invoke
clean
,build
andflash
targets to do all the magic. -
We provide a makefile to each sample project our users can download, but it is not touched thereafter. The makefile is well-explained, with plenty of comments.
Hardcoding (part of) the flash procedure in the IDE itself defeats this goal. The user cannot run his project outside our IDE anymore.
3. Potential solutions
I see two solutions to this dilemma:
-
We find a way to implement the first two steps in the makefile anyhow. I looked into this with my colleague Johan - who is a true makefile wizard - but we couldn't figure it out. If you have an idea, please let me know.
-
We improve the AVRDUDE software such that it can handle this particular situation.
I believe the second solution is the cleanest and will help most AVRDUDE users - also those that have nothing to do with Embeetle IDE. I would love to help with the implementation, but I'm afraid I need a little help and guidance, as I'm not familiar with the source code.
Kind regards,
Kristof Mulier