A development board for an STM32G081 MCU Jul08

Tags

Related Posts

Share This

Project Difficulty

Recent Posts

A development board for an STM32G081 MCU

I’ve been an avid user of ST’s F0 series ever since it was launched. The 48MHz Cortex M0 is almost always the perfect MCU for every project that I tend to build and it’s so easy to program and debug that, for me, it’s the default answer to ‘which MCU should I use for this project?’ So when I noticed that ST had launched a ‘G0’ range I just had to have a closer look.

What’s the difference?

In short, there’s a Cortex M0+ core at the heart of the G0 series instead of the M0 that’s in the F0. To find out the difference between the M0 and the plus we have to visit ARM’s website.


Cortex M0+ block diagram

There’s a slight increase in performance and an optional Memory Protection Unit (MPU) that the RTOS guys may get excited about but really there’s not much else in the way of additional features.

The headline claim made by ARM is a further decrease in the already class-leading power consumption and a scarcely concealed attack on the remaining market for 8-bit MCUs. ARM really want you to choose this core for projects that might previously have used an 8-bit device.

A shorter pipeline

One interesting way that they’ve managed to decrease power consumption is by reducing the number of clocks required for the instruction pipeline from three to two by squashing the instruction decode stage across the two clocks and reducing the need for power-expensive access to flash memory.


Pipeline clocks and stages

I have to say that I’m not convinced that this is a good thing for performance. The marketing blurb correctly states that a shorter pipeline increases responsiveness but we engineers will immediately point out that faster response means lower throughput. High-end devices such as the Intel i7 have more than 20 pipeline stages and even ARM’s own Cortex-M7 has 6 stages.

However, ST have given us more features that I think will make the G0 series the default choice for my future designs.

F0 vs G0

Clock speed. You can’t fail to notice that the maximum clock speed for the G0 is 64MHz compared to 48MHz for the F0. The cynic in me says that this is compensation for the performance hit incurred by shorter instruction pipeline.

Flash memory. The F0 goes up to 256k. ST has plans for the G0 to go up to 512k but so far they’ve only released the G071 and G081 that go up 128kb.

SRAM. The F0 goes up to 32k. The G0 improves slightly on that with 36k. More SRAM is always good so that’s a welcome improvement.

Price. They’re about the same. If I compare the STM32F091RBT6 to the similarly spec’d STM32G081RBT6 then they come about about the same with the G0 edging it with the 36k SRAM and 64MHz maximum clock.

ST’s development boards

At the time of writing ST are offering two development boards. There’s the low cost G071 Nucleo that features a degree of Arduino compatibility though goodness knows why they bother with that.


The G071 nucleo board

At just $10 the Nucleo is really cheap and a great way to kick the tyres of the G0 series if you want to get started really quickly.

The other board on offer is a full-featured eval board featuring the STM32G081RBT6 MCU and costing an eye-watering $400.


The G081 eval board

To be fair, for that $400 you do get a ton of peripherals to play with. If your employer is paying then this might be the board you want to buy.

I almost bought a Nucleo board but then reconsidered and decided that the best way for me to learn about the ins and outs of the G0 would be to build my own development board. So that’s what I did.

My development board design

I decided that I’d go for the following features on my board.

  • STM32G081RBT6 MCU with 128k/36k flash/SRAM in the LQFP-64 package.
  • All GPIO pins to be available on top pin headers, grouped by port and ordered by pin.
  • All pins also to be available in breadboard-friendly 100mil spaced headers on the bottom of the board.
  • Three selectable power supplies: 3.3v, 2.5v and 1.8v.
  • Three user LEDs routed to ports that have timer outputs available so flash/fade effects can be protyped.
  • A third-party USB-to-serial IC will connect an MCU USART to the outside world through a mini-USB port.
  • External 8MHz HSE oscillator so that the USB-to-serial IC can be used at high speeds.
  • External LSE 32.768kHz oscillator for RTC use with backup coin-cell battery.

