Tuesday, June 28, 2011

Porting FreeRTOS on miniSTM32

FreeRTOS source comes with a bunch of demos for various boards. You can choose the project for Atollic (CORTEX_STM32F100_Atollic) for your starting point. Atollic TrueSTUDIO is nothing but Eclipse with GCC, so it is almost ready to go if you are using gnu tool-chain. Besides, it has recent version of ST peripheral library. Actually this is only ST library compliant with CMSIS standard among the FreeRTOS demos.

First, gather the source code you need and put them under the ST peripheral library tree (stm32f10x_stdperiph_lib). There is a batch file in the CORTEX_STM32F100_Atollic directory:

$ CreateProjectDirectoryStructure.bat

So, you just fire it up then it will do the job for you. It collects the FreeRTOS source files and put them in the

$ FreeRTOS_Source

directory. Copy this directory under the ST library tree. Also create a demo project directory(you can use CodeLite as described in the previous post) and copy these two files:

$ Simple_Demo\FreeRTOSConfig.h
$ main.c


into the project directory. Then the directory structure would be


In the above tree, FreeRTOS_Demo is the project directory. Other file you need in the project directory is

$ stm32f10x_conf.h

Unlike other project,

$ stm32f10x_it.c
$ stm32f10x_it.h


are not used here. It's routines are replaced by FreeRTOS.

As usual, prepare Makefile and a linker script. Be sure to include the following paths

$ INCLUDEPATHS += -I ../../FreeRTOS_Source/include
$ INCLUDEPATHS += -I ../../FreeRTOS_Source/portable/GCC/ARM_CM3


in your INCLUDEPATHES and the following source codes

$ C_SRC += ../../FreeRTOS_Source/list.c
$ C_SRC += ../../FreeRTOS_Source/queue.c
$ C_SRC += ../../FreeRTOS_Source/tasks.c
$ C_SRC += ../../FreeRTOS_Source/timers.c
$ C_SRC += ../../FreeRTOS_Source/portable/GCC/ARM_CM3/port.c
$ C_SRC += ../../FreeRTOS_Source/portable/MemMang/heap_1.c


in your source list to compile. Others are pretty much the same with other projects.

In order to run the demo, you will need BSP(board support package) for your board. Fortunately, ST library comes with plenty of BSP source code for varous STM32 evaluation board and it is quite well organized. So, it is easy to make a BSP by yourself. Create a directory under Utilities/STM32_EVAL tree for miniSTM32


and write your BSP files there. STM32100E_EVAL source would be a good reference. If there is no error in the BSP, FreeRTOS demo code will be compiled with no problem.

Monday, June 27, 2011

STM32F GCC IDE on Windows(2)

Test Project Build
Let's test build with some examples provided by ST. First copy the GPIO/IOToggle source files to the project directory just created.



Then create a make file and linker script file for the project. In this state, you can build(F7) and clean the project as you typed in the previous post. Actually everything is done by make utility and CodeLite is just invoking it.

It would be nice you can navigate and edit each file. At the left Workspace pane, right click on the project name and select the "Import Files from Directory".


Then you can select directories(and files) you want to show on your Workspace pane, which will probably match the source list of your Makefile. If there is no (sub)directories to select, you can choose as many as you want by clicking the Browse button on the top right of the dialog.


Resulting directory structure probably matches the source list of your Makefile. Be sure to remember that this tree is created regardless of project structure itself and you are not suppose to compile each individual file.

Flash Utility Integration
You can bring up the external flash utilities by registering those as external tools. Select Plugins-> External tools ->Configure external tools or just click the corresponding button from the menu bar


Then you can register your flash program.


Surely it is not as convenient as a native flasher but it is still useful.

Sunday, June 26, 2011

STM32F GCC IDE on Windows(1)

You can easily build a GCC IDE for Cortex-M3 using a open source IDE.  If you are not a big fan of Eclipse like me, you will probably like CodeLite or Geany. Both programs are cross platform, open source, and light-weight. Geany is more minimalistic of two. If you are familiar with Visual Studio, you will find CodeLite is more comfortable.

I'm going to use the following programs:


GCC and Make
For the CSG++ Lite, be sure to download the installer version(EABI). Install is straight forward. You don't have to change any settings. After install, you should add the following directory to your PATH.

> C:\Program Files\CodeSourcery\Sourcery G++ Lite\bin

You can verify that your PATH is set up correctly by running

> arm-none-eabi-gcc -v

on your console window.
Other than the compiler collection, you may need at least GNU make utility. You can install Cygwin for the make utility. But the simplest way is using GnuWin32. Download and install the GnuWin32 make package. You also have to add its bin directory to you PATH. You can install as many GnuWin32 packages as you need.

> C:\Program Files\GnuWin32\bin

STM32F Library and CodeLite Project
Download the library(stm32f10x_stdperiph_lib.zip) and extract it on your work directory. Then install CodeLite and fire it up to create initial workspace and project. For convenience, create a Codelite workspace under the STM32F library directory. (Workspace->New Workspace)


By selecting the workspace name and path as shown and deselecting the "Create the workspace under a separate directory" check box, you can use the STM32F library project directory as your workspace. But it is only for convenience sake. You can choose your workspace anywhere you like.

Now create a new project.(Workspace->New Project)


For the Categories, choose "Others" then you can select "Custom Makefile" type for the template. Type in your project name. And select compiler type. Compiler type here is not important because you will use your own build and compile command strings. Resulting directory structure would be



For now, there is no file under GpioTest directory except the CodeLite project file.

After the  project creation, go to the project settings by right click on the project "GpioTest" and select the last menu item.


Go to "Customize" on the left, then check "Enable custom build". You want  change "Working Directory" from $(WorkspacePath) to $(ProjectPath) where you have your own Makefile. Now fill in the Build Command with "make" and the Clean Command with "make clean". In this way, you can use your Makefile to build your project instead of CodeLite's own makefile.