CodeBlocks as debugging IDE with STM32Duino

michael_l
Wed Jul 27, 2016 12:12 pm
Does anybody use CodeBlocks as a debugging IDE using ST Link and SWD debugging ? I just saw that CodeBlock has OpenOCD support which essentially means OpenOCD provides GBD “interface” to IDE.

Before I go on trying that I would like to know has anybody tried it ? Being much more lightweight IDE than Eclipse I’d like to try if I get SWD Debugging working with STM32F103. This would anyway still mean that compiling would be done in Arduino IDE but CodeBlocks would use the output directory that has binaries and symbol files, etc. Thanks.


Slammer
Wed Jul 27, 2016 12:26 pm
Yes it is possible to use Codeblocks as arduino IDE with OpenOCD support. I am using it and it is working very well.
The setup of building system and debugging is a bit complex but it is possible. I plan to write a full guide for this…

For now you can see the building system for stm32 for halmx applications from my repo, and to use it as a template : http://www.stm32duino.com/viewtopic.php?f=46&t=1267
There is also a guide in polish (i dont know polish but it is pretty illustrated) for gdb/openocd : https://www.google.gr/url?sa=t&rct=j&q= … 3897,d.d2s

Take a look also here : http://www.hackvandedam.nl/blog/?p=707


michael_l
Wed Jul 27, 2016 12:47 pm
Thanks, I’ll take a look at that. A guide would definitely be nice. Even a simple for starters :-) Ok.. you have full building in that CodeBlock. So a bit different what I’m using now.

The thing is .. with Eclipse it is very easy to set up debugging since there are OpenOCD plugins. I still compile with Arduino IDE though but in Eclipse you only need to create debugging project once and after that you just compile in Arduino IDE and then in Eclipse start debugging.. quite easy and painless.


Slammer
Wed Jul 27, 2016 12:50 pm
Codeblocks supports gdb by default, but you need to change some settings to support gdb/openocd… is not so difficult (IMO much easier than eclipse)

michael_l
Wed Jul 27, 2016 12:58 pm
Slammer wrote:Codeblocks supports gdb by default, but you need to change some settings to support gdb/openocd… is not so difficult (IMO much easier than eclipse)

michael_l
Fri Jul 29, 2016 9:00 am
Hi,

So is there any “ready-made” OpenOCD plugin for CodeBlocks ? I couldn’t find any..

Thanks.


zmemw16
Fri Jul 29, 2016 12:26 pm
google “OpenOCD plugin for Code Blocks” gives first 2 as
http://forums.codeblocks.org/index.php?topic=11359.0
http://www.codeblocks.org/cbplugins
ok fairly old, but …

if you register with the first and search openocd, there’s quite a bit more

srp


Slammer
Fri Jul 29, 2016 6:27 pm
No need for a special plugin… C::b supports gdb, only correct setup is needed.

Slammer
Fri Jul 29, 2016 11:22 pm
I will describe the procedure briefly.

1. First, I assume that the arm compiler is correctly defined and you can build the binary (always with -O0 for debugging).

2. It is important to set up correctly the debugger. In the Settings>Debugger define a new debugger (let’s call it ‘OpenOCD’) you have to define the executable to your arm-none-eabi-gdb and some settings (look screenshot).

debugger-settings.png
debugger-settings.png (50.18 KiB) Viewed 3030 times

Slammer
Fri Jul 29, 2016 11:29 pm
Here is the main window showing the main program and the calling function during execution with the debug windows while the debugging is active (the screenshot is distorted to reduce the size)

The plain codeblocks is not dedicated to stm32 development but it can do the job as it is using the gdb. Emblokcs/Embiz is a fork of Codeblocks dedicated to embedded development and it offers more debug windows with register views of peripherals etc, but it is available only for Windows.


michael_l
Sat Jul 30, 2016 8:15 pm
Thanks! I’ll try this in near future and let you know. So would you say that Eclipse offerw more ‘debugging’ capabilities (register windows etc) than CodeBlocks/EmIde ?

Slammer
Sat Jul 30, 2016 8:51 pm
I don’t think that Eclipse offers more debugging capabilities than Codeblocks. Both systems support standard gdb. Embiz is a bit different, it is Codeblocks with some plugins dedicated to embedded development.
Actually, I am using codeblocks for many years as my professional development IDE for developing linux embedded systems (same sources, different architectures), and I am very familiar with it, this is the main reason for me, to use it for stm32 development.
Codeblocks is small and fast, with very good editor (code completion, symbol browser etc) and a versatile build system. Except from its own build system supports plain makefiles. I tried eclipse, but it is very slow in my machines….

