CodeBlocks as debugging IDE with STM32Duino

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
michael_l
Posts: 289
Joined: Mon Aug 24, 2015 6:11 pm

CodeBlocks as debugging IDE with STM32Duino

Postby 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.

User avatar
Slammer
Posts: 241
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: CodeBlocks as debugging IDE with STM32Duino

Postby 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 : 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
Last edited by Slammer on Wed Jul 27, 2016 12:52 pm, edited 1 time in total.

michael_l
Posts: 289
Joined: Mon Aug 24, 2015 6:11 pm

Re: CodeBlocks as debugging IDE with STM32Duino

Postby 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.

User avatar
Slammer
Posts: 241
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: CodeBlocks as debugging IDE with STM32Duino

Postby 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
Posts: 289
Joined: Mon Aug 24, 2015 6:11 pm

Re: CodeBlocks as debugging IDE with STM32Duino

Postby 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)


Please write a few lines if you have time :-)

Arduino IDE compiler chain seems to do quite a lot to .ino file during compile or does it really ? I dont know but it seems so and that's why a bit difficult and time consuming to replicate the exact steps. I'm fine with compiling in Arduino IDE but I'd like to use Codeblocks as editor and debugger.

michael_l
Posts: 289
Joined: Mon Aug 24, 2015 6:11 pm

Re: CodeBlocks as debugging IDE with STM32Duino

Postby 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
Posts: 1075
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: CodeBlocks as debugging IDE with STM32Duino

Postby 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

User avatar
Slammer
Posts: 241
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: CodeBlocks as debugging IDE with STM32Duino

Postby Slammer » Fri Jul 29, 2016 6:27 pm

No need for a special plugin... C::b supports gdb, only correct setup is needed.

User avatar
Slammer
Posts: 241
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: CodeBlocks as debugging IDE with STM32Duino

Postby 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 1084 times


3. Go to your compiler settings (select the Compiler that you are using for your project) and set the Debugger to 'OpenOCD' from pulldown menu. Now the compiler and the debugger are linked.

4. Now the tricky part. Go to Project>Properties and select the Debugger tab, select on the menu bottom-left your target and on the 'Remote Connection' tab fill the IP address with the word localhost and the Port with 3333. Dont close the window yet, select the 'Additional GDB Commands' tab and fill the After Connection box with two lines, the first is:monitor reset init and the second load binaryname (change the binaryname to your target binary, I am using macros to make this independent of the name of the target ).
target1.png
target1.png (48.78 KiB) Viewed 1084 times

target2.png
target2.png (47.52 KiB) Viewed 1084 times


5. Build the binary as usual. Open the main program in the codeblocks and place a breakpoint in a line near the start of the program or anywhere you want. Open a terminal window and execute there the openocd with the correct arguments for your mcu/debug hardware, for example for BluePill/STLink the command is: openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg. Return to codeblocks and select Debug>Start, the program will start in your hardware and will stop on the breakpoint, you can continue or step the execution as you wish. You can also open some debugging windows as variables watch, cpu registers, etc for more info during execution. You can automate more the procedure, by using the Tools menu for automatic execution/termination of openocd. A Tool is simply a predefined command with optional arguments.
Last edited by Slammer on Fri Jul 29, 2016 11:37 pm, edited 2 times in total.

User avatar
Slammer
Posts: 241
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: CodeBlocks as debugging IDE with STM32Duino

Postby 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.
Attachments
debug.jpeg
debug.jpeg (93.35 KiB) Viewed 1083 times
Last edited by Slammer on Sat Jul 30, 2016 9:00 pm, edited 3 times in total.


Return to “IDE's”

Who is online

Users browsing this forum: No registered users and 1 guest