Author Topic: Codeblocks MCU / OpenOCD plugin  (Read 23860 times)

Offline martind

  • Multiple posting newcomer
  • *
  • Posts: 46
Codeblocks MCU / OpenOCD plugin
« on: January 12, 2009, 02:45:47 am »
Hi All,

Although still very much a work in progress, I have placed my microcontroller / OpenOCD plugin code at:

http://developer.berlios.de/projects/cbmcu/

The plugin supports OpenOCD, but hopefully in the future will support the likes of Qemu etc...
I work mainly with ST and Microchip MCU's, so have been using it for STR7 and STM32 development.
I have placed a couple of screenshots also.

I am about to release a patch to enable cbEVT_DEBUGGER_STARTED, cbEVT_DEBUGGER_PAUSED and cbEVT_DEBUGGER_FINISHED which are needed for the plugin to work.

I welcome and comments, suggestions, fixes etc...

Thanks,


Martin.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 5933
    • My Best Post
Re: Codeblocks MCU / OpenOCD plugin
« Reply #1 on: January 12, 2009, 03:31:45 am »
Directions to build workspace you need to set global variable "zip" to the folder that holds the zip executable.

Good work; I have only compiled it; but, it compiled well.

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline mmkider

  • Almost regular
  • **
  • Posts: 150
Re: Codeblocks MCU / OpenOCD plugin
« Reply #2 on: January 12, 2009, 06:31:58 am »
Hi All,

Although still very much a work in progress, I have placed my microcontroller / OpenOCD plugin code at:

http://developer.berlios.de/projects/cbmcu/

The plugin supports OpenOCD, but hopefully in the future will support the likes of Qemu etc...
I work mainly with ST and Microchip MCU's, so have been using it for STR7 and STM32 development.
I have placed a couple of screenshots also.

I am about to release a patch to enable cbEVT_DEBUGGER_STARTED, cbEVT_DEBUGGER_PAUSED and cbEVT_DEBUGGER_FINISHED which are needed for the plugin to work.

I welcome and comments, suggestions, fixes etc...

Thanks,


Martin.
I am very interested in this cbmcu.
Thank you for your cbmcu.
« Last Edit: January 12, 2009, 06:49:54 am by mmkider »

Offline Joerg

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Codeblocks MCU / OpenOCD plugin
« Reply #3 on: January 12, 2009, 11:00:29 am »
Hi Martin,

is this plugin just for starting OpenOCD,
or is it addressing the odd break problem too?
Do I need to download your sourcefiles via
SVN and then compile C::B ?

It's never too late to fail!

Offline martind

  • Multiple posting newcomer
  • *
  • Posts: 46
Re: Codeblocks MCU / OpenOCD plugin
« Reply #4 on: January 12, 2009, 11:35:59 am »
Hi,

Thanks for you comments.

Hi Tim. I have set the zip global but it stores it in my global conf file which you don't have... should have put a note sorry.

BTW I strongly recommend a seperate mcu.conf for your microcontroller version of CB so it does not get mixed up with your windows version. You can change this on the command line, but I have hard-coded my CB version.

Hi Rekisum. Yes it does address that old break problem that has given us grief. When the cbEVT_DEBUGGER_PAUSED event is received it establishes a telnet interface and executes halt. Need to create a proper queue for OpenOCD but I will in the future.

I have submitted a patch btw for the above events. I will post the patch here and on the cbmcu website.


Cheers,


Martin.
« Last Edit: January 12, 2009, 11:37:53 am by martind »

Offline martind

  • Multiple posting newcomer
  • *
  • Posts: 46
Re: Codeblocks MCU / OpenOCD plugin
« Reply #5 on: January 13, 2009, 11:14:00 pm »
Hi All,

Patch for debuggergdb.cpp to dispatch cbEVT_DEBUGGER_x messages.

Martin.

[attachment deleted by admin]

Offline Joerg

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Codeblocks MCU / OpenOCD plugin
« Reply #6 on: January 19, 2009, 10:43:28 am »
Hi martind,

some dump questions:
On the berlios project site I only found the sources via svn.
Does that mean I have to checkout these and copy them over
my codeblocks sources?

Just came to my mind:
If the break command does not work for us embedded remote
debugging freaks, does that mean it doesn't work for codeblocks
user debugging under windows either?
This can't be, right?
But whats the difference between sending a CTRL+C event to gdb
when debugging remotely and debugging erm.... 'not' remotely????

It's never too late to fail!

Offline mmkider

  • Almost regular
  • **
  • Posts: 150
Re: Codeblocks MCU / OpenOCD plugin
« Reply #7 on: January 19, 2009, 12:45:22 pm »
Hi martind,

some dump questions:
On the berlios project site I only found the sources via svn.
Does that mean I have to checkout these and copy them over
my codeblocks sources?

Just came to my mind:
If the break command does not work for us embedded remote
debugging freaks, does that mean it doesn't work for codeblocks
user debugging under windows either?
This can't be, right?
But whats the difference between sending a CTRL+C event to gdb
when debugging remotely and debugging erm.... 'not' remotely????
hi, rekisum:
I have a question.
how to send CTRL+C to gdb without console windows?
Thank you for your reply.

Offline martind

  • Multiple posting newcomer
  • *
  • Posts: 46
Re: Codeblocks MCU / OpenOCD plugin
« Reply #8 on: January 19, 2009, 03:05:38 pm »
Hi Reksium,

Sorry I need to write some docs... am working them...

