-
Notifications
You must be signed in to change notification settings - Fork 15
Debugging
The memory_debugger process periodically prints the free bytes of the SRAM of the ATMega on the UART:
UDP sender process started
-- MEMDBG: INIT
MEMDBG: 2558 bytes free
MEMDBG: process started
IPv6 Address: fe80::50:c4ff:fe04:83f6
.Socket online with fixed 16880 byte web content
State machine: Received event
state machine: Current state: 0
Checking condition 0
state machine: Now in state: 0
State machine: Received event
state machine: Current state: 0
State machine: Received event
state machine: Current state: 0
MEMDBG: 2693 bytes free
The MEMDBG line will be printed every 10 seconds (configurable in hexabus_config.h). The code just calculates this (see also):
stack pointer - heap end = free memory.
Please note that if you do memory-expensive stuff in your code, it may still run out of memory. You can run the calculation manually like this:
#include "mem-debug.h"
void print_mem_usage(void) {
PRINTF("MEMDBG: %d bytes free\r\n",
get_current_free_bytes());
}
You need avarice and avr-gdb in order to debug the code while it is running. So, please install
$ sudo apt-get install avarice
The purpose of avarice is to connect the target (=the hexabus board) to gdb. This is currently supported for the JTAG2 and AVR DRAGON programmers. For the dragon, start avarice like this:
$ avarice -g -j usb -P atmega1284p :4242
AVaRICE version 2.10, Feb 8 2010 07:22:18
Defaulting JTAG bitrate to 250 kHz.
JTAG config starting.
Found a device: AVRDRAGON
Serial number: 00:a2:00:02:77:58
Reported JTAG device ID: 0x9705
Configured for device ID: 0x9705 atmega1284p -- Matched with atmega1284p
JTAG config complete.
Preparing the target device for On Chip Debugging.
Disabling lock bits:
LockBits -> 0xff
Enabling on-chip debugging:
Extended Fuse byte -> 0xff
High Fuse byte -> 0x10
Low Fuse byte -> 0xe2
Waiting for connection on port 4242.
Now, you can attach a gdb to the target. You need to specify which ELF is currently running on the target:
$ avr-gdb Hexabus-Socket.elf
GNU gdb (GDB) 7.2
Copyright (C) 2010 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=i686-linux-gnu --target=avr".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/md/Projects/hexabus/firmware/Hexabus-Socket/Hexabus-Socket.elf...done.
(gdb)
Now, connect to the target:
(gdb) target remote localhost:4242
Remote debugging using localhost:4242
0x00000000 in __vectors ()
Then start the execution of the program:
(gdb) continue
Continuing.
You can use a lot of commands of gdb. Please document your favorites here.