"Hello World" tutorial
Below you will find instructions for setting up the environment allowing
to flash EFM32 MCU using OpenOCD. The manual was tested with Linux, but
there is a high chance that it works with Windows as well.
IMPORTANT: Please note that the following example is described for the
EFM32 Breakout Board. Steps for flashing are the same for the Freewatch,
but the code is different!*
Prerequisities
Software:
- Toolchain
- OpenOCD (I have used 0.8.0)
- 'Hello world' source code
Hardware:
- EFM32 Breakout Board (documentation)
- SWD debugger (more informations below)
- 5V power supply
EFM32 Breakout Board
Connect 5V power supply to connector P1: pins 1 & 2 are 5V, 3 & 4 serve as ground.
SWD debugger
I had two evaluation boards by hand with integrated ST-Link debugger to test:
STM32VL Discovery
You need to remove 2 jumpers from CN3 pinhead to enable ST-Link. Then connect cables between EFM32 Breakout Board (connector P3) and ST-Link (connector CN2 "SWD") as following:
EFM32 BB pin number | signal name | ST-Link v2 pin number |
---|---|---|
1 | Vref | 1 |
2 | SWDIO | 4 |
3 | SWDCLK | 2 |
6 | GND | 3 |
Connecting Vref is optional. Please note that neither SWO nor NRST are connected. I do not know why, but connecting reset causes an error in OpenOCD. SWO is used for debugging purposes, though I am not sure if OpenOCD is able to make any use of it.
Picture 1. STM32VL Discovery to EFM32 Breakout Board connection diagram.
Nucleo F401RE
You need to remove 2 jumpers from CN2 pinhead to enable ST-Link. Then connect cables between EFM32 Breakout Board (connector P3) and ST-Link (connector CN4 "SWD") as following:
EFM32 BB pin number | signal name | ST-Link v2.1 pin number |
---|---|---|
1 | Vref | 1 |
2 | SWDIO | 4 |
3 | SWDCLK | 2 |
5 | NRST | 5 |
6 | GND | 3 |
Connecting reset & Vref is optional. The debugger is able to reset the MCU even when it is not connected. It may be significant for other operations.
Picture 2. Nucleo F401RE to EFM32 Breakout Board connection diagram.
Source code
Ready-to-run demo is in orson_sw_dev branch of the project repository. The source code & OpenOCD scripts are located in sw/efm32_hello.
$ git clone git:https://www.ohwr.org/freewatch.git -b orson_sw_dev
$ cd freewatch/sw/efm32_hello
$ make
If you have installed the toolchain somewhere else than it was suggested, you need to pass the path to 'make' command:
$ LINUXCS=/path/to/toolchain make
Flashing
Commands below may require root privileges, therefore you have to either invoke them using sudo or apply udev rules that grant you permission to use the debugger interface (recommended). A good example of such rules is available here:
Given that you have connected hardware and installed prerequisities, the following commands will make LEDs on the board blink in sequence. Depending on the debugger:
* STM32VL Discovery (ST-Link v2)
$ [sudo] OOCD_IFACE=stlink-v2 make flash
* Nucleo F401RE (ST-Link v2.1)
$ [sudo] make flash
You may try out other debuggers by substituting environmental variable OOCD_IFACE with any OpenOCD interface configuration file (check /usr/share/openocd/scripts/interface or documentation). Keep in mind that SWD support is required both in debugger and OpenOCD driver.
Debugging
You need to run an instance of OpenOCD in one terminal (I assume that
you are in efm32_hello directory, otherwise you have to modify
paths).
For ST-Link v2
(Discovery):
$ [sudo] openocd -s ../common/openocd -f interface/stlink-v2.cfg -f init.cfg
or for ST-Link v2.1 (Nucleo):
$ [sudo] openocd -s ../common/openocd -f interface/stlink-v2-1.cfg -f init.cfg
Do not close the terminal. In a different one you can invoke gdb:
$ /opt/gcc-arm-none-eabi-4_8-2014q1/bin/arm-none-eabi-gdb -ex "target remote localhost:3333" exe/blink.out
While in gdb console, you need to reset and halt the CPU. Otherwise it will not trigger any breakpoints.
monitor reset halt
continue
Afterwards you may continue with common gdb commands.