The template-g0 project uses a makefile to compile and link out of the box, it is not limited to build the project, also comes with several extra targets that helps you to run some others tasks like flashing or linting the project. But first let me explain how to add more files to the compilation process in case you need it.

By default the makefile only builds the project with the most basic files needed to blinky a led connected to GPIO port A5. You can write the new files to compile using the lines 4,5 or 6 or you can add a new line using SRCS =+ <file to compile>.c

# Project name, you can change it for your prefered name
TARGET = temp

# Files to compile, you must add the new files you need and want to compile
SRCS  = main.c ints.c msps.c startup_stm32g0b1xx.s system_stm32g0xx.c 
SRCS += stm32g0xx_hal.c stm32g0xx_hal_cortex.c stm32g0xx_hal_rcc.c stm32g0xx_hal_flash.c
SRCS += stm32g0xx_hal_gpio.c

# linker file, (Do not move)
LINKER = linker.ld

# Global defines
SYMBOLS = -DSTM32G0B1xx -DUSE_HAL_DRIVER

# Directories with files to compile (.c & .s)
SRC_PATHS  = app
SRC_PATHS += cmsisg0/startups
SRC_PATHS += halg0/Src

# Directories with headers files .h
INC_PATHS  = app
INC_PATHS += cmsisg0/core
INC_PATHS += cmsisg0/registers
INC_PATHS += halg0/Inc
After those lines do not attempt to modify anything else if you are not experience in make

Make Targets

  • make: Build the project and recompile only the files that has been updated
$ make
:
arm-none-eabi-objcopy -Oihex Build/temp.elf Build/temp.hex
arm-none-eabi-objdump -S Build/temp.elf > Build/temp.lst
arm-none-eabi-size --format=berkeley Build/temp.elf
   text    data     bss     dec     hex filename
   2188      20    1572    3780     ec4 Build/temp.elf
  • make clean Remove all the previous build, with this we can run make again to compile from scratch
$ make clean
rm -rf Build
  • make flash Transfer the build program to the microcontroller
$ make flash
openocd -f board/st_nucleo_g0.cfg -c "program Build/temp.hex verify reset" -c shutdown
Open On-Chip Debugger 0.11.0+dev-00715-g480d4e177-dirty (2022-06-22-18:51)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : clock speed 2000 kHz
Info : STLINK V2J40M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.244649
Info : [stm32g0x.cpu] Cortex-M0+ r0p1 processor detected
Info : [stm32g0x.cpu] target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for stm32g0x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x0800005c msp: 0x20024000
** Programming Started **
Info : device idcode = 0x10006467 (STM32G0B/G0Cx - Rev A : 0x1000)
Info : RDP level 0 (0xAA)
Info : flash size = 512kbytes
Info : flash mode : dual-bank
Warn : Adding extra erase range, 0x080008a0 .. 0x08000fff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
shutdown command invoked
  • make open Opens a OpenOCD connection to the nucleo board
$ make open
openocd -f board/st_nucleo_g0.cfg
Open On-Chip Debugger 0.11.0+dev-00715-g480d4e177-dirty (2022-06-22-18:51)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V2J40M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.249376
Info : [stm32g0x.cpu] Cortex-M0+ r0p1 processor detected
Info : [stm32g0x.cpu] target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for stm32g0x.cpu on 3333
Info : Listening on port 3333 for gdb connections
  • make debug Opens a gdb debug session. It is mandatory to make open in another terminal previous to run this command
$ make debug
arm-none-eabi-gdb Build/temp.elf -iex "set auto-load safe-path /"
GNU gdb (GDB) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from Build/temp.elf...
0x08000396 in HAL_Delay (Delay=1000) at halg0/Src/stm32g0xx_hal.c:394
394       while ((HAL_GetTick() - tickstart) < wait)
Loading section .isr_vector, size 0xbc lma 0x8000000
Loading section .text, size 0x7d0 lma 0x80000bc
Loading section .init_array, size 0x4 lma 0x800088c
Loading section .fini_array, size 0x4 lma 0x8000890
Loading section .data, size 0xc lma 0x8000894
Start address 0x08000218, load size 2208
Transfer rate: 5 KB/sec, 441 bytes/write.
Unable to match requested speed 2000 kHz, using 1800 kHz
Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x08000218 msp: 0x20024000
Breakpoint 1 at 0x8000198: file app/main.c, line 27.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at app/main.c:27
27          HAL_Init( );
(gdb) 
  • make docs Generates doxygen documentation
$ make docs
doxygen .doxyfile
Doxygen version used: 1.9.3
Notice: Output directory 'Build/doxygen' does not exist. I have created it for you.
Searching for include files...
Searching for example files...
Searching for images...
Searching for dot files...
Searching for msc files...
Searching for dia files...
Searching for files to exclude
Searching INPUT for files to process...
Searching for files in directory /home/diego/Workspace/projects/templates/template-G0/app
warning: source 'README.md' is not a readable file or directory... skipping.
Reading and parsing tag files
Parsing files
Preprocessing /home/diego/Workspace/projects/templates/template-G0/app/app_bsp.h...
Parsing file /home/diego/Workspace/projects/templates/template-G0/app/app_bsp.h...
Preprocessing /home/diego/Workspace/projects/templates/template-G0/app/app_ints.c...
Parsing file /home/diego/Workspace/projects/templates/template-G0/app/app_ints.c...
Preprocessing /home/diego/Workspace/projects/templates/template-G0/app/app_msps.c...
Parsing file /home/diego/Workspace/projects/templates/template-G0/app/app_msps.c...
Preprocessing /home/diego/Workspace/projects/templates/template-G0/app/main.c...
Parsing file /home/diego/Workspace/projects/templates/template-G0/app/main.c...

...

Generating file member index...
Generating example index...
finalizing index lists...
writing tag file...
Running plantuml with JAVA...
lookup cache used 11/65536 hits=0 misses=11
finished...
  • make lint run the cppcheck linter to validate MISRA rules
$ make lint
mkdir -p Build/checks
cppcheck --addon=misra.json --suppressions-list=.msupress --inline-suppr --quiet --std=c99 --template=gcc --force --platform=unix32 --cppcheck-build-dir=Build/checks app
app/app_ints.c:10:6: warning: A compatible declaration shall be visible when an object or function with external linkage is defined [misra-c2012-8.4]
void NMI_Handler( void )
     ^
app/app_ints.c:18:6: warning: A compatible declaration shall be visible when an object or function with external linkage is defined [misra-c2012-8.4]
void HardFault_Handler( void )
     ^
app/app_ints.c:26:6: warning: A compatible declaration shall be visible when an object or function with external linkage is defined [misra-c2012-8.4]
void SVC_Handler( void )
     ^
app/app_ints.c:34:6: warning: A compatible declaration shall be visible when an object or function with external linkage is defined [misra-c2012-8.4]
void PendSV_Handler( void )
     ^
app/app_ints.c:42:6: warning: A compatible declaration shall be visible when an object or function with external linkage is defined [misra-c2012-8.4]
void SysTick_Handler( void )
     ^
app/app_bsp.h:2:0: warning: #define and #undef shall not be used on a reserved identifier or reserved macro name [misra-c2012-21.1]
#define _BSP_H_
^
app/app_msps.c:6:6: warning: A compatible declaration shall be visible when an object or function with external linkage is defined [misra-c2012-8.4]
void HAL_MspInit( void )
     ^