How can a MCU based FreeRTOS talk to a smart phone through BlueTooth to get sensor data?
Part 1 - Short Answer
Part 2 - TL;DR Long Answer
Part 1 - Short Answer
1.1 Prerequisite and Recommended Reading
This answer is for newbies who has no previous experience with RTOS (Real Time Operating Systems) and very little knowledge and skills in the following:
(a) "process" concepts, such as multi-tasking/multi-threading/multi-processing,
(b) "processing synchronizing/locking concepts, such as seamaphore, critical section, mutex, coroutines etc.
I would recommend the newbies to read the following *free Operating Systems eBook:
Operating System Concepts, 8th Ed (The Free Electronic PDF "Dinosaur" OS book 980+ pages!), Silberchatz 2009,
paying particular attention on the following chapters:
Ch 3 - Process Concept (pipes, interprocess communication),
Ch 4 - Multi-threaded Programming (for multi-core systems),
Ch 5 - Process Scheduling (virtual machine scheduling and multithreaded, multicore architectures etc),
Ch 6 - Synchronization (mutual exclusion locks etc)
1.2 Practice makes thing clear
Multiprocessing and/or event programming stuff is very hard to develop and debug. For newbies, I strong recommend NOT to dive into any RTOS but be humble to start with writing python multi-processing toy programs. A good getting started is the python multiprocessing library/module, which you can import into the very newbie friendly Thonny Python IDE (more about this later).
1.3 Which MCU to use
For those who are not familiar with modern MCUs, I would recommend to watch the MCU comparison YouTube by the Swiss guy Andreas Spiess:
After watching the Swiss guy's MCU review, I think it is a good idea for newbies to dip their fee wet into Rpi Pico + Thonny IDE + MicroPython. I would also recommend to use WinPC over Rpi/ESP as the host machine.
My recommendation is based on playing with Pico and MicroPython and learnt from the Rpi Foundation's newbie tutorial on the following:
(1) Blinking a LED (using interrupt), reading a push button,
(2) Using on board 12 bit ADC and also external sensor DS18B20,
(3) Two two core (PIO) Programmable I/O programming with NeoPixel RGB LED strips.
(4) DC motor drivers
1.4 Incremental Learning Plan
The Swiss guy Spiess mentioned that he spent 4 hour struggling with Pico C++ SDK. The other RUST expert Jonathan Tan mention that he knew how to blink a LED. RUST base FreeRTOS seems not yet very mature in Pico. So I would recommend newbies not to start with Pico C++ or RUSt, but be humble and play with barebone python programs on multi-processing (yes, playing with interrupt to blink a LED is already multiprocessing). So I would recommend to eat the big elephant bite by bite, in three big bites.
(1) Win10 PC Thonny python IDE and Rpi Pico (for newbies)
(2) Rpi4B and Rpi Pico C++ SDK (ninjas only)
(3) Rpi Pcio RUST FreeRTOS (hackers only)
1.5 Learning Rpi Pico MicroPython Multiprocessing Programming
How to use the two Cores of the Pi Pico (for multi-processing)? And how fast are Interrupts? - Andreas Spiess
Another good newbie friendly video to learn Pico based FreeRTOS is also from the Swiss guy Spiess. This video shows how to use MicroPython to write a very simple two core/thread program to do multiprocessing using an interruptable button to blink a LED. In other words, you don't need FreeRTOS to learn or appreciate the very basic idea of multiprocessing in RTOS, with the limitation of only two threads/processes are allowed in the demo program. Ah yes, 64-bit Rpi4B with 4 cores can do 4 processes in real time, and more than 4 processes "a bit slower" using a process queue/pool.
1.6 General Reading List Before Micro Python Multiprocessing Programming
I skimmed more general RTOS tutorials to make sure I have refresh my memory on all the necessary knowledge and skills required. I found Refs 9 ~ 13 very good in learning the concepts. The Arduino based C++ FreeRTOS is a bit tedious to follow. So I skipped them and start now the real Rpi Pico basic multiprocessing demo programs using Rpi Thonny Python 3.9 Multiprocessing Module (Not the old Multi-threading Module)
Note - I self taught all the basic OS concepts using the Dinosaur OS book, and also another good text book by HM Deitel.
Part 2 - Long TL;DR Answer
(1) Operating System Concepts, 8th Ed (The Free Electronic PDF "Dinosaur" OS book 980+ pages!), Silberchatz 2009
(2) The Python 3.9 Standard Library » Concurrent Execution » multiprocessing — Process-based parallelism
(3) Rpi Pico vs ESP32 and STM32 (15 min YouTube) - Andreas Spiess 2021jan31
(4) Rust, RT-Thread OS & FreeRTOS come to the Raspberry Pi Pico - Jonathan Tan, SeeedStudio 2021Jan
(5) FreeRTOS - Wikipedia
(6) FreeRTOS Real-time operating system for microcontrollers Home page and down load - FreeRTOS
(7) Rpi Pico vs ESP32 and STM32 - Andreas Spiess, 2021jan31, 190,293 views
(8) How to use the two Cores of the Pi Pico (15 minutes YouTube video)? And how fast are Interrupts? - Andreas Spiess
(9) Understanding Real Time Operating System (RTOS) and How to use it for your next Embedded Design - Sunakshi, CircuitDigest 2019aug29
(10) Arduino FreeRTOS Tutorial - How to use FreeRTOS to Multi-tasking in Arduino - SeeedStudio
(11) Arduino FreeRTOS Tutorial 1 - Creating a FreeRTOS task to Blink LED in Arduino Uno - Rishabh Jain, CircuitDigest, 2020mar26
(12) Arduino FreeRTOS Tutorial 2 - Using Queues in Arduino FreeRTOS - Rishabh Jain, CircuitDigest, 2020apr06
(13) Arduino FreeRTOS Tutorial 3 - Using Semaphore and Mutex in FreeRTOS with Arduino - Rishabh Jain, CircuitDigest, 2020apr09
(14) FreeRTOS Kernel Quick Start Guide - FreeRTOS
(15) Complete FreeRTOS Documentation - FreeRTOS
(16) Mastering the FreeRTOS Real Time Kernel - FreeRTOS
(17) The FreeRTOS V10.0.0 Reference Manual - FreeRTOS
(18) FreeRTOS Source Code for Book Examples Download - FreeRTOS
(19) System Analysis, Design, and Development Concepts, Principles, and Practices 1st ed - Charles S. Wasson, Wiley (free eBook) 2006
Appendix A - Wikipedia's short introduction to FreeRTOS
FreeRTOS is a real-time operating system kernel for embedded devices that has been ported to 35 microcontroller platforms. It is distributed under the MIT License.
FreeRTOS is designed to be small and simple. The kernel itself consists of only three C files. To make the code readable, easy to port, and maintainable, it is written mostly in C, but there are a few assembly functions included where needed (mostly in architecture-specific scheduler routines).
FreeRTOS provides methods for multiple threads or tasks, mutexes, semaphores and software timers. A tick-less mode is provided for low power applications. Thread priorities are supported. FreeRTOS applications can be completely statically allocated. Alternatively RTOS objects can be dynamically allocated with five schemes of memory allocation.
3. Key features
Small memory footprint, low overhead, and fast execution.
Tick-less option for low power applications.
Intended for both hobbyists and professional developers working on commercial products.
Scheduler can be configured for both preemptive or cooperative operation.
Coroutine support (coroutines in FreeRTOS are simple and lightweight tasks with limited use of the call stack)
Trace support through generic trace macros, including task scheduling and kernel calls for semaphore and queue operations.
Appendix B - Getting Started with newbie friendly FreeRTOS tutorials
My learning plan is summarized below.
Skim Arduino FreeRTOS tutorials to get a rough idea of what sort of multliprocessing stuff they usually recommend, eg. interrupt, semaphore, mutex etc. Then write some newbie demo programs using Rpi4B and Rpi Pico using the same stuff: semaphore, mutex etc
Following the Swiss guy Andreas Spiess's YouTube video tutorial, write a 2 core/two process Rpi Thonny Python/Rpi Pico MicroPython multiprocessing demo program, illustrating the use of (a) Interrupt, (b) Semaphore, (c) Process queue/pool to do the following event driven program:
(i) any one of two buttons pressed would cause an interrupt routine to setup a semaphore and blink a LED 3 times,
(ii) while the button service is in progress, no further interrupt from the other button will be serviced.
(iii) when the blinking service is completed, locked semaphore will be released, and all interrupt will be entertained again.
This two processes program using Interrupt and Semaphore can be seen as a very very oversimplified portion of RTOS. So when the real RUST FreeRTOs ofr Rpi Pico arrives, hopefully in a couple of months time, this demo program can be used as a starting started test of the FreeRTOS.