The STM32G081RBT6 was selected because it’s currently the biggest one that ST have released and it always helps to have the most resources available on your dev board.


The 64-pin G081 IC

When it comes to transferring your design from the dev board to a custom PCB then that’s when you can downsize to a device optimised for your resource usage.

I decided right away that the pin headers would expose every GPIO port and pin group and the headers would be grouped by port and ordered by pin. I’m seriously bored with hunting for pins on development boards that have been ordered to facilitate easy PCB routing!

Pin headers will be provided on the top and bottom of the board, just like the ST Discovery boards except mine will have pins on top that are long enough to actually accept a jumper wire without them falling off because they’re too loose.

A selectable power supply has always been something I’ve wanted from a development board. If my project is standalone then I’ll probably run it at 3.3v but there are times when I need something else. For example interfacing with an FPGA might require 2.5v and a battery-powered design might be spec’d to run at 1.8v to optimise power consumption.

A standalone IOT device might be required to keep accurate time so I decided to include a 32.768kHz LSE oscillator and the associated backup battery. This will be a 3v CR1220 coin-cell.

It’s quite common for an MCU to have to connect back to something more powerful such as a PC or Raspberry PI so I’ve included a USB-to-serial device – the cheapo CH340E – on my board. To enable driving the CH340E at high data rates I’ve included an 8MHz HSE oscillator so that the MCU peripheral clocks will be as accurate as they can be.

The CH340 saga

I’ll start with a confession. This is my second attempt at building this board. The first attempt was largely the same as the second except that first time I used the CH340G instead of the CH340E. And the CH340G didn’t work.

The CH340/341 series are a family of USB to serial converters that fulfil the same role as the much more well known FTDI chip that you can find on official Arduino boards. The CH340 is made by a Chinese company, WCH, and is much cheaper than the FTDI chip. I bought my CH340’s for about £3 for 10 on Ali Express. The internet says good things about the CH340 so I felt confident.

The CH340 is actually a series of ICs that come in different packages that provide different levels of functionality. The datasheet is all in Chinese but has been translated to English and can be found here.


All the CH340s (so far)

The 340G is the first one that I bought, and it arrived in packaging that I would not describe as confidence-inspiring.


Loose packed ICs

Nevertheless I made a board with it and selected a good quality Abracon surface mount 12MHz oscillator to support it. Unfortunately it would not enumerate as a USB device. I think it was having trouble getting the oscillator to start as I couldn’t detect a signal coming from it and I’m fairly sure my probes weren’t loading the crystal down as I could probe another, similar oscillator on the board. On power up I could see short spurious waveforms come from the oscillator but they never stabilised and the output always went flat.

I tried higher load-capacitors, then lower. Then a new CH340G. Nothing worked and I was out of options so I decided to cut my losses, and my time, and replace the CH340G with the CH340E that has a built-in oscillator and requires only decoupling capacitors to use it. I could of course have switched to an FTDI but that would be giving up and I wasn’t ready to do that. Unfortunately the IC package was different so I also had to redesign that part of the board.

Three weeks later and the new boards arrived and so have the new ICs, again from Ali Express. This time though the packaging was much more like they’d actually come from a production reel and not some trader’s back pocket.


Proper IC packaging

We’ll see how I get on later in this article, but now let’s have a look at the schematic for the development board.

Schematic


Schematic image

Click on the full image to see a PDF of the schematic. It’s quite a modular design so let’s break it down into its parts.

The power supplies and the USB interface

I wanted to have a choice here and linear regulators are cheap so I designed in three of them to give power supply options of 3.3v, 2.5v and 1.8v. A jumper is provided to select the desired level. Since the power input comes from the potentially very noisy 5V USB line I’ve included my usual filter network consisting of a ferrite bead and some capacitors.

The USB interface is provided by a mini-B connector. I only ever use the mini-B or the full size B connector on my boards because they’re the most reliable. The micro-B connector used by most smartphones before they started switching to type-C is too delicate and easy to tear off the board. The on-board components are protected from static by the USBLC6 IC that I include as a matter of course with every USB design.

