FreeRTOS CortexM3 HowTo
Getting Eclipse (Ganymede/Helios)
- Download Eclipse CDT
- If you choose Eclipse(GANYMEDE)you will need to install Zylin GDB embedded debugging plugin. Therefore run Eclipse, go to Help->Install new Software. Download and install Zylin Embedded CDT from:
- Download the newest Version of FreeRTOS
- The next step is to get a Toolchain. In our case, we decided to work with Sourcery G++ Lite because it supports us with a library for the Thumb2 Instruction Set for the Cortex M3.
- After all that, be sure using the newest Version of OpenOCD. Therefore download the Windows Installer for OpenOCD or the OpenOCD Project Files which has to be configured first, before using it.
- Because of a GPL license violation OpenOCD cannot be distributed with support for ftd2xx.dll library. FT2232 JTAGs have to be used via libusb-win32 drivers and OpenOCD will be linked with libftdi library. If there were FTDI drivers installed in the system, they have to be manually removed and then libusb-win32 drivers have to be installed manually.
Configuring Eclipse (GANYMEDE)
There are different ways to create a FreeRTOS specific Project under Eclipse. In this case where the STM32F103RB has been used, the Project structure contains the following folders:
- FreeRTOSSource - STMSourceFiles - SourceCodes - Boot - Scripts
The FreeRTOSSource folder includes all FreeRTOS specific Header and Source files. The STM Source Files are located in the STMSourceFiles folder. The Boot folder contains all files which are necessary for the Board, e.g the startup file. The Script folder holds the linker scripts.
The following steps describes how to create an empty C Makefile Project which is running FreeRTOS.
- Create a new empty C Makefile Project
- Add the folder structure mentioned above. All folders except the Script folder are declared as source folders.
- Fill the FreeRTOSSource folder with the FreeRTOS specific files you will need.There should be also a copy of Port.c, Portmacro.c and the heap_n.c files. Port.c and Portmacro.c can be found at ..\FreeRTOS Install Path\Source\portable\GCC\ARM_CM3 if an CortexM3 is used with the GCC. If the GCC is not the compiler you are using, the portable folder contains all by FreeRTOS supported compiler and Microcontroller. The MemMang folder which can also be found at ..\FreeRTOS Install Path\Source\portable\ holds heap_1.c, heap_2.c and heap_3.c. In our case heap_2.c is used.
- Go to Project Settings->C/C++ Build
- under "Settings" select "GNU Elf Parser"
- under "ToolChain Editor" select "No Toolchain"
- Go to Project Settings->C/C++ General->Paths and Symbols and add the following folder to GNU C
\Code Sourcery Root\arm-none-eabi\include
- After preparing the folder structure, the next step will be to configure OpenOCD and GDB.
For configuring OpenOCD click Run->External Tools->External Tools Configurations.
- Create a new configuration for OpenOCD by:
- Choosing a name for the new created configuration
- Setting the location of the OpenOCD.exe
- Setting the working directory
- Specifying the arguments to run OpenOCD
- Save changes by clicking on the Apply Button
Below is a simple example for the arguments used for the Olimex STM32, Olimex JTAG TINY:
-f \openocd-0.4.0\0.4.0\board\olimex_stm32_h103.cfg -f \openocd-0.4.0\0.4.0\interface\olimex-jtag-tiny.cfg -c init -c reset run -c halt -d 3 -l openocd.log
-f can be used to load e.g. a configuration file. -c specifies commands for openocd. -d chooses the debug level and with "-l openocd.log" a Log file will be created and saved under openocd.log
The next step is to set the Debug Configurations, therefore go to Run->Debug Configurations
- Create a new configuration for Debugging
- Create a new Zylin Embedded debug (native) configuration
- Choose a name for the new configuration
- Select the Project
- Pick the C/C++ Application which should be used
- Click on Debugger Tab and load the GDB debugger
- Remove .gdbinit in the GDB Command file field
- Click Command Tab and specify 'Initialize' Commands for GDB
- Save changes by clicking on the Apply Button
Example GDB init commands:
target remote localhost:3333 reset init load reset init tbreak main continue
Configuring Eclipse (HELIOS)
For using Eclipse Helios version, first download C/C++ Development Tooling - CDT (Install CDT: Help->Install new Software) Debugging in Eclipse Helios is slightly different.
- select Run->Debug Configurations
- double click on GDB Hardware Debugging will create a new Configuration
- after adding project specific information change the Launcher from GDB (DSF) Hardware Launcher to Standard GDB Hardware Debugging Launcher
- change to Debugger Tab and replace gdb with add arm-none-eabi-gdb
- uncheck Use remote target
- last step is to add Startup information (see picture)
- Use window 1 for initialization commands
- Use window 2 for run commands
- do not check "break at: " and "resume"
- Replace SVCHandler, PendSVHandler and the SysTickHandler in the startup file with the FreeRTOS specific handlers:
SVCHandler -> vPortSVCHandler PendSVHandler -> xPortPendSVHandler SysTickHandler -> xPortSysTickHandler
- Check the CPU Clock in FreeRTOSConfig.h
Debugging Example Project
- Download the FreeRTOS LED Blink Example Project and import it into Eclipse.
- Build the project and follow the steps mentioned above
- After that go to Run->External Tools and select the created external Tool and wait until OpenOCD is ready
- Click on Run->Debug Configurations and run the created Debug Configuration
- Change to Debug view Window->Open Perspective->Debug
- The debug session will start at the first executable
- Breakpoints will be set/removed by double click
- Eclipse provides shortcut buttons for running External Tools and Debugging. These can be used instead of the first steps above.