(newbie) ATmega2560 won't stop at breakpoint

I must be missing something very simple and basic. I have an ATMega2560. I compile and load a simple program which appears to be running correctly (lighting an LED to a set rhythm). The program in VSCode also appears to break and step as you would expect. The problem is that the board continues running while the VSCode debugger is stepping - implying that it is looking at a simulation rather than the actual board.

My platformio.ini:

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
debug_tool = simavr
debug_init_break = tbreak setup
monitor_filters = debug
lib_deps = 
      miguelpynto/ShiftDisplay @ ^3.6.1

I’ve tried using gdb from the CLI and that too acts as if it is working, but through a simulator and not the actual board. I used the Platformio home to set up the project in VSCode which appeared to work correctly.

Is there something else I should be doing? (main.cpp posted below).
Thx,
–Don

#include <Arduino.h>
#include <ShiftDisplay.h>

#define PIN_LED_8            (8u)
#define PIN_LED_9            (9u)
#define PIN_LED_10           (10u)
#define PIN_LED_11           (11u)

#define DIGIT_1              PIN_LED_8
#define DIGIT_2              PIN_LED_9
#define DIGIT_3              PIN_LED_10
#define DIGIT_4              PIN_LED_11

ShiftDisplay display1(COMMON_CATHODE, 1);
ShiftDisplay display2(COMMON_CATHODE, 1);
ShiftDisplay display3(COMMON_CATHODE, 1);
ShiftDisplay display4(COMMON_CATHODE, 1);
unsigned int digit_table[] = {DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4};

void setup() {
    pinMode(DIGIT_1, OUTPUT);
    pinMode(DIGIT_2, OUTPUT);
    pinMode(DIGIT_3, OUTPUT);
    pinMode(DIGIT_4, OUTPUT);
    for (int i = 5; i > 0; i--) {
        digitalWrite(digit_table[0], LOW);
        display1.show(i, 400, ALIGN_CENTER); // store number and show it for 400ms
        display1.setDot(1, true); // add dot to stored number
        display1.show(400); // show number with dot for 400ms
        digitalWrite(digit_table[0], HIGH);
    }
    display1.set(8); 
}

void loop() {
    for (int i = 5; i > 0; i--) {
        digitalWrite(digit_table[0], LOW);
        delay(500);
        digitalWrite(digit_table[0], HIGH);
        delay(500);
    }
    for (int i = 50; i > 0; i--) {
        digitalWrite(digit_table[0], LOW);
        delay(50);
        digitalWrite(digit_table[0], HIGH);
        delay(50);
    }
}

Indeed. You’re setting

So pressing will launch the simavr program for simulating AVRs. It will not touch your running board.

If you want to debug the real board via the existing serial connection, have a look at the debug_tool = avr-stub option described in Atmel AVR dev/platform v3.0.0: updated Arduino cores, support for AVR GDB stub and the related docs. (This needs extra libraries and code additions in the firmware to work!)

2 Likes

Thx, It was pretty obvious what was going on - I just couldn’t read the docs properly!