The CH340E can only run at 3.3v and can be enabled with the P2 jumper. D1 ensures that when 2.5v or 1.8v are selected then that level does end up being routed to the VCC pin of the CH340. The voltage drop of that same diode also has the effect of making VDD for the MCU actually about 3.0 to 3.1v instead of 3.3v. Something to be aware of.

The CH340E only requires a pair of decoupling capacitors to run at 3.3v, one on the VCC pin and the other on the V3 pin. The use of the diode D1 actually means that the CH340E will be powered at 3.3v and the signal levels will be about 3.0v but that’s within spec so I don’t expect any issues.

The STM32G081RBT6 MCU

Here’s the heart of the system, the MCU. All the GPIOs are broken out to pin headers Except those that have crystals attached, though I don’t think those are any great loss to a designer.

External 8MHz and 32.768kHz surface mount crystal oscillators are provided as the HSE and LSE clock sources. There’s a reset button and the SWD programming interface is broken out to the ungainly 20 pin ARM connector that connects directly to my ST-Link programmer via the ribbon cable.

Three LEDs are provided that source current from the 3.3v supply regardless of the selected core voltage so that the brightness won’t vary — and in the case of the blue LED so it will actually light at all — when the supply is 1.8v.

ST have optimised the pins on the G0 series so that you get more GPIOs. In their older chips you’d find a pair of VDD/GND pins on each side of the package which I think tells you a bit about the internal floor planning of the device and how things are arranged internally on the die. This G0, however has a single VDD/VDDA pin and a single GND pin. VREF is there but they’ve done the decent thing and placed it right next to VDD/VDDA so you can tie them together and right next to those is VBAT, which obviously has to be separate.

I’ve designed in a coin-cell holder for a CR1220 3v backup battery, protected from reverse-current by a schottky diode with a low forward voltage. According to ST’s datasheet the worst-case current consumption for VBAT when VDD = 3.0v is 470nA. A quick look at Energizer’s datasheet shows that you can expect to get about 30mAh from it before the voltage starts to drop off. 0.00047mA into 30mAh gives 63829 hours or 7 years. I’m sure there are other losses and inefficiences to consider but still, that’s a long time.

IO connectors

They’re all there with the exception of those used by oscillators. One of the great things about ST’s package redesign is that there are now more GPIO pins available. GPIO ports A, B and C are fully available although in my design PC14 and PC15 are taken by the 32.768kHz LSE. This is great for designs that might need to bit-bang a parallel bus. GPIO port D has pins 0 to 9 available.

Bill of materials

Here’s the full bill of materials for this project.

IdentifierValueQuantityDescriptionFootprintComment
B11CR1220 holderCustomavailable on ebay
C122µ1Polarized Capacitor (Radial)CAPPR2-5x11
C2100µ1Polarized Capacitor (Radial)CAPPR2-5x11
C310n1Capacitor0603
C4, C12, C13, C17, C20, C23100n6Capacitor0603
C5, C224.7µ2Capacitor0805
C6, C7, C8, C9, C10, C11, C217Capacitor0603
C144.7n 250v1Capacitor0805
C15, C1622p2Capacitor0603
C18, C1910p2Capacitor0603
D1, D5STPS0520Z2Schottky RectifierSOD123
D21LED2012RED
D31LED2012YELLOW
D41LED2012BLUE
FB1BLM18PG221SN1D1Ferrite bead0603
P11Header, 3-Pin, Dual rowHDR2X3POWER
P21Header, 2-PinHDR1X2CH340 EN
P31USB Mini BUSB Connector
P4, P52Header, 16-PinHDR1X16GPIOA
P6, P72Header, 14-PinHDR1X14GPIOC
P8, P112Header, 10-PinHDR1X10POWER
P9, P122Header, 10-PinHDR1X10GPIOD
P101Header, 2-Pin, Dual rowHDR2X2BOOT
P13, P142Header, 16-PinHDR1X16GPIOB
P151Header, 10-Pin, Dual rowHDR2X10SWD
Q1, Q2, Q3SI2374DS3MOSFET-NSOT23-3N
R1, R33302Resistor0805
R2, R410k2Resistor0805
R51501Resistor0805
R6, R7, R8100k3Resistor0805
R91M1Resistor0805
SW11ButtonPCB ButtonRESET button
U1MCP1700T-3302E/MB1SOT-89-MB3_NLDO, 3-Pin SOT-89
U2MCP1700T-2502E/MB1SOT-89-MB3_NLDO, 3-Pin SOT-89
U3MCP1700T-1802E/MB1SOT-89-MB3_NLDO, 3-Pin SOT-89
U4USBLC6-2SC61SOT23-6_L
U5CH340E1MSOP-UN10_N
U6STM32G081RBT61ARM Cortex-M0+STM-LQFP64_L
Y1ABRACON ABM3B18MHz crystalCustom
Y2Epson FC-135132.768kHz crystal2012

