Meet the STM32 Primer2

Obligatory disclaimer: I’m a “hardware guy”, not a software guy. I learned – taught myself, actually – BASIC in… 1984, or so, on a Commodore VIC-20. I learned PASCAL years later, on an Apple II. Many years after that – we’re talking 1994 or so, maybe – I learned a little bit of LPC. In about 1995, I learned HTML, and that was pretty much the end of my development as a coder or scripter. I understand the basics, but as far as actually writing code in anything other than (X)HTML, I’m rustier than the Lusitania.

Anyway.

Way back in the day when men were men and women were women and “microcontrollers” were arcane, obscure, and expensive, there were pretty much two and a half flavors of the things: the venerable BASIC stamp, the equally venerable PIC, and the good old 8051 family of microprocessors, which were used by Real, Serious Programmers and hardly accessible to the amateur.

If you were going to become a microcontroller programmer, you could advance from one platform to the next as you went on, gaining access to slightly more impressive hardware along the way.

But why bother?

That was always my attitude. Oh, you can build a giant rat’s nest of wires of a breadboard, and make your little microcontroller flash an LED, or something? Big whoop. Now, obviously there was, and is, a lot more that you can do with a microcontroller than just blink an LED or three, but back in the pre-internet era, that meant (relatively) Big Money, at least to a half-starving college student.

Several years ago, the “Arduino” came around, and kind of challenged my perceptions – and those of a lot of other people – about what you could do with an 8-bit microcontroller. Millions of the things have been sold, and people all over the world have… made LEDs blink with them. (I kid, I kid. A little bit.) An Arduino or clone will set you back $25-50 USD, depending on the model and where you get it from, and pretty much anything you want to do beyond the three LEDs onboard requires yet more hardware to be interfaced, at yet more cost to the end-user.

Now, to be fair, there is a tremendous volume of resources on the web about interfacing an Arduino with everything from a piezo buzzer to a nixie display tube to a television to an airplane, which is quite impressive. But it doesn’t really change the fact that an Arduino doesn’t do much of anything all on it’s own, or even tethered to a computer, and I can’t help but wonder how many people who bought one tossed it into a drawer after an hour or two and never looked at it again, because of the perceived limitations of the basic development platform.

That brings me around to STMicroelectronics’ STM32 microprocessor, and (one of the) development platforms for it.

The ST32 is a family of ARM Cortex-M3 32-bit microcontrollers, introduced a couple of years ago. Most are capable of running at speeds up to 72MHz, about 4.5 times as fast as most Arduinos. They’re fairly powerful devices that pack a lot of features, are fairly power-efficient, and relatively inexpensive.

The downside, alas, is that if you want to program one, you’d pretty much have to learn C. Until recently, anyway. A group called Leaf Labs have started porting the Arduino programming environment over to the STM32 architecture, to go with their Maple device, which is a bit like an Arduino on steroids.

This is cool, because it makes a fairly powerful modern 32-bit ARM-family microprocessor accessible to the great unwashed masses, for around $55 USD, shipped. But, as far as I’m concerned, it still lacks a certain something, because there’s still almost bugger all you can do with one on its own.

Well, meet the STM32 Primer2, which I really really hope might be thing that rocks the microcontroller hobbyist world.

For the same price – about $50 USD – you get a vaguely cellphone-shaped, quasi-ergonomic device with an STM32 processor in it, a color LCD touchscreen, a five-way joystick, four buttons, a three-axis accelerometer, a microphone, a speaker, an earphone jack, a microSD port, two LEDs, an IrDA port, and a built-in rechargeable lithium battery. Which, I might add, runs a somewhat Unix-like real-time operating system, and is programmable via USB with no other special hardware required.

STM have been pushing this device as a “fun, innovative development platform” and a “complete, low-risk environment” for designing applications around their STM32 chips. And why not? As a hardware hacker, this thing is pretty awesome – there’s a lot of potential there, and the price is stellar. There’s even an expansion header inside so that you can easily interface your own peripherals.

The only downside is that they kind of, from the hobbyist market perspective, flubbed the support for this thing. It’s not really ST’s fault; as far as I can tell, they never really wanted to support or target the college-student, basement hobbyist experimenter market in the first place. Professional engineers looking for an affordable rapid-prototyping platform, on the other hand… sure. Need noob-ish support? You’re out of luck, sorry.

That said, I’ve been playing around with one quite a bit since last week, and I’m increasingly impressed with it as a development platform for the hobbyist. I’m not one to get my undies in a bunch about whether something is open-source hardware, and I’m not one to go whining about the limitations of the GPL, or whatever. I think of it as a piece of inexpensive commercial hardware that just happens to be relatively easy to hack on.

CircleOS, the real-time operating system that comes preloaded on the Primer2, is actually surprisingly easy to work with – maybe even (dare I say?) easier than the vaunted Arduino. Don’t believe me?

On an Arduino, if you want to blink the LED – the “hello, world!” of microcontroller code – you wind up writing something like this:


int ledPin = 13; // LED connected to digital pin 13

void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}

void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}

Not too terribly hard to follow, right?
On the Primer32, with CircleOS, alternately flashing the two LEDs looks something like this:


(
toggle_count++;
if ( toggle_count >= max_toggle_count)
( toggle_count=0;
CurrentLedMode = (CurrentLedMode == LED_ON) ? LED_OFF : LED_ON;

LED_Set ( LED_Green, CurrentLedMode);
LED_Set (LED_Red, !CurrentLedMode);
)
)

(Both bits of code shamelessly taken from sample programs on the WWW.)

Practically human-readable. Obviously the Primer2 cheats a little bit, courtesy of its homogenized hardware design and the C libraries for it, but for the hobbyist who’s just fooling around, nigh-endless amounts of flexibility and control probably aren’t as important as the Open Source Ninjaz would like you to believe. And to be fair, the hardware design is public, so directly copying some of the peripheral setups in another product wouldn’t be particularly challenging.

So, in short: The Primer2 is a very spiffy and undeservedly unpopular piece of hardware well-suited to hacking on, and is an excellent bargain for anyone unencumbered by irrational FOSS biases. If you enjoy playing around with microcontrollers, go buy one, already!

The Primer’s website is here, when it’s up. The STM32 microcontroller’s page is right here, which includes links to all the gory technical details, if things like “512kB flash, 32kB RAM, three 12-bit DACs” and so on are exciting and/or meaningful to you.

Published in: Geekiness, General | on September 22nd, 2010| 2 Comments »

You can leave a response, or trackback from your own site.

2 Comments Leave a comment.

  1. On 5/14/2012 at 10:18 pm Raihan Said:

    Hello
    are you familiar with Circle OS or Ride 7 that come with stm32?

  2. On 5/29/2012 at 4:30 am Nicholas Said:

    Hello,

    I need a help with my STM32-Primer2+MB850 kit.

Leave a Comment