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

Following the Series with Arduino Uno and FreeRTOS #1

Closed
itopaloglu83 opened this issue Feb 24, 2021 · 3 comments
Closed

Following the Series with Arduino Uno and FreeRTOS #1

itopaloglu83 opened this issue Feb 24, 2021 · 3 comments

Comments

@itopaloglu83
Copy link

Hello everyone,

Although this repository is built upon ESP32 in particular, I have been following along the YouTube videos with my Arduino Uno and the Arduino port of FreeRTOS library. It's quite informative and entertaining.

As I was experimenting with task scheduling I stumbled upon an issue which I think is related to how the Arduino library is implemented. I thought I should share this in case somebody else faces the same issue.

Even when adopted for Arduino Uno, the solution code for the LED challenge (source) fails to work whenever there's any calls to vTaskDelay or vTaskDelete in the setup function. I believe this is due to implementation differences between libraries, though I'm not so sure.

I checked the source code for the Arduino library and it looks like the library is starting the scheduler right after calling the setup function (Source Code). Maybe the setup function is defined as an ordinary function (not as a task) and therefore functions like vTaskDelay doesn't work because of that.

Anyway, removing the calls for vTaskDelay or vTaskDelete in the setup function resolved my problem.

@ShawnHymel
Copy link
Owner

Awesome! Thank you for this helpful info. I have not played with the Uno port of FreeRTOS, so I'm glad to hear it works. From what I've found, the setup() and loop() functions both run in a task in the ESP-ISF RTOS, which is why vTaskDelay() and vTaskDelete() work.

I'm not sure how the Uno port of FreeRTOS works, so I'm not surprised to hear that setup() is not inside a task. Perhaps loop() is in a task? Could you try running Serial.println(uxTaskPriorityGet(NULL)); in loop() to see if it prints out a priority? If that works, it means loop() is inside a task. If it fails, it means loop exists outside the scheduler (and you probably don't want to use loop() if that's the case).

@itopaloglu83
Copy link
Author

That was a great tip Shawn, thank you.

Calling uxTaskPriorityGet(NULL) in loop function returned 0 and I also tried Serial.println(pcTaskGetName(NULL)); which also return the name IDLE. On a side note, FreeRTOS documentation states that there should always be at least one task ready to be run and functions like vTaskDelay() should not be called from it.

Strangely calling uxTaskPriorityGet(NULL) in the setup function return a decimal 10 even though configMAX_PRIORITIES is defined as 4 in FreeRTOSConfig.h file.

As I was discovering around, I also found about vTaskList (reference) which returns an ASCII based task list table of all tasks. The returned table (example) shows all the tasks running, their states, priorities, and stack high water mark.

@itopaloglu83
Copy link
Author

Just a follow-up for future reference.

Calling uxTaskGetNumberOfTasks() in the setup function returns 0. Which means there are no tasks present while the setup function is running.

Reminder. This is only true for the Arduino Uno port of FreeRTOS.

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

2 participants