You can check-out the SVN sources to anywhere you want.
Load the mcu workspace file in CodeBlocks. Ensure that the $(#cb) global variable is set to c:\...(wherever your codeblocks source is)..\src, and $(#zip) is set to point to zip.exe etc..

(BTW need to do some tweaks for Linux, I've been a bit windozy of recent)

Then build...and run your devel version.

The trouble I had with GDB is that to pause or break it, you would have to send a CTRL-C under windows, or SIGxx something or other under Linux. I could not do this programmatically under windows, and I don't think CodeBlocks can do it either.

So the work-around when debugging windows programs is to "prod" the program being debugged (Kernel break). This causes GDB to halt.
However, when debugging an embedded application, GDB is making a remote TCP/IP connnection (OpenOCD), therefore this is not possible. We have to tell OpenOCD to tell GDB to halt. And the simplest way I could think of was to telnet to OpenOCD and issue a "halt" command. Then it sends a command interrupt back to GDB.

Of course I bet there is some way of doing it, I just went for the easy "halt" option... perhaps somebody will come up with a solution.
However, if you run GDB in MI mode (change the interpreter), I believe GDB still has the command line available, even though it's debugging in the background. This might allow to queue a "stop" command on the fly.


Cheers,


Martin.

Offline Joerg

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Codeblocks MCU / OpenOCD plugin
« Reply #9 on: January 21, 2009, 03:39:58 pm »
Hi Martin,

after some wiki and forums reading I got so far that
I could load your mcuplugin.workspace and compile.
After compiling the linker complains:

Compiling: telnetclient.cpp
Linking dynamic library: D:\Dateien\VStudio\Codeblocks\trunk\src\devel\mcumgr.dll
C:\Programme\CodeBlocks\MinGW\bin\ld.exe: cannot find -lcodeblock

I did compile wx and c::b successfully but there is no codeblocks.a around?

c::b: svn 5394
cbmcu: svn 10
It's never too late to fail!

Offline Joerg

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Codeblocks MCU / OpenOCD plugin
« Reply #10 on: January 22, 2009, 10:17:21 am »
Hi, its me again ;-)

I got further, and could build all the project in your workspace.
I did compile cb earlier with the project files therein.
I didn't know I have to build them in your workspace in the right order.
Anyway, after building and running update.bat I got my own version own CodeBlocks :-)

Starting my STR7 project a screen shows up telling me to select a MCU.
Under Project/Properties there is a MCU tab.
But there is nothing to select there.
Probably I have to copy some plugin files to somewhere ?
It's never too late to fail!

Offline Joerg

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Codeblocks MCU / OpenOCD plugin
« Reply #11 on: January 22, 2009, 02:45:22 pm »
I copied the mcudrv directory to
\output\share\ CodeBlocks\plugins
Now I'm able to select MCU and settings.
A quick test lets me break the program.
After that the controller resets, maybe because
the active Watchdog of my STR7.

I'm missing the Envars and Library tabs in the project settings!
It's never too late to fail!

Offline Joerg

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Codeblocks MCU / OpenOCD plugin
« Reply #12 on: January 22, 2009, 02:59:48 pm »
I'm not able to set breakpoints
the breakpoint gets listed in the breakpoints tab
and the red circle appears
but nothing gets send to the debugger not directly
or over the openocd plugin
It's never too late to fail!

Offline martind

  • Multiple posting newcomer
  • *
  • Posts: 46
Re: Codeblocks MCU / OpenOCD plugin
« Reply #13 on: January 24, 2009, 01:43:04 am »
Hi Joerg,

I need to create the mcudrv directory if it does not exist... thanks for that...
I have an example project I will commit to SVN, these are the extra debug commands I send to the debugger:

In Project/targets options, debugger, additional commands after connection:

monitor soft_reset_halt
monitor mww 0xFFFFFF00 0x01
monitor reg pc 0x20000000
monitor ARM7_9 sw_bkpts enable
set remote memory-write-packet-size 1024
set remote memory-write-packet-size fixed
set remote memory-read-packet-size 1024
set remote memory-read-packet-size fixed
set remote hardware-watchpoint-limit 2
set remote hardware-breakpoint-limit 2
load
b main
continue

For an STR7 project.


Martin.

Offline Joerg

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Codeblocks MCU / OpenOCD plugin
« Reply #14 on: January 26, 2009, 10:55:05 am »
Hi martin,

I can't find your example project in svn yet.

I'm able to set a breakpoint once or twice
and the program stops as expected.
After that, setting of breakpoints doesn't work any more.
I don't know if gdb usually counts up the breakpoints every time,
but if i delete and set a breakpoint on the same line
I get the following output:

> delete breakpoints 3
>>>>>>cb_gdb:
> break "D:/Projekte/test-sw/src/MainTask.c:808"
Breakpoint 4 at 0x16c8c: file D:/Projekte/test-sw/src/MainTask.c, line 808.
>>>>>>cb_gdb:
> delete breakpoints 4
>>>>>>cb_gdb:
> break "D:/Projekte/test-sw/src/MainTask.c:808"
Breakpoint 5 at 0x16c8c: file D:/Projekte/test-sw/src/MainTask.c, line 808.
>>>>>>cb_gdb:
> delete breakpoints 5
>>>>>>cb_gdb:
> break "D:/Projekte/test-sw/src/MainTask.c:808"
Breakpoint 6 at 0x16c8c: file D:/Projekte/test-sw/src/MainTask.c, line 808.
>>>>>>cb_gdb:
> delete breakpoints 6

As only 2 breakpoints are available when debugging a program in FLASH
maybe the problem lies here?
I use 'monitor arm7_9 force_hw_bkpts enable' after connection.

Did you have a look for the missing tabs in the project/properties window?

I use an older OpenOCD version svn r520 and GDB 6.8.5.
It's never too late to fail!