 Hello! Within this part we'll focus on Event Flux. We'll start from stm32-cubemix and our cubic IDE. This is my case. I'll create a new project with an existing workspace, so File New and the stm32 project. I'm using Nucleo L476RG board and this is why I'm selecting the micro L476RG and the name of the project would be 7 underscore event underscore flux. I press finished. You can reuse any of previous exercises because in these exercises we would need only three tasks with equal priority and one interrupt. In our cases we are using the Nucleo board. It will be blue button connected to PIN PC-13. There is no configuration of N3RG as a part of the tasks, so all components related to Event Flux we need to specify manually within the coding part. So starting our exercise I would first declare PC-13 as external interrupt. Okay we can we can specify its label as well. So this blue button. Please remember that the labels are defined within main.h file later on after we generate the project. What is important is to select the debug interface so within the system and core and this group I'm selecting as a debug trace asynchronous SW to have this serial single-wire viewer or serial wire output PIN and I'm changing the time-based source from default SysTick to Timer 6. This time-based source is used by the library to define all the timeouts and delays and it should not be the same like let's say the timer used by the operating system which is the SysTick in this case. Okay so from hardware point of view at this moment that's all. Let's continue with 3R2S so I go to middle-wares. 3R2S I select interface CMC's V2 and then from the configuration I go directly to tasks and queues and I will change the default task into the task 1. So I double-click on its name and within this window I just rename it to task 1 priority normal I would keep it. I would change the stack size for this to 256 words and then the entry function to be start task 1 and that's it. Then I would add two more tasks. Task 2 would be used within the first part of the exercise task 3 would be used a bit later on. Okay so task 2 the same priority level so normal 256 start task 2 as an entry function that's it and task 3 the same priority so normal 256 words and start task 3 as an entry function and what would be the role of those of those three components you can see it on the slides but let me repeat so task 1 we'll wait for an external interrupt in our case this is our blue button connected to PC 13 and it will wake up for task 2 action in order to let's say perform further actions so in order to perform an action within task 1 we need to do something within task 2 and press a button. It will in fact give to let's say event event flux which would unblock our task 1. Task 2 will set 1 within event group which we will use here or let's say event flux and the next part of this event group or event flux would be given by our interrupt which is used within blue button. Task 3 we will use later on just to demonstrate that some combination of the flux can be reused by more than one tasks at the moment. Okay so we've got three tasks let's continue with the configuration of the 3-year task because as we can see hip size is let's say too small the declared one so within config parameters I need to change it to 4,000 bytes and the second point just to verify library max syscall interrupt priority set to 5. I will come back to NVic configuration so interrupt configuration and I would first enable the interrupt from our blue button and then I need to specify its priority to the level which is in the range from this max syscall to the lowest possible priority level so from 5 to 15. This is due to the fact that this interrupt will be used to execute operating system functions and to protect the complete system it is strongly recommended that all of the interrupts which are using operating system functions should be they should have the priority within those boundaries so from max syscall to a minimum possible priority so between 5 and 15 in our case. Okay this is all for this part so I will generate the code clicking for example this icon and we should have our main.cfile opened if not we can open it from core and SRC this is this one I would like to mention one thing which is quite important even if we have not put any configuration concerning event flags those are automatically added to our middleware library and all of the functions were right now use are stored within this file event underscore group dot c and it's header file event underscore groups dot hfile of course we'll use cmcs OS version too so the porting functions are within this folder and are stored within cmcs underscore OS 2 dot cfile. Okay let's continue with code processing then so I just opened main.cfile it is located within core SRC and main.c so as I told you there is no configuration of event flags or event groups event cube ID or cube mix so we need to declare everything manually so we'll start with private variables of this object and as usual we will start with some handler so this component is called event flags so the beginning of the type def would be the same then there is ID underscore t and I would name the variable of this type event groups event group 1. Okay so this is declaration of the handler then we need to create it and the good place for this is for example this one so event group 1 is equal to OS event flags as it is let's say name within cmcs OS and I would not use any arguments so I just put null and that's it so our event flags object is created its name is event group 1. Okay before we continue I would just add one function which is our interface between our OS and the console it is using ITM interface to let's say to send the data from the tasks and interrupts into the console so this function is task action accepting one argument and it can be of course implemented in a different way using for example uward I would locate it when this part to be sure that it will be it will be not removed and during create generation of the project as I'm using ITM interface I would start from ITM then send control space there's no proposal so send char there is a functions like function like this then I need to pass one argument and then in the second line I would just send a sign of new line okay so this is our task action then we need to say fill our task tasks functions body so as I as I told you at the beginning task 1 would be the task which would wait for some specific combination of the event flux it will be 51 hexadecimal and part of those flux would be set by task 2 and part of those would be set within the external interrupt callback so we'll start from this function waiting for the flux so OS event flag control space weight this group is event group and the flux flux is 51 hexadecimal and the options concerning options I would come back to the declaration of the function and I need a definition so I would go to middleware's third party's freer task source and CMC so as V2 and this file CMC so as 2.c file and within this function I need this field this flux this flux means that we will wait for all of the flux specified within this white function so this is something which we are interested in we don't we don't want to have either 1 or 50 for example but 51 hexadecimal time out would specify as OS wait forever and then after this will give sign of life and that's it as we are waiting for the flux there is no need to put this task additional in the blocked state please remember that this OS flux weight function is sending this task to the blocked state till all of the let's say flux specified here would be set within this object event group one okay so now let's continue with task 2 within task 2 will set part of the flux so OS event flux control space set and again it will be event group one and the flux in this case it will be on the one the rest one would be set from the interrupt routine then we are giving sign of life so task action 2 and we are sending this task for three seconds for example to the block state we are not modifying task 3 at the moment we will do it in next step of our exercise so at the moment we are setting part of the flux within task 2 and we need to add the remaining part so 50 hexadecimal because those flux would be odd with an interrupt routine so we will switch to STM32L4XX underscore IT.c file which contains the interrupt routines active ones and I would need to find this external interrupt handler for external interrupts from line 10 to 15 I will go to this declaration I can see that my flux are cleared so I don't need to take care of them and then after this there is a callback call this callback is defined a bit below as a week so I can just copy paste it and reuse it in a my code so it will be called within this external interrupt routine so I will use again this user code for section for this and within this I would set just copy paste will just set the remaining part of the event crew event flux so it will be 50 hexadecimal and my sign of life would be exclamation mark okay let's build it and let's check whether everything is working I can see no errors no warnings so now it is a time to start the back session my port is already connected so I'm clicking on this back icon then on the debugger tab I need to enable this serial wire viewer which is used to send the data over ITM interface I need to change the core clock to 4 megahertz which is the case in let's say our exercises because this swv is clocked with the system clock then apply and okay okay next we need to configure and start let's say the ITM data console I've got already this tab but in case you do not have it please go to the quick access over here press swv and select this line with the monitor icon after this we need to configure it so we've got this icon we need to set this zero channel which is this swo line pb3 and we need to start tracing after this I can start the complete application I can see that once per three seconds I would see some activity on task 2 now I would try to enter task 2 is sending one within the event flux so task 1 cannot be unblocked because it is waiting for 51 hexadecimal so I will try to add this missing 50 because the event group or event flux is orring together the things which are setting something to the selected event group or event flag so if I press the button I can see that there is a sign of life from the interrupt this is this exclamation mark and I can see immediately task 1 which is woken up if I would press again the button I can see the same action if I would press more frequently I can see a lot of interrupts but still only one let's say execution of this task 1 this is due to the fact that there is no accumulation of the flux so even I tried to set this event flux many times if it will be not taken so absorbed by let's say the task 1 which is waiting for it it cannot be accumulated anywhere so it is not like for example counting semaphores so as you can see it is quite nicely working in the next step I will check whether it is possible to wake up or activate more than one tasks on the same event flux object so thank you for watching this video and let's continue with more extended exercise okay let's continue with our let's say experiment on event flux so I stop debug session and within our main.c file I would add some code within task 3 entry function so what I would just do I will copy paste the code from task 1 but I would change these to 3 so we will have at the moment two tasks task 1 and task 3 waiting for the combination of let's say two different let's say event event flux so in total is 51 and those event flux are set from task 1 and from interrupt so let's now compile the code and start a debug session okay there is no additional configuration because we already did it I would just show this data console configuration should be already done I start tracing and start an application so again once per three seconds I can see let's say the activity of task 2 if I press the button I can see that there is exclamation mark coming from the interrupt routine and then I can see the activation of both tasks task 1 and task 3 and the second interrupt and again activation of both tasks so as you can see using the let's say the combination of task flux we can unblock more than one event which is not the case when we are using for example semaphores so it can be better mechanism to synchronize to unblock multiple tasks on multiple events so this is very very effective communication channel which can be used in more extended operating system based applications okay that's all for this part thank you for watching this video