Over 10 years we help companies reach their financial and branding goals. Engitech is a values-driven technology agency dedicated.

Gallery

Contacts

411 University St, Seattle, USA

engitech@oceanthemes.net

+1 -800-456-478-23

FreeRTOS RTOS

Creating tasks in FreeRTOS (using CMSIS)

This video is in continuation to series of FreeRTOS tutorial blogs, checkout previous blog if you wanna know how to get started with RTOS using FreeRTOS. Now in RTOS one of the very first things that we do, is TASK creation and then schedule it via the concept of priority wise. After which tasks are executed according to the scheduling algorithm chosen. If we were to understand in simple terms, TASKS are something that needs to be done. There are multiple tasks running parallel in RTOS but at a time only one task is getting executed(if MCU is single core). It is characteristic of the RTOS kernel which makes us visible that all tasks are running simultaneously. Each task has its own memory, requires the system resources, has its own variables and etc. So we are going to first implement this thing only, we will see how to create multiple tasks, and how to write Software for each task which will perform some kind of Input/Output action. Then make them run simultaneously by starting the FreeRTOS kernel. Each task is a small program on its own. Each has an entry point & will normally run forever with an infinite loop.  The task function is the entry point where we write the program for corresponding tasks. There is TCB( Task Control Block) which will be having all the information about TASKS. This will be used to debug  & understand the tasks creation and working. Sensor & modules Drivers to run them as tasks in FreeRTOS: ESP8266 as Client With HOST MCU. W25QSPI Flash memory for logging with HOST MCU. INA219 DC Current sensor with HOST MCU. HLW8012 AC metering IC with HOST MCU. OLED Screen Display with HOST MCU. DHT11 temperature sensor with HOST MCU. Making FreeRTOS project in STM32CubeIDE At first, we created the project with the FreeRTOS as middleware in STM32CubeIDE. We would be using STM32F103 bluepill as our controller. I hope you guys know how to create a project in STM32CubeIDE, if viewers don’t they can refer to this video (in the video I have chosen different MCU, you can choose whatever MCU you are using) for that and then come back here. After STM32CubeIDE Project is created, open the .ioc file in your STM32 project directory from the project explorer.  (I am skipping the basic configuration of RCC and SYS, assuming that viewers already know how to do that. if they don’t, they can have a look from this video.) Now go to the last section Middleware in the categories of the .ioc file. Select the FreeRTOS. Select Interface as CMSIS_V1.   Now you can see in the configuration there are many heading with the name of RTOS components. So, from here, we can configure our FreeRTOS directly in a GUI-based way, thus I started with STM32CubeIDE as it becomes easy for beginners to start with FreeRTOS. Now seeing the headings for beginners, it might be confusing which components are used when and for what purpose. If you have read the PDF on RTOS which i have mentioned in my previous blog: Starting with RTOS: FreeRTOS | gettobyte, you would be having a rough idea of these headings.But for now, we would only be focusing on the Tasks and Queues heading, which is used for the creation/management of tasks and queues. As in this blog, we are only creating tasks, so we would be creating tasks for now and understanding how to configure their different parameters. Don’t worry!!, we don’t need to learn all things at one time.

FreeRTOS Mbed OS RTOS ThreadX

What is Real Time Operating System (RTOS) ?

What is Real Time Operating System(RTOS) ? Operating System must have heard this name earlier but only in relation to Windows, Linux, and MAC OS which are there in Laptops and Computer devices. Most people are aware of only these Operating Systems in general terms which are there in most the General Purpose Computers. But what if I told you that there is an Operating System in most of the electronic devices (Embedded devices) around us like Earphones, Setup Boxes, Cars, speakers, Air Conditioners, Smart Watches, Medical devices and etc? Operating System is basically a software stack that allows the Electronic/Electrical devices to mimic the sensing of multiple inputs, their processing and correspondingly controlling multiple outputs at an instantaneous time. All of these Embedded devices have multiple inputs that need to be sensed, then processed, and correspondingly control the outputs. All of this happens in a real-time and mimic to happen at an instantaneous time. These Embedded devices work in Real-time data on time-critical and small memory space constraints. To put it in a different perspective, imagine a manned spacecraft in low earth orbit traveling about 17,000 miles an hour. Suppose that every 1,000 seconds, it has to fire an orbital maneuvering system rocket for 3.8 seconds to avoid deorbit. A one-second unit of time translates to 25,000 feet of distance covered. Imagine what nightmare would ensue if the spacecraft avionics had to stop, wait for the navigation system to page back in, fire the rockets, and then wait for the next interruption to stop firing the rockets. It could take five seconds or more. In that time the spacecraft will deviate 25 miles from its projected course. You can take any example, let\’s say of speakers. Speakers are connected to our phones for playing music, the moment when we press a song to be played at just a fraction of sec that music gets start playing. But have you ever thought that what all process is behind this? There is Bluetooth signal that has to be send from our phone to speakers, then speakers process and compute the signal that it receives. Then according to signal, speaker base start vibrating to play the music. The connection between phone and speakers should be continuous, so that signal to play the music (lyrics basically) is not interrupted. If in between to this we need to lower the volume or change the BASS of music those signals also have to be processes, computed and executed. Same way out you can try to think the flow of working of electronic devices around you and realize that Operating System is everywhere not just in our desktops. Operating system used in Embedded devices is called Real Time Operating System (RTOS). RTOS is very important topic and concept to be understood to make complex electronics/electrical application projects which are time critical like nuclear monitoring devices, Anti-brake system, automotive ECU\’s, Programmable logic Controllers (PLC\’s), Automated guided vehicle\’s (AGV), Motor drivers which are there in metros/airplanes/vehicles, and many such examples (In some cases, instead of RTOS, Linux OS is also used. That is different topic to be touched).

