avr-stub is a source level debugger based on GDB stub mechanism. It works with ATmega328 and Arduino Mega microcontrollers without an external programmer. The official reference can be found here.
In a nutshell, avr-stub is a piece of software (stub) that is added to your application and communicates with PlatformIO when a debug session is running. It requires several additional configuration steps in order to use it as a debug tool. To use avr-stub, the following settings in “platformio.ini” (Project Configuration File):
[env:myenv]
platform = atmelavr
board = ...
debug_tool = avr-stub
debug_port = SERIAL_PORT
; GDB stub implementation
lib_deps =
jdolinay/avr-debugger @ ~1.4
Where the value in debug_port is a serial port connected to your
board and jdolinay/avr-debugger
is a special library that implements the GDB stub.
In order to enable the GDB stub in your application, a call to the special function
debug_init
must be added at the beginning of your application. For example, with
the Arduino framework it might look like this:
#include "Arduino.h"
#include "avr8-stub.h"
#include "app_api.h" // only needed with flash breakpoints
void setup()
{
// initialize GDB stub
debug_init();
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
Warning
If your program doesn’t stop on a breakpoint, try specifying an explicit breakpoint
directly in the code using the breakpoint
function:
...
void loop()
{
breakpoint();
digitalWrite(LED_BUILTIN, HIGH);
delay(300);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
...
The avr-stub tool supports the following three breakpoint modes:
Description |
AVR8_BREAKPOINT_MODE |
---|---|
FLASH breakpoint mode, which works only with atmega328 based boards and requires a special bootloader |
|
RAM breakpoint mode, the default mode which works out of the box with all atmega328, atmega1280, and atmega2560 based boards |
|
FLASH breakpoint mode through Optiboot, which works with all atmega328, atmega1280, and atmega2560 based boards and requires the version 8 of the bootloader. |
|
To switch between modes, specify a special macro definition AVR8_BREAKPOINT_MODE
with the appropriate value from the table above, for example:
[env:myenv]
platform = atmelavr
board = uno
; Set breakpoint mode
build_flags =
-DAVR8_BREAKPOINT_MODE=2
debug_tool = avr-stub
debug_port = SERIAL_PORT
lib_deps =
jdolinay/avr-debugger @ ~1.4
One external interrupt pin must be reserved for the debugger.
Any part of your application that uses the UART module (e.g. Arduino Serial class) cannot be used in your program together with the debugger.
When using flash breakpoints the watchdog cannot be used.
More detailed information can be found in the Important limitations of the debugger
section in the official documentation.
Name |
Description |
---|---|
Atmel AVR 8-bit MCUs deliver a unique combination of performance, power efficiency and design flexibility. Optimized to speed time to market-and easily adapt to new ones-they are based on the industry’s most code-efficient architecture for C and assembly programming |
Name |
Description |
---|---|
Arduino Wiring-based Framework allows writing cross-platform software to control devices attached to a wide range of Arduino boards to create all kinds of creative coding, interactive objects, spaces or physical experiences |
Note
For more detailed board
information please scroll tables below by horizontal.
Name |
Platform |
Debug |
MCU |
Frequency |
Flash |
RAM |
---|---|---|---|---|---|---|
On-board |
ATMEGA1280 |
16MHz |
128KB |
8KB |
||
On-board |
ATMEGA2560 |
16MHz |
256KB |
8KB |
||
On-board |
ATMEGA328 |
16MHz |
32KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
32KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
12MHz |
28KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
28KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
28KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
30KB |
2KB |
||
On-board |
ATMEGA2560 |
16MHz |
248KB |
8KB |
||
On-board |
ATMEGA1280 |
16MHz |
124KB |
8KB |
||
On-board |
ATMEGA2560 |
16MHz |
248KB |
8KB |
||
On-board |
ATMEGA328P |
16MHz |
28KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
28KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
30KB |
2KB |
||
On-board |
ATMEGA2560 |
16MHz |
248KB |
8KB |
||
On-board |
ATMEGA2560 |
16MHz |
248KB |
8KB |
||
On-board |
ATMEGA2560 |
16MHz |
248KB |
8KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA2560 |
16MHz |
252KB |
8KB |
||
On-board |
ATMEGA328P |
8MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA2560 |
16MHz |
252KB |
8KB |
||
On-board |
ATMEGA2560 |
16MHz |
252KB |
8KB |
||
On-board |
ATMEGA328P |
8MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA2560 |
8MHz |
252KB |
8KB |
||
On-board |
ATMEGA2560 |
16MHz |
248KB |
8KB |
||
On-board |
ATMEGA2560 |
8MHz |
252KB |
8KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
8MHz |
30KB |
2KB |
||
On-board |
ATMEGA328P |
16MHz |
31.50KB |
2KB |