Sunday, March 8, 2015

Seting up the stm32F4 discovery board from ST for development


I am constantly seeking micro controller board for experiment control or other automation project. For complex tasks the beagle bone is a good thing to be used since it runs an linux operating system. Using the bleeding edge tool chain it is possible to develop software for this platform on a Windows PC. You don't need to flash any thing since the software is simply deployed on a file system.

For simpler tasks (cheaper hardware) i have prefered in the past PIC processors from Microchip.There are millions of different evaluations and development boards out there for this controller type but only one vendor. This is the major difference between ARM and PIC architecture. 

My personal feeling about the ecosystem around this controller is that the ARM has a richer and diverse ecosystem then the PIC processors and i decided to go the ARM way in the future. 


I came across the ST32F4 board from ST costing less the 30 Euros. The processor provides a 2M flash and 512KB of memory; the board it self provides a few gadgets like and LCD display, two LED's, USB etc. I selected this board mainly because of it's availability; but for a start it is good enough.

Development Environment

I have tried a few free environments like CooCox, emIDE but at the end i cam back to eclipse CDT since these tools did not have any advantage over eclipse. 

ST proivides for free a programmer (ST-Link V2) which is nicely supported by the CooCox and the emIDE.

All three tools are taking different assumptions about the API's are going to use; but all three environment are using some version of the ST HAL_Driver. But at the bottom line it might be rather difficult to fit in the software provided by ST because they made these software packages to fit IAR Embedded Workbench, Keil® MDK-ARM or Atollic TrueSTUDIO. These environments are a bit too expensive for an enthusiast like me. There for i decided to go the the plan approach using the GNU Tool for ARM software which comes free.

Since there are different debugging probes from different vendors using different protocols i have decided not to use the ST-Link V2 but to use openOcd which is an open on chip debugger. Eclipse supports this directly.

Getting Eclipse working

I am skipping the process of installing eclipse CDT. After CDT is available it need to be configured to support the ARM tool chain and the openOCD. 

  1. First download the GNU tool chain for ARM and install it at some reasonable place. In my case i have been using the default location under Program Files (x86). 
  2. Download openOCD. It does not come with a Windows Installer; which means you have to move it your self to a reasonable place. In my case i have a directory c:\ARM where i put most of the ARM related stuff.
  3. Configure eclipse to use both; which means basically to tell CDT where all the stuff is located. This is done by  Windows -> Preferences -> Run/Debug -> String Substitution.

Creating the first Project

CDT comes with a project template for the STM32F4xx chip line. Simply create a new C++ project; select STM34F4xx C/C++ Project and select as contenst the "Blinky (blink a led)" project. This will provide you with a small project which is expected to toggle an LED via the GPIO interface of the processor chip. In order to make this example work with the discovery board from ST you need to adopt the port and the pin number where the LED is connected to in the file BlinkLed.h as shown below:

#define BLINK_PORT_NUMBER               (6)
#define BLINK_PIN_NUMBER                (13)
//#define BLINK_ACTIVE_LOW                (0)

Build the stuff and you are basically done, Before testing this software by using the on chip debugger you need to configure the debugger server. Actually openOCD runs as an gdb server and before you start debugging the server has to be started up. You can do this either manually or leave it to eclipse. In any case you need to create a debug configuration for your project. Your debug configuration needs to contain in the tab debugger the startup settings for openOCD as shown below: 

Every time you start debugging with this configuration your software get flashed on the device and the openOCD is started with the right parameters for your board.

Now you are ready to start with your project!

Used Software

This section summarizes the Software and there version i have used.

Package Version
Eclipse CDT
GNU Tool Chain for Arm  4.9
openOCD  0.8.0

No comments:

Post a Comment