The big ARM adventure – part 1

I’ve been programming 8-bit micro controllers for some years now. I started with PIC (PIC16F628, like everybody else), bought a PicKit 2 (because that did work on a 64-bit OS) and started coding in CCS C. Looking back it’s all terrible but it got me going. Of course I can across some AVR code but I never used it until the whole Arduino revolution. A friend wanted to do some stuff with Arduino so I helped him out and I started looking at Arduino myself. Mostly because you can buy Pro Mini’s (with all components already on a board) so dirt cheap from China it really is a no-brainer. I looked at some 32-bit stuff and bought some Ti Launchpads etc. But never really got my head around it and because I never needed it I stayed with 8-bitters.

Then I came across a post on Hackaday about repurposing a AVR-programmer as a USB Arduino. I’ve seen those modules thousands of times on eBay but never bought one. (I use a Arduino as ISP.) Although the hack is neat I don’t find it very useful because of the limited I/O. For less you can just use a Nano with a lot more I/O. (Okay, you can’t present it as a HID or something else.) I started reading the comments to see how other people thought about it and then I spotted something that I found interesting. Especially the comment of [wongsta / drojf] about cheap ARM boards. So I fired up eBay and looked up that STM32F103C8T6 he talked about. And well be damned, even cheaper then the $3,50 he talked about. So I ordered a board right away. Together with a STlink v2 that was mentioned there.

Tool chain jungle

The Chinese moved fast this week and I received it within a week. The STlink is still on it’s way. And once you have it you want to program it! So started my search for a way to programming the device. And after digging around you really get to appreciate the Arduino work. It’s just such a simple and easy package to get going. In ARM land however things are not as easy. There is no real all round ecosystem for STM32. So this kept me busy searching for a couple of hours…

I first came across some pages talking about the LeafLabs Maple. Apparently the Maple was an early attempt to make a Arduino-ish ARM board. Complete with a forked Arduino IDE for the device. The Maple Mini used the same STM32F103C8T6 as the core and apparently that’s why you can now buy them in China. It’s a pity really that didn’t work out. But the site has some nice information about it but the IDE is a no-go now.

I’m still in researching about tool chains but here are some options I found. I didn’t really test any of those yet. Coming from 8-bit it’s kind of a lot to handle! I’ll just post them for reference now.

Because I fire up Arduino IDE almost daily and I want to have a Blinky quick I started with the STM32druino. I’m still planning on diving deeper into ARM, tool chains and debugging etc. But for now STM32druino seems to be a quick “cheap” to get it running. But it lacks any kind of debugger and that seems to me like a wonderful tool. But my STlink’s still in the mail so I’m stuck with serial for now.


So serial it is for now. I found that the STM32F103 comes with a bootloader so you can program the STM32. For the STM32F103C8 this can only been done via USART1 but higher models also it via multiple USART’s, CAN and DFU.

But then followed something about boot switches (or headers on my board). All said Boot0 should be 1 and Boot1 should be 0. Took me some extra reading to find out what it really did:

BOOT0BOOT1Boot mode
X0User Flash memory
01System memory (bootloader)
11Embedded SRAM

The state is checked at reset. A program is normally stored in the user flash so you select that to run it after programming. But I found that STM32duino did return to flash after programming so the program starts running after programming. So to start the program after reset BOOT0 needs to be 0. I didn’t dug deeper into the SRAM part of it.

On the photo, the upper jumper is BOOT0 and the lower BOOT1.


Installing STM32duino (I’m going to call it that) isn’t that hard. Just grab the zip from GitHub and extract it to the hardware folder inside your Sketchbook. It might have some problems with the newer Arduino IDE’s but I’m still at 1.6.4 because I find that to be a stable version and higher versions have all kinds of bugs. For the same reason I stayed on 1.0.6 for a long time. In 1.6.x the ARM compiler (used for the Arduino Due) isn’t installed by default. It’s needed for the SMT32 as well so you have to install it via Tools -> Board -> Boards Manager and install the Arduino SAM boards. At this time of writing I installed the latest version, version 1.6.7 which works fine.

Roger Clark (guy behind SMT32duino) up-loader two videos to YouTube about setting it up. Part 1 and the followup part 2.

So next up was to connect it to serial. I grabbed my CH340 and set it to 3,3V. (It’s a 3,3V device but apparently USART1 is 5V tolerant.) But then, where to connect? From the Maple pin map page I found it to be PA9 for Tx and PA10 for Rx. Later I saw the same in the YouTube video of Roger Clark and the YouTube video from Michael Steele about serial programming STM32F103. Because the CH340 isn’t really capable of supplies power at the 3,3V I just plugged in the USB to power it via it’s onboard 3,3V regulator. Because both connect to the same PC I didn’t connect GND. The PC doesn’t recognize the board by default. Windows cries out for “Device Descriptor Failed” when you plug it in.


I fired up the Arduino IDE and opened the board menu. It looks a bit different then all the YouTube video’s I saw but it’s only better. The boards are now neatly arranged and you can select board, variant and upload method in separate menu’s. So I selected Board: Generic STM32F103C series, Variant: STM32F103C8 (20k RAM, 64k Flash) and upload method Serial. By now I selected BOOT0 to be 1 and BOOT1 to be zero. I gave the board a reset (to enter the bootloader) and I hit upload. The code compiled and it uploaded like a charm! Whooohooo! I had a blinking led!

I didn’t really went any further the this for now. But I opened up some of the core files to see how things are done. Apparently it’s all based on the libmaple from Leaflabs and a Wire style API is added to make it Arduino proof. While browsing some files I came across the usb_serial files. Apparently USB serial is assigned Serial if SERIAL_USB is defined. So I defined it and initialized Serial.

#define SERIAL_USB

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin PB1 as an output.
  pinMode(PC13, OUTPUT);

// the loop function runs over and over again forever
void loop() {
  digitalWrite(PC13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(PC13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second

After this I indeed have a Maple Serial port. I must say I did “install” the Maple drivers by running \hardware\STM32\drivers\win\install_drivers.bat.
I wasn’t quickly able to send data over it (maybe baud rate issue) but at least that keeps Windows quiet when you plug it in.


That’s it for now. I will investigate more about STM32 etc. But all the info is just scattered all over the internet. It’s just not that easy to get it up and running. That’s why I wanted to document my findings on the STM32F130 in a single place. I hope this way other people can get this board up and running much quicker then I did… If I go deeper down the rabbit hole I’ll make a part 2 (3, 4…) so others can get to know the device as well. I will end this post with some random bits of info I found.




Extra links which I don’t mention in the text.

Dangerous Prototypes – STM32 ARM quick start
ST Application note – STM32 microcontroller system memory boot mode (PDF)
Kevin’s blog – Getting started with STM32 microcontrollers
STM32 tutorial part.1 – Set up a project in KEIL ╬╝Vision (YouTube)
Getting started with STM32 using MDK-ARM IDE from Keil (YouTube)
[pic18fxx]’s STM32F103C8 with Keil (YouTube)
Electronic Wonders – STM32CubeMX
LeafLabs Maple board info
STM32druino Wiki

One thought on “The big ARM adventure – part 1

  1. I’m working on mbed framework support for stm32 blue pill boards, as they already have support in ChibiOS. It’s very similar to one of Nucleo boards (less flash and some pins missing).

Leave a Comment

Your email address will not be published. Required fields are marked *