PCB layout


3D view of the board

The physical layout of the board is optimised for ease of use. I’m tired of boards that lazily route the GPIOs to the headers based on where they are on the IC package making me hunt up and down the tiny and often faded silkscreen legend for the right pin. On this board the GPIOs are grouped by port and ordered by pin number. It only takes a few extra seconds of routing time, even with ST’s knack of placing a port’s pins at seemingly random locations around the package.

I’ve provided rows of downward and upward facing pins for each port. The downward facing pins are designed to be the standard 100 mil apart all down the board and the rows on the opposite side of the board are a multiple of 100 mil away so that the board will mate with a breadboard.

The upward-facing pins are designed to accept the usual jumper wire-interconnects that we use so often.

Overall the board was easily routed on two layers with a ground plane top and bottom and is a little larger than ST’s discovery boards. I even had space for four M3 screw holes if the board ever needs to be permanently mounted into a chassis.

I uploaded the boards to JLPCB in China and paid the ridiculously low fee of $2 for a pack of 5. The lowest price shipping option added about $7 shipping to the price. Delivery took about 3 weeks.

Building the board



Top and bottom view of the bare board

The boards arrived and are looking great. I was particularly pleased to see that JLPCB have ignored the solder mask expansion around the pads. Solder mask expansion is the gap between the edge of a pad and where solder mask starts and is used to counter inaccurate placement of the solder mask in the manufacturing process.


Accurate solder mask placement

I set a rule of 4 mil which would leave a tiny solder mask sliver of about 1 mil between the MCU pins. It appears that JLPCB have enough confidence in their process to ignore the expansion rules and place the mask right up to the pins. The benefit of this is that I’ve got, as you can see above, a complete mask between the 0.5mm pitch pins of the MCU and that will greatly reduce the chance of accidental solder bridges.

My process for building a board is quite slow but I find it reliable. I first tin the pads with solder, then I reapply flux to the pads, then I place the surface mount components on the tinned pads and then I reflow the board in my halogen reflow oven. When the reflow is complete I touch up any problems manually and then solder in the through-hole components by hand. Finally I wash the board using hot soapy water and a toothbrush, rinse it off with cold water and leave it out to dry for at least a day.


All built and ready for testing

The reflow went OK this time. The only issue was that one of the 0603 capacitors got blown off its pads by the oven fan before it could reflow. I fixed that manually with my hot air gun.

One interesting thing I noticed while inspecting the board under my microscope was the design of the 32.768kHz crystal package.


It took a 2x macro and many megapixels to shoot this

It appears that the designers wanted to show off the internals so they fitted a clear plastic window into the top of the 1206 package so you can see how it works. I have no idea how crystals are constructed but I do find it fascinating and it looks a bit like a tuning fork. Does anyone out there know what’s going on in there?

Testing the board


ST-Link hooked up to the board

With the first revision of this board giving me so many CH340-related problems I was naturally a little apprehensive when connecting this for the first time.


USB View looking good

I need not have worried, the CH340E enumerated first time, showing up immediately there in the Windows USB View utility. I could proceed with firmware testing.

