Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't debug when used in conjunction with ChRT - no thread support? #11

Open
davidbuzz opened this issue Jan 3, 2022 · 3 comments
Open

Comments

@davidbuzz
Copy link

davidbuzz commented Jan 3, 2022

#include "TeensyDebug.h"
#include "ChRt.h"
... etc ...

When trying to debug something as simple as one of the ChRt example scripts, just adding the above #include ... to it....
https://github.com/greiman/ChRt/blob/master/examples/chBlink/chBlink.ino

It seems that TeensyDebug doesn't provide enough functionality to work with 'threads'... its my guess that that its missing the ability to properly respond to one of the thread commands that VSCode / PIO uses [my debuggger gui of choice], eg , not 100% sure what the command is that PIO is trying to do, but perhaps its trying to switch thread with 'thread x' or 'info threads' or similar.

assorted VSCode error/s:

Could not continue: Invalid thread id: 1 (from exec-continue --thread 1)
Reply contains invalid hex digit 116 (from data-evaluate-expression chRegFirstThread)

exception at:

chRegFindThreadByWorkingArea (wa=<optimized out>) at .pio/libdeps/teensy40/ChRt/src/rt/src/chregistry.c:251

https://sourceware.org/gdb/onlinedocs/gdb/Threads.html

@davidbuzz
Copy link
Author

Cannot access memory at address 0x0 (from break-insert "/home/buzz/Teensy4/piotest/.pio/libdeps/teensy40/ChRt/src/rt/src/chregistry.c:257")

@davidbuzz
Copy link
Author

I'm not sure exactly what the GDB command is that its running, so i'm pasting a few of the messages that VSCode/PIO debugger gives me.

@davidbuzz
Copy link
Author

here's a short app that causes it:

#pragma GCC optimize ("O0")
#include <Arduino.h> 
#include "TeensyDebug.h"
#include "HardwareSerial.h"
#include <stdio.h>
#include "ChRt.h"

volatile uint32_t count = 0;
static THD_WORKING_AREA(waThread1, 64);
static THD_FUNCTION(Thread1 , arg) {
  (void)arg;
  pinMode(LED_BUILTIN, OUTPUT);
  while (true) {  // this thread just flashes a led
    digitalWrite(LED_BUILTIN, HIGH); 
    chThdSleepMilliseconds(50);
    digitalWrite(LED_BUILTIN, LOW);
    chThdSleepMilliseconds(150);
  }
}
void chSetup() {
  chThdCreateStatic(waThread1, sizeof(waThread1),
                    NORMALPRIO + 1, Thread1, NULL);
}
void setup() {
  chBegin(chSetup); // chBegin() resets stacks and should never return.
  while (true) {}
}
void loop() {  // this thread just prints to usb at 1hz
  chThdSleepMilliseconds(1000);
  Serial.print(F("Count: "));
  Serial.print(count);
  count = 0;
  Serial.println();
}

and my platformio.ini:

[env:teensy40]
; using git url, gets latest... ie 1.156.0 instead of 1.155.0 which is busted
platform = https://github.com/platformio/platform-teensy.git
board = teensy40
framework = arduino
monitor_speed = 115200
build_type = debug

lib_deps =
    https://github.com/ftrias/TeensyDebug
    https://github.com/greiman/ChRt

build_flags = 
    -DGDB_DUAL_SERIAL
    -DUSB_DUAL_SERIAL

debug_port = /dev/ttyACM1
debug_tool = custom
debug_load_mode = manual
debug_server = 
debug_init_cmds =
  target extended-remote $DEBUG_PORT
  $INIT_BREAK
  define pio_reset_run_target
  interrupt
  tbreak loop
  continue
  end
  define pio_restart_target
  echo Restart is undefined for now.
  end

debug_init_break =

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant