nrf51822 + ST-Link V2 Debugging - debugging

I'm working on a project where I need to program an NRF51822 using an ST-Link V2 (well, perhaps I don't have to do it this way, but that's what I'm currently doing/own).
I'm pretty sure it's running properly, but I really need a debug console to get some information back from the NRF51 module to make sure things are connected OK.
I'm not going to lie:
I'm really quite new to this, and most of my success thus far has been thanks to quite in-depth tutorials.
I'm using ubuntu and openOCD for programming
I'm not sure what I need to put in my program in order to get debug/console info out (and I'm not even sure what I would do to receive it on my computer).
I would really appreciate some help on:
What to add to my program to log info to the console, and
How to view that debug console on my computer.
Thank you very much!

You need to use such OpenOCD config file to connect with ST-Link
#nRF51822 Target
source [find interface/stlink-v2-1.cfg]
transport select hla_swd
set WORKAREASIZE 0x4000
source [find target/nrf51.cfg]
You need to insert your version stlink-v2-1.cfg or stlink-v2.cfg
Also you need to add this to your makefile to write program
flash: $(OUTPUT_BINARY_DIRECTORY)/$(HEX)
$(OPENOCD) -d2 -f $(TEMPLATEROOT)/openocd.cfg -c 'init_reset halt; program $(OUTPUT_BINARY_DIRECTORY)/$(HEX) verify; reset; exit'
Debug is more complex. You'd better set eclipse with OpenOCD/GDB to make it. For console solution you can follow this lesson
This worked for me. Good luck.

Related

How can I debug my emulated programs with GDB?

I wrote a simple fake processor emulator (dcpu-16). I would like to know if it's possible (and how) to integrate my target into gdb such that I could debug the programs compiled and executed in that emulator.
It seems like it would be related to the gdb "target" or maybe "target exec" commands although I didn't manage to understand how to make it work.
Any help would be appreciated :) Thanks!

Installing Z-Wave Device Applications

I am curious about the Lab of Things and i've just started to learn it.
I am studying it in the network lab of my university. We have a z-wave controller stick, 2 on/off switch, 1 dimmer receiver and 1 sensor.
To set and run the platform, i followed the instructions in this link below:
http://www.lab-of-things.com/GettingStartedLoT_Beta1.pdf
While running the source code and adding a z-wave device, I faced an annoying problem here.
After adding the z-wave driver and running the code i saw 4 different device on the dashboard, it looks like below:
I tried to install these nodes and applications but apps are not installed. I think that's why i get an error message like below when i run the platform:
I searched on the internet for this error and i found a discussion like this error but i couldn't apply the solution. In this discussion they say that the applications (alerts, sensor, lights etc.) should be compiled seperately. I tried to do it but Visual Studio still gives the same error.
Here is the link of discussion that i found on the internet:
https://labofthings.codeplex.com/discussions/476781
All answers will be appreciated.
Thank you in advance.
I solved this problem by following these instructions which are written in this link:
https://labofthings.codeplex.com/discussions/476781
" For starters, it looks from the screenshot posted on stackoverflow that you have broken configuration at this point—the access control rules (in output\configs\config\rules.xml) have a reference to module Alerts but that module is not listed in output\configs\config\modules.xml
To fix the config, 1) run reset.bat, which will reset your configuration to default; or 2) fix it manually if you think you understand the semantics.
Then, make sure that the apps you want to use are compiled. Their binaries should show up in output\binaries\pipeline\addin\homeos.hub.apps.alerts.
Then, go through the setup process again, and things should work at this point in time.
A little more on this: we have confirmed that broken configuration will occur when app binaries are not found. We will post a bug fix soon, but for now, the remedy in my original response (reset, compile, then install device) should work. Let us know if you are still seeing issues. "
I hope this would be helpful for someone.

Customizing gdb -tui

