Getting started with the STM32G071

I bought a couple of STM32G071’s about a month ago but didn’t do much with them as openocd as supplied in Ubuntu didn’t support them. There is however a snapshot of openocd that does. It’s a little out of the way for now and no doubt will be included in the next release so check before trying any of this. So the steps I followed are:

Download and extract : http://openocd.zylin.com/gitweb?p=openocd.git;a=snapshot;h=dcec354bfc756c4a4e1034c9461b5d3f4e55a63e;sf=tgz
Go in to this directory and run the following
git clone http://openocd.zylin.com/jimtcl
Now, I wasn’t expecting to have to do the next edit but I got compiler errors without it – I suspect my gcc version (8.3.0) is different from the original author’s.
Open file src/flash/nor/stm32g0x.c and starting at line 929 you will see the following code:
COMMAND_HANDLER(stm32x_handle_options_read_command)
{
struct target *target = NULL;
//struct stm32g0x_flash_bank *stm32x_info = NULL; // <—— COMMENT OUT THIS LINE

if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;

struct flash_bank *bank;
int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;

//stm32x_info = bank->driver_priv; // <—— COMMENT OUT THIS LINE

target = bank->target;

if (target->state != TARGET_HALTED) {
LOG_ERROR(“Target not halted”);
return ERROR_TARGET_NOT_HALTED;
}

etc.

run ./bootstrap
run ./configure –enable-stlink –enable-maintainer-mode –disable-internal-libjaylink
make
sudo make install
This left me with an installation of openocd in /usr/local

Now that I had openocd I needed to get set up for blinky. The STM32G071 version I have is an LQFP32 so a breakout board is needed along with pin headers. Lots of flux and some solder wick was used to fix errors.

The picture below shows the finished circuit
stm32g0blinky

Next step was to put together a simple blinky program. A little background work was needed first to get register definitions and so on. I dug around the web and found the appropriate SVD file for this chip and used svdconv to generate a header file. The final code and the openocd configuration script (stm32g0.cfg) can be found over on github. More examples will follow.