New 8-pin ARM Core: the STM32G031J6

It has been about nine months since ST released their new STM32G0 line of microcontrollers to ordinary people like us, and recently they released some new chips in the same linup. It sounds like ST wants this new line of chips to compete with smaller 8-bit micros such as Microchip’s venerable AVR cores, and for that market, their first round of STM32G071xB chips might be too expensive and/or too difficult to assemble on circuit boards with low dimensional tolerances.

Previously, your best bet for an STM32 to run a low-cost / low-complexity application was probably one of the cheaper STM32F0 or STM32L0 chips, which are offered in 16- and 20-pin TSSOP packages with pins spaced 0.65mm apart. They work great, but they can be difficult to use for rapid prototyping. It’s hard to mill or etch your own circuit board with tight enough tolerances, and it’s not very easy to solder the chips by hand. Plus, the aging STM32F031F6 still costs $0.80 each at quantities of more than 10,000 or so, and that’s pretty expensive for the ultra-cheap microcontroller market.

Pinout and minimal circuit for an STM32G031J6 – you only really need one capacitor if you have a stable 3.3V source.

Enter the STM32G031J6: an STM32 chip which comes in a standard SOIC-8 package with 32KB Flash, 8KB RAM, a 64MHz speed limit, and a $0.60 bulk price tag (closer to $1.20-1.40 each if you’re only buying a few). That all compares favorably to small 8-pin AVR chips, and it looks like they might also use a bit less power at the same clock speeds. Power consumption is a tricky topic because it can vary a lot depending on things like how your application uses the chip’s peripherals or what voltage the chip runs off of. But the STM32G0 series claims to use less than 100uA/MHz, and that is significantly less than the 300uA/MHz indicated in the ATTiny datasheets. Also, these are 32-bit chips, so they have a larger address space and they can process more data per instruction than an 8-bit chip can.

Considering how easy STM32 chips are to work with, it seems like a no-brainer, right? So let’s see how easy it is to get set up with one of these chips and blink an LED.

Step 1: Hardware Design

Good news, everyone! You don’t have to do any hardware design to get one of these chips running.

Companies such as Sparkfun and Adafruit sell generic SOIC8 breakout boards, which you can use if you don’t want to design your own PCB. All you have to do is solder one of these chips onto one of those, plug it into a breadboard, and connect a 100nF decoupling capacitor across the ‘VDD’ and ‘VSS’ power supply pins.

8-pin STM32 on a generic SOIC8 breakout board. Please ignore the silkscreen markings – they’re wrong because all I had on hand were some boards meant for 8-pin Flash, RAM, and EEPROM chips. I also soldered a small 100nF capacitor across the power supply pins, but you can use a through-hole capacitor plugged into your breadboard instead.

No other connections are required. Unlike most other STM32 chips, the G0 series does not have a BOOT0 pin which needs to be pulled to ground by default. And the ‘reset’ pin has an internal pull-up resistor which means that you can leave it floating. You should avoid leaving reset pins floating when you design a real PCB – ST recommends a 10nF decoupling capacitor – but it’s fine for this sort of testing.

Step 2: Blink an LED

We can use a simple ‘blinking LED’ program to test that we are able to upload code to the chip and debug it, but first we need to decide which pin to use. My first instinct was to use PA0, but that doesn’t work out-of-the-box because PA0 shares a pin with PF2, which is configured as the chip’s reset pin by default. I’m not quite sure how this works yet, but you can read more about it in the STM32G0 hardware development application note. Look for the section that talks about “multi bonding”.

Once you build a test program, you should be able to upload it normally using the SWCLK / SWDIO pins with an ST-Link debugger. At the time of writing, the open-source ST-Link project does not support STM32G031 or G041 chips, but you can either add that functionality using the same method described in this post, or use the official closed-source utility which ST distributes.

STM32G031J6 blinking an LED. This board is about the same size as the generic SOIC8 breakout board from the last image, but it has a diode, a 3.3V regulator, and a few capacitors on the reverse side.

