Debug Mega328p with JTAGICE_MKII

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey everybody,

I'm new in this forum, but at least not too new into AVR-programming =).

But I never ever debugged a program on the chip itself (only with LEDs and a scope). But now I want to do it the right way with help of a debugger.

So I bought an old MKII on ebay and got one of my Atmega328p's of my drawer and started.

To get into the topic, i just used a simple blinky-program:

#include <avr/io.h>
#include <util/delay.h>

int tmp_var;

void init(){
	tmp_var = 0;
	DDRB |= (1<<DDB5);
}

int main(){
	init();
	while(1){
		tmp_var++;
		PORTB ^= (1<<PB5);
		_delay_ms(250);
	}
}

The program was compiled with "-g2 -gstabs"-flags to have the debug-info into the elf-file.

I flashed the program with my new MKII in ISP-mode and the LED flashes. ... now I want to debug it and get used to avr-gdb

I set the fuses of my AtMega to lfuse:0xF7 hfuse:0x9F and efuse:0xFF to have DWEN set (no JTAG on mega328p ... only DebugWire)

 

So I started avarice:

$ avarice --mkII -j usb --debugWire --part atmega328p :4242
AVaRICE version 2.13svn20141210

JTAG config starting.
Found a device: JTAGICEmkII
Serial number:  ff:ff:ff:ff:ff:ff
Reported debugWire device ID: 0x950F
Configured for device ID: 0x950F atmega328p -- Matched with atmega328p
JTAG config complete.
Preparing the target device for On Chip Debugging.
Waiting for connection on port 4242.

Then I connect to the avarice:

$avr-gdb blinky.elf

GNU gdb (GDB) 7.10.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=avr".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from EclipseDebugTest.elf...done.
(gdb) target remote localhost:4242
Remote debugging using localhost:4242
0x00000000 in __vectors ()
(gdb)

the gdb-commands like "list" and "step" are working. So I know that I"m on the target.

"print tmp_var" works as well, while the program is running.

 

Now to come to my problems:

- breakpoints do not work properly (breakpoint can be set, but are somehow completely ignored ... "continue" just runs over them)

- I can not get it working into AVR-Eclipse. I followed the tutorial on http://avr-eclipse.sourceforge.net/wiki/index.php/Debugging but my problem is, that the relation between the gdb and my source-code is missing. I can only step from address to address and not from codeline to codeline. There is no association between my code and the debug-interface. Eclipse always opens a new "codefile" named "0x0" and gives me the error: "no source available for 0x0". So I hope somebody can help me, figure out what I am missing.

 

Thank you guys very much in advance.