Giter VIP home page Giter VIP logo

Comments (3)

tsandmann avatar tsandmann commented on June 19, 2024

That's an interesting bug...

First, you can't use (interrupt driven) peripherals before calling vTaskStartScheduler(), because the system initialization isn't complete at this point (that's why the call to Serial7.flush() never finishes). Using the usb serial (Serial) is fine, because it is setup by a startup hook to allow some early debug printing. I think I have to add some documentation about that...

To handle it, you can move the initialization code in a setup task, that is called first, e.g.:

static void setup_task(void *)
{
  pinMode(STO_KNEE, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(9600);

  while (!Serial)
  {
    delay(50);
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  }

#ifdef USE_SPI
  test_spi();
#endif
#ifdef USE_UART
  test_serial();
#endif

  Serial.println("Done all");

#if __has_include("arduino_freertos.h")
  xTaskCreate(led_task, "led_task", 128, nullptr, 2, nullptr);
  vTaskDelete(nullptr);
#endif
}

void setup()
{
#if __has_include("arduino_freertos.h")
  xTaskCreate(setup_task, "setup_task", 1024, nullptr, configMAX_PRIORITIES - 1, nullptr);
  vTaskStartScheduler();
#else
  setup_task(nullptr);
#endif
}

However, there seems to be a second problem: using LED_BUILTIN in digitalWrite() doesn't work when using SPI in the same program. If I change LED_BUILTIN to another pin (not used by SPI), your example works for me. I don't have an explanation for that, except that LED_BUILTIN is shared with SPI SCK. But this problem also exists for me in your without_freertos environment, if I add some code that uses the LED comparable to the FreeRTOS version:

static void setup_task(void *)
{
  pinMode(STO_KNEE, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(9600);

  while (!Serial)
  {
    delay(50);
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  }

#ifdef USE_SPI
  test_spi();
#endif
#ifdef USE_UART
  test_serial();
#endif

  Serial.println("Done all");

#if __has_include("arduino_freertos.h")
  xTaskCreate(led_task, "led_task", 128, nullptr, 2, nullptr);
  vTaskDelete(nullptr);
#else
  while (true)
  {
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    if (digitalRead(LED_BUILTIN))
      Serial.println("Hey");
    delay(250);
  }
#endif
}

void setup()
{
#if __has_include("arduino_freertos.h")
  xTaskCreate(setup_task, "setup_task", 1024, nullptr, configMAX_PRIORITIES - 1, nullptr);
  vTaskStartScheduler();
#else
  setup_task(nullptr);
#endif
}

from freertos-teensy.

tyalie avatar tyalie commented on June 19, 2024

Thank you so much for your help. I'll try using the setup task. It makes much more sense in many aspects to call all initialization after xTaskStartScheduler. I actually thought that there wouldn't be a solution as freeRTOS also uses interrupts and those are naturally limited in the system.
But I think a mention in the docs, wouldn't be that bad 😅

Regarding the BUILTIN_LED: I noticed that too yesterday. The next iteration will put the SCK pin somewhere else than pin 13.

from freertos-teensy.

tsandmann avatar tsandmann commented on June 19, 2024

Since I don't like that limitation either, I'll see if it can be addressed in a future version. But the setup task workaround should work for most cases.

from freertos-teensy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.