Saturday, November 17, 2012

STM32F3 Discovery + Eclipse + OpenOCD

Hi,

ST launched in September a very interesting development board(STM32F3-Discovery). It is a very cheap one(I have got myself one for ~10$). It has a debugger integrated(STLINK) and also some great sensors:
- ST MEMS LSM303DLHC, which contains 3 axis accelerometer(to measure acceleration intensity on each axis) and 3 axis magnetometer(to measure angles to a fixed point - the Earth's magnetic North)
- ST MEMS L3GD20, which has 3 axis gyrometer(to measure rotation speed)
This board is very good for automated pilot controller projects.

After unpacking the board I have found that it was supported just by commercial software and tools. As I am an opensource kind of guy I have struggled myself some time to get this working with Eclipse, OpenOCD and a free toolchain, on Linux.
I have used Ubuntu, but I think the process is the same on every distribution. Also, with little adjustments it can work on Windows.

Here are some steps, that you have to follow to get the led blinking example to work:
1. Install Java Runtime Environment. Here are some steps for Ubuntu:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

2. Install Eclipse. Get Eclipse IDE from here (grab the Eclipse IDE for C/C++ Developers) and unpack it somewhere

3. Install GDB Hardware Debugging. Open Eclipse go to Help->Install New Software and then search for GDB Hardware Debugging and install it.

   Install GNU ARM Eclipse plugin. Get it from here and install it from Help->Install New Software->Add->Archive and select the downloaded .zip file.

4. Install some dependencies. Paste following text in Terminal:
sudo apt-get install git zlib1g-dev libtool flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential libftdi-dev libusb-1.0.0-dev

5. Install OpenOCD(version>0.6.1). Get it from here and unpack it. Then, navigate to the extracted folder and type in Terminal:
./configure --enable-maintainer-mode --enable-stlink 
make 
sudo make install

6. Add rule for Stlink to be accessed without sudo. Type in Terminal:
sudo gedit /etc/udev/rules.d/99-stlink.rules
Paste the following text:
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3748", MODE="0666"
Type in Terminal:
sudo udevadm control --reload-rules
Now, with the board connected to PC you can enter  in Terminal:
openocd -f /usr/local/share/openocd/scripts/board/stm32f3discovery.cfg
The following text should appear:
Open On-Chip Debugger 0.6.1 (2012-10-29-22:02)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
srst_only separate srst_nogate srst_open_drain
Info : clock speed 1000 kHz
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
You can close the Terminal now.

7. Install toolchain.  You can use Codesourcery toolchain, like described in this step, or you can use GCC Arm Embedded toolchain(from here) which has support for hardware floating point unit and which is free and it is easier to install.
For Codesourcery follow the next steps:
Go to Codesourcery and download IA32 GNU/Linux Installer. To install it open the Terminal and navigate to the folder where it is downloaded. Type:
chmod a+x arm-2012.03-56-arm-none-eabi.bin 
./arm-2012.03-56-arm-none-eabi.bin
Then select next at every step. 

8. Download sample project stm32f3.tar.gz file and unpack it.

9. Open the project in Eclipse. Open Eclipse and go to Workbench. Click File->Import and then select General->Existing Projects into Workspace. Select the downloaded project and click finish.
This is a makefile project, so you have to edit makefile if you want to change some project settings. The frst thing you should do is open the Makefile file and check at the very beginning if the toolchain path is correct. This should be like:
TC = <path_to_toolchain>/arm-none-eabi
Now you can build. right click on project name and select build. The correct output is in the Console tab from Eclipse(ignore the warnings and errors from Problems tab).

10. Debugging. After the project was builded correctly select Run->External Tools->External Tools Configuration. Select OpenOCD(restart) in the left tab and click run.
Now, right click project and select Debug as->Debug Configuration and then
select in the left stm32f3-debug and then click Debug.
Note: If you want to add more source files you can add them in the src folder. New headers should be added into hdr folder. If you want to add another folder you have to specify it like the LIB_SRCS in the Makefile and also create LIB_OBJS like variable in the Makefile.

Happy free coding and debugging! :-)

