STM32 FreeRTOS UART EXAMPLE with Task Priorities #osPriorityAboveNormal #osPriorityNormal

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i am going to show you the easiest way of using the uart in the free rtos with the stm32 project let's create a new project and choose your discovery board which i'm using sem32 f4 discovery board you can select it from the board selector by typing your board name or simply by clicking on the search menu and searching for the right microcontroller series in my case stm32f4 next i need to navigate to the stm32f4 and on the board section i need to search for my stm32 discovery board it has a lot of options but i need to choose the stm32f407g discovery board next i need to name my project in my case i'm naming it free our toes underscore youtube underscore your auth or you could say it use that or but i'm using it in asynchronous mod so uh initialize without the default parameters because i'm going to set the parameters myself i'm not going to use much peripherals because i'm only going to use the uart peripheral the next i need to wait for this project to finish its initialization and the creation project after that it will take you to the cube mx setting like this this is ioc file all you need to do is to check that all your peripherals like the onboard leds are highlighted because these leds are initialized for you uh uart2 is available which i am going to use and all i need to do is to enable it in asynchronous mod after that i need to go to the parameter sections and make sure everything is perfect pa2 is for tx and pa3 is for rx you need to attach ft232 converter chip so you can see the values on your laptop this is a 11.5200 path rate for now and all these parameters should be remain same next we need to move to the free auto section and i'm going to choose the kempsis version one after that make sure that you are using the preemptive preemptive enabled in the kernel section in the advanced settings use the neolib enable after that go to the sys menu like this and put it down choose some other timer for time build source once done you are good to generate the code it will take you to the c plus perspective uh click yes because we want to generate the code even the nvic we are not using any interrupt for our uart for now for the sake of simplicity because i want to make sure that everything is simple i'm going to show you the simplest way and the easiest way to get started not the complex configurations uh most of things are as it is and next uh what i'm going to uh go through here we have a default task we need to create more tasks so you we can play with the uart and the free autos so we need to move back to the ioc file and we can make any changes we want so we will go to the uart sections uh everything is good here we need to move to the free autos and here we need to create more tasks so we need to create move to the task and cue bar tab and here we are going to add another task just put it back and come back here um click on add button create a new task you can name it uh whatever you like this name is not gonna effect on your function because uh the function is the entry function uh so we can leave the everything else as it is we are going to create three three tasks and next one is you are task two and normal priority and let's create one more task and we can change the priority level as well we can put it down below the normal and for task 2 normal is fine and the task three which is gonna use the start task zero for for entry function and we can put the priority above normal so the different priority levels will uh able to run the task force start passport function uh with the highest priority and after that the task two and the task one um create a code if you save the ioc file it will ask you to donate the code for the file and all you need to do is press yes and once the code is done you will see in your code section uh that three more functions start tabs two three and four are created for you and these are the three types that we are gonna use we will leave the default task as it is and here you can see the entry level for all of these three um tasks here you can see the first argument is the uart one two and three that we name it and uh but the entry functions are uh start task two three and four uh so the highest priority level is for the um the task for and we are going to leave the default task as it is uh moving to the start task function here we are actually writing the code for the uart and we are creating an character array uh so all we're going to you uh use as the u n 8 and underscore t data type and we are naming the text array and we are creating a array of characters which is string and i'm just going to print some function some text to display on the serial terminal and text from the task 2 would work fine because we are just going to demonstrate and the function to transmit the uart text over the uart as the hull underscore your auth and underscore transmit and you can find that function under the recommendation uh this id is pretty uh for just like that eclipse so the transmit function and we have the hua 2 handler and the text one that we want to transmit and here we need to mention how much how many characters we need to transmit so we will grab the size of the text and we put that here and for timeout we are just 500 milliseconds we would work and after that we need to put some delay here so we can modify it to 300 millisecond or the 500 millisecond and just copy um these three lines and we are going to paste it all over uh our task so uh just change the number so we would be aware which function is transmitting with text and after that we are going to run this code in over sem32f4 discovery board so all we need to select our project from the project menu and under under the run we will run it as stm32 project and we need to wait for it for the bell to finish and once the build is finished it will automatically download the code into our stm32f4 discovery board and meanwhile i plugged my discovery board leave all the configuration as it is and the build is done and after that the code download process is started make sure you plugged in your stm32 f4 discovery board before starting the build process and once everything is done you need some kind of serial terminal and make sure you have attached the fd232 chip with the proper wiring settings tx to rx and rx to tx and after that one when you are finished with your connections make sure you put the usb cable with your r ft-232 chip as well and put that chip onto your laptop and next use some kind of serial monitor for monitoring the values or from the board and in my case i'm just using the arduino ide which have involved serial terminal and uh select the com port and here you can see uh the garbage value because the bart rate is 9 600 i think the 9600 default market is good so instead of changing the baud rate in the terminal uh let's go back into the code and i'll show you how to change the bard rate if you need to change the baud rate in your code so all you need to do is move to the your project configuration file which is ioc file and in under the uart section under the parameter tab uh you can change this number 11500 to simply 9600 so uh that's all you will build your code again and once your code is generated all you need to do is to upload that code into your sm32f4 board just like we did before um i think we need to make one more a little bit changes into our record before we download that code into our microcontroller you will see a problem that over text are pretty much merged into each other so if we download this code into our microcontroller and try to visualize the characters receiving from the c microcontroller you will see that all the values are much so just put a line break into every uh string and change it into your every task uh slash r and slash n will put a line break as well as new line character so these are two characters um that you need to put into every line of text that you are transmitting it will help you to send the new line as well so make sure your board is connected you will receive this error if your board is not connected so plug your board and download the code into your stm32f4 discovery board and once your code is downloaded go back to your serial monitor in my case it is an arduino ide so let's go back to the arduino ide to see if our code is working as we expected so here you can see um my ide [Music] and let's select the serial monitor and yes you are seeing that all three messages coming or right together because the delay is same but the priority is different because uh the task forward having the highest priority which is above normal and has three half normal and that's it for all
Info
Channel: Abdul Rehman 2050
Views: 7,316
Rating: undefined out of 5
Keywords: stm32, stm32 freertos, stm32 freertos uart, freertos stm32, stm32cubeide freertos
Id: kDg5jUKOwYs
Channel Id: undefined
Length: 14min 21sec (861 seconds)
Published: Wed Sep 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.