A year later - but really appreciating this series. I need to build a custom motor driver to control 4 full h-bridge drivers chips with single on/off pulses as short as 5uS, in addition to also receiving output from an absolute encoder to get rotor angle information, throttle input, etc. to calculate and drive those 4 other stator control tasks. A general purpose OS is not going to cut it. Now if this supply chain issue can get resolved so I can actually purchase some of these demo boards to work with...
This series is great! Your teaching style in inspiring. Such depth of knowledge and attention to detail. Hopefully Digikey will keep producing material with Shawn Hymel 🙏
This gives a greater understanding of the language instead of coping & pasting then just changing the time sequence! Thanks for the tutorial because I learn every time..
Every time I see this opening scene I think of an old cartoon but can't remember the name of the show or the character. Great series BTW, very informative.
I struggled a bit to understand why #if, BaseType_t, and few other terms used. After few background search I found out: 1. # - these are pre-processor directives. i.e., processed before actual compilation. Thus, #if statement already decides what's the value of app_cpu even before actual compilation. 2. BaseType_t is typedef (keyword to create new type alia) in header file, and it was int. This is what I understood, do point out if I have mistaken these terms.
This series is really great. Thanks a lot Shawn. Will be waiting for future videos. Just wanted to know at what frequency you would be uploading videos over here?
Absolutely love this video. We developed a game for the ODROID GO (based on the ESP32), and we could not deal with the arduino IDE. It’s OK for small projects, but it does not scale very well. Your video makes me want to dive back into ESP32 projects. We had to create tasks for Display refresh and pin it to Core 1, with the main game loop running on Core 0. We also setup an ISR to manage the creation of music using LibXMP. Fun stuff!!
I am very grateful for your great videos! There is a small problem, UA-cam has identified the video language as Korean and incorrectly generates subtitles. You have excellent diction and as a non-native speaker I understand most of it, but without subtitles it's a bit difficult. I will be very grateful for the subtitles!)))
I am using archlinux for this, I had to do several step to get everything working: - install pyserial (python -m pip install pyserial) - give permissions to dev (sudo usermod -a -G uucp && sudo usermod -a -G tty - logout -> login - make sure the usb cable has data wires and not only power - hold the boot button when I upload
Great video. I just hope the audio is balance for all your videos, because I need to lower the volume whenever instrument/music is filled in the video (TOO LOUD).
my solution to the challenge - (written in esp-idf, on vs code) hope it helps. i have worked with freertos before but a long time back, so needed to start from basics again as i was not using it in day to day basis until now, and now i will which i why here i am again to study it . (will read docs later) #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" #include "esp_system.h" #include "driver/gpio.h" #include "esp_random.h" #define LED_GPIO 2 #define PREV_LEVEL 0 volatile int DELAY = 500; volatile int count = 0; QueueHandle_t delayQueue; gpio_config_t my_gpio_config = { .mode = GPIO_MODE_OUTPUT, .pin_bit_mask = (1
I wind up here as I got to the point in my automation programming experience where I've recognized how useful fanuc's shared memory multi processor systems concurrent execution on thier six axis robot architecture is.
Great video Shawn! Thank you for the work that you put into it, it's very valuable for me. I was just leaving Arduino IDE behind and moved to VSCode with ESP-IDF. It might be something to consider for your videos as i feel the Arduino IDE is a dead-end?
Can someone please clear something for me? in 10:06 he said " In other systems, you would need to call the vTaskStartScheduler function". what did he mean by "other systems" here. I'm sorry... I'm really new in this. i just want to clearly understand the context here.
I'm not quite following the first question. If you're trying to calculate the stack size, it's somewhat of a guess--I plan to cover stack and heap usage in part 4. The timing in most RTOSes is on the millisecond scale (I discuss this in part 3), so you cannot get nanosecond precision using an RTOS whose tick timer is 1 ms (the default in ESP-IDF). You can still set up a hardware timer outside of the RTOS to do things like delay and get a timestamp (this is dependent on the individual microcontroller). However, remember that a 100 MHz has a period of 10 ns, so even with a really fast microcontroller, you still can't get nanosecond precision. You'd need a 1+ GHz clock to get there or look at using other hardware (e.g. external hardware or custom hardware via FPGA) to do that.
It would be better if led responds to some input form (at the very least pressing a switch); this way you really showcase the purpose of an RTOS which has to react immediately to an external event
I have an ESP32 sat doing nothing so this seems like a great way to make use of it whilst also learning about RTOS 🙂 I am mainly interested for STM32 development though as that’s what I base my projects on. I bought the ESP32 after hearing how cheap and powerful they were, only to find that the IDF dev environment is pretty horrible. It makes sense to use Arduino IDE for this even though it feels like beginner programming as it smooths all the rough edges of the ESP32 experience. I couldn’t bring myself to use it in a professional setting though.
I'm seeing more ESP32s used in professional settings, so they seem to be gaining in popularity as an IoT device (and they're cheap!). However, I agree that the ESP-IDF feels a little rough sometimes (I haven't used it much, so that's based on my limited experience). If you're mostly interested in using STM32, I might recommend seeing how to get FreeRTOS running on a Nucleo board from their CubeIDE and then working through the challenges in these videos with that. Some of the function calls will be a little different (e.g. xTaskCreate()), but all of the concepts should be the same. STM32's official video on using FreeRTOS: ua-cam.com/video/QGVAayFI5ZQ/v-deo.html My FreeRTOS on STM32 video: ua-cam.com/video/OPrcpbKNSjU/v-deo.html
I'm new to microcontrollers, and decided to get and start with the adafruit huzzah esp32 that is also used in this video series. I knew I didn't want to use the Arduino IDE, but found it pretty easy to get setup using "arduino-cli" for compilation and upload, and VS Code as my IDE. The hardest part was figuring out where all the header files were located so I could tell VS Code about them and get intellisense. When I decided to learn about creating custom partitions and using the SPIFFS file system, I had to use some of the tools that (i guess?) are part of the IDF, but were included with the things the arduino-cli downloaded when I set up the board. A short read of the docs and some experimenting, and I had figured out how to create and upload my own partitions, make/upload a spiffs image, and up upload an executable binary compiled with arduino-cli.
@@quillaja Sounds good. When I had to work on the ESP32 at an old job we used Visual Studio and the VisualGDB extension which made things a bit nicer. It was a nightmare to ensure matching environments between different developers though, one person could be using GNU Make while another CMake and Ninja and have different versions of ESP-IDF checked out. For personal use and just faffing about I think Arduino IDE is fine but when you want strict control over everything and have all the source under version control (rather than just your code under version control and the library dependencies pulled from elsewhere and linked at compile time) then it’s no good. I like the idea of intellisense though so I’ll try your way too 👍🏻
Great video! Just hoping you will not be reading a script. A video without error or misspeaking is impressive, but for the audience it is much more important to be able to follow your thoughts easily.
this is fascinating.I know you said you were only going to talk about using one core for this series. I am curious if you could use both cores to control an LCD display.one core could retrieve a bmp file from an SD card and the second core could load the image into the display.This could potentially double the frame rate of the set up?
Yes, you can. The dual-core ESP32 is very powerful and lets you truly run concurrent tasks. Please note that by default, the second core in the ESP32 is often reserved for WiFi and Bluetooth stacks. However, there's nothing preventing you from using that second core to draw stuff to an LCD faster! Just note that you will need to use something like a double buffer and a lock (e.g. semaphore) to let the drawing task know that a new buffer is ready. You don't want to accidentally overwrite a buffer while you're trying to read from it at the same time!
@@ShawnHymel thank you.It is something I may try once I learn more about RTOS.I think with the increased frame rate I may be able to play 10-20 fps video using an ESP32 and a 160 by 128 LCD screen. I have been reading about binary semaphores to coordinates the tasks, but it is a bit complicated.Your videos are so much easier to understand.
Hi there is a big question in me about Freertos! Imaging if we have 3 functions and compiler needs to run every function in 1us so all functions needs 3us to run Can Freertos do all of these 3 functions just in 1us and same time?
I have one question, is the priority set or can the priority be changed during runtime by the thread/task? I ask because I can see situation where a certain thread requires higher priority when certain parameters are consistently changing and a lower priority when a certain steady state is reached by one or more other parameter(s) dependent on other thread/task results.
Great question! Yes, you can change the priority of a task at runtime using vTaskPrioritySet(), which you can read about here: www.freertos.org/a00129.html. There are times when you need to change the priority, as you've described. There's a particularly nasty bug called "priority inversion" that can happen, and you need to be able to change priorities of tasks on the fly to fix it.
Hi Shawn, thanks for the tutorial. A question: While I could get your Part2 challenge code to compile and load it would not run on my standard ESP32 WROOM-32 dev board. By changing just one thing in the code, 'app_cpu' to 'NULL' it would then run. My Arduino IDE and libraries and json links are all up-to-date. Looks like it only runs if it can pick its own 'core' ???? Any thoughts? Geoff
Ok, if I change from core1 to core0, the code will run without any other changes. #if CONFIG_FREERTOS_UNICORE static const BaseType_t app_cpu = 1; #else static const BaseType_t app_cpu = 0; #endif I am still learning about esp32 and rtos so I would like to understand why the code will compile and load without any problem but will only run on core0 but not core1. Could it be that core1 is busy doing something else???
ANSWER: Yes is was busy! For anyone else having the same issue I used - Serial.println(xPortGetCoreID()); - to track down what was happening. Once the code entered the 'main loop' on 'core1', that's where it stayed endlessly looping, consequently the rtos tasks never execute. I don't know why this happens. Once some code (like Serial.print()) is entered in the 'main loop' the rtos tasks execute in their respective cores. I have no explanation for this either, maybe it will be explained in one of Shawn's later, excellent RTOS UA-cams which I'm currently working my way through. This is the code I used to see what was happening in each of the cores... #include // * Solution to 02 - Blinky Challenge /* // Use only core 1 for demo purposes #if CONFIG_FREERTOS_UNICORE static const BaseType_t app_cpu = 0; #else static const BaseType_t app_cpu = 1; #endif */ // LED rates static const int rate_1 = 500; // ms static const int rate_2 = 300; // ms // Pins static const int led_pin = 2; // Our task: blink an LED at one rate void toggleLED_1(void *parameter) { while(1) { digitalWrite(led_pin, HIGH); vTaskDelay(rate_1 / portTICK_PERIOD_MS); digitalWrite(led_pin, LOW); vTaskDelay(rate_1 / portTICK_PERIOD_MS); Serial.print("Created task1: Executing on core "); Serial.println(xPortGetCoreID()); } } // Our task: blink an LED at another rate void toggleLED_2(void *parameter) { while(1) { digitalWrite(led_pin, HIGH); vTaskDelay(rate_2 / portTICK_PERIOD_MS); digitalWrite(led_pin, LOW); vTaskDelay(rate_2 / portTICK_PERIOD_MS); Serial.print("Created task2: Executing on core "); Serial.println(xPortGetCoreID()); } } void setup() {
Serial.begin(9600); delay(1000);
Serial.print("Setup: Executing on core "); Serial.println(xPortGetCoreID()); // Configure pin pinMode(led_pin, OUTPUT); // Task to run forever xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS toggleLED_1, // Function to be called "Toggle 1", // Name of task 1024, // Stack size (bytes in ESP32, words in FreeRTOS) NULL, // Parameter to pass to function 0, // Task priority (0 to configMAX_PRIORITIES - 1) NULL, // Task handle 1); // Run on one core1 (ESP32 only) // Task to run forever xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS toggleLED_2, // Function to be called "Toggle 2", // Name of task 1024, // Stack size (bytes in ESP32, words in FreeRTOS) NULL, // Parameter to pass to function 0, // Task priority (0 to configMAX_PRIORITIES - 1) NULL, // Task handle 0); // Run on one core0 (ESP32 only) // If this was vanilla FreeRTOS, you'd want to call vTaskStartScheduler() in // main after setting up your tasks. } void loop() { Serial.print("Main Loop: Executing on core "); Serial.println(xPortGetCoreID()); delay(1000); }
The ESP8266 does not run FreeRTOS out of the box, so you would need to include it in your build system. There are a couple of options for doing so: github.com/espressif/ESP8266_RTOS_SDK and github.com/SuperHouse/esp-open-rtos. I have not tried FreeRTOS on the ESP8266, so I can't promise how well it will work.
Shawn Hymel I feel like your challenge is highlighting something you should NOT normally do with schedulers, that is, use the same system resource (a single LED) between two threads without a semaphore. I was cringing inside when you talked about the erratic blinking behavior because stuff like that can be very hard to debug as the threads fight for control! Maybe when you get to semaphores and mutexes, mention this is a bad practice in general!
Indeed it is not good practice :) I just wanted to get people comfortable creating their own tasks and start to understand that they can affect the same resource. This will come into play in future episodes when I cover kernel objects like mutexes and semaphores.
If I want to make a professional product that needs a more robust framework but I want to use an ESP32, does it make sense to work with ESP-IDF? Or is the Arduino framework and libraries robust enough to make products in the professional setting?
I would tend to say use ESP-IDF for more professional use cases, as you get greater control over what's happening in the code. However, I know lots of people deploy Arduino code, as it makes time to market faster (but they run the risk of not knowing if some bugs may crop up that were outside of their control). I suppose it's a tradeoff: how much control do you want in the program vs. how fast do you want to get something deployed?
There is. I'm just avoiding it because it's specific to C++. I know that things like Serial are C++ objects, but I wanted to show how to use FreeRTOS with mostly C.
Arduino: 1.8.19 (Windows 10), Board: "ESP32 Wrover Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), QIO, 80MHz, 921600, None" sketch_may02a:8:28: error: 'LED_BUILTIN' was not declared in this scope static const int led_pin = LED_BUILTIN; ^ exit status 1 'LED_BUILTIN' was not declared in this scope Dieser Bericht wäre detaillierter, wenn die Option "Ausführliche Ausgabe während der Kompilierung" in Datei -> Voreinstellungen aktiviert wäre.
what are the pre requisites for this course. I am C++ application developer and do not have any experience withh embedded programs and RTOSs. So whats the best point to start learning embedded programming?
I'm on Windows, but didn't find it as well, so maybe it helps you. At my PC it's located at: "...\AppData\Local\Arduino15\packages\esp32\tools\esp32-arduino-libs\idf-release_v5.1-33fbade6\esp32\include\freertos\esp_additions\include\freertos" it seems, that in newer versions, there is no such file as "sdk".
Yes. Part 3 continues here: ua-cam.com/video/95yUbClyf3E/v-deo.html. Part 4 is also out. The cards at the end of the video should point you to the next episode. Right now, I'm planning on a total of 12 episodes. Once they're all out, I'm hoping we can get a playlist of them made.
6:45 this is wrong info. The Arduino delay() function is in fact calling vTaskDelay() on the esp32. If you were using a proper IDE like VSCode and Platformio you could just right click and go to definition to see how the function is implemented. I do in fact think that for digikey it would be appropriate to actually use vscode instead of the arduino ide. Installation is about as simple, download vscode, install platformio plugin from within the ide and you're set.
Good to know delay() explicitly calls vTaskDelay() in ESP-IF. It’s technically non-blocking then, so it’s not exactly wrong. I do like PlatformIO and VSCode much better, but I chose Arduino thinking that more people have experience with it (even beginners). If more people are familiar with VSCode, I’m happy to start using that in a future series.
@@ShawnHymel well it's really just my personal opinion. Arduino IDE has it's place and it's covered extensively already. This was just a particular example where using VSCode enables you to simply see what's happening below the toplevel arduino functions. Great series anyway!
@@wolfganglienbacher Thanks! I do love the ability to go to a function definition and step-through debugging. I'm hoping to do more intermediate/advanced firmware series in the future, and some of those will probably necessitate step-through debugging, which means I'll likely have to use VSCode or a vendor-specific IDE :)
i also think it will be valuable to show this more !! >> the concept that these standard arduino functions are viewable is super important and will probably be eye opening to beginners
The Arduino IDE and language feels almost intentionally designed to limit users. That makes some sense considering its real target, yesterday's microcontrollers. The ESP8266, and even more so the ESP32, mark a point where a "Visual Basic" for microcontrollers is overdue.
From what I've seen, the modern equivalent of Visual Basic for microcontrollers is MicroPython and CircuitPython. Please keep in mind any of these high level languages introduce a good amount of overhead. While they make things much easier to program, there will still be developers wanting to use lower-level languages like C to keep things as fast and optimized as possible on the microcontroller.
2 things, 1.) sudden music TOO LOUD! stop trying to blow my ear drums. 2.) You should start with a brief definition of RTOS; I am over a minute in and still don't know what you're talking about.
Noted on the music, thank you. I have reduced the music volume going forward for parts 3 and beyond. Please see Part 1 where I define RTOS and talk about what it's used for: ua-cam.com/video/F321087yYy4/v-deo.html
Just finished a course in embedded systems using FreeRTOS. With these videos I can keep learning!
Where u have learned ?
@@SaiKrishna-wl1ql The Royal Institute of Technology in Sweden.
@@tehmudjinkhan2207 okay bro ....all the best ...
@@tehmudjinkhan2207 big L
- Chalmers Student
I love this series. Haven't had the need to use an RTOS yet, but I'm really enjoying learning about it.
finally UA-cam algorithm that is on point! Thanks Shawn!
A year later - but really appreciating this series.
I need to build a custom motor driver to control 4 full h-bridge drivers chips with single on/off pulses as short as 5uS, in addition to also receiving output from an absolute encoder to get rotor angle information, throttle input, etc. to calculate and drive those 4 other stator control tasks. A general purpose OS is not going to cut it.
Now if this supply chain issue can get resolved so I can actually purchase some of these demo boards to work with...
This series is great! Your teaching style in inspiring. Such depth of knowledge and attention to detail. Hopefully Digikey will keep producing material with Shawn Hymel 🙏
I can't believe this information is provided for free. Thank you so much for making this knowledge accessible.
This gives a greater understanding of the language instead of coping & pasting then just changing the time sequence! Thanks for the tutorial because I learn every time..
Right after i get courses on RTAI Linux , it is pretty the same concept but you made it so much easier and fun !
Thank you for these FreeRTOS videos. They're super helpful for me. I'm looking forward to future videos!
No fluff and quickly moving through it in good detail thanks.
Amazing! Clear, and very information dense, but not overwhelming.
These Videos are great! Looking forward to the next one (hopefully very soon).
This series looks great! Looking forward for the next videos and next series!
Thank you this makes start using FreeRtos and ESP32 much simpler!
Not gonna lie this series seems to be great!
Fascinating topic and thanks for taking the time to create this series and others.
Every time I see this opening scene I think of an old cartoon but can't remember the name of the show or the character. Great series BTW, very informative.
I struggled a bit to understand why #if, BaseType_t, and few other terms used. After few background search I found out:
1. # - these are pre-processor directives. i.e., processed before actual compilation. Thus, #if statement already decides what's the value of app_cpu even before actual compilation.
2. BaseType_t is typedef (keyword to create new type alia) in header file, and it was int.
This is what I understood, do point out if I have mistaken these terms.
This series is really great. Thanks a lot Shawn. Will be waiting for future videos. Just wanted to know at what frequency you would be uploading videos over here?
Should be 3 or 4 each month, so about once per week (with a few off weeks). The plan is to make 10 episodes right now.
This Series is awesome! I would love to see something similar for ESP-IDF. I can't make the transition from the Arduino Framework to the IDF Framework
Absolutely love this video. We developed a game for the ODROID GO (based on the ESP32), and we could not deal with the arduino IDE. It’s OK for small projects, but it does not scale very well.
Your video makes me want to dive back into ESP32 projects. We had to create tasks for Display refresh and pin it to Core 1, with the main game loop running on Core 0. We also setup an ISR to manage the creation of music using LibXMP. Fun stuff!!
Does modern-day robotic industry use a 16bit microcontroller?
I am very grateful for your great videos! There is a small problem, UA-cam has identified the video language as Korean and incorrectly generates subtitles. You have excellent diction and as a non-native speaker I understand most of it, but without subtitles it's a bit difficult. I will be very grateful for the subtitles!)))
Thanks for the heads up. I flagged this is a problem, and hopefully UA-cam will auto-generate new English captions soon.
Please put the link in the description for the webpage @2:53
Also add in the description the JSON link to add in the Preference of Arduino IDE.
Good catch, thanks. I'll see if I can get those links added to the description.
Thanks 👍👍Brother , for help me write my first rtos program
Thank you so much for this free content.
I am using archlinux for this, I had to do several step to get everything working:
- install pyserial (python -m pip install pyserial)
- give permissions to dev (sudo usermod -a -G uucp && sudo usermod -a -G tty
- logout -> login
- make sure the usb cable has data wires and not only power
- hold the boot button when I upload
Amazing stuff! Very well presented! Congrats
Great video. I just hope the audio is balance for all your videos, because I need to lower the volume whenever instrument/music is filled in the video (TOO LOUD).
All your posts are awesome 👍
Thank you Sir ! I'm from Vietnam.
my solution to the challenge - (written in esp-idf, on vs code)
hope it helps.
i have worked with freertos before but a long time back, so needed to start from basics again as i was not using it in day to day basis until now, and now i will which i why here i am again to study it . (will read docs later)
#include
#include
#include
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_system.h"
#include "driver/gpio.h"
#include "esp_random.h"
#define LED_GPIO 2
#define PREV_LEVEL 0
volatile int DELAY = 500;
volatile int count = 0;
QueueHandle_t delayQueue;
gpio_config_t my_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = (1
I wind up here as I got to the point in my automation programming experience where I've recognized how useful fanuc's shared memory multi processor systems concurrent execution on thier six axis robot architecture is.
Great video Shawn! Thank you for the work that you put into it, it's very valuable for me.
I was just leaving Arduino IDE behind and moved to VSCode with ESP-IDF. It might be something to consider for your videos as i feel the Arduino IDE is a dead-end?
Can someone please clear something for me?
in 10:06 he said " In other systems, you would need to call the vTaskStartScheduler function".
what did he mean by "other systems" here. I'm sorry... I'm really new in this. i just want to clearly understand the context here.
Thanks for all! How can I know how much size I most use the Stack Size?
How can I do a NanoSeconds Delay?
I'm not quite following the first question. If you're trying to calculate the stack size, it's somewhat of a guess--I plan to cover stack and heap usage in part 4.
The timing in most RTOSes is on the millisecond scale (I discuss this in part 3), so you cannot get nanosecond precision using an RTOS whose tick timer is 1 ms (the default in ESP-IDF). You can still set up a hardware timer outside of the RTOS to do things like delay and get a timestamp (this is dependent on the individual microcontroller). However, remember that a 100 MHz has a period of 10 ns, so even with a really fast microcontroller, you still can't get nanosecond precision. You'd need a 1+ GHz clock to get there or look at using other hardware (e.g. external hardware or custom hardware via FPGA) to do that.
It would be better if led responds to some input form (at the very least pressing a switch); this way you really showcase the purpose of an RTOS which has to react immediately to an external event
Stay tuned ;) I'm building up to that slowly to give people a feeling for working with multiple threads.
I have an ESP32 sat doing nothing so this seems like a great way to make use of it whilst also learning about RTOS 🙂 I am mainly interested for STM32 development though as that’s what I base my projects on.
I bought the ESP32 after hearing how cheap and powerful they were, only to find that the IDF dev environment is pretty horrible. It makes sense to use Arduino IDE for this even though it feels like beginner programming as it smooths all the rough edges of the ESP32 experience. I couldn’t bring myself to use it in a professional setting though.
I'm seeing more ESP32s used in professional settings, so they seem to be gaining in popularity as an IoT device (and they're cheap!). However, I agree that the ESP-IDF feels a little rough sometimes (I haven't used it much, so that's based on my limited experience).
If you're mostly interested in using STM32, I might recommend seeing how to get FreeRTOS running on a Nucleo board from their CubeIDE and then working through the challenges in these videos with that. Some of the function calls will be a little different (e.g. xTaskCreate()), but all of the concepts should be the same.
STM32's official video on using FreeRTOS: ua-cam.com/video/QGVAayFI5ZQ/v-deo.html
My FreeRTOS on STM32 video: ua-cam.com/video/OPrcpbKNSjU/v-deo.html
I'm new to microcontrollers, and decided to get and start with the adafruit huzzah esp32 that is also used in this video series. I knew I didn't want to use the Arduino IDE, but found it pretty easy to get setup using "arduino-cli" for compilation and upload, and VS Code as my IDE. The hardest part was figuring out where all the header files were located so I could tell VS Code about them and get intellisense. When I decided to learn about creating custom partitions and using the SPIFFS file system, I had to use some of the tools that (i guess?) are part of the IDF, but were included with the things the arduino-cli downloaded when I set up the board. A short read of the docs and some experimenting, and I had figured out how to create and upload my own partitions, make/upload a spiffs image, and up upload an executable binary compiled with arduino-cli.
@@quillaja Sounds good. When I had to work on the ESP32 at an old job we used Visual Studio and the VisualGDB extension which made things a bit nicer. It was a nightmare to ensure matching environments between different developers though, one person could be using GNU Make while another CMake and Ninja and have different versions of ESP-IDF checked out. For personal use and just faffing about I think Arduino IDE is fine but when you want strict control over everything and have all the source under version control (rather than just your code under version control and the library dependencies pulled from elsewhere and linked at compile time) then it’s no good.
I like the idea of intellisense though so I’ll try your way too 👍🏻
4:21 I couldn't stop laughing went you went searching for the header file - in an infinitely deep level of hidden folders
Oh yeah...they buried those RTOS files deep in the Arduino labyrinth of folders :D
4:37
Great video! Just hoping you will not be reading a script. A video without error or misspeaking is impressive, but for the audience it is much more important to be able to follow your thoughts easily.
Most content creators do follow a script in order for people to easily follow their thoughts.
thanks for sharing video, i should only esp32 for use free rtos, other microcontroller doesn't work?
vannila free what does that mean?
A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header, anyone knows how to solve this??
this is fascinating.I know you said you were only going to talk about using one core for this series. I am curious if you could use both cores to control an LCD display.one core could retrieve a bmp file from an SD card and the second core could load the image into the display.This could potentially double the frame rate of the set up?
Yes, you can. The dual-core ESP32 is very powerful and lets you truly run concurrent tasks. Please note that by default, the second core in the ESP32 is often reserved for WiFi and Bluetooth stacks. However, there's nothing preventing you from using that second core to draw stuff to an LCD faster! Just note that you will need to use something like a double buffer and a lock (e.g. semaphore) to let the drawing task know that a new buffer is ready. You don't want to accidentally overwrite a buffer while you're trying to read from it at the same time!
@@ShawnHymel thank you.It is something I may try once I learn more about RTOS.I think with the increased frame rate I may be able to play 10-20 fps video using an ESP32 and a 160 by 128 LCD screen.
I have been reading about binary semaphores to coordinates the tasks, but it is a bit complicated.Your videos are so much easier to understand.
great videos, but do some volume balancing please...
Great channel. Would be nice to see more about internet, web, server, websockets, cameras and video streaming on freertos.
Hi there is a big question in me about Freertos!
Imaging if we have 3 functions and compiler needs to run every function in 1us so all functions needs 3us to run
Can Freertos do all of these 3 functions just in 1us and same time?
i cant find esp32 library by espressif in Library Manager after adding link to "Additional Boards Manager URLs"
I have one question, is the priority set or can the priority be changed during runtime by the thread/task? I ask because I can see situation where a certain thread requires higher priority when certain parameters are consistently changing and a lower priority when a certain steady state is reached by one or more other parameter(s) dependent on other thread/task results.
Great question! Yes, you can change the priority of a task at runtime using vTaskPrioritySet(), which you can read about here: www.freertos.org/a00129.html. There are times when you need to change the priority, as you've described. There's a particularly nasty bug called "priority inversion" that can happen, and you need to be able to change priorities of tasks on the fly to fix it.
Hey, can I use the same tutorials on an ESP82?
Hi Shawn, thanks for the tutorial.
A question:
While I could get your Part2 challenge code to compile and load it would not run on my standard ESP32 WROOM-32 dev board.
By changing just one thing in the code, 'app_cpu' to 'NULL' it would then run. My Arduino IDE and libraries and json links are all up-to-date.
Looks like it only runs if it can pick its own 'core' ???? Any thoughts?
Geoff
Ok, if I change from core1 to core0, the code will run without any other changes.
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 1;
#else
static const BaseType_t app_cpu = 0;
#endif
I am still learning about esp32 and rtos so I would like to understand why the code will compile and load without any problem but will only run on core0 but not core1. Could it be that core1 is busy doing something else???
ANSWER:
Yes is was busy!
For anyone else having the same issue I used - Serial.println(xPortGetCoreID()); - to track down what was happening.
Once the code entered the 'main loop' on 'core1', that's where it stayed endlessly looping, consequently the rtos tasks never execute. I don't know why this happens. Once some code (like Serial.print()) is entered in the 'main loop' the rtos tasks execute in their respective cores. I have no explanation for this either, maybe it will be explained in one of Shawn's later, excellent RTOS UA-cams which I'm currently working my way through.
This is the code I used to see what was happening in each of the cores...
#include
// * Solution to 02 - Blinky Challenge
/*
// Use only core 1 for demo purposes
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
*/
// LED rates
static const int rate_1 = 500; // ms
static const int rate_2 = 300; // ms
// Pins
static const int led_pin = 2;
// Our task: blink an LED at one rate
void toggleLED_1(void *parameter) {
while(1) {
digitalWrite(led_pin, HIGH);
vTaskDelay(rate_1 / portTICK_PERIOD_MS);
digitalWrite(led_pin, LOW);
vTaskDelay(rate_1 / portTICK_PERIOD_MS);
Serial.print("Created task1: Executing on core ");
Serial.println(xPortGetCoreID());
}
}
// Our task: blink an LED at another rate
void toggleLED_2(void *parameter) {
while(1) {
digitalWrite(led_pin, HIGH);
vTaskDelay(rate_2 / portTICK_PERIOD_MS);
digitalWrite(led_pin, LOW);
vTaskDelay(rate_2 / portTICK_PERIOD_MS);
Serial.print("Created task2: Executing on core ");
Serial.println(xPortGetCoreID());
}
}
void setup() {
Serial.begin(9600);
delay(1000);
Serial.print("Setup: Executing on core ");
Serial.println(xPortGetCoreID());
// Configure pin
pinMode(led_pin, OUTPUT);
// Task to run forever
xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS
toggleLED_1, // Function to be called
"Toggle 1", // Name of task
1024, // Stack size (bytes in ESP32, words in FreeRTOS)
NULL, // Parameter to pass to function
0, // Task priority (0 to configMAX_PRIORITIES - 1)
NULL, // Task handle
1); // Run on one core1 (ESP32 only)
// Task to run forever
xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS
toggleLED_2, // Function to be called
"Toggle 2", // Name of task
1024, // Stack size (bytes in ESP32, words in FreeRTOS)
NULL, // Parameter to pass to function
0, // Task priority (0 to configMAX_PRIORITIES - 1)
NULL, // Task handle
0); // Run on one core0 (ESP32 only)
// If this was vanilla FreeRTOS, you'd want to call vTaskStartScheduler() in
// main after setting up your tasks.
}
void loop() {
Serial.print("Main Loop: Executing on core ");
Serial.println(xPortGetCoreID());
delay(1000);
}
Looking foward to next video!
Can I use ESP8266 for this workshop?
The ESP8266 does not run FreeRTOS out of the box, so you would need to include it in your build system. There are a couple of options for doing so: github.com/espressif/ESP8266_RTOS_SDK and github.com/SuperHouse/esp-open-rtos. I have not tried FreeRTOS on the ESP8266, so I can't promise how well it will work.
Thanks Shawn
Shawn Hymel I feel like your challenge is highlighting something you should NOT normally do with schedulers, that is, use the same system resource (a single LED) between two threads without a semaphore. I was cringing inside when you talked about the erratic blinking behavior because stuff like that can be very hard to debug as the threads fight for control!
Maybe when you get to semaphores and mutexes, mention this is a bad practice in general!
Indeed it is not good practice :) I just wanted to get people comfortable creating their own tasks and start to understand that they can affect the same resource. This will come into play in future episodes when I cover kernel objects like mutexes and semaphores.
You need to crawl before you can walk or run.
Love your series and the pace in which you increase knowledge, Shawn.
If I want to make a professional product that needs a more robust framework but I want to use an ESP32, does it make sense to work with ESP-IDF? Or is the Arduino framework and libraries robust enough to make products in the professional setting?
I would tend to say use ESP-IDF for more professional use cases, as you get greater control over what's happening in the code. However, I know lots of people deploy Arduino code, as it makes time to market faster (but they run the risk of not knowing if some bugs may crop up that were outside of their control). I suppose it's a tradeoff: how much control do you want in the program vs. how fast do you want to get something deployed?
Super video... But i did not understand the purpose of downloading the freertos.. Is it being used in this sketch?
No constexpr on arduino?
There is. I'm just avoiding it because it's specific to C++. I know that things like Serial are C++ objects, but I wanted to show how to use FreeRTOS with mostly C.
Arduino: 1.8.19 (Windows 10), Board: "ESP32 Wrover Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), QIO, 80MHz, 921600, None"
sketch_may02a:8:28: error: 'LED_BUILTIN' was not declared in this scope
static const int led_pin = LED_BUILTIN;
^
exit status 1
'LED_BUILTIN' was not declared in this scope
Dieser Bericht wäre detaillierter, wenn die Option
"Ausführliche Ausgabe während der Kompilierung"
in Datei -> Voreinstellungen aktiviert wäre.
can I run a command based browser on RTOS?
what are the pre requisites for this course. I am C++ application developer and do not have any experience withh embedded programs and RTOSs. So whats the best point to start learning embedded programming?
link to json Board Manager library for esp32 is no longer there
You mean this one? It still works for me: dl.espressif.com/dl/package_esp32_index.json
Hi , is there a FreeRTOS IDE ??
There is not. FreeRTOS is just a library (a collection of C source and header files). You can import it into any IDE or build system you wish.
@@ShawnHymel Thank you very much for your answer. So can I equally do that with the STM IDEs?
Kind Regards
@@George-jg6ry Yes. In fact, I have a video showing how to import FreeRTOS into STM32CubeIDE: ua-cam.com/video/OPrcpbKNSjU/v-deo.html
Can I use free RTOS in Raspberry pi 3?
Sir, please explain how to install Esp8266 also, I have Rsp8266 only, here Esp 32 not available
4:13 "Do as I say, not as I do"
Oops...hahaha. I was doing that action so quickly I didn’t notice that I had selected a previous version.
I'm on macOS, and struggling to find the FreeRTOSConfig.h file. Does anyone know where it is?
I'm on Windows, but didn't find it as well, so maybe it helps you.
At my PC it's located at: "...\AppData\Local\Arduino15\packages\esp32\tools\esp32-arduino-libs\idf-release_v5.1-33fbade6\esp32\include\freertos\esp_additions\include\freertos"
it seems, that in newer versions, there is no such file as "sdk".
Playlist Link please?
Excelent video. 👍
very good info ! thanks man !
Can't auto generate subtitles. Language was tetermined (automatically) as korean ((
Give it a few more days. It seems UA-cam needs some time to generate those subtitles.
@@ShawnHymel Cool )
Don't believe but it really worked
You gonna finish this series? :/
Yes. Part 3 continues here: ua-cam.com/video/95yUbClyf3E/v-deo.html. Part 4 is also out. The cards at the end of the video should point you to the next episode. Right now, I'm planning on a total of 12 episodes. Once they're all out, I'm hoping we can get a playlist of them made.
Outstanding!
nice introduction ,thanks for shear
Thanks for the video =)
6:45 this is wrong info. The Arduino delay() function is in fact calling vTaskDelay() on the esp32. If you were using a proper IDE like VSCode and Platformio you could just right click and go to definition to see how the function is implemented. I do in fact think that for digikey it would be appropriate to actually use vscode instead of the arduino ide. Installation is about as simple, download vscode, install platformio plugin from within the ide and you're set.
Good to know delay() explicitly calls vTaskDelay() in ESP-IF. It’s technically non-blocking then, so it’s not exactly wrong. I do like PlatformIO and VSCode much better, but I chose Arduino thinking that more people have experience with it (even beginners). If more people are familiar with VSCode, I’m happy to start using that in a future series.
@@ShawnHymel well it's really just my personal opinion. Arduino IDE has it's place and it's covered extensively already. This was just a particular example where using VSCode enables you to simply see what's happening below the toplevel arduino functions. Great series anyway!
@@wolfganglienbacher Thanks! I do love the ability to go to a function definition and step-through debugging. I'm hoping to do more intermediate/advanced firmware series in the future, and some of those will probably necessitate step-through debugging, which means I'll likely have to use VSCode or a vendor-specific IDE :)
i also think it will be valuable to show this more !! >> the concept that these standard arduino functions are viewable is super important and will probably be eye opening to beginners
A shame that a proper IDE is not used; for example Eclipse CDT
thank you! it made easy
The Arduino IDE and language feels almost intentionally designed to limit users. That makes some sense considering its real target, yesterday's microcontrollers. The ESP8266, and even more so the ESP32, mark a point where a "Visual Basic" for microcontrollers is overdue.
From what I've seen, the modern equivalent of Visual Basic for microcontrollers is MicroPython and CircuitPython. Please keep in mind any of these high level languages introduce a good amount of overhead. While they make things much easier to program, there will still be developers wanting to use lower-level languages like C to keep things as fast and optimized as possible on the microcontroller.
So super hit
seems all I have are esp8266s :/
I bet you that the reason why FreeRTOS is never abbreviated as FRTOS is to keep people from calling it "Fart OS"
❤️❤️
good luck
#ifndef LED_BUILTIN
#define LED_BUILTIN 2
#endif
Thanks. This is needed if your board does not have LED_BUILTIN defined in its Arduino package (most should), and you have an LED connected to pin 2.
Yea, some boards straight up have the built in LED connected to pin 2 and not defined in the Arduino package. Kudos for the good content
What is RTOS?!? 🤔
I cover that in the first episode: ua-cam.com/video/F321087yYy4/v-deo.html :)
Thanks
Amazon ??? Actually Amazon forest in the 24th century have been fully regenerated
Cool🇬🇧
cool
Does
Drop the bowtie and I'll subscribe
in time span of 10 second, im listerning atleast 2 unfamiliar words!!...
Hii brow
Lies
2 things, 1.) sudden music TOO LOUD! stop trying to blow my ear drums. 2.) You should start with a brief definition of RTOS; I am over a minute in and still don't know what you're talking about.
Noted on the music, thank you. I have reduced the music volume going forward for parts 3 and beyond. Please see Part 1 where I define RTOS and talk about what it's used for: ua-cam.com/video/F321087yYy4/v-deo.html
Great vídeo btw.
Do you really feel you have reinforce the stereotype of engineers being nerds by wearing a ridiculous bowtie?