88 comments:

  1. Thank you for this post. It was a great help in getting it going with openOCD and Eclipse, and the gcc-arm-embedded toolchain. I've actually got the demo project that comes with the board successfully compiling for debug now.

    ReplyDelete
  2. You are welcome. Good luck with your project!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I don't understand what to download from Codesourcery.
    Can you give any more details?

    Thanks, Bill

    ReplyDelete
    Replies
    1. Hi Bill!
      I recommend you to use GCC ARM toolchain which has better support. You can use this tutorial:
      http://engineering-diy.blogspot.ro/2012/11/free-arm-toolchain-with-floating-point.html
      For Codesourcery, you have to click 'Download Lite Edition' then register and then download IA32 GNU/Linux Installer.

      I have also updated step 7 in this tutorial.

      Regards,
      Andrei

      Delete
    2. Got both toolchains working. Thanks.

      Now I'm wondering, should I be able to take the example project from the ST website, stm32f3discovery_fw.zip, and run build and flash it to the board?

      This is the program the board comes with.
      Did you ever try that?

      -Bill

      Delete
    3. It should be very easy to add the files from the st example. This demo was created based on the st example. I have removed the usb part.

      Regards,
      Andrei

      Delete
    4. I've copied in that code and it builds and runs.

      Except -- the timer interrupt SysTick_Handler() is never fired. Being new to this chip, Eclipse, and the compiler chain I'm at a loss as to why.

      -Bill

      Delete
    5. OK, scratch that.

      Problem was fixed by unplugging/replugging the USB to the debugger. And restarting Eclipse. It's pretty delicate about getting in weird states.

      I am doing this all in Ubuntu under VMware, so I'm lucky the USB works at all, I guess.

      -Bill

      Delete
  5. Hi Andrei,

    Thanks for the great tutorial! I tried on PCLinuxOS, but stuck at step 6: there's no "XX-stlink.rules" in /etc/udev/rules.d/ . I'm downloading Ubuntu now, but if you'd have any hint on this would be great (as expected, just pasting the text from above didn't work).

    Regard, Daniel

    ReplyDelete
    Replies
    1. Hi Daniel!
      If the file doesn't exist it will be created when you will exit gedit and save.
      So, the complete step would be to create that file and paste the text, using root permission.
      I am glad that my tutorial is helpfull:-)

      Regards,
      Andrei

      Delete
  6. I've managed to fire up and debug pgms with OpenOCD.
    But how do you just let it run w/o the debugger?

    -Bill

    ReplyDelete
    Replies
    1. Hi Bill!

      The code is being written in the flash, so, if you just power up the board the code should work.

      Andrei

      Delete
  7. Hello What do we have to do to port this to a windows environment?
    This is the first ARM board I got my hands on

    ReplyDelete
  8. Hi Bill!

    In order to port this to windows you have to:
    1. Install GCC arm embedded for Windows and set the TC variable in the Makefile
    2. Install Openocd for Windows http://www.freddiechopin.info/en/download/category/10-openocd-dev and change the path for Openocd binary in the External Tools Configuration in Eclipse
    3. Install make for Windows http://gnuwin32.sourceforge.net/packages/make.htm

    ReplyDelete
    Replies
    1. Hi Andru,

      Good jobs.
      My PC is running Windows 7/64bits.
      1. " gcc-arm-none-eabi-4_8-2014q2-20140609-win32.exe (md5)" was found when searching "GCC arm embedded for Windows", which seemed to be 32bits version. Is it OK? Where to find the Makefile?
      2. Openocd for windows was found and unzip. Do you mean to run "openocd-x64-0.9.0-dev-swd-140623233947.exe" to install?
      3. In my newly installed Eclipse, I found no items when opening Run->External Tools->External Tools Configurations. Where will be the right location to change the path?
      4. I guess I need to fix the problems above to install make for windows, right?

      Ted

      Delete
  9. I got it to work under Windows!

    I did everything a few times first in Ubuntu in a VM just to get the feel of things.

    Installing in Windows was even easier.

    It did run me all over editing paths, which I had to find all the hard way. I'm going to do it again in a VM from scratch and I'll write down all the steps and post here.

    -Bill

    ReplyDelete
    Replies
    1. that's great.. but where's your walkthrough? I've been battling this for days. keep going down the internet rabbithole trying to decipher your post.

      Delete
  10. I believe I have followed your instructions, but I am getting errors while building the example code. It appears that uint16_t and uint32_t are not defined. Any clue to what I missed?

    ReplyDelete
  11. Never mind I switched to the "this" or free tool chain and the problem was corrected.

    ReplyDelete
  12. does not work anymore under linux

    22:22:20 **** Build of configuration Default for project stm32f3 ****
    make all
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
    sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-writer.o): In function `_write_r':
    writer.c:(.text._write_r+0x10): undefined reference to `_write'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-closer.o): In function `_close_r':
    closer.c:(.text._close_r+0xc): undefined reference to `_close'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-fstatr.o): In function `_fstat_r':
    fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-isattyr.o): In function `_isatty_r':
    isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-lseekr.o): In function `_lseek_r':
    lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-readr.o): In function `_read_r':
    readr.c:(.text._read_r+0x10): undefined reference to `_read'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libg.a(lib_a-abort.o): In function `abort':
    abort.c:(.text.abort+0xa): undefined reference to `_exit'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libg.a(lib_a-signalr.o): In function `_kill_r':
    signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
    /usr/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7e-m/softfp/libg.a(lib_a-signalr.o): In function `_getpid_r':
    signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
    collect2: ld returned 1 exit status
    make: *** [stm32f3.elf] Errore 1

    22:22:21 Build Finished (took 998ms)

    ReplyDelete
    Replies
    1. Hi!

      you have to add this file http://code.google.com/p/andrei-development/source/browse/branches/dev/stm32f3-discovery/Navigation/src/newlib_stubs.c in your src folder, as it is in the post with printf(http://engineering-diy.blogspot.com/2012/11/stm32f3-discovery-usart-with-printf.html). This file contains all the newlib functions needed when using printf.

      Andrei

      Delete
    2. thanks, it work"

      Delete
  13. I am running into errors when I get to step 5.
    I run the command:
    ./configure --enable-maintainer-mode --enable-stlink
    and it runs fine, but when I run the next command:
    make
    this is what is displayed next:

    make all-recursive
    make[1]: Entering directory `/media/Local Disk/openocd-0.6.1'
    Making all in jimtcl
    make[2]: Entering directory `/media/Local Disk/openocd-0.6.1/jimtcl'
    /media/Local Disk/openocd-0.6.1/jimtcl/.././jimtcl/autosetup/jimsh0 ./make-load-static-exts.tcl aio array clock eventloop exec file history load namespace pack package posix readdir regexp signal syslog tclprefix binary glob nshelper oo stdlib tclcompat tree >_load-static-exts.c || ( rm _load-static-exts.c; exit 1)
    /bin/sh: 1: /media/Local: not found
    make[2]: *** [_load-static-exts.c] Error 1
    make[2]: Leaving directory `/media/Local Disk/openocd-0.6.1/jimtcl'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/media/Local Disk/openocd-0.6.1'
    make: *** [all] Error 2

    Could someone give me some help?

    ReplyDelete
    Replies
    1. Hi!

      I think that there is a problem with the path name, which contains a space character("Local Disk"). try put the openocd extracted folder in your home and build it from there.

      Delete
    2. Thanks for some help. I changed the volume name to D. I am still having the same error. How ever I ran ./configure again then used make and its flawless. Thanks for the suggestion.


      Delete
  14. I have encountered another problem on the final step. When I choose to Debug I get the error message:

    'Launching stm32f3-debug' has encountered a problem.

    The program file specified in the launch configuration does not exist

    ReplyDelete
    Replies
    1. Fixed this problem, now I have a new one.

      'Launching stm32f3-debug' has encountered a problem

      Error creating session

      Details>>

      Error creating session
      Cannot run program "/home/andrei/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/arm-none-eabi-gdb": Unknown reason
      Cannot run program "/home/andrei/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/arm-none-eabi-gdb": Unknown reason
      Cannot run program "/home/andrei/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/arm-none-eabi-gdb": Unknown reason

      Delete
    2. Hi Riley!

      You have to provide the correct path to your arm-none-eabi-gdb binary.
      To do this, right click project->Debug As->Debug Configurations->GDB Hardware Debugging->stm32f3-debug->Debugger tab. Here, at GDB COmmand click Browse and set the link to your arm-none-eabi-gdb file.

      Andrei

      Delete
    3. I made that change but still the same error:

      Error creating session
      Cannot run program "/home/Developer/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/arm-none-eabi-gdb": Unknown reason
      Cannot run program "/home/Developer/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/arm-none-eabi-gdb": Unknown reason
      Cannot run program "/home/Developer/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/arm-none-eabi-gdb": Unknown reason

      Delete
  15. Can you please be sure that you can run arm-none-eabi-gdb, from your folder?(navigate there using terminal and try from terminal).
    Also, can you please install the toolchain from this(http://engineering-diy.blogspot.com/2012/11/free-arm-toolchain-with-floating-point.html) post and see if you can run it?

    ReplyDelete
  16. Thanks for the useful intro .. after getting it working I found there is an eclipse-arm project (http://sourceforge.net/projects/gnuarmeclipse/) which works pretty well. I'd be happy to provide the above project as an Eclipse project if anyone wants it ..

    My problem is getting it to work with hard fpu .. everything is fine if I build with softfp but I get the "XXX uses VFP register arguments, stm32f3.elf does not" errors.

    I'm using -mfpu=fpv4-sp-d16 and mfloat-abi=softfp (works) or mfloat-abi=hard (gives errors). Any clues?

    ReplyDelete
    Replies
    1. ah, never mind .. evidently softfp *is* using the fp hardware, the difference between hard and softfp has to do with calling conventions

      Delete
  17. Thanks for the guide! Do you know how to fix the uintX_t error? No problem with your exemple andrei but impossible to compile something more complex.

    ReplyDelete
    Replies
    1. Carlos,

      In order to fix the IDE errors for uintX_t you have to add path to include folder of the toolchain:
      - right click project -> Properties
      - go to C/C++ Build -> Environment
      - select PATH entry and click edit
      - add to the Value textbox \arm-none-eabi\include
      Then right click project and click Index -> Rebuild and then right click project Index -> Freshen all files.

      Andrei

      Delete
    2. Great tutorial...

      "In order to fix the IDE errors for uintX_t you have to add path to include folder of the toolchain:
      - right click project -> Properties
      - go to C/C++ Build -> Environment
      - select PATH entry and click edit
      - add to the Value textbox \arm-none-eabi\include
      Then right click project and click Index -> Rebuild and then right click project Index -> Freshen all files."

      This just isn't working for me can you include a little more explicit instructions? I am using Code Sourcery, I know the path the includes, just can't get Eclipse to see it!

      Ideas?

      Delete
    3. Hi!

      Please install this plugin:
      http://sourceforge.net/projects/gnuarmeclipse/

      Andrei

      Delete
  18. Thank you! 0 errors now!
    For managed build project I find this Eclipse plugin that you can use for Summon ARM toolchain. The only thing you have to do is rename the toolchain folder to summon-arm-toolchain and change the $PATH variable.
    Good luck coding!

    ReplyDelete
  19. Thanks for the great tutorial :-)

    I will to optimize out the eclipse part (to each it's own, i prefer bash & vim), but the Makesfiles etc. are of great help :)

    ReplyDelete
  20. Thank you very much for your tutorial, it is very helpful. However, I encountered a problem when first checking if openOCD is running. When I enter the command, openOCD outputs this instead:

    Open On-Chip Debugger 0.6.1 (2013-03-06-10:25)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
    adapter speed: 1000 kHz
    srst_only separate srst_nogate srst_open_drain
    Info : clock speed 1000 kHz
    Error: open failed
    in procedure 'transport'
    in procedure 'init'

    I continued on, and everything seems to build fine, but when I try to debug, eclipse outputs this:

    The program file specified in the launch configuration does not exist
    /home/biosproject/workspace/stm32f3/stm32f3.elf not found

    I looked and there is no stm32f3.elf in that directory. Are these problems related?

    ReplyDelete
    Replies
    1. EDIT: I completely missed that this was for a specific board. How much needs to be changed to get the toolchain, openocd, etc working on a Raspberry Pi? Sorry for the stupidity.

      Delete
  21. Hello,

    Thank you for your tutorial!

    Can you please post for us an stm32f3 eclipse template project? So that we can have a pre-configured project each time we create a new one?

    Thank you :)

    ReplyDelete
    Replies
    1. Hi!

      I don't know how to create an Eclipse template project, but I suggest you to keep a copy of the project folder as template.

      Regards,
      Andrei

      Delete
  22. Hello,
    I'm a beginner and I like to know if we can use this IDe to develop new project using differente ST boards too.
    Is it possible? Do you have any tutorial?

    Thanks in advance,
    Giuseppe.

    ReplyDelete
    Replies
    1. Hi Giuseppe!

      You can use this tutorial for other ST boards. You just have to edit the Makefile and change everything which contains STM32F3 to your board.
      Also you have to use your board .ld file and the correct .cfg file for OpenOCD.

      Regards,
      Andrei

      Delete
  23. Hi Andrei,
    thanks a lot for your answer and if I can I would make some question in order to clarify some concepts in my mind :-)
    I want to say I am a starter and until now I have installed the IAR software for windows (32kB size limited). Then I found this blog and I want to use this solution too... I use ubuntu 12.10.
    well, here some questions of mine:

    1. the Function names used to program the stm32 (for example the ST library) can be used with any IDE or not?
    2. what's the best way to use the ST API library?
    3. When I create a new project, is there any guide or tutorial to explain how to... ?

    For the moment it's enough.

    ReplyDelete
    Replies
    1. Hi Giuseppe!
      1. the function names can be used with any ide. The IDE is a tool to make the editing and the compilation easier.
      2. I don't understand what do you mean by this question.
      3. I don't know if there are tutorials for this. The steps I follow are:
      - create a folder with my source files and header files
      - add startup source file to sources folder
      - add linker file(.ld)
      - create a makefile
      - start Eclipse and select File->New->Makefile Project with Existing Code
      - create debug configuration and also run configuration(if external tools are needed)
      Please email me if you need more details.

      Andrei

      Delete
    2. Hi Andrei,
      thanks very very much for your answer and excuse me if I made some "stupid" question. It's a new world for me and I'm trying to learn as fast as possible.
      Now I have my open source IDE tool without 32KB size limitation (GREAT).
      When I'll receive my ST-link V2 I try to connect my board to pc and try to erase, program and debugging session.
      Then I'll try to write a new simple program.

      PS: were you able to connect your discovery board to openocd using the debugger inside th discovery board instead of ST-link?

      Delete
  24. Hi, thanks for the tutorial, I have managed to get openocd working at the command line and the command arm-none-eabi-gcc --version works in terminal.

    The problem I am having is when I come to build the example project is I get the result:
    arm-none-eabi-gcc: Command not found
    make: *** [Libraries/STM........./..._adc.o] Error 127

    ****Build finished***


    Any ideas on this?

    I have tried following other instructions here:
    http://embeddedprogrammer.blogspot.co.uk/2012/09/stm32f4discovery-development-with-gcc.html

    With the similar Error 127 result, although I am not sure how comparable this is as it seems to use .cpp files, not .c

    Thanks for the help,
    Ian

    ReplyDelete
    Replies
    1. As a follow up to this. I am getting the warnings:
      Program 'arm-elf-g++' is not foudn in $PATH
      Program 'arm-elf-gcc' is not foudn in $PATH
      Program 'arm-none-eabi-g++' is not foudn in $PATH
      Program 'arm-none-eabi-gcc' is not foudn in $PATH

      Delete
    2. error fixed by running eclipse from terminal, assume some privileges need changing somewhere, now I have a liblto_plugin error

      Delete
    3. fixed this by simply 're unpacking' the toolchain, how odd! apologies for all the comments, hopefully these will help other users

      Delete
    4. I am glad you have found a solution.

      Best Regards,
      Andrei

      Delete
    5. Compiling properly now, just having problems with debugging. With OpenOCD I get an error of 'cannot identify target as STM32 family.' ....best keep digging!

      Delete
  25. Hi Andrei,

    first of all great thanks for this clear and detailed tutorial. Really helps getting started.

    But after spending 14 hours and eliminating most of the known errors yesterday i still didn't get it work properly on mint 14 (cinnamon).

    Basically I start eclipse (with all needed plugins and software installed), import the project, build it, start openOCD(restart), start the debugger and the code works in let's say 1 in 10 cases. I adjusted the DELAY time to approve it really had compiled and flashed onto the stm32f3 discovery.
    But most of the time the board does nothing. The LED at the port blinks fast and the user LEDs won't do anything. If i push the reset button it works in about one out of ten cases by some kind of magical coincedence. And I really tried hard to ensure reproducable conditions.

    I don't know any further. The console doesn't report any severe errors even with debugger in verbose mode.

    The only error I didn't get rid of was the 'uintX_t could not be resolved error'. I installed the gnuarmeclipse plugin and I tried to change the path. There is not really a 'PATH' entry, only 'PWD' and 'CWD', so I added 'PATH' and gave it the suggested value. Didn't do anything.

    If you or anyone else had an idea what I could further do I would be pleased to hear about it!

    Best Regards,
    Jo

    ReplyDelete
    Replies
    1. Hi Jo!

      I am sorry that I cannot provide some help on this issue. Maybe someone will help.

      Best Regards!
      Andrei

      Delete
    2. Hi Andrei!

      Thanks anyway. I have finally solved it. Even if i don't know what did the trick in the end... but I think I learned a little about toolchains and linux and stuff... even if it took me 40+ hours and it's 1:00 AM on friday night and I'm still in front of my computer at the university 8-B

      What I can tell at the end: Relaunch openOCD after every build and keep an eye on it's console...

      Best Regards,
      Jo

      Delete
  26. Great tutorial,
    I just have few problems. Since I used esden summon arm tool chain instead of CS. I have installed eclipse and I can use the summon arm tool chain. The program builds and everything is fine but when I try to debug. It does not go to the correct line on start. Also If I single step it, the variable values are not what are expected and the sequence in the code is not followed. Can you help.
    I have used the o0 flag as suggested.
    Can it be a problem with toolchain. I am a newbee to arm as well as linux.
    Regards,
    nd

    ReplyDelete
  27. I keep getting errors on Step 6. when trying to start OpenOCD:

    openocd -f /usr/local/share/openocd/scripts/board/stm32f3discovery.cfg
    Open On-Chip Debugger 0.7.0 (2013-09-13-01:50)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
    srst_only separate srst_nogate srst_open_drain connect_deassert_srst
    Info : This adapter doesn't support configurable speed
    Error: open failed
    in procedure 'transport'
    in procedure 'init'

    Do you have any hints what to try?

    ReplyDelete
    Replies
    1. Hi!

      I haven't tried with OpenOCD 0.7.0, just with 0.6.1.

      Delete
  28. Hello I use STM32F3 discovery and Openocd 0.7.0 and Ubuntu 12.04 LTS 64bit
    I've got some errors:

    Open On-Chip Debugger 0.7.0 (2013-09-09-10:58)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
    srst_only separate srst_nogate srst_open_drain connect_deassert_srst
    Info : This adapter doesn't support configurable speed
    Info : STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748
    Info : Target voltage: 2.887038
    Error: init mode failed
    in procedure 'transport'
    in procedure 'init'


    I try on openocd 0.6.1 and did not works too i've got:

    Error: open failed
    in procedure 'transport'
    in procedure 'init'

    Can i fix this?? or maybe is something wrong on my board?? Ofc i connected on USB ST-LINK, and i did all following the tutorials

    ReplyDelete
    Replies
    1. Hi!

      I have tested this only on 32 bit machine using OpenOCD 0.6.1. I am sorry but I don't know how to help you more with this. Maybe you can try on OpenOCD forums.
      Also please check that the .cfg file is the one for your board.

      Delete
  29. Thanks man this was a big help. I really didn't want to boot windows.
    Also if your using the GCC Arm Embedded toolchain, before you debug
    right click project folder -> debug as -> debug configurations -> GDB Hardware Debugging -> stm32f3-debug
    go to debugger tab and change the gdb command path to your tool chain location bin/arm-none-eabi-gdb

    ReplyDelete
  30. I have just installed this stuff and am new to STM32F3. I am running ubuntu 13.04 64bit.

    I have openocd 0.7.0 installed and I have created the udev rules and restarted udev

    When I execute
    openocd -f /usr/local/share/openocd/scripts/board/stm32f3discovery.cfg

    Open On-Chip Debugger 0.7.0 (2013-12-11-08:35)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
    Error: The specified debug interface was not found (hla)
    The following debug interfaces are available:
    Runtime Error: /usr/local/share/openocd/scripts/interface/stlink-v2.cfg:5:
    in procedure 'script'
    at file "embedded:startup.tcl", line 58
    at file "/usr/local/share/openocd/scripts/board/stm32f3discovery.cfg", line 4
    in procedure 'interface' called at file "/usr/local/share/openocd/scripts/interface/stlink-v2.cfg", line 5

    I notice another person on this site has commented having similar problems with open ocd on a 64 bit OS.

    I will try to figure out a fix from open ocd forums.

    Please update me if you are aware of any fix for this.


    ReplyDelete
    Replies
    1. I realised that I only ran ./configure and not

      ./configure --enable-maintainer-mode --enable-stlink

      After re configuring and rebuilding, my problem has disappeared.

      Delete
  31. Thank you for your code, I modify it to use with Coocox CoIDE, these are same of examples.
    http://www.electoday.com/index.php/topic,11432.0.html
    Thanks!

    ReplyDelete
  32. I can not download the sample project from the both link you give (step 8).
    Can I download the sample project from an other source?

    ReplyDelete
  33. Just I must to say about OpenOCD, that I had a permissions problems and
    sudo udevadm control --reload-rules
    doesn't fix the problem, but after rebooting starts working.
    So, if you use Fedora (3.19.8-100.fc20.x86_64 in my case), may be reloading control rules is not sufficient

    ReplyDelete
  34. Hi Andrei, I seem to have the following problem when I try to run the stm32f3 project on eclipse. I get this error on the console:

    Open On-Chip Debugger 0.9.0 (2016-05-09-00:31)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
    adapter speed: 1000 kHz
    adapter_nsrst_delay: 100
    Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
    none separate
    srst_only separate srst_nogate srst_open_drain connect_deassert_srst
    Info : Unable to match requested speed 1000 kHz, using 950 kHz
    Info : Unable to match requested speed 1000 kHz, using 950 kHz
    Info : clock speed 950 kHz
    Info : STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748
    Info : using stlink api v2
    Info : Target voltage: 2.897285
    Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
    adapter speed: 1000 kHz
    target state: halted
    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0x08003cc8 msp: 0x20000640
    adapter speed: 8000 kHz
    background polling: on
    TAP: stm32f3x.cpu (enabled)
    target state: halted
    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0x08003cc8 msp: 0x20000640

    Do you know what this means, and can you help me with it? Thank you.

    ReplyDelete
  35. Hi, thank you for the guide!

    I have faced with the following issue on the 6th step:

    openocd -f /usr/local/share/openocd/scripts/board/stm32f3discovery.cfg
    Open On-Chip Debugger 0.10.0
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
    adapter speed: 1000 kHz
    adapter_nsrst_delay: 100
    Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
    none separate
    srst_only separate srst_nogate srst_open_drain connect_deassert_srst
    Info : Unable to match requested speed 1000 kHz, using 950 kHz
    Info : Unable to match requested speed 1000 kHz, using 950 kHz
    Info : clock speed 950 kHz
    Error: open failed
    in procedure 'init'
    in procedure 'ocd_bouncer'

    Did somebody have the same issue? Any solutions?

    Best regards,
    Vlad

    ReplyDelete
    Replies
    1. lsusb
      Bus 003 Device 005: ID 0483:374b STMicroelectronics ST-LINK/V2.1 (Nucleo-F103RB)

      So, the 1st problem was probably connected with the idProduct.

      After that, I did following steps:
      1. Changed idProduct to "374b"(see the 6th step of the Andrei's guide)
      ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", MODE="0666"
      2. Checked the list (ls) of available interfaces in the directory "/usr/local/share/openocd/scripts/interface", and found stlink-v2-1.cfg there.
      3. After that I went to the folder "/usr/local/share/openocd/scripts/board", opened the file "stm32f3discovery.cfg" (sudo gedit stm32f3discovery.cfg), changed the interface to stlink-v2-1.cfg (instead of tlink-v2.cfg) and saved.

      The result:
      openocd -f /usr/local/share/openocd/scripts/board/stm32f3discovery.cfg
      Open On-Chip Debugger 0.10.0
      Licensed under GNU GPL v2
      For bug reports, read
      http://openocd.org/doc/doxygen/bugs.html
      adapter speed: 1000 kHz
      adapter_nsrst_delay: 100
      Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
      none separate
      srst_only separate srst_nogate srst_open_drain connect_deassert_srst
      Info : Unable to match requested speed 1000 kHz, using 950 kHz
      Info : Unable to match requested speed 1000 kHz, using 950 kHz
      Info : clock speed 950 kHz
      Info : STLINK v2 JTAG v27 API v2 SWIM v15 VID 0x0483 PID 0x374B
      Info : using stlink api v2
      Info : Target voltage: 2.917340
      Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints

      Delete
  36. Hello,
    did smb face with further message after launching of OpenOCD?

    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0x08003cc8 msp: 0x20000640

    I use Eclipse Neon, OpenOCD 0.10.0 and stm32f3discovery board.

    Looking forward to hear an advice from anybody.

    ReplyDelete
  37. This comment has been removed by a blog administrator.

    ReplyDelete
  38. Hi,I had several question about debugging method,Im not clear about the GDB Hardware Debugging -> stm32f3-debug -> Debugger -> Remote Target -> JTAG Device ,
    What did I need to choose ,and what is exact port number for STlinkv2-1 ,Thanks

    ReplyDelete