using open source tools for stm32 cross development under linux

41
Using Open Source Tools with STM32 Micros Using Open Source Tools for STM32 Cross Development under Linux. Revision 4 Author: Michel Catudal [email protected] January 16 th 2010 Page 1 of 41

Upload: others

Post on 03-Feb-2022

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Using Open Source Tools for STM32 Cross Development under Linux.

Revision 4

Author: Michel Catudal

[email protected] 16th 2010

Page 1 of 41

Page 2: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Introduction For those on a limited budget, use of open source tools to develop embedded software for the ARM devices is the only way. The goal of this document is to help those interested in doing development with Linux by making their installation of an ARM development system a bit easier. So far most of the information for ARM development is for windows while the Linux users are ignored. For development on Linux you are usually on your own.

The goal of this document is not to do everything for you but to make your life easier. You still need to be somewhat familiar with your Linux environment to use this document. This document describes an installation on Mandriva 2010.0 Linux. Installation on any other Linux system should be similar. The favorite development environment appears to be eclipse. Mandriva uses an old version of Eclipse that crashes often. Version 3.6 has the bug fixed so this document will explain how to install it and how to use it. If you prefer to use the old buggy version take note that the procedure is similar to what is documented here.

For the debugging part you will need the Zylin plugin, you can install it with the install new software option in Eclipse. You will also need my project plugin which is derived from GNUARM.

For development you will need set of tools. The package that I provide fully support ARM7TDMI and cortex-m3 devices such as STM32 and Luminary.

I provide some RPM and Ubuntu packages on my website. For $10 you can get files for some other distribution.

For this demo I use a board from Olimex designed for IAR called STM32-SK.

Page 2 of 41

Page 3: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Hardware Information

As a hardware platform to exercise our ARM cross development tool chain, we will be using the STM32-SK evaluation board from Olimex at the cost of around $250.00. You can purchase this board at digikey , future or some other distributor of STMicros. Olimex sells a slightly different board which is somewhat cheaper. You can get some cheaper boards at MicroController Pros. Type STM32 in the search box. You will see several interesting boards using the STM32 processor.The STM32-SK board includes two serial ports, a USB port, 1 CAN port, 16 LEDs, a LCD display, a potentiometer connected to an A/D port, a connector for a microphone and one for a headphone. It also has a connector in the back for a flash SD drive. It has standard JTAG connector for debugging.This board comes with a limited version of the IAR Compiler. The Full version is good but very expensive. The ARM GCC Compiler compares well against IAR compiler and is open source.

Page 3 of 41

Page 4: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Olimex has a few USB devices that you can buy at MicroController Pros

The device used with this tutorial is the ARM-USB-TINY which costs $41.00. You could use something different like the ARM-USB-JTAG which costs $72.00. Unless you need the extra serial port and need the power supply this device has no real advantage over the tiny device.

Open Source Tools To install an ARM cross development tool chain, we need the following components:

1. Eclipse IDE version 3.6 2. The latest Zylin plugin.3. Modified version of the gnuarm eclipse plugin.4. Binutils, GNU C++/C Compiler for arm-elf targets5. Latest working OpenOCD for JTAG debugging

Here is a list of the files available at Catudal Software.

1. arm-elf-binutils-2.20.51-3mdv2010.0.catu.i586.rpm 2. arm-elf-binutils-2.20.51-3mdv2010.0.catu.src.rpm 3. arm-elf-binutils-locale-2.20.51-3mdv2010.0.catu.i586.rpm 4. arm-elf-gcc-4.4.2-2mdv2010.0.catu.i586.rpm 5. arm-elf-gcc-4.4.2-2mdv2010.0.catu.src.rpm 6. arm-elf-gcc-locale-4.4.2-2mdv2010.0.catu.i586.rpm 7. arm-elf-gdb-7.0-1mdv2010.0.catu.i586.rpm 8. arm-elf-gdb-7.0-1mdv2010.0.catu.src.rpm 9. libftdi-0.16-1mdv2010.0.catu.i586.rpm 10. libftdi-0.16-1mdv2010.0.catu.src.rpm 11. libftdi-devel-0.16-1mdv2010.0.catu.i586.rpm 12. openocd-0.4.0-2mdv2010.0.catu.i586.rpm 13. openocd-0.4.0-3mdv2010.0.catu.src.rpm 14. org.eclipse.cdt.arm_elf_0.5.0.tar.lzma

Page 4 of 41

Page 5: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Installation of C Compiler and utilities

You need to open a terminal window. You can either su root or use sudo to install the applications.

You do a cd to the directory where the files have been downloaded and install them

sudo rpm -i -vv libftdi-0.16-1mdv2010.0.catu.i586.rpmsudo rpm -i -vv openocd-0.4.0-2mdv2010.0.catu.i586.rpm sudo rpm -i -vv arm-elf-binutils-2.20.51-3mdv2010.0.catu.i586.rpmsudo rpm -i -vv arm-elf-gcc-4.4.2-2mdv2010.0.catu.i586.rpmsudo rpm -i -vv arm-elf-gdb-7.0-1mdv2010.0.catu.i586.rpm

