Not the best of the designs, part 3

Knowing the u-controller at least powers on, we can encouple it with a programmer.

Chicken & egg

Atmel has a more than exorbitant price for their programmers, which makes absolutely no sense, not only given the production cost, but, from the point of view of someone that barely knows programming, or someone who’s starting to learn it, it’s a useless investment. Sure, if you were to ask them, maybe it’s ‘at the cost of a “coursebook”‘, because either daddy or the bank must pay for it. And you can always buy their premade board, their software and their books, and never learn a thing a all, but, hey, you get a bachelor’s with that1!
stmprog.jpg
Thanks to this blog post I have a functional programmer.

I won’t picture the wiring but: 3.3V goes to Vin, GND to obvious, SWDIO and SWCLK go to PA31&30 as per the datasheet.
stmprog2.png

Openocd

While man openocd should be just enough2, the documentation, or, rather, the useful commands are sparser in the documentation than StackEx, so you might want to install openocd and them simply navigate the scripts folder.

Editing /usr/share/openocd/scripts/interface/jlink.cfg might be of interest, since the JLink clone can’t do JTAG, and the used protocol shall be SWD, so adding transport select swd eliminates the need of this variable in the command.
stmprog3.png
stmprog4.png

Blinky

I’ll copy this for blinking purposes, which is

atmelstudio1.png

You might want to check the pinout against the datasheet.

After building the project3, the command sequence in openocd is:

reset init
flash write_image file.hex 0
reset run

alternatively,

reset halt
flash protect 0 0 0 off
flash erase_sector 0 0 0
flash erase_sector 0 1 1
flash erase_check 0
flash write_image file.hex 0
reset run

And, for the sake of 2000s, begifs

blink.gif

I’m pretty sure you’ll appreciate my test lamp made out of a led and a resistor.

testlight.jpg

Some useful links

-the microcontroller’s footprint;
-some code examples;
-how do I openocd erase;
-this gpio tutorial;
-AS 6.2 & ASF.

Footnotes

  • ^1 that’s exactly the average coursework for a Bachelor’s in Electronic Engineering, except most universities actually accept Arduino;
  • ^2 ‘rtfm’
  • ^3 Atmel Studio 6.2 works just about fine in a WXP VM.