In this tutorial we will set up a simple template for progamming ST32 -Discovery baord. For this we are going to use latest Code Sourcery and Eclipse IDE. To make things simpler we are going to use ARM-based 32-bit MCU STM32F10x Standard Peripheral Library v3.5.0 that can be downloaded from ST site. Also we are going to use STM32VLDiscovery firmware package for example files. And why write our own linker, startup and make scripts.
For this we are going to use Michael Fischers example project for yagarto.
[download id=”1″]
We only need small modifications to fit our needs.

In this stage we assume that you have set up Eclipse and Code Sourcery and we can go further.

First of all create new C project in Eclipse File->New:

Enter project name, select the path where project will be stored and select Makefile project->Empty project in Project type list. In Toolchain list select Other Toolchain. This will create empty project that will run make to compile project.

Now we can start adding files. In order to avoid significant mess in project folder it is good practice to create some logical folder structure. There are no particular rules how this can be one exactly but you will find what works best for you. In my case I create two root folders Device and Libraries. Then in Device folder create two subfolders –linker and startup.

After our folders are set we need to copy source and library files that will be needed for our project. First of all we import linker scripts. Import stm32f103xb_flash.ld andstm32f103xb_ram.ld files to Device/linker folder from STM32Test/prj. Open each of them and edit memory configuration to fit your board like this

As our Discovery board has 128K of flash and 8K of RAM memory. There are two linker scripts for two cases – one to run code from flash and another from ram memory. We will be using flash mode for now.

Next step is to import startup code. Now we import crt.c andvectors_stm32f10x_md.c files in to Device/startup directory from STM32Test/src. These are more general and well commented comparing to our earlier discussed. We don’t have edit anything here as startup files are ready for medium level arm cortex-m3 devices.

Now we have to import necessary libraries in to our project. These will be CMSIS and STM32Discovery specific. Import latest CMSIS library from downloaded Standard Peripheral Library in to Libraries folder. This library includes core support library and device support libraries. This is where register definitions are made, system level initializations and standardized access to processor features (Probably we will need to make separate post about CMSIS). From same location import STM32F10x_StdPeriph_Driver package where all peripheral access drivers are stored. Then import STM32Discovery board specific library from downloaded STM32VLDiscovery firmware package. It lies in an3268\stm32vldiscovery_package\Utilities folder. So import whole Utilities folder in to projects Library folder. We sould have following view in project explorer:

We have set up the base. Now all we need is a main program and makefile. stm32vldiscovery_package has a set of code examples. So we are going to use one. So import source files in to root project folder from an3268\stm32vldiscovery_package\Project\Examples\GPIOToggle:

import only files.

Last thing to do is to create makefile. I used make file from STM32Test package and slightly modified to comply with project directories and also added size function to display memories used on target. So Create new blank Makefile in project root folder and copy following contents to it:

Now you’re all set. Build project and upload .hex file to Discovery board. You should see blinking LEDs.

Same way other examples can be compiled and used.

Download project files here:
[download id=”2″]