If you don't have the locales for gcc already installed you can install the ones for arm-elf-gccsudo rpm -i -vv arm-elf-gcc-locale-4.4.2-2mdv2010.0.catu.i586.rpm

Installation of Eclipse

You need to first download Eclipse. The 3.6M3 version is a good version, you could use a nightly build if you prefer to get the latest and greatest. Just decompress the compressed file on the root of your user account. You also need to install Sun Java and switch to it. The Eclipse that comes with Mandriva is the old version 3.4 and crashes often.

First copy the plugin org.eclipse.cdt.arm_elf_0.5.0.jar to the ~/eclipse/plugins directory.After that you need to create a menu item so you can start Eclipse thru the menus.

Start Eclipse using the menu.

Page 5 of 41

Page 6: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

The Eclipse splash screen opens up as shown here.

The first time that you run eclipse or if you have never selected a default workspace it will bring this menu. To accept the default workspace select “Use this as the default and do not ask again”.You can change the name if you prefer a different directory name.

Page 6 of 41

Page 7: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

The first time that you run Eclipse, it will show the “Welcome” page. You can discard the page by clicking on the “x ” next to the word Welcome.

In order to do some development you will need to install the C and C++ support as well as the Zylin plugin.

Click on Help – Install New Software.

Page 7 of 41

Page 8: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Select “All Available Sites” and pick the C/C++ Development Tools in Programming Languages.Click on Next.

Page 8 of 41

Page 9: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Click on Next.

Page 9 of 41

Page 10: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

It would probably be a good idea to accept the license agreement.

Page 10 of 41

Page 11: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

When the installation is done it wants to restart, click on Yes

Click on Yes.

Page 11 of 41

Page 12: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

For Debugging the Zylin plugin is a must. Go to the same procedure as previously. This time you will need to click on Add. Type in the following information and click OK.

Page 12 of 41

Page 13: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

The installer is not familiar with the Zylin plugin so it enters into the paranoiac mode.

Since this Zylin plugin is safe, click on OK

After the installation you will be asked again to restart eclipse. You need to accept.You will then get a welcome page which you need to remove by clicking on the X.

Page 13 of 41

Page 14: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Now you need to switch the perspective to C/C++. Click on “Open Perspective” and “Other”

Highlight C/C++ and click on OK

Page 14 of 41

Page 15: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

We now create a new project. Click on new and C Project.

Enter a name for the project. We will use the default location for the project. It will be a GCC ARM project. The GCC ARM project uses the arm-elf-gcc compiler.

For now we just press on Finish. We will come back to the properties later on to fix the project configurations.

Page 15 of 41

Page 16: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

We will import some files from a working project. We don't bring any makefiles since the plugin will take care of creating the proper makefiles needed.

Page 16 of 41

Page 17: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

We now need to find the files to import. Click on Browse and find where the project to import is.We pick all the files on the root directory of ~/temp_eclipse/STM32-SK_LCD_Demo as well as the LCD directory. All the files will be copied to the ~/workspace/STM32-SK_LCD_Demo directory.Do not mark the STM32-SK_LCD_Demo directory.

Press finish when all the files have been selected

Page 17 of 41

Page 18: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

The project is almost ready. Before we try to compile though we need to adjust the properties.

Page 18 of 41

Page 19: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

First change the configuration so we will modify the Debug Properties by default.

Right click on STM32-SK_LCD_Demo. On the bottom click on Properties.

Page 19 of 41

Page 20: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Expand C/C++ Build settings

We will have to add a definition. Click on the add button.

We then enter __thumb2__ and press on OK.

Page 20 of 41

Page 21: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

We need to identify the linker script. Press on Browse and pick the file STM32-SK-FLASH.ld on the project directory.

Page 21 of 41

Page 22: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

The next step will be to set the library paths.

Click on add in the Library search path section. Enter the path for the libgcc library for thumb2 and click on OK.

Page 22 of 41

Page 23: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Click again on add and enter the patch for the library for libc for thumb2 and click on OK.

Next we need to setup the include paths

Page 23 of 41

Page 24: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Click on the add button and enter the local path the LCD directory.

Click on the add button and enter the local path the project directory.

Click on the add button and enter the include path for libc.

Page 24 of 41

Page 25: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Click on the add button and enter the include path for libgcc.

Page 25 of 41

Page 26: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

We need to add a few options. The flags -std=gnu99 is added to support some new features.The flag –-freestanding tells gcc that it is an embedded application where main doesn't require a return value. The flags -msoft-float and -mfpu=vfp are needed to make sure that the proper style of floating point is picked. It won't link if there is a mismatch between the libraries and the application code. When newlib or libgcc are not used and there are no floating point in the application the flags are not needed. If you use printf there will be a problem without those flags. When you use printf the floating point library is linked in as requested by newlib.The newer compiler complains about aliasing. To forbid it breaks embedded code, there is no easy way around it, we need to disable it with -Wstrict-aliasing=n.