FreeRTOS RTOS

Starting with RTOS: FreeRTOS

Table of Contents Intro From this blog, we will be starting with RTOS(FREERTOS). In RTOS there are many concepts & things related to kernel, tasks management, task scheduling, IPC, and many other terminologies. In the tutorial series, we are not going into a theoretical understanding of the RTOS topics, we would be mainly focusing on developing different applications in RTOS. Like how to use mutexes, and semaphores in different applications, we will get into the RTOS kernel and understand its different components like scheduler, task management and etc., compare different scheduling algorithms in terms of time and how to create multiple tasks and pass information between them, how to use Software timers, queues and etc. while writing firmware for industrial projects. As there are many resources & tutorials to understand these theoretical concepts and how to use RTOSes APIs to build different kinds of applications is not much there. So, we would be focusing on that thing. RTOS is used in applications like that AGV(Automated Guidance Vehicles), Automotive ECU, and industrial automation products (Like metering instruments, industrial smart sensors and etc.). I have a personal interest and passion for these, so I would be making projects using RTOS related to these by interfacing sensors and modules used in these applications. Ultimately making the different tasks run together to utilize the power of RTOS to make an efficient project. To Know about what RTOS is, refer to this blog What is Real Time Operating System (RTOS) | gettobyte Now to start with RTOS, there are many open source RTOSes available like FreeRTOS, embed OS, Zypher OS, ThreadX OS and etc. But starting with FreeRTOS would be my choice that too with STM32 because the integration of STM32CubeIDE with FREERTOS is pretty easy & gives an easy starting point for beginners. Subsequently, we will migrate to NXP controllers with FreeRTOS. Once getting hands-on with FreeRTOS via STM32. Requites: Bare metal coding On MCU’s (Register level programming, working of MCU’s, SoC/processor architecture, boot process: linker script, startup code, GNU GCC, Debugging and etc.). Knowledge of peripheral of UART, I2C, SPI, ADC, Interrupts, DMA and etcC/CPP programming, etc). Device driver development to integrate different sensors & Modules with MCU. (Datasheet reading, communication protocols, sensors and modules working/Cpp programming). Knowledge of C/CPP programming. Software Development Kit, IDE, HAL, RTD drivers and etc. FreeRTOS What is FreeRTOS? FreeRTOS is Real Time Operating System, which is highly used in industry. It is also best recommended for beginners to start with if one wants to learn RTOS, because of its wide number of resources available, documentation, and community support. FreeRTOS is a market-leading embedded System RTOS, which is available for many processor architectures, it supports more than 40 processor architectures including ARM cortex processors. Also portable to a wide number of compilers and hardware platforms. FreeRTOS is supported by a wide number of silicon vendor chips like NXP Semiconductors, STMicroelectronics, Texas Instruments, and many others. You can find a full list of that here: Microcontrollers and compiler toolchains supported by FreeRTOS. Features of RTOS Highly configurable kernel. FreeRTOS has Microkernel architecture. Pre-emptive or co-operative operation. Inter Processor Communication techniques like Mutex and Semaphore for synchronization. Support for message queues. Software Timers. Event groups. Memory management to maintain heap memory. Also, advanced features for debugging the tasks in Real Time. FreeRTOS Kernel The kernel is the most important thing and core of the RTOS. For the understanding you can have analogy that Human body is RTOS, and Human Brain is RTOS kernel. As without our brain we can’t do any work and loose our capabilities. Same without the kernel, RTOS can’t work. It is kernel which makes electronic devices, a multitasking system. It is kernelling whose responsibility is to run different tasks and have communication between them. Kernel act as the interface between system resources and user application. Kernel has different services for making multitasking system. Just like human brain has different biological parts to make us work. ( In the upcoming blogs and in this also, i would be using analogy of Human brain and Human body for understanding). The basic services of RTOS kernel are:  Task/Process Managment (Creation and deletion of tasks) Task/Process Scheduling (Scheduler) task/Process synchronization (Inter Process Communication) Memory Managment (heap & static) Interrupt Handling Error/Exception handling Coming to the FreeRTOS, it has highly configurable kernel. We can configure how to use the FreeRTOs kernel and which features/services of it. FreeRTOS is configured by FreeRTOSConfig.h header file. This file contains application specific definitions to configure FreeRTOS kernel. Every RTOS has one such configuration file which has macros, which can be enabled or disabled. Like we can configure which scheduling algorithm to use, how to create the tasks (static or dynamic), which IPCs to use for communication between tasks, enabling of run-time trace and debug features. When you will download the FreeRTOS kernel zip file, you will find many numbers of files. But core FreeRTOS is runned by just 2 files tasks.c and list.c. They are located in FreeRTOS/Source directory. In addition to these files, imp files whose Api’s we would be using are queue.c, timers.c, event_groups.c, croutines.c. Examples of RTOS Kernel: Mach QNX VXworks FreeRTOS Chibios ThreadX mbedOS FreeRTOS Libraries In addition to FreeRTOS kernel, there are add on libraries to extend the RTOS functionality. FreeRTOS+: To add support of TCP/IP stack and command line interpreter. FreeRTOS Core: To add support of cloud connectivity with HTTP, MQTT, JSON, Cellular interface. FreeRTOS AWS: To add support of AWS services. How To Start with RTOS? So, as of now, I have told you many things about RTOS and FreeRTOS. Most of you must have come up with that now how to start with FreeRTOS to learn RTOS. When we go to the FreeRTOS website for starting with RTOS, there are many things on the website, lots of documentation, articles, and resources on the website that might become overwhelming and confusing for beginners to start with it. At least for me, it does become like that, so I

Stay Updated With Us

Error: Contact form not found.