So besides the fact that most of the pins share a few different GPIO signals, it looks like there aren’t many differences between coding for this 8-pin STM32 compared to its bigger siblings. That’s great!

Conclusions

This was a short post, because it turned out to be very simple to get started with these new 8-pin STM32G0 chips if you have a passing familiarity with other STM32 lines. And I am very excited to finally stop using AVR cores for throwaway hobby projects – it sure took long enough!

This is my first time seeing die pads with different functions connected to the same pins, though – that’s an interesting feature. I guess that it introduces the potential for new bugs, like if you pulled one pad high and one pad low to create a dead short inside the chip. But I also wonder if you could use it to make more fault-tolerant applications by setting things up so that, for example, the same pin outputs a PWM signal and uses a timer input to trigger an interrupt if that signal ever stops or changes frequency.

And speaking of random errors, I think that there is a small downside to the smaller 90nm process node that these chips use: they might be a bit more susceptible to cosmic radiation and EMI than their older siblings. I’m not too clear on this, and I would really appreciate any input from someone who understands the physics of these tiny transistors, but in my limited understanding smaller process nodes are more likely to see unwanted bit-flipping in a noisy environment. I think that as they get smaller and more power-efficient, each transistor’s gain increases and it takes less energy to influence the gate or base, and in some cases a tiny charged particle barrelling through the atmosphere can be enough to flip a bit. Does that sound right?

Anyways, I hope that this was helpful. Please let me know if you do use one of these in place of a PIC or AVR – I’d be interested to see how well they compete in practice for people who are loyal to their favorite cheap/small MCU core. And if you do really like AVR cores, I am sorry for the dismissive tone in this post.

Comments (2):

Sai

September 21, 2019 at 8:38 am

There seem to be so many alternative pin functions e.g.: B7/B8/B9 etc. How do they work?

Vivonomicon

October 15, 2019 at 2:07 pm

I think that ST tried something new with this chip, and bonded multiple pads on the chip’s “die” to a single pin. So when there are multiple pads listed (like B7/B8/B9/etc), it literally means that those pads are all connected to the same pin.

That means that if you’re not careful, you can damage one or more of the pads by configuring them incorrectly. For example, if you setup pins B7 and B8 as push-pull output and set B7 to ‘low’ and B8 to ‘high’, something bad would probably happen.

Related posts:

Across the globe, people seem to enjoy decorating their homes, communities, and outdoor spaces with lights and ornaments during the winter holidays. Maybe it helps with the depressingly early sunsets for those of us who don’t live near the equator. Anyways, I thought it’d be fun to make some ornaments with multi-color addressable LEDs last year, and I figured I’d write about what worked and what didn’t.

I didn’t have many microcontrollers at the time because I was visiting family for the holidays, so I ended up coding the lighting patterns for a cheap little STM32F103 “black pill” board which was in the bottom of my backpack. And it’s a convenient coincidence that I just started learning about the very similar GD32VF103 chips with their fancy RISC-V CPUs and nearly-identical peripheral layout, so this also seems like a good opportunity to write about how to cross-compile the same code for two different CPU architectures.

Pretty holiday stars! “Frosted white” acrylic sheets aren’t the best way to diffuse light, but they are cheap and easy to work with.

This was a fun and festive project, and it might not be a bad way to introduce people to embedded development since there are so many ways to drive these ubiquitous “NeoPixel” LEDs. Sorry that this post is a little bit late for the winter holidays – I’ve been traveling for the past few months – but maybe it’ll get you thinking about next year 🙂

I’ll talk about how I assembled the stars and what I might do differently next time, then I’ll review how to light them up with an STM32F103, and how to adapt that code for a GD32VF103. But you could also use a MicroPython or Arduino board to set the LED colors if you don’t want to muck around with peripheral registers.

I’ve written a little bit in the past about how to design a basic STM32 breakout board, and how to write simple software that runs on these kinds of microcontrollers. But let’s be honest: there’s still a bit of a gap between creating a small breakout board to blink an LED, and building hardware / software for a ‘real-world’ application. Personally, I would still want a couple of more experienced engineers to double-check any designs that I wanted to be reliable enough for other people to use, but building more complex applications is a great way to help yourself learn.

