Blog for my various projects, experiments, and learnings

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.

STM32G031J6 schematic

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

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”.

The full test code that I used is available in the same GitHub repository as my last STM32G0 post; I won’t go over it in detail because it looks very similar to the examples from my previous STM32G0 post.

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 LED

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):

  1. 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?

    Reply
    • 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.

      You can find more information in section 4.3.4 (‘Multi-bonding’) of this document: https://www.st.com/resource/en/application_note/dm00443870.pdf

      Reply

Leave a Reply

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