During all the training we are going to focus on preparing your skills to know several features of the microcontrollers like gpio, timers, uart, interrupts and etc. It is important to know the resources and more important to know the target, in this case, will be the ST stm32g0b1re, a 32bit microcontroller with an ARM Cortex-M0+ core, do not forget to download the following documentation: datasheet and reference manual
Prior to anything you will need to read and install the tools from the way we work
Linux
Ok, we need a new compiler if want our C program to run in our microcontroller, we choose the official GNU ARM compiler, open a terminal and type the following
$ sudo pacman -Syu arm-none-eabi-gcc arm-none-eabi-gdb arm-none-eabi-newlib
Once we have our program compiled we need somehow transfer it to the on-chip memory, and for that, it is necessary OpenOCD
$ sudo pacman -Syu openocd
Since openocd needs to access our USB port we need to run with sudo, BUT it is not recommended at all to run any application with sudo. So we gonna fix this inconvenient setting of some user permissions. Verify if plugdev
group exists
$ grep plugdev /etc/group
If the above doesn’t return anything, then it doesn’t exist and you need to create it and also add your user. Replace with your username
$ sudo groupadd plugdev
$ sudo usermod -a -G plugdev <username>
We copy a certain file with the access rules for openocd and activate them. NOTE: The file name may be different; to find out, just run ls /usr/share/openocd/contrib
and check which file appears.
$ sudo cp /usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules
$ sudo udevadm trigger
NOTE: I do not why, but sometime it will be necessary to type sudo udevadm trigger again in time to time
Windows
Ok, we need a new compiler if want our C program to run in our microcontroller, we choose the official GNU ARM compiler, open a terminal and type the following
$ choco install gcc-arm-embedded
Once we have our program compiled we need somehow transfer it to the on-chip memory, and for that, it is necessary OpenOCD
$ choco install openocd
NOTE: In Windows everything needs a driver!!!!, and the St-Link is no exception, download from here
Test your new compiler
$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=C:\ProgramData\chocolatey\lib\gcc-arm-embedded\tools\gcc-arm-none-eabi-10.3-2021.10\bin\arm-none-eabi-gcc.exe
COLLECT_LTO_WRAPPER=c:/programdata/chocolatey/lib/gcc-arm-embedded/tools/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/lto-wrapper.exe
Target: arm-none-eabi
Configured with: /mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/src/gcc/configure --build=x86_64-linux-gnu --host=i686-w64-mingw32 --target=arm-none-eabi --prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw --libexecdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/lib --infodir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/share/doc/gcc-arm-none-eabi/info --mandir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/share/doc/gcc-arm-none-eabi/man --htmldir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/share/doc/gcc-arm-none-eabi/html --pdfdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-mingw-wildcard --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-headers=yes --with-newlib --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/arm-none-eabi --with-libiconv-prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-gmp=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-mpfr=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-mpc=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-isl=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-libelf=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Arm Embedded Toolchain 10.3-2021.10' --with-multilib-list=rmprofile,aprofile
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.3.1 20210824 (release) (GNU Arm Embedded Toolchain 10.3-2021.10)
The template
For every newbie, the best way to start is through a working out-of-the-box project. Here is my advice, create a specific directory where you gonna put all your projects, and be disciplined with all the projects you create, the last thing you want is to have directories all over your computer. For instance:
$ mkdir Workspace
$ cd Workspace
$ git clone https://github.com/ModularMX/template-g0.git myNewProject
$ code -r myNewProject
The template is basically a simple blinky led, the hello world of microcontrollers, to flash and run the program type ( do not forget the terminal shall be in your project directory ). This is the project base you will use for every program you make across the entire training.
$ 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
2244 20 1572 3836 efc Build/temp.elf
Connect and flash your board
$ 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.253088
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: 0x0800023c 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, 0x080008d8 .. 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.
Enjoy watching your led blinking, and if you want to know more about all the target you can use with the project makefile take a look at
An here is a nice video introduction from ST