Over the years, I just can't seem to find a free debugger that suits me. Normally, I just connect to my university's cluster and use DDT, but I'd like to find something free that I can use locally on my machine. I've been playing with gdb -tui, but it doesn't have a window to show the other project files or a window for watched variables. I can't find a way to open up another file in the project in the source window so that I can scan the source code and see where I want to set my breakpoint. I have to open the other file in vim, find the line number, then set the breakpoint in gdb. I have switched to doing all my code writing in vim, and that seems to work pretty well for me, but I still haven't found a good all-in-one package for debugging the code after I write it. Any suggestions from anybody who have a good code development setup would be greatly appreciated.

simple gui based gdb debugging over ssh

I ssh into a linux VM which is setup remotely. I use Vim to write my code. For debugging however, I use netbeans through X11 which can sometimes be painfully slow. I tried using gdb buts its an efficiency killer. I love to hover over my variable and get to now their value rather that doing p variable_name , plus I like see and navigate through the code. Is there something light simple gui based debugging tool I can use. I have tried to use clewn http://clewn.sourceforge.net/ , but that doesnt work because it has a missing netbeans_intg feature. Is there any other similar vim gui based debugging tool ?
You can try ddd
which is a gui for gdb, I think it's lighter than netbeans.
cgdb is an interface to gdb but it is not a graphical one. It does not offer the possibility of hovering over a variable, but it shows you a window with the source code.
Well, I was in sort of your situation sometime ago, and you can have a look at my question about using gdb with remote sources.
First of all, your problem with netbeans_intg feature is related to vim which has been compiled with no support for it. If you can rebuild vim yourself, you can then enable it. Otherwise, as you can see in the answer that I gave myself to my question, you can leverage clewn's remote-vim capabilities.
In a nutshell, you can have a "local" vim (i.e. on a desktop/laptop machine presumably), which must still be built with netbeans_intg support, but now it is a vim under your complete control (i.e. it's on "your" machine), while clewn will run on the linux host where gdb and your debuggee will run.
You can then keep the source files on your desktop/laptop and have the remote clewn sort of "drive" your local vim to the proper source files while debugging.
IOW: clewn will get information out of gdb to know exactly which file/line you're into and connect to remote vim and tell it: "hey, go grab this file and show it around this line", highlighting current line, breakpoints etc.
This is a great solution for when you have far-away deployed systems and you need to debug them with minimum impact on the host where they are running, and presumably no option to transfer there all of your source files.
I don't know if this fits in any way with what you're trying to do, but it did really change things for me.
Hth,
Andrea.
Check out GDB server. Theoretcially, you should be able to start gdb on your linux machine in server mode and connect via GUI of your choice. As long as that GUI supports remote gdb connections, which Netbeans does.

Debugging with Bochs + GDB: "cannot find bounds of current function"?

I'm working on writing an OS and I'm running into problems trying to debug my code. I'm using GDB to connect to Bochs' GDB stub to "remotely" debug my kernel. Connecting works fine, as does loading debugging symbols from the kernel file. I set a breakpoint for the kmain function, which is successfully located, and the debugger breaks correctly (inside my kernel). However, I can't "step" or "next" through my code, nor can GDB apparently determine which line of code is the current line.
When I try to "step", I get the following message: "Cannot find bounds of current function". This is the only error message I get at any point.
My code is being compiled in GCC with the -g flag (I've tried other types of debugging information using GCC options; none have worked.) I have tried looking through the GDB manual , as well as searching for the answer, and I'm totally stumped. Any help would be amazing.
Thanks!
Well, I got debugging working, but I had to switch emulators. I was able to get GDB working with Qemu, even though I also had problems doing that. To get GDB to connect to the Qemu gdbserver, I had to pass the following option to Qemu: "-gdb tcp::1234,ipv4". Took me forever to figure that out... Debugging works perfectly now!
Googling throws up "This is because when you attached to gdbserver, the process under
debug has not completed the C start-up code" http://www.cygwin.com/ml/gdb/2005-03/msg00237.html... http://www.bravegnu.org/gnu-eprog/c-startup.html describes the process for when you are coding for embedded devices, maybe this will help?
If you find the answer please post here as I'd like to know what the solution to the problem is too.
I don't know why but bochs with gdb-stub enabled seems to be picky with the config options. On some system following options will break it:
--enable-x86-64, --enable-vmx

Resources