Hey folks,
> It is a good idea.IMHO
Yeah, I like this idea as well. I wonder if the Arduino dev team
considered this approach for the original Arduino designs?
I guess the bootloader approach might be chosen since it is simpler, but
now that we're using a 16u2 on most Arduino boards and the Arduino
platform has matured, this might be a great way to make things more
powerful, at little extra cost.
> I already implemented it a year ago and it works great.
Nice! Did you share any of your code somewhere?
> The down side is if you are using the 16u2 in SPI mode you can not use
> it as a serial link for debug messages without some programming magic.
> Any debug text you type in could be interpreted as a programmer
> command and hang the serial port. I have not needed it but I wanted
> you to know its there. Maybe somebody knows how to block that.
This is indeed something that would need to be solved. I can think of a
few solutions:
- Only accept programming commands when a specific baud rate is
configred, like the 1200 baud reset trick for the Leonardo. Since
the configured baud rate only affects the serial link between the
16u2 and the 328, which is not used in programmer mode, this "magic
baud rate" can be an arbitrary low baud rate, since its value is not
actually used.
- In another reply, Nico suggests that you could perhaps have two
ports: a serial communication port and a programmer (and perhaps also
debugwire?) port. This is probably the cleanest solution, though it
requires changes to the IDE (which now assumes it can use the same
serial port for both serial monitor and programming.)
- A timeout could be used, so that programming commands are only
accepted if one is received within a few seconds. This still creates
problems if the serial port is used for transmitting (binary) data
that looks like a programmer command. It also again introduces
possible timing problems, so this is probably not a very good
approach.
- Use a native USB protocol for programming. i.e. instead of using a
virtual serial port, send data through custom USB messages. On the PC
side, this would need support from avrdude, but perhaps we can mimic
the protocol of another similar device (the stk600 seems to use
native USB, for example) so no changes to avrdude are needed.
The downside of this approach is that there might be permission
issues. On linux, permission to all (virtual) serial ports is
typically managed using a single "dialout" group, but permission to
a native USB device typically needs custom udev rules, which quickly
becomes more complicated for users. Not sure how OSX and Windows
handle this.
On a related note: If this is implemented, the 16u2 should probably
double-check the fuse settings to prevent disabling the ISP programming
fuse (which needs a high voltage programmer to re-enable it).
Gr.
Matthijs