FYI, Here are the links for programs used:
Arm toolchains : https://launchpad.net/gcc-arm-embedded
Code::Blocks : http://www.codeblocks.org/downloads/binaries
OpenOCD : https://sourceforge.net/projects/openoc … rce=navbar
STM32 Codeblocks library project and Templates for halmx/mbed (I will try to make one for arduino_stm32) : https://github.com/evark/cbp-mbed & https://github.com/evark/cbp-halmx


zmemw16
Sun Jul 31, 2016 7:42 pm
quick tip, took longer for the “whats’s it looking for?” thought to occur :D
change the executable names from arm-elf-xyz to arm-none-eabi-xyz

cb-setup.png
cb-setup.png (105.94 KiB) Viewed 1272 times

michael_l
Wed Aug 03, 2016 10:42 am
Installed CodeBlocks but I’m currently having problems with OpenOCD. I suspect some problems with USB Driver library it uses. I’m not exactly sure what USB Driver should be installed for ST Link V2-1 under windows.

C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility>ST-LINK_CLI.exe -c
STM32 ST-LINK CLI v2.5.0
STM32 ST-LINK Command Line Interface

ST-LINK SN : 0671FF485452785087212719
ST-LINK Firmware version : V2J27M15
Connected via SWD.
SWD Frequency = 4000K.
Target voltage = 3.2 V.
Connection mode : Normal.
Device ID:0x410
Device flash Size : 128 Kbytes
Device family :STM32F10xx Medium-density


Slammer
Wed Aug 03, 2016 10:56 am
Try binaries from here: http://gnuarmeclipse.github.io/openocd/install/

PS: probably you are already using these binaries….


michael_l
Wed Aug 03, 2016 10:58 am
Slammer wrote:Try binaries from here: http://gnuarmeclipse.github.io/openocd/install/

PS: probably you are already using these binaries….


michael_l
Wed Aug 03, 2016 11:39 am
michael_l wrote:Slammer wrote:Try binaries from here: http://gnuarmeclipse.github.io/openocd/install/

PS: probably you are already using these binaries….


michael_l
Wed Aug 03, 2016 4:51 pm
Got it working with BP.

EDIT: seems to work okay! Couldn’t find global variables though..

Anyway. I added these in ‘Additional GDB commands’

load <file.elf>
symbol-file <file.elf>

And in debuuger search dirs I added build folder from Arduino IDE and some folder from STM32F1/cores

Image


Slammer
Wed Aug 03, 2016 7:40 pm
Open Variables window (watch) on Debug session… below Local variables in an empty cell, write the Global’s variable name, it should work….

PS: I compile the sources with -ggdb flag, I think this helps because the debug info are oprimised for gdb…. (use also -Og optimization for better debug experience)


michael_l
Wed Aug 03, 2016 8:23 pm
Slammer wrote:Open Variables window (watch) on Debug session… below Local variables in an empty cell, write the Global’s variable name, it should work….

PS: I compile the sources with -ggdb flag, I think this helps because the debug info are oprimised for gdb…. (use also -Og optimization for better debug experience)


Slammer
Wed Aug 03, 2016 8:29 pm
Adruino STM32 is using -Os optimization flag, this is very aggressive for debugging purposes. Due to optimizations it is possible to lose stepping on some lines or some variables etc…
You can change the flag on platform.txt inside STM32F1 directory from -Os to -Og for better results.

michael_l
Thu Aug 04, 2016 7:04 am
Slammer wrote:Adruino STM32 is using -Os optimization flag, this is very aggressive for debugging purposes. Due to optimizations it is possible to lose stepping on some lines or some variables etc…
You can change the flag on platform.txt inside STM32F1 directory from -Os to -Og for better results.

michael_l
Mon Feb 06, 2017 7:37 pm
Is there a way in CodeBlocks to start only debugging for a specific .elf file ?

Now the IDE wants to compile my program first which returns an error and does not let the debugging start. I’m using Arduino IDE for compiling.


Leave a Reply

Your email address will not be published. Required fields are marked *