Arduino does not support “REAL” parallel tasks (aka Threads), so I want to introduce ArduinoThreads library.
Multithreading is mainly found in multitasking operating systems. Multithreading is a widespread programming and execution model that allows multiple threads to exist within the context of a single process. These threads share the process’s resources, but are able to execute independently. The threaded programming model provides developers with a useful abstraction of concurrent execution. Multithreading can also be applied to a single process to enable parallel execution on a multiprocessing system. https://en.wikipedia.org/wiki/Thread_(computing)
ArduinoThreads is a library for managing the periodic execution of multiple tasks. Download the Master branch from gitHub.https://github.com/ivanseidel/ArduinoThread
Don’t use the delay function. (well, you can use short delays for specific purposes but its generally best to avoid using delay() )
Either use the FSM to handle the delays or use hardware timers and interrupts.
e.g. see the Arduino “blink without delay” example, for one alternative method to using delay.
On the STM32 you can also make use of DMA for some tasks, hence still allowing then microprocessor core to execute code , while the DMA hardware does things like transferring to or from SPI ( or serial or memory or even from GPIO)
Everyone seems to be missing the Op’s point, a class-library is available to perform pseudo-threading on the uC. This is educational, but will impose some overhead.
I’ve looked over the class implemention and example. I see no problem in the approach, but limitations could show in testing, which I did not perform.
To the comments, “yes” all are correct. We have all used a multitude of approaches to implement code that does not stall; the pseudo-thread implemention is just another approach.
Ray
Those past months, I’ve been re-design this board with STM32F405, still lots of work to finalize testing.
But, early in re-design, I decide to go all the way with stm32duino, and with help of people here, the FreeRTOS port was the way to go.
I’m happy with it since weeks. I’ve even think (if “time-missing-indredient” is there) to try to port it to ESP82266 world …
And the SAME hardware, when used with Particle’s Arduino-alike C code environment, runs FreeRTOS.
These both permit the WiFi networking and other management to run so long as the user program doesn’t hog all the CPU time.
They’ve both done well to “hide” the existence of the RTOS from the typical user. But advanced users can make RTOS calls to create tasks.
(RTOS has long used the term task, where each task has its own stack. Other worlds use the term thread. There are some single-stack “threaded” schedulers, and then can task switch based on time-slices or yields by the thread.)
Still, my experience is that finite state machines can handle 90%+ of the situations with tiny code and with simplicity.
Still, my experience is that finite state machines can handle 90%+ of the situations with tiny code and with simplicity.
Still, my experience is that finite state machines can handle 90%+ of the situations with tiny code and with simplicity.
Actually Iran is located in West of India. the weather is good but we don’t have good rainfall up to now. Iran is spectacular country, Shiraz and Isfahan are specially spectacular in spring.
RTOS analysis for microcontrollers-Warning PDF=45KB
For systems comprising 16 or more tasks, the Non-
Preemption Group concept, combined with integrated
priority allocation and schedulability analysis results in
a reduction in the number of preemption levels re-
quired by a factor of 4 or more
Ray
Multithreading example using a minimal context switcher
Multithreading example using a minimal context switcher
RTOS analysis for microcontrollers-Warning PDF=45KB
For systems comprising 16 or more tasks, the Non-
Preemption Group concept, combined with integrated
priority allocation and schedulability analysis results in
a reduction in the number of preemption levels re-
quired by a factor of 4 or more
Ray
Almost for 10 years there has been Contiki OS that is based on protothreads. It is widely used in communication systems where the time management is essential with minimum waiting times and large number of timeout conditions.
I was involved in realtime OS development for communication and industrial control over 30 years ago and based on my observations over the past 40 years, my recommendation is a solution that reduces the complexity of the total system.
Cheers, Ollie
<…<However typical ARM MCUs have moved to 16kB SRAM, where real preemptive multitasking is less of a problem, and the advantage of proper software layering is more important.
My reading is that it is very close to plain Arduino without any kind of OS. What are the RTOS systems that you are using and can you recommend some of them to this audience?
Cheers, Ollie
My reading is that it is very close to plain Arduino without any kind of OS. What are the RTOS systems that you are using and can you recommend some of them to this audience?
Cheers, Ollie

