en.radzio.dxp.pl

Programming STM32VLDISCOVERY with open source toolchain

Eclipse However the Keil uVision is good choice for beginners and it is very easy for use, that have some restrictions. Maximum otuput size is 32KiB, and still it is a commercial compiler. There are some more or less "open" build environments that do not have restricted maximum build size output and are available for free. One of them is Sourcery CodeBench Lite, known before as Codesourcery G++ Lite. This is free version of paid CodeBench environment,. In free version there is no IDE, only command-line toolchain. So let's use one of most popular IDE for programing : Eclipse IDE. Eclipse is also used as editor in commercial edition of CodeBench (and more of other commercial toolchains for ARM). In conenction with Sourcery CodeBench and GNU ARM Eclipse Plugin makes free and easy to use environment for creating software for STM32 (and other) microcontrollers with ARM core.

 

Important words about debugging
Unfortunetly, there is no direct way to debug code on STM32VLDISCOVERY with opensource tools. OpenOCD will be support ST-Link only in V2 version, and only with JTAG transport layer. On STM32VLDISOVERY there is ST-Link/V1 and SWD connection, so OpenOCD do not support STM32VLDISCOVERY. You can debug STM32VLDISCOVERY only with external JTAG interface.

Installing Sourcery CodeBench
Sourcery CodeBench Lite can be downloaded from Mentor Grpahics website. Unfortunetly, Mentor Graphics require simple registration to get access to download section for CodeBench. This is difference in comparsion to previous supplier of Codesourcery toolchain, when downloads don't require registration. CodeBench is available in two forms : with installer and in archive. I recommend use version with installer.

Installing Eclipse
Eclipse can be downloaded from website of Eclipse Project. There is a lot versions of Eclipse IDE, for us important is Eclipse for C/C++ developers. Eclipse is distrubuted in zip archive, and don't need installation. Just extract archive into hard disk and use it by launching eclipse.exe.

Installing GNU ARM Eclipse Plugin
To make work with Eclipse almost as easy as with Keil, we use GNU ARM Eclipse Plugin. Installing plugins for Eclipse is easy. I show step-by-step plugin installation procedure :

  1. From 'Help' menu select 'Install New Software' option : [step 1] [step 2]
  2. On displayed window in 'Work with' combo box type http://gnuarmeclipse.sourceforge.net/updates and click 'Add' button [step3]
  3. In next dialog type name for site (for example : GNU ARM Eclipse Plugin): [step4]
  4. Now Eclipse should check available updates of plugin : [step5]
  5. When update will be found, should be displayed in window in CDT GNU Cross Development Tool group : [step6]
  6. Expand tree, select GNU ARM C/C++ Development Support and click 'Next' button: [step7]
  7. Review of plugin to be installed (click Next): [step8]
  8. License agreement (read, select 'I accept...' and click 'Next') : [step9]
  9. Security warning, click 'OK' : [step10]
  10. Restart request, click 'Restart Now'. [step11]
  11. GNU ARM Eclipse Plugin are installed!. We can create now new project.

Creating project with GNU ARM Eclipse Plugin
After succesfull installation of plugin, we can now create first project. To do that, from 'File' menu select command 'New -> C project [step 1]. Next, specify project name and select proper toolchain [step 2] . Options on next windows leave unchanged [step 3]. After You click the 'Next' button project will be created [step 4] . Now, expand the project tree [step 5]. If You see references to include files located in toolchain subfolder everything is OK. Our project has no source files, so let's create new source file [step 6]. Save this file as main.c into project directory [step 7]. File should be automatically visible on project tree [step 8]. Now write main function [step 9] and try build project. Open the 'Build' directory. There are present some files generated by GNU ARM Eclipse Plugin [step 10] .

Now we are ready to add to project device support files from CMSIS library. Download archive and exctract from CMSIS folder following files : stm32f10x.h, system_stm32f10x.c, system_stm32f10x.h and startup_stm32f10x_md_vl.s (from arm-gcc subfolder). You can download only required files from here, but I do not quarantee that files are up to date with files supplied by STMicroelectronics on thier website. Copy files into folder with project, and refresh projec tree [step 11]. Now, try build project. There are some errors [step 12].

We must define from which group of STM32 microcontrollers we are used. On STM32VLDISCOVERY is mounted microcontroller from Medium Density Value Line group (MD_VL). So open properties window [step13], expand C/C++ build tree and select "Settings" section [step 14]. On tab 'Tool settings' select the 'Preprocessor' section in ARM Sourcery Windows GCC C compiler [step 15]. Click on the icon with white sheet and green plus sign in 'Defined symblos' section and type STM32F10X_MD_VL in dialog window [step 16]. After you click 'OK' button, defined symbol should be present on list [step 17]. Now try build application again. There should be no errors, but one warning [step 18]. We missed one important file - script for the linker. Linker script contains informations about location of application sections in microcontroller memory. Download linker script for STM32VLDISCOVERY : stm32vldiscovery.ld and save it in project directory.

Now open again project properties window and go to 'General' settings for linker and specify location of linker script [step 19]. Now try build application again. There should be no errors and warnings [step 20]. Switch to 'Console' tab [step 21]. You should see informations about used space in sections : text, data and bss [step 22]. In 'text' section are stored code of application. In section data are stored variables initialized with value different than zero. In section bss are stored variables uninitialized (initialized with value zero). Now expand "Debug" folder on project tree [step 23]. Look for files with *.o extension. This file should be exist for each source file (*.c and *.s). But there is no *.o file for startup_stm32f10x_md_vl.s! Compiler is case-sensitive and assembler source files should have upper case extension *.S. So, change extension of startup file and rebuild application again.

Look again into 'Debug' folder [step 24]. Now in folder is present startup_stm32f10x_md_vl.o file, so everything is fine. Now, copy into main.c file code form lesson 1 and build application [step 25]. Output code size is about two times bigger than output code this same example compiled by Keil uVision. Open project properties window and go to 'Optimization' section of compiler settings [step 26] and select option "Optimize size" [step27]. Rebuild application, now code size should be smaller [step 28].

Programming flash memory
To programming flash memory we use ST-Link Utility. This program is avaiable in GUI and command-line version, we use command-line version. Select from menu "Run->External Tools" command 'External tool configurations...' [step1]. Double click on "Program" item [step2] and specify location of command-line version of ST-Link Utility (st-link_cli.exe) [step3]. After you click 'Apply' button position 'Program with ST-Link' shoud be on left panel [step4] and under 'Run' button on main toolbar of Eclipse [step5]. Now we have complete environment for programming STM32VLDISCOVERY evaluation board with open source tools (except ST-Link utility).

 

 
(c) Radosław Kwiecień