A work in progress.
The esp32 makes it easy to have multiple tasks performing different functions. For example a task could update an LED display when required.
There are several options to communicate data to a task - for example to change the LED colour.
For example there are queues, semaphores and notifications.
Of these - notifications are simplest. I wrote a simple component - to allow notifications (which are a 32 bit value) to be passed to a task. The task is 'asleep' until it receives a notification - at which point it wakes, performs its task and then sleeps again until another instruction is passed.
Here is a very simple example - the main task creates a 'task' that prints the value of any notifications received to UART (note that it also has a delay which is not strictly necessary here - this is to allow testing of some of the notification types - which can 'fail' if the task is not ready)
I haven't included instructions for adding a component here...
Note that in more recent versions of FreeRTOS - the task can have an array of notifications. Tasks can receive notifications from other tasks or from ISRs.
Martin
Esp32 Tasks - communication and control
-
- Valued Contributor
- Posts: 1453
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
-
- Valued Contributor
- Posts: 997
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
Re: Esp32 Tasks - communication and control
Hi Martin
I have looked at a few examples of yours and learnt a lot. Thanks to you.
It works with the additional task to create.
In the additional task I can send UART and write to the sd-card.
I can also take over variables from the main.
I will try to place the saving of data to sd-disc in an additional task in my program.
Special I had to increase the stack size to 10240
File is ok: uart is ok my program
I have looked at a few examples of yours and learnt a lot. Thanks to you.
It works with the additional task to create.
In the additional task I can send UART and write to the sd-card.
I can also take over variables from the main.
I will try to place the saving of data to sd-disc in an additional task in my program.
Special I had to increase the stack size to 10240
File is ok: uart is ok my program
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Esp32 Tasks - communication and control
Hi Stefan,
Glad your project is moving along.... The esp32 really is quite a remarkable MCU - and it looks like the trend towards more performance is continuing with espressif's new releases.
I'm sure Matrix will continue to support them in Flowcode making it easy (well easier) to tap into some of that power...
Martin
Glad your project is moving along.... The esp32 really is quite a remarkable MCU - and it looks like the trend towards more performance is continuing with espressif's new releases.
I'm sure Matrix will continue to support them in Flowcode making it easy (well easier) to tap into some of that power...
Martin
-
- Valued Contributor
- Posts: 997
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
Re: Esp32 Tasks - communication and control
Hi Martin
One more question.
It works with the task and writing to the disk.
Only during writing, the sampling slows down.
Can I also run the task in the other core?
One more question.
It works with the task and writing to the disk.
Only during writing, the sampling slows down.
Can I also run the task in the other core?
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Esp32 Tasks - communication and control
I've never tried it - but xTaskCreate allows you to specify the priority and you could try increasing that.. You could also try xTaskCreatePinnedToCore - but the normal xTaskCreate should allow the task to run on either core - so this might not make much difference.
Make sure no tasks are busy-waiting (for pin change etc) - but yield and use a 'wait' procedure to pause until an event - as the system relies on tasks passing control back to the task-handler whenever possible.
Martin
Make sure no tasks are busy-waiting (for pin change etc) - but yield and use a 'wait' procedure to pause until an event - as the system relies on tasks passing control back to the task-handler whenever possible.
Martin
-
- Valued Contributor
- Posts: 997
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
Re: Esp32 Tasks - communication and control
Hi Martin
It looks like this is working
during writing, the sampling is not slows down! If the task is in core1 and not in core0
I will test it more.
It looks like this is working

during writing, the sampling is not slows down! If the task is in core1 and not in core0
I will test it more.