Press on apply to finish the properties settings. Now it is time to do a build. Click on the pulldown menu Project and then Rebuild Project. It should compile without error. Double check on the console at the bottom.

Page 26 of 41

Page 27: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Page 27 of 41

Page 28: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Now we need to setup some way to debug. Click on Run and Debug Configurations.

Page 28 of 41

Page 29: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Page 29 of 41

Page 30: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Double click on Zylin Embedded debug (Native) and type the name that you want for the debugger menu. Click on browse and enter the correct name for the debugger, arm-elf-gdb.

The following configuration is necessary if you want to have functional interrupts and be able to trace without just tracing interrupts. The default for Openocd is to mask the interrupts. The problem with that is that interrupts no longer work. If you just remove the mask then all you trace are the interrupts. If you don't have any interrupts then don't bother with this configuration because there seems to be a serious bug in gdb, openocd or eclipse since using this slows debugging to a crawl. You may go around this by using telnet and issue the mask commands thru telnet and use breakpoints.

define hook-step mon cortex_m3 maskisr on end define hookpost-step mon cortex_m3 maskisr off end

Before debugging can start some initialization is necessary.

This command tells the debugger to use the remote connection of openocd :target remote localhost:3333

Page 30 of 41

Page 31: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

This command resets the processor and put it in the halt mode :monitor reset halt

This command loads the program. You could create a different launcher that doesn't do any loading so you would not reflash the device when it is not needed. The launcher would be identical to this one with the load command missing.

load

This command sets a breakpoint at main

thbreak main

This command tells gdb to run the code. It will run the startup code and stop at main.

c

We unmark “Launch in background” so we know when loading is done and don't assume that it is crashed, it also gives us the option to cancel if we conclude that it did crash.

Mark the box near Debug so it add it to the top menu.

Page 31 of 41

Page 32: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Page 32 of 41

Page 33: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

In the Main menu enter the project name and click on Apply and Close

Page 33 of 41

Page 34: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

arm-elf-gdb communicates with OpenOCD with target remote localhost:3333. We need to create a launcher to start OpenOCD before we attempt to load the debugger. Click on “External Tools – External Tools Configurations”

Page 34 of 41

Page 35: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Double click on Program

Page 35 of 41

Page 36: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Type /usr/bin/openocd in the location. For the Working Directory click on Browse Workspace and accept the workspace where the project is. For the argument enter the configuration used for your JTAG programmer.

Click on Apply and change to the Common page.

Page 36 of 41

Page 37: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Mark the box for External Tools so it appears as a menu and remove the mark so it doesn't launch in the background, that way you will know if it hung or not.

Page 37 of 41

Page 38: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

Now we need to test our setup. Click on Run – External Tools OpenOCD. This will start OpenOCD.

Page 38 of 41

Page 39: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

If you use the Olimex Tiny this will appear on the bottom console

Open On-Chip Debugger 0.4.0-rc1-dev-00115-g1837657 (2010-01-16-10:39)For bug reports, read

http://openocd.berlios.de/doc/doxygen/bugs.html1000 kHzjtag_nsrst_delay: 100jtag_ntrst_delay: 100Info : clock speed 1000 kHzInfo : JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)Info : JTAG tap: stm32.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)Info : stm32.cpu: hardware has 6 breakpoints, 4 watchpoints

Now that OpenOCD is running we can start the debugger. Because of a bug in Openocd or gdb the programming will always fail on the first time after the STM32 is powered up.

On a successful reflashing you should see something like this.

source /home/michel/travail_STM32/STM32-SK_LCD_Demo/gdb.cfgtarget remote localhost:33330x00000000 in ?? ()monitor reset haltJTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)JTAG tap: stm32.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)Invalid ACK 0x7in JTAG-DP transactiontarget state: haltedtarget halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x080003b0 msp: 0x20004800loadLoading section .text, size 0x416c lma 0x8000000Load failedthbreak main Hardware assisted breakpoint 1 at 0x8000222: file ../main.c, line 185.c

Page 39 of 41

Page 40: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

You now have a working debugger. If you have several monitors you could move some of the windows so you can have an easier debugging session.

Page 40 of 41

Page 41: Using Open Source Tools for STM32 Cross Development under Linux

Using Open Source Tools with STM32 Micros

This document is Copyright (C) Michel Catudal 2009-2010 All rights reserved.

If you feel that this has been helpful to you feel free to make a donation with paypalat [email protected]

Revision History

Release 1 : First draftRelease 2 : Updated to reflect latest tools. Notes added to inform about issues when using floating points (hard versus soft)Hard floating point is not supported for Cortex-m3 and ARM7 but sometimes the compiler assumed that hard float was requested.Release 3 : Modified to support Eclipse 3.2 that comes with Fedora 9A few issues with plugins were discovered.

Release 4 : Updated to support the latest changes in OpenOCD

Page 41 of 41