So in this post, I’m going to walk through the process of designing a small ‘gameboy’-style handheld with a GPS receiver and microSD card slot, for exploring the outdoors instead of video games. Don’t get me wrong, you could still write games to run on this if you wanted to, and that would be fun, but everyone and their dog has made a Cortex-M-based handheld game console by now; there are plenty of better guides for that, and many of those authors put a lot more time into their designs and firmware than I ever did.

Assembled GPS Doohicky. I left too much room between the ribbon connector footprint and the edge of the board on this first revision, so the display couldn’t fold over quite right. Oh well, you live and learn.

The board design isn’t too complicated, but there are several different parts and it gets easier to make small-but-important mistakes as a design gets larger. It mostly uses peripherals that I’ve talked about previously, but there are a couple of new ones too. The display will be driven over SPI, the speaker uses a DAC, the GPS receiver talks over UART, the battery and light levels will be read using an ADC, and the buttons will be listened to using interrupts. But I haven’t written about the USB or SD card (“MMC”) peripherals, and those will need to go in a future post since I haven’t actually worked them out myself yet. Note that SD cards can technically use either SPI or SD/MMC to communicate, but the microcontroller that I picked has a dedicated SD/MMC peripheral, and I wanted to learn about it.

Several years ago, a company called Future Technology Devices International (FTDI) sold what may have been the most popular USB / Serial converter on the market at the time, called the FT232R. But this post is not about the FT232R, because that chip is now known for its sordid history. Year after year, FTDI enjoyed their successful chip’s market position – some would say that they rested too long on their laurels without innovating or reducing prices. Eventually, small microcontrollers advanced to the point where it was possible to program a cheap MCU to identify itself as an FT232R chip and do the same work, so a number of manufacturers with questionable ethics did just that. FTDI took issue with the blatant counterfeiting, but they were unable to resolve their dispute through the legal system to their satisfaction, possibly because most of the counterfeiters were overseas and difficult to definitively trace down. Eventually, they had the bright idea of publishing a driver update which caused the counterfeit chips to stop working when they were plugged into a machine with the newest drivers.

FTDI may have technically been within their rights to do that, but it turned out to be a mistake as far as the market was concerned – as a business case study, this shows why you should not target your customers in retaliation for the actions of a 3rd party. Not many of FTDI’s customers were aware that they had counterfeit chips in their supply lines – many companies don’t even do their own purchasing of individual components – so companies around the world started to get unexpected angry calls from customers whose toy/media device/etc mysteriously stopped working after being plugged into a Windows machine. You might say that this (and the ensuing returns) left a bad taste in their mouths, so while FTDI has since recanted, a large vacuum opened up in the USB / Serial converter market almost overnight.

Okay, that might be a bit of a dramatized and biased take, but I don’t like it when companies abuse their market positions. Chips like the CH340 and CH330 were already entering the low end of the market with ultra-affordable and easy-to-assemble solutions, but I haven’t seen them much outside of Chinese boards, possibly due to a lack of multilingual documentation or availability from Western distributors. So at least in the US, the most popular successor to the FT232R seems to have been Silicon Labs’ CP2102N.

It’s nice to have a cheap-and-cheerful way to put a USB plug which speaks UART onto your microcontroller boards, so in this post, I’ll review how to make a simple USB / UART converter using the CP2102N. The chip comes in 20-, 24-, and 28-pin variants – I’ll use the 24-pin one because it’s smaller than the 28-pin one and the 20-pin one looks like it has some weird corner pads that might be hard to solder. We’ll end up with a simple, small board that you can plug into a USB port to talk UART:

Drivers for the CP2102N are included in most popular OSes these days, including Linux distributions, so it’s mostly plug-and-play.

It’s worth noting that you can buy minimal CP2102N boards from AliExpress or TaoBao for about $1, but where’s the fun in that?