Talking to the SAM-BA Bootloader
So far, we've been using
upload our program to the microcontroller. This has been working
okay, but recently, when picking up this little project again
after a few months of absence, a problem appeared: The program
upload stopped working completely. The
command would just hang forever. This was a huge problem of
course, as it blocked all further development efforts.
After performing the typical "programmer in trouble" rain dance for a while (which is usually an alternation between trying everything I can think of and increasingly desperate Google searches that only turn up useless forum posts), I bit the bullet and downloaded Atmel's official upload tool, SAM-BA. I had wanted to avoid this, as this is the kind of software that requires you leave your name and address before you can even download it. But I was desperate, so I involuntarily signed up to Atmel's mailing list and gave the tool a try.
It took me a moment to figure out how to use it, but I succeeded in using it to upload my program. That gave me a working solution and told me that at least the microcontroller wasn't broken.
I wasn't very happy about that though. First, I'd rather use an open source tool that I can understand and modify, if need be. Second, I'd like to make my development process as smooth as possible, and fooling around with some GUI application every time I need to test a program on a microcontroller just doesn't cut it.
Both BOSSA and SAM-BA use the
to communicate with the microcontroller. I don't fully
understand this topic, but basically, the Linux kernel makes
even modern hardware look like a
from days of yore. User space programs can access such a device
via a file in the
/dev directory. Microcontrollers
seem to end up as a
/dev/ttyACM* file, for example
Now, if a device is presented to me as a file, I should be able
to use standard tools like
echo to talk to the device, shouldn't I? Well,
let's try it. Follow these steps:
- Connect the Arduino to your computer via USB, using the native USB port on the board. That's the one closer to the reset button.
- Press the erase button for a few seconds.
There should be at least one
/dev. If there are multiple, pick one that looks right and re-try the following steps until you figured out the one that connects to the microcontroller. I'll use
/dev/ttyACM0as an example in the following steps.
Start a background process that will print anything the
cat /dev/ttyACM0 &
Tell the bootloader to print its
echo V# > /dev/ttyACM0
You should see something like the following:
v1.1 Dec 15 2010 19:25:04
Now we know how to talk to the microcontroller directly, without using some complicated program that we don't understand as a mediator. I don't know yet where this will lead, but it certainly is exciting.
That's it for today. As always, the full code is available on GitHub. See you next time!