I decided that the quickest way to test out the board would be to use ST’s STM32CubeMX software to auto-generate some code that would set up USART2 to talk to the CH340E and also the three pins that are connected to the LEDs.


CubeMX pin configuration

I decided to enable RTS and CTS for USART operation even though I was going to operate in asynchronous mode for this test. I clicked through the CubeMX screens to enable the core clock at 64MHz using the external HSE as a clock source and then got it to generate a project for the free System Workbench for STM32 IDE. I’m pleased to see that this is yet another Eclipse-based IDE and I’ve been an Eclipse user for more than 15 years so I immediately feel at home and ready to code.

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

Auto-generated code

ST’s auto-generated code isn’t too bad at all. I’ve seen all types of auto-generated code that range in quality from ‘that compiles?’ to some that really look like a human wrote it. ST’s code contains comments that mark out where you can place your code without fear of it being overwitten by re-runs of CubeMX when you need to change your design. That’s great but my advice would be to keep your modifications of auto-generated files to a minimum and always check in or stage your changes before you re-run CubeMX.

  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_13);
    HAL_Delay(200);
    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);
    HAL_Delay(200);
    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_15);
    HAL_Delay(200);

    HAL_UART_Transmit(&huart2, (uint8_t *) "hello world\r\n", 13, 1000);
    HAL_Delay(400);
  }
  /* USER CODE END 3 */

My small additions to test the firmware

I added a few lines of test code to write out Hello World every second to the USART at 115200kbps and also cycle the LEDs. Compilation was immediately successful and the firmware was uploaded through the IDE’s connection to ST-Link via OpenOCD.

That CH340 again…

The firmware started running and the LEDs were cycling as expected but Windows was now having problems detecting the CH340E. What the? It was working before. Had I broken it? I fired up USB View and found it there with a different vendor ID than it had before.


USB View showing the unexpected VID

When I first plugged in the board it had a VID of 1A86 which matches the VID in the Windows driver package that I downloaded. Now it’s got a VID of 9986 that doesn’t match anything in the driver. Weird.

My first reaction was to modify the driver package to include 9986 in the .INF file and re-install it. This worked so I was half pleased and half uneasy about what had actually happened. I decided to do some more research and it turns out that if the RTS pin ‘has too much load resistance’ at boot time then the CH340E will enumerate with a VID of 9986. This behaviour is undocumented (thanks for that) and my guess is that it’s a bootstrap configuration feature designed for a specific customer.

One solution is to not configure RTS if you’re not going to use it, or if you are then wait until USB enumeration is complete before you configure the pin and keep your fingers crossed that the CH340E doesn’t reset independently of the MCU. Another solution is to configure your drivers to accept both possible VIDs. That’s what I’ve done with Windows.

With my VID driver hack still in place I fired up Realterm, my favoured serial port test utility and configured it with the correct virtual port number and configuration. It immediately started ticking away with the expected Hello World message every second.


Realterm receiving data from the board

That’s a relief. Now I’m pleased that it all seems to work and I can go on to develop actual projects using the STM32 G0 series confident in the knowledge that they’ll work as expected.

Free gerber files

If you’d like to build this board yourself then you can download the Gerber files from here. They should be accepted by your favourite online PCB manufacturer.

Video and conclusion

If you’d like to watch a video of me faffing about with the PCB, explaining badly how it works and then stumbling through the firmware testing then it’s here on YouTube.

Embedding a video in the webpage looks cool but really you want to go to YouTube to watch it for the full high definition experience.

