I would like to tell you about the various microcontrollers out there. There are many out there, and I can impossibly describe them all. However, I will point out some interesting ones, especially for hobby projects, which also means, affordable. Quite a while ago I wrote about the Teensy 2.0. This is an Atmel ATMega32u4 based microcontroller. This board is available for US$ 16.00 at the official store. For a single board, this is still affordable but if you want a bunch of them, it’s getting costly. So, I went looking on eBay for ATMega32u4 boards. Results show up, starting at US$ 2.15 (at least, today… back then… I don’t know what the price was) Well… it’s an Arduino Pro Mini clone. I’ve never looked at the Arduino platform, not then, not now. But don’t mind the Arduino in the title, it’s just an ATMega32u4 soldered to a board. But this gave me the idea to search for Arduino in stead, leading me to Arduino Mini Pro boards. These are ATMega328p chips soldered to a board. They start at US$ 1.86 at eBay and US$ US $1.50 at AliExpess.

Now… let’s have a look at the hardware. Both microcontrollers are part of the Atmel AVR family. This is an 8 bit microcontroller. The first time I came in contact with this family of microcontrollers was during my education at Fontys University of Applied Science. I did a project involving an AT90USB1287 microcontroller. This project involved USB communication, controlling an KS108 based LCD display, and passing data to an FPGA. This project is also the thing that made me distrust abstraction layers. The thing was, I’ve implemented the KS108 display, working as a charm, then I added the USB support, using a library provided by Atmel, and the display stopped working, the timing was way off. This all happened many years ago, 2008 or something, I don’t know. But the thing is…. it messed with my timings… and that made me distrust abstraction layers, and this is the reason why I keep away from the Arduino environment. It’s not specific against Arduino, but I’m just afraid such an abstraction is doing stuff behind my back, writing to some register values I am not aware off, breaking stuff I am trying to do.

Well… let’s have a look at the hardware. For both ATMega32u4 and ATMega328p we have a core that can run at multiple speeds. It can run up to 8 MHz when powered at 3.3 Volts and up to 16 MHz when powered at 5 Volts. The boards sold at eBay are generally configured to run at 5 Volts and are equipped with a 16 MHz crystal. A divisor can be configured, thus it is possible to run the board at a lower speed, thus operation at 3.3 Volt is possible. As setting this divisor is a run time operation, it will power up at 16 MHz in default state. However, an ATMEL AVR microcontroller has so called fuses, these are configuration bits that determine the power up sequence. One of the options is to start the MCU with a divisor of 8. This will bring up the board at 2 MHz, which is fine for 3.3 Volt operation. Teensy boards ship with this option enabled by default, however boards from eBay generally come with this option disabled.

To program an ATMEL AVR microcontroller, there are several options. A chip can have a bootloader installed, allowing it to program itself. The microcontrollers from the Teensy series, which USB, come with a proprietary boot loader. However, this bootloader implements the USB DFU protocol, the bootloader protocol according to the USB specifications, allowing it to be used with standard programming tools. Back at the project at Fontys, I had a microcontroller boards directly from AVR, which shipped wit the Atmel FLIP bootloader, another proprietary bootloader, also implementing the standard DFU protocol. The ATMega32u4 microcontrollers from eBay implement some USB CDC protocol. They enumerate as a serial port, implementing an Arduino-specific protocol. (Yuck…. use the fucking standard protocols, damnit). I don’t use the Arduino enviorement, and even though avrdude (a software to program Atmel AVR chips) is supposed to implement this protocol, I haven’t been able to communicate through this USB Serial port it provides. The ATMega328p based boards, obviously, don’t offer USB support as they lack an USB port. (There are boards out there which have an USB to serial converter on boards, but I am not considering those.) When using those with my own USB-to-serial-TTL-boards, I am able to program them using avrdude and the arduino protocol I mentioned.

There is also a way to program an Atmel AVR board using an external programmer, implementing the Atmel ISP protocol. There are open source projects to turn an ATMega328p into such a programmer. An ATMega328p programming another ATMega328p, quite nice to see the programmer is equal to the device being programmed. All the projects I’ve seen so far use the Arduino environment, so, this is the one and only time I’ve used the Arduino IDE, to compile an Atmel ISP programmer. The programmer is connected to an USB-to-serial-TTL board, and then avrdude is used to program the target board. The connection between the programmer board and the target goes over the SPI pins of both boards, and uses an Atmel proprietary protocol. One thing to keep in mind, the ISP protocol only allows programming, but not debugging.

Another search on eBay lead me to STM32F103C8T6 boards. eBay sellers also mention “Arduino” in their titles, but don’t be distracted by that. We are talking about an ARM. This is a ARM Cortex-M3 microcontroller, 20 KiB RAM, 64 KiB Flash, running at 72 MHz. And these boards are selling for US$2.13 at eBay, and even less at AliExpress, US$ 1.67 at the time of writing. Dirt cheap, and free shipping, no kiddin’. I would like to add a note about free shipping when ordering at AliExpress. It seems, when ordering 3 or more, they do charge shipping costs, but 1 or 2, they don’t. So I suggest to place multiple orders at different sellers if you like to order more then two boards.

To program these boards, an SWD programmer is required. (Stricly speaking, it is not, there exists a built-in bootloader, which enables programming over a serial interface, this requiring an USB to Serial (TTL level) adaptor. I have not tried this method). For about US$2, you can get a “ST Link V2” on eBay or AliExpress. (The price is similar…. but so is the hardware, another case of the same hardware being both programmer and target)

Basically, in the same price range, we have a 16 MHz 8 bit microcontroller and a 72 MHz, 32 bit microcontroller. So, I would say, this looks definitely interesting. Another thing to keep in mind, the SWD protocol does not only allow programming, but also debugging. SWD is an industry standard protocol, meaning many debuggers are available, ranging from the $2 to professional programmers which can cost a couple of hundreds, or even over a thousand dollars. But well, I’m talking about hobby usage so let’s stick to a $2 ST-Link for now. Programming and in circuit debugging.

There is much more to say about these chips, their programming environments, their debugging environments, properties of their architectures, etc. etc. There are more architectures and chips I would like to discuss, there is more coming in follow up articles, thanks for reading so far,

cheers,

André

«