 Hello and welcome to a new lab for our STM42C0 MOOC. In this lab, we will learn how to create a RTOS, so real-time operating system application, on a STM42C0 using ST development tools and Microsoft Azure RTOS FredX, which is included in our STM42Cube environment. The purpose of this lab is to create a simple project using STM42CubeIE and Azure RTOS FredX. We will be using the STM42C031 nuclear board and we're going to create an application that will read the user button state and work with that to turn on the LED and send the messages on the UART. So we will have different threads running using the RTOS FredX. We will follow the steps below. First, create a new project. Second, select a part number, STM42C0 part number. Then do the STM42CubeMX settings configuration part. Then do the pinout, the pin configurations. And then finally, we will add some code, you know, to add our application code. First, let me give you a little bit of introduction to our STM42Cube software suite, ecosystem or environment. Starting from the left, we have the software tools including the STM42CubeMX, the STM42CubeID, so that's what we have been using in this MOOC so far. And we're also going to use this, so this is our ID for this lab. But we also have the STM42Cube programmer and the STM42Cube monitor. In the center, we have the embedded software where we offer our STM42CubeMCU packages, including the drivers, so the HAL and the low level drivers that we have seen previously in this MOOC. Then we have the middleware and finally some application code examples that we provide. For the STM42C0, the middleware integrates all Microsoft Azure RTOS suite for free. This includes Azure RTOS FedEx, so for real time operating system. Azure RTOS FileX, so this is for file system. And for some part numbers of STM42 that includes Ethernet and USB peripherals, we also include Azure RTOS NetEx and Azure RTOS USBX. Now we can start the lab. So you know these steps very well by now. So first we're going to create a new project under STM42CubeID. We're going to select the STM42C031C6T6, so this is the one that is used on our nuclear board, so the Nucleo C031. Okay, let's create a new project. So make sure all your previous projects are closed and now we can create a new project for this lab. So you know the steps. Now in the STM42 project for the MCU selector, we'll select as before the STM42C031C6T6. So that's the one that is included here in the nuclear board. So we'll select that and click next. Now give a name to your project. So for example I'm calling it STM42C0 underscore RTOS and then click finish. The tool might ask you to change perspective to open the device configuration tool. So if this is the case, then press yes. This will bring us to the STM42CubeMX settings. So this is where graphically you can configure your project. First in the system core we will select the sys, so for system, so sys and you're going to select a different time source than the sys stick. So because we're using RTOS applications, so we will use a timer for the hull, so for the cube library. So select for example the timer 16. So this is the STM42CubeMX part of the project in the pinout configuration tab. Under system core we will select for sys, so for system and then for the time base source we'll select, instead of sys stick we'll select a timer, so timer 16. Secondly, so under connectivity we will enable the user2. So this is in order to get some user messages that will be part of our application. So same thing, on our nuclear bomb. So now, under connectivity, so look for connectivity here, look for user2 and we will enable it in asynchronous mode. Last but not least, we will go into the middleware section and then open middleware, select fredex and then enable core. So next to core there is a checkbox, enable it. Enable the azure auto fredex feature in your project. Scroll down all the way here, middleware so expand it select fredex and click here on core. So this will import all the files necessary for your auto application using fredex. Now we can take care of the pin configuration. So for example we want to use the user button so we configure PC13 that is connected to the user button as a GPIO EXTI-13 so external interrupt mode so like we did in a previous lab. So in the pinard view right there we're going to expand a little bit look for PC13 so it's located here and we're going to configure it as GPIO EXTI-13 so external interrupt line 13. Now we will configure the IO that is connected to the LED as output push-pull so to drive the LED high or low. So the IO on the board is pf5 so connected to the circuit to turn on the LED or turn it off. So we configure it as GPIO output pf5 so we will add some labels to the two IO's we configured so PC13 will label it to user button and pf5 will give a user label as LED to enter a user label you're going to right click on the pin so here enter user label so for PC13 we will enter user button so to be compatible you make sure that you put user underscore button uppercase B4 button and then enter and then now we're going to add another user label for pf5 which is connected to the LED and we'll name it LED uppercase now we can configure the NVIC so the interrupt controller so to do this you can go to NVIC from the system core also from the system view the following window will pop up and display a warning so displaying the following so if interrupts handler call RTOS functions please make sure their preemption priorities are lower so numerically higher than the highest sys call interrupt priority so this is something to keep in mind so in our case we don't have any functions or RTOS functions called so we won't have the problem but you know that's something to remember so press ok ok so the NVIC you can find it here so in the system core or also in the system view so we open it here so this is the pop up message that I was telling you about and press ok in the NVIC enable the EXI line 4 to 15 so this is the interrupt for the EXI line 13 which is remember the user button so PC13 connected as external interrupt that we will use for the user button ok so in the NVIC let's expand it a little bit to see what's going on so we want to enable the EXI line 4 to 15 interrupts so this is for the user button now we can generate the code so remember the little icon like this with a gear or you can also press ok or just save your project so that will ask you to generate the code and then press yes ok we will generate the code so using this little icon there and change perspective yes we will enter the C and C press perspective where we are going to add some code now it's time to code so this is the first view of your project so as you can see so this is your project right here project explorer so you see all the different folders of your projects and in core source you will see that you already have some new files with you know the azure auto support right there and then we will see that in the middle where you also have some additional files and directories you can also notice that in your main.c you already have an include for app underscore fredex.h so this is your project right here so the user files are going to be here so we are going to be modifying or adding code in main.c and also app underscore fredex.c now I want it also to show you in the middleware so where are the fredex files so all of them are right here so this is included in your project first we are going to add some code to redirect the printf to the uart2 so we did that in a previous lab so if you want to do to know a little bit more about the process you can review the MOOC lab about the printf so we give more details about how to redirect the printf to a uart so uart2 in this case and we are going to add the code in the user code 0 section so remember to add the code within this user code begin and end so that it doesn't get deleted when you regenerate the code from the stm5 to kubemax part of the project so we are going to add this code in the main.c in the user code begin 0 section same as before, so for the code to be added you can find it in the description of the video right here and you can just copy and paste or otherwise if you want to type it you can do that also so this is the code here and in my case I will just copy and paste from the description of the video so in main.c scroll down and look for the user code 0 so this is the section we are going to add the code to redirect the printf to the uart2 that we configured previously so this is done now we can open app underscore fredex.c to add the following code so first we are going to add some includes so include stdiu.h and also include main.h ok I am going to save main.c and now I am going to open app underscore fredex.c which is located into core and source so double click on it and first we are going to add the includes so right here in this section right there includes please add the stdiu.h and also main.h now we can add the size so the stack size for the three different freds we are going to use and also for the different queues we are going to use in this example so in the private defined in the user code pd section please add the different stack size and also the queue size so let's keep on coding and adding some code so in this code section here we are going to add some code to create the freds create the queues create the variables and functions prototypes for the code so two parts first in the private variables in the user code pd section please add the following so this will define the stack the queues so the size of the queues that we defined previously and also for the stack size and then we define some pointers for the freds and also for the queues step 2 of this task is to go to the function prototypes and add the three different function prototypes for the three different freds now let's create the threads needed to use the button status to control the led and the messages sent via uart so using printf so scroll down now and we are looking for this section here so which is app underscore fredex underscore init so in the function app underscore fredex underscore init so in this section let's add this code so to create the queues and create the threads so we're going to create two different queues to send messages so for the button status and the led status and three different freds one for the button status the other one for the led action and the third one for led status almost there so now what we're going to do is add some code to create the thread functions to work with the button, led and the uart for the printf so we're going to add that in the user code one section and we're going to add basically the three different threads that we're going to create right here so this is the code for example we're going to start with adding the code for the button status and then we'll move on to the two other tasks or threads so in the user code one section at the end of the file so still in app underscore fredex.c in this section we're going to add the three different functions for the three different threads so let's start by the button status so this is the first function to be added here at this location now we're going to add the second function so led action so still in the user code one section so right after this first function we're going to add the second one right here so this is led action now we're just missing one to be added and last part finally we made it let's add the last function which is led status we can now have a look at the code that we added especially the different threads so different tasks so here let's start with the button status so what do we do in the while loop, so infinite loop we put a delay and then we're going to read basically the user button depending on the status of the user button that we're going to read we're going to set or reset a variable right there and we'll send it send using a Q, so a message Q so txq send we'll send the message to another task so this is the second task here where we're going to receive the message that was sent by the first task depending on the message we're going to turn on the led or turn it off and then at the end of the message using Q1 this time where we send a new message to another task and so this is the last task and depending on the message we're going basically to display the leds on or the leds off alright, so now it's time to test our code so we're going to build it and we're going to run the code it's time for our debug session now let's build the code first we're going to build the code so remember the little icon like that the hammer to build the code or you can do project build all make sure we have no errors and no warnings let's build the code pressing the icon here and we'll wait for the end so it might take more time on your machine so you can pause the video if needed so zero errors zero warnings so that's great, good starts let's continue now we can enter the debug so make sure your board is connected of course and you can do run debug as stm42 c++ application or directly click on this little icon like the green bug so we can now click on this little icon you can see it here so this is to enter the debug session we're going to press ok now we're going to load the code and also change a perspective so that's coming here we switch and now we are ready to execute our code so to execute the code remember resume ok, so at this point we talk about that in a previous lab so I'm going to go fast on this and you might already have a console that is being created that you can select otherwise I will show you again here how to create a new you know like terminal a serial port, you know terminal within stm32 cube ID so those are the steps first you're going to find shell console from here, from this menu then you're going to create a serial port new or select a previous one if you add one but in this case we create a new one ok select the parameters so first you will give the connection name like here we're going to give a name like terminal one select the proper serial port that is associated to dstlink virtual comports so in this case this is com18 in this example and for the parameters we're going to use 115-200 for the board rate, data size 8 parity none and one subit then click finish to complete the creation of the terminal we're going to select the encoding so for example here I'm selecting utf8 but previously I selected iso which also works so there's no issue there and then just press ok ok so let's create this terminal so let's find the icon that we're talking about it's located here in the bottom right here expand it go to command shell console so this is where we can create our connection type so first select serial port so in this case I had a previous one that was created but I will show you how to create a new one so click on new then give a name to your project so we said terminal one and then select the proper comports so if you're not sure which one go to your device manager and make sure you select the proper one so in my case it's com18 and then we keep the rest by default then click finish select we said we tried a new one so utf8 that also works iso also works and then press ok now I can test my code so let's press this user button which is the blue one on your board press it press press press as long as you press it's going to turn the led on you release turn it off release turn it off and you have ofc the led also that changes so the green led connected to pf5 that changes ok so it works perfectly fine so we have a good example about Artos application so ofc of course you know it doesn't enter Il y a des détails sur comment utiliser Fredx, donc il y a plus. Nous avons des autres vidéos de collection sur notre channel STM32, où nous parlons de plus de détails sur comment utiliser les Fredx. Mais ici, je veux juste vous donner une idée de comment vous pouvez créer, facilement, comme une application Arthos sur votre STM42 C0 avec notre outil. Vous pouvez maintenant arrêter l'exécution, donc cliquez sur cet icon là-bas, le red square, et fermez votre projet. Alors cliquez, fermez le projet, et nous sommes prêts. Merci beaucoup d'avoir regardé.