STM32 Basics

A Bit of Etymology

The STM32 family of microcontrollers has a very obvious and unoriginal name : it’s made by STMicroelectronics and it’s 32-bit microcontrollers. I like it when a big corporation doesn’t waste effort coming up with esoteric product names or puns such as “Spresense” or “Raspberry Pi”. We’re technical people, a bunch of letters and numbers that obey a simple logic is all we need. I mean, I have trouble remembering the names of people I haven’t seen for a month, do you honestly expect me to remember fancy product names ? Know you audience !

STM32 are based on ARM Cortex-M processor cores. It used to be, each microcontroller vendor had their own processor core architecture, with their very own instruction sets, quirks and bugs. And that was sort of fine back in the days of 8-bit and 16-bit computing… but then came along 32-bit and I’m guessing that it’s the point where a lot of major players in the industry just said “screw it” and decided to license ARM technology so they wouldn’t have to design and maintain the hard part of their products any more. Smart move. Cardinal rule of engineering : don’t reinvent the wheel unless you’re getting paid to… and it turns out nobody wants to pay anyone to reinvent the 32-bit processor. This ain’t the 80’s anymore, Marvel movies notwithstanding.

You’ve probably heard of ARM, if only because it’s that name they keep mentioning about every smartphone you buy. ARM is a company that’s very good at designing very efficient processors, but has zero interest in actually making them. Instead, they sell their technology to anyone who wants to buy it. Modern smartphones run on Cortex-A cores, which are 64-bit processors very much similar to an actual computer processor : they run at several gigahertz and can use several gigabytes of RAM, and all of that is gobbled up by a Linux-based operating system that lets you play Angry Birds and YouTube videos. Or read this website, if your tastes are a bit less pedestrian.

The Cortex-M cores, however, are optimized for low-cost and energy-efficient microcontrollers. Some of them can also handle DSP (Digital Signal Processing). These days, you’re most likely to encounter four flavors : M0, M3, M4, M7. As you’d expect, the higher the number, the more badass the core. The M4 and M7 can also come with an FPU (Floating Point Unit), meaning they can do math on real numbers without resorting to slow software emulation. Because this is a logical world, such cores are called M4F and M7F. Such logic… this must be how it feels to be a Vulcan; well, except of course Vulcans don’t feel.

Concrete Example

Enough talk about corporations and galactic federations, let’s see what’s under the hood. We’ll start with something small, the STM32F303 (or F303, if you’re in a hurry). There are hundreds of STM32 devices : you may not know why just yet, but I haven’t picked this one randomly. You’ll find out if you stick around. Yep, that is a teaser.

Here’s what (one variant of) that chip looks like :

It’s known as a QFP-32, which stands for “Quad Flat Pack, 32 pins”. Engineers : reserving our imagination for what really matters, PowerPoint !

And here’s what’s inside that sexay boday :

And all this can be yours for the low, low price of two Euros !

Did I mention this is one of the smaller STM32 ? Don’t worry, though : one thing you need to know about MCU’s is that you’ll never eat more than half of what’s on the menu. There are two reasons : your intended application won’t need everything, and even if it did, many features will turn out to be mutually exclusive. Anything you don’t or can’t use is one less thing you need to learn about.

Another reason you don’t need to worry is that eventually I’ll publish on this website everything you need to know about this chip and its family. Granted, this might take me a long time.

Now, as you can see, the STM32F303 has a single 72 MHz Cortex-M4F core. That’s the part ST bought from ARM. Then they added everything else : the peripherals that make it a true microcontroller instead of just a processor.

Typically, you choose an MCU which mix of peripherals will meet the needs of your application. This ain’t no PC, you won’t be running a bazillion different applications on a single microcontroller. MCU’s tend to be monogamous : when an MCU and an application really like each other, they mate for life, exchange a special kiss, and several months later a single piece of code is born. It’s like the birds and bees, but with less bodily fluids and more lead-free solder. Ask your parents.

That being said, most MCU’s have the same sort of peripheral mix; you just get more or less of each. You’ll never find an MCU that has no timer, or no UART. It’s like Frenchmen and croissants. High-end devices will also have more advanced versions of the same peripherals. That’s why the F303 is a nice place to start : it’s relatively simple and should you outgrow it, you can keep your skills and just use the phrase “like on the F303 but better” six times a day.