Comments (3)
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.
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.
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)
- Support for teensy 3.1 and 3.2 HOT 1
- analogWriteResolution(12), freezes the task and stop the PWM HOT 4
- Unaligned access UsageFault HOT 2
- Issue with using PlatformIO HOT 2
- Failure to run __libc_init_array when using GCC 11.3.1 on Teensy 4.1 HOT 6
- Compile error on timeval freertos::clock::offset_ in teensy.h HOT 1
- PlatformIO: Can't find 'arduino_freertos.h' when using strict library compatibility mode HOT 1
- Can't use std::mutex in PlatformIO library. HOT 2
- Latest PULL example stdThread Hangs at runtime HOT 4
- Volatile Error On Compilation Fix HOT 1
- Linker error: can't find reference to serialEvent_default HOT 1
- #include "arduino_freertos.h" breaks other libraries that use the arduino namespace HOT 3
- teensy-FreeRTOS event group handler Issue when trying to use C++ Exceptions HOT 2
- freertos-teensy porting for Teensyduino HOT 16
- Changing FreeRTOS Tick rate HOT 1
- reent.h missing HOT 1
- Platform IO SD Card Example HOT 4
- Compiler error when using LTO HOT 1
- Teensy 4 compile error due to missing symbol HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freertos-teensy.