A few months ago I received an STM32F3DISCOVERY evaluation board, similar to the STM32F4DISCOVERY that I’ve used for prototyping at work, but for the new STM32 F3 series Cortex-M4. Since ST doesn’t provide a development environment like TI and NXP do, and the commercial packages available are expensive and windows only, I’ve decided to put up a step-by-step tutorial on how to setup an opensource environment for Mac OS X based on eclipse, GCC ARM and openOCD.
All the packages are multi-platform, so it should be easy to configure a similar environment for Linux or Windows.
Download and Install the GCC ARM toolchain, Eclipse IDE + plugins and OpenOCD
GNU Tools for ARM Embedded Processors
The first thing you need is a toolchain. The GCC ARM is maintained by ARM employees, and is the best open source compiler you can find. It includes the debugger GDB. Download the mac installation tarball of the 4.7 series release and uncompress it in your home folder, no installation needed.
A lot of the closed source IDE used in ARM development are heavily based on the Eclipse IDE. Download the last version (currently Kepler) of the Eclipse IDE for C/C++ Developers package, selecting the Mac OS X 64 Bit version, and uncompress it in your home or applications folder.
Now open Eclipse and install the plugins needed: Eclipse CDT, GNU ARM and Zylin embedded CDT.
Go to Help > Install New Software. Click on the “Available software sites”, select the CDT checkbox and click OK.
Select CDT from the Work with: dropdown and the packages will appear below. Click all the CDT Main Features and from the CDT Optional Features the ones that are selected in the following image.
Click Finish and the plugins will download and install.
Next we will install the GNU ARM plugin. Click again on Help > Install New Software and now click on the Add… button next to the top dropdown, to add a new repository. Insert the locationhttp://gnuarmeclipse.sourceforge.net/updates and click OK. The component “CDT GNU Cross Development Tools” will appear below. Select and install it.
Finally, repeat the process to install the Zylin Embedded CDT plugin, necessary to debug and flash. Add the repository with the location http://opensource.zylin.com/zylincdt and install the component “Zylin Embedded CDT”.
OpenOCD is an open on-chip debugger and progamming tool. It will communicate with gdb to debug and flash the board by using the stlinkv2 debugger. The easiest way to install it is using Homebrew, a pacakage manager for OS X similar to MacPorts or Fink. If you don’t use Homebrew already, follow the one-step installation instructions on its website. After that, open a Terminal and paste the following line:
brew install openocd --enable_ft2232_libftdi --enable_stlink
# Script for connecting with the STM32F3DISCOVERY board source [find interface/stlink-v2.cfg] source [find target/stm32f3x_stlink.cfg] reset_config srst_only srst_nogate
Now connect your STM32F3DISCOVERY board to the computer and click the Run button. If everything is correct, you will see in the console something similar to this:
Info : This adapter doesnt support configurable speed Info : STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748 Info : Target voltage: 2.892453 Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
Creating a new project
After installing all the packages, we are going to create a blinking led example project.
First, click on File > New > C Project and select Executable > STM32F3xx StdPeriph Lib v1.0 C Projectand Cross ARM GCC. Give it a name, for example Bliking_STM32F3.
Click Next several times, leaving the default options, until you reach the last step, where you select the toolchain name and path, as you can see in the image. You will have to browse for the path of thebin folder where you installed the GCC ARM Toolchain.
Click Finish and the project will be created.
For now, you can leave the example code as is, but you need to comment the printf lines, since OpenOCD doesn’t seem to support retargeting for this board at the moment.
Another thing we should do is enable the FPU unit, that is disabled by default. Go to Project > Properties and select C/C++ > Settings on the left tree. In the Tool Settings, click on the Target Processor item. On the right dropdowns, select the “FP instructions (hard)” option of the Float ABImenu, and “fpv4-sp-d16″ of the FPU Type and click OK.
After that, click on Project > Build Project. Now that the program is compiled, the only thing left is to add a debug configuration. Click on Run > Debug Configurations… and double-click on Zylin Embedded debug (Native). On the “Debugger” tab, click on the GDB debugger field and browse to select the gdb executable of the GCC ARM toolchain. It will be something likePATH_TO_GCC/bin/arm-none-eabi-gdb.
Finally, go to the “Commands” tab and paste this in the ‘Initialize’ commands box:
target extended-remote localhost:3333 monitor reset init load monitor reset halt
Click Apply and then Debug. The debugging session will start, Eclipse will switch to the Debug perspective and the program will be downloaded to flash. Then, when you click on the Resume (F8)icon, the program will start executing, stopping at main. Clicking again on Resume will continue the execution. If everything is configured correctly, you will see the green led flashing on your board. You can pause/stop the execution, set breakpoints and watch variables and registers.