If you’d like to comment on this article then please leave a comment below or click here to visit the forum thread that I’ve started if you’d like to have a more lengthy conversation.

  • Marvin Cabrera

    Hi, very interesting project. Would you mind to share the PCB design file for the CH350G version that did not work?, to check if was some of the quirks of the CH340G or to test it with a different oscillator.
    Also it would be great if you share the design files in Github of the working version, In particular I would like to change it for a micro usb type b version and to have it like a educational tool for the STM32 G0, that seems to be a nice MCU.

    • Hi Marvin, the relevant part of the CH340G design is shown in the attached image. I didn’t keep it, I had to dig this out of Altium’s storage history feature. Y1 is an Abracon ABM8G 10pF surface mount crystal.

      https://uploads.disquscdn.com/images/e47b7ab43deb86ca2f9836752aff439375bc031219912aea8906ff89eda4c4f1.png

      I don’t make the Altium design files available because most people can’t read them, I have concerns about personal data that could be embedded in their binary file format and they cross-reference my own library files (which are a mess) that I also don’t make available. One day I might migrate to an open source package like KiCad but my fingers and brain are hard-wired the Altium way so it’ll be difficult for me to do.

      • Marvin Cabrera

        Thanks Andy for the answer. As you pointed I also believe there was an incompatibility between the crystal and the CH340G. Could you give me the full model number of the Abracon ABM8G. I believe the Load Capacitance was too low for what was reasonable for your PCB traces and capacitors used. The 10 pF is indeed in the lower extreme of the usual Load capacitance in other Crystals.

        • The full part number from Digikey was ABM8G-106-12.000MHZ-T. As well as the caps on the schematic I tried higher, lower and none at all! And the CH340G was also swapped out for a replacement too.

  • jl

    The G0 series are on a 90nm manufacturing process whereas the F0 series on a 180nm, G0 series are inherently faster

    • Presumably that also means they’re more power-efficient as well?

  • Álvaro

    Very nice article. Many thanks the english datasheet, I could only find an older version English.
    I’m currently waiting for my first board with a ch340e and hope I manage to solder it my hand.
    In any case, when researching the ch340 family found out that the ch340c and ch340g have the same pinout, except that the ch340c has an internal oscillator like the ch340e. So you can still use the failed failed boards.
    Also the strange behaviour you discover for the rst pin is.suposed to be a feature of the ch340b.

    • Álvaro

      Also, I’m considering to use a HT42B534 for my next board. It has a built-in 3.3V regulator and a separate pin to power the signal pins (from.1.8V to Vdd). In your case, you could power the IC directly from the USB independently of the MCU voltage.

      • The HT42B534 looks like a good part if you can find a supplier and the SOP packages with the 1mm pitch will be easier to solder by hand compared to the 0.5mm pitch of the CH340E which will need a bit more attention and good magnification.

        • Álvaro

          LCSC carries them and the cost about the same as the ch340e

  • Kenneth Scharf

    I’ve never tried the STM ARM Cortex parts, but I have been using the Atmel/Microchip SAMD21 and SAMD51 parts. The SAMD21 and SAMD20 series are Cortex M0+ parts (D20 lacks the USB interface), while the SAMD51 and SAME51 parts are Cortex M4 processors. The SAME51 adds ethernet to the mix.

  • Chris S

    Thanks for the writeup, this was very helpful when I was designing a G081 board! It was my first STM32 board coming from AVR so you saved me a few hours for sure just having the basics all in one place.

    I was able to get it working with a CH340G – I think you might have had it’s 3V3 reference pin tied to 5V, assuming you were running it at 5V. Here’s how I set it up, when running at 5V the V3 pin just has a 100nF cap to ground. Your original boards might work if you just lift the V3 pin, and perhaps add a capacitor.

    https://uploads.disquscdn.com/images/1469dd179f88e6e9d0301071443201054b949261f1e3dcae75d731df4e4c1245.png

    Here’s an english datasheet I found

    Cheers!

    • Hi Chris, the version of my board that used the 340G had VCC=V3=3.3V, decoupled with 100n. That’s how the datasheet says it’s to be hooked up. I ran out of patience to fully debug it but I suppose I either got reject parts which is a risk I accept with AliExpress or the parts weren’t compatible with the SMD crystal I selected.

      • Chris S

        Ah alright. On the schematic part you posted above it was going to a connector labeled USB so I thought it was getting 5v, no worries.

        The ones I got work fine at 3.3V with V3 tied to VDD so must have been bad chips/clock as you say.