STM32F3 Discovery – 1st Look

So I got my hands on this curious little evaluation / development board. Windows has an IDE for it, but it’s expensive, and Linux and Mac users are on their own.

Since it has an ARM-Cortex-M4, it’s possible to get it working with POSIX type OSes.

When you plug it in after unboxing, the circle of LEDs blinks seductively, and there are a bunch of functions built in out-of-the box. Notable among them, of course being the accelerometer and gyroscope.

So, of course, it was exciting to see if we could use this as the brains of a homebrew Oculus Rift!

But wait, we still have to get it working! These are the steps:

Download and Install the GCC ARM toolchain, Eclipse IDE + plugins and OpenOCD

GNU Tools for ARM Embedded Processors

The first thing you need is the GCC ARM toolchain with the debugger GDB. Download the mac installation tarball of the latest series release and uncompress it in your home folder, no installation needed.

Eclipse IDE

  1. Download the latest version (currently Neon) of the Eclipse IDE for C/C++ Developers package,  Mac OS X 64 Bit version, and uncompress it in your Applications folder.
  2. Open Eclipse and install the plugins needed: Eclipse CDT, GNU ARM and Zylin embedded CDT.
  3. Go to Help > Install New Software. Click on the “Available software sites”, select the CDT checkbox and click OK.
  4. 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.
  5. Click Finish and the plugins will download and install.
  6. 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.
  7. Finally, repeat the process to install the Zylin Embedded CDT plugin, necessary to debug and flash. Add the repository with the locationhttp://opensource.zylin.com/zylincdt and install the component “Zylin Embedded CDT”.

Open OCD

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

Once installed, you have to create an empty file called stm32f3discovery.cfg in your home folder, and paste the following lines:

# 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

To be able to run OpenOCD inside Eclipse, you have to add it clicking in the menu Run > External Tools > External Tools Configuration…. Create a new item clicking in the New launch configuration icon and fill in the location, working directory and arguments as in the following image and click Apply. The working directory will be where you created the stm32f3discovery.cfg file.

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

Every time you start Eclipse, you will need to start OpenOCD with Run > External Tools > OpenOCD. When you exit Eclipse, it will kill the OpenOCD daemon. If for some reason it is still running, paste in a Terminal the command

killall openocd.

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 Project and Cross ARM GCC. Give it a name, for example Blinking_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 the bin folder where you installed the GCC ARM Toolchain.

 

Click Finish and the project will be created.

 

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 theTool Settings, click on the Target Processor item. On the right dropdowns, select the “FP instructions (hard)” option of the Float ABI menu, 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.

Oculus Rift

Oh, and if you’re wondering how to get that baby going, Yetifrisstlama has done the reverse engineering for you! Check out the code on his Github page.

One thought on “STM32F3 Discovery – 1st Look

Leave a comment