A wise grizzled old engineer once told me that the most important rule of embedded engineering is, “Always use quality tools.” Without quality tools that you can 100% trust, you’ll never be certain of the source of a problem. You’ll constantly be asking yourself, “Is it me or is it the tools?” I’ve validated this engineer’s axiom multiple times, staring for glacial epochs staring at code which should work but doesn’t. I once spent a solid month tweaking and tweaking simple code only to find in the end that a manufacturer’s compiler was incapable of executing logical shifts correctly. I’ve vowed in the past never to suffer again and I reinforced my opinion during this microcontroller selection process. That’s a later part of this story. First, let’s look at how I started this selection process.
The Contenders: Atmel vs. ST
In choosing a microcontroller for the synth cube project, I basically looked at the two companies I know the best, Atmel and ST Microelectronics. I struggled with the decision at first, but now that I’m down the road, I’m not looking back. They’re both fine manufacturers and, for different projects or different people, I might recommend one over the other at different times. For this project and probably for here on out for me, only one micro could reign supreme.
Atmel AVR: The Good and The Bad
I’ve been intimate with Atmel for many years through the AVR line of micros. I used the 8-bit ATMEGA micros for my first synthesizers and I played with the 32-bit AVR32 micros for the Illmatic sequencer. You can read about my selection of the ATMEGA for Rockit here. I’ve built a solid relationship with AVR micros and they’re a great choice for many reasons.
Atmel studio = Open Source Happiness
Atmel is an appealing solution for the open source enthusiast. The GCC compiler integrates seamlessly with Atmel Studio with one click compilation and programming. Atmel Studio, since version 5, now 6, is hands down the best microcontroller development environment I’ve ever used. It’s available for the right price, free, and is based on Microsoft Visual Studio, which is rightfully awesome tool. My favorite feature is never having to remeber variable or function names. You just start typing and it offers suggestions. It sounds simple, but it speeds up the process so much that you’ll miss those little suggestions dearly when you have to live without them. Atmel also provides, like most manufacturers, a very nice standard library and sample projects that greatly accelerate the startup process. With Atmel Studio, you can go from nothing to running in hours without having to dwell on the intricacies of compilers, linker scripts, startup code or any other embedded matters that are generally toxic to quick development.
AVR micros provide an excellent low cost entry point for the hobbyist and have proven popular particularly because of their use in Arduino boards. However, the case for AVR becomes decidedly less rosy as you move from hobbyist to certified maker. Where AVR isn’t competitive, at least in sub-100,000 unit volume, is cost. AVR micros are expensive relative to competitive chips from ST and Atmel offers no decent price break for volume in my production range. For instance, an AVR32 chip, the AT32UC3A1128 is $6.34 on Digikey with no break on price above 100 pieces. An STM32F103CB, a comparable micro, is $4.99 at 100 pieces and the price falls to $3.51 at 2,000 pieces with likely breaks for volumes above that. For a small manufacturer of a niche product, this presents a serious problem. Using Atmel micros will add several dollars to the price of my product or reduce my profit by that amount should the market not bear my higher price. For a small manufacturer, profit really means what buys food and shelter. This is pretty much a dealbreaker. No matter what other advantages there are, cost is king.
As I mentioned, ST is the price leader. Not just for 32-bit micros, but down the line to the 8-bit STM8 as well. I’ve used STM8 micros for years. They’re in the millions of battery chargers and power supplies that I’ve designed. Pricing on STM8 micros borders on ridiculous with pricing for totally useful chips in the low tens of pennies range. No other manufacturer comes anywhere close. Believe me, I’ve looked.
For the STM8, ST does provide a development environment, ST Visual Develop, but it’s nowhere near the quality of Atmel Studio. And they don’t make a compiler, leaving you at the mercy of third party vendors. They’ll get you hooked with a free compiler for small code sizes, but start charging you for an unlimited version. For the STM32, they don’t offer any IDE at all and leave you to find your own way. This is by far the greatest problem with using an STM32 microcontroller. For a rookie, this challenge may very well be unsurmountable. The initial learning curve of embedded development is a steep one. Without some serious cash, you’ll be at the mercy of the internet to figure out how to get started. If you’re well-funded, you can buy a Keil IDE and compiler for many thousands of dollars. It will work beautifully, just like Atmel Studio, probably even better, but few of us have thousands of dollars to relish on our hobbies. So, what’s a broke electronics nerd to do?
Fortunately, some pioneering and enterprising individuals have developed a way for the poor embedded masses to access powerful chips on the cheap. Eclipse is an open source development environment that can be used for a huge variety of projects, from Java x86 GUIs to lowly microcontrollers. Being open source, developers can make plug-ins and drivers to make Eclipse speak the right language to compile, program, and debug STM32, and any other ARM-based microcontroller as well. The open source nature has a side effect though. Not being developed by a single cash-loving entity, it’s a piecemeal approach. You’ll have to get the compiler from over here, find a linker script there, figure out the startup code, dabble with a library, and on and on. What was a small investment of a few hours to get Atmel Studio running can stretch to days or weeks with an open source approach to STM32. You’ll learn a lot in the process if you get to the end, but you may just give up before you get there. There are a number of tutorials on the web, but I found them to be lacking and sometimes conflicting. So, after a week of struggling with the fully open source approach, I started looking for alternatives.
Low Cost IDE
Some enterprising companies have noticed the gulf between basic open source Eclipse and Keil, and offer some intriguing alternatives, which work well and won’t end your marriage when the credit card bill arrives.
Mikroelectronika is a popular and cost-reasonable option. At $249 for the compiler, IDE, and some libraries, it can be money well spent. The libaries provide easy-to-use functions for handling most basic tasks. The problem for me is that these libraries are proprietary and not internally debuggable. And, MikroC is their internally developed compiler, which makes it unique and less likely to be interactive with open source libraries designed to work with GCC.
For these reasons, I chose to go with Code Bench from Mentor Graphics. Code Bench also comes with optimized run-time libraries which reduce code size, particulary for some of the more space hungry functions, like malloc(). I also wanted to learn more about using an RTOS, preferably an open source free one, and those are much more likely to be designed to work with GCC. Code Bench costs a little bit more, $399, but it just better met my needs, so I didn’t mind the extra cost.
STM32 IT IS
So far, developing with Code Bench and STM32 has been a lot of fun, especially since I ported over FreeRTOS. I’ll be back with a post about FreeRTOS and getting it running with STM32. If you’ve got the patience and the will, learning to develop with STM32 can be a worthwhile endeavor, particularly if you’re interested in developing a product that you intend to sell. The cost alone makes the effort worthwhile and just think how big your brains will be after all that learning! I’m doing neck exercises just to support all this new information.