 Let's have a closer look at binary semaphores implemented within 3R2s using CMC's OS V2. Let's do some practice. We will prepare an example where task 2 is waiting for semaphore being on blocked state for maximum 4 seconds and task 1 is releasing the semaphore within its time slot, each 2 seconds. In next part of this example we will add an external interrupt which could release the semaphore in asynchronous mode on each button press. Let's start from stm32cubemix or stm32cube IDE operations. We can reuse any of existing examples. Within 3R2s configuration please go to tasks and queues tab. By click on add button please add 2 tasks. Task 1 with entry function start task 1 and task 2 with entry function start task 2. Set the same priority for both of them to OS priority normal and set the same stack size to 256. We will need an external interrupt in our example. So we need to configure PC13 as GPIO XT13 within pinout configuration, assuming that our blue button on Nucleo board is connected to PC13 pin. We can specify the label on this pin but it is not necessary. Then within nvc configuration we need to enable XT line 15-10 interrupts and select it within column uses 3R2s functions. In this case we would be able to release semaphore from external interrupt callback. Let's come back to our 3R2s configuration. Please select time as a semaphores tab, click on add within binary semaphores section and create a new semaphore. This name can be MyBinarySem01. The rest we can keep in default state. Then press OK button. Now you should see this new semaphore within binary semaphores list. After this operations please generate the project and open main.c file. Main.c file we can notice new handlers within the private variables so there are two handlers for the tasks, task1, handle and task2 handle and as well there is a handler to our binary semaphore. Then within main.c function after hardware initialization we can see the semaphore creation process. So at the beginning there is a set of attributes in this case only the name and then in the second line using os semaphore new there is a creation of a new binary semaphore. Next code modification we will do within start task1 function. We will start with os delay function to send our task1 to blocked state for 2 seconds. Then after its return to run state we will send one over swo using task underscore action function. After this we will release the semaphore. Next step is implementation of task2 entry function. When start task2 function we will wait for semaphore for maximum 4 seconds using os semaphore acquire function. After this task2 will be sent to blocked state till semaphore will be given or 4 seconds timeout will elapse. After this being in run mode again task2 will send 2 over swo interface using task underscore action function. Please notice that this task action would be executed either in the situation the semaphore has been given to our task or the timeout will elapse. So in such a case it is always better to check the return value of this os semaphore acquire function and check whether the value is positive or negative. Please remember that the positive value in our case is 0 means that the function has been executed successfully while any negative value means that there was an error in code execution and one of those errors is os error timeout which means that the semaphore has not been given within the maximum timeout specified in the function. Let's release our semaphore from external interrupt callback. Within HAL GPIO XT callback please send an exclamation mark over swo interface using task underscore action function. Then please release semaphore. Each press on the blue button will repeat those actions. After this please compile the code, start a debug session, open switm console and start an application. Here is our expected result. Let's focus on a selected area. What is happening there? 2 means that there was a binary semaphore so task2 was unblocked. Then IRQ was triggered releasing semaphore once again so task2 can take it from next time. Task2 was blocked as semaphore is binary and cannot be given more times. After task2 took semaphore it could be given once again by task1 and then taken again by task2. Thank you for watching this video.