Unable to begin ChibiOS thread (ChRt library, Teensy 4.0)

Status
Not open for further replies.

banans

Member
Hello,

I'm trying to implement the ChRt library on a Teensy 4.0 board, and I'm starting with a simple blinking LED function. I'm just trying to follow a basic example, but it's not working and I'm getting unexpected behavior.

First off, here's my code:

Code:
#include <Arduino.h>
#include <ChRt.h>
 
// working area
static THD_WORKING_AREA(waThreadHEART, 64);
// actual function
static THD_FUNCTION(ThreadHEART, arg)
{
  (void)arg;
  //basic heartbeat thread to tell us whether weve crashed
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  while (1)
  {
    digitalWrite(LED_BUILTIN, HIGH);
    chThdSleepMilliseconds(83);
    digitalWrite(LED_BUILTIN, LOW);
    chThdSleepMilliseconds(166);
    digitalWrite(LED_BUILTIN, HIGH);
    chThdSleepMilliseconds(125);
    digitalWrite(LED_BUILTIN, LOW);
    // Serial.print(".");
    chThdSleepMilliseconds(626);
    
  }
}
 
void chStartup()
{
  chThdCreateStatic(waThreadHEART, sizeof(waThreadHEART),
                    NORMALPRIO + 1, ThreadHEART, NULL); 
}
 
void setup()
{
  Serial.begin(9600);
  while (!Serial)
  {
    delay(1);
  }
  
  Serial.println("Serial was started!");

  chBegin(chStartup);
  while(1) {}
}
 
void loop()
{
}

Not only does the LED on the board not blink, but I don't get any Serial output either. Commenting out the chBegin and while loop below it yields Serial output.

Note: I'm using PlatformioIDE (Core 5.0.1 Home 3.3.1) on macOS Catalina 10.15.7

Anything helps, I'm very stuck!
 
Just as a test I downloaded ChRt from https://github.com/greiman/ChRt.

I ran the blink example and your code and it appears to be working fine on the T4.0. Your example is blinking the LED and printing the serial monitor.

With that said I am using the Arduino IDE and am on a Windows 10x64 pc. Don't know anything about PlatformioIDE so can't help you there. All I can tell you is that it does appear to work on the T4. Maybe a problem with PlatformioIDE?
 
Just as a test I downloaded ChRt from https://github.com/greiman/ChRt.

I ran the blink example and your code and it appears to be working fine on the T4.0. Your example is blinking the LED and printing the serial monitor.

With that said I am using the Arduino IDE and am on a Windows 10x64 pc. Don't know anything about PlatformioIDE so can't help you there. All I can tell you is that it does appear to work on the T4. Maybe a problem with PlatformioIDE?

Thanks, that helped a lot! I switched over to Teensyduino and was still having issues, but it turned out to be a matter of following the troubleshooting tip of changing the USB type from Serial to Raw HID. I'm not sure myself how to do this on Platformio or why this only seems to be a problem with the code I have ChRt on. Anyways, I was able to upload the sketch successfully and observe desired output.
 
Another update, I removed the ChRt dependency from my platformio.ini file and instead just cloned the library from GitHub. I also specified upload_protocol = teensy-gui, but i'm not sure if that did anything. I'm now able to upload via PlatformIO on VSCode :)
 
Status
Not open for further replies.
Back
Top