 Let's continue with the next part and it will be a first hands-on STM32WL-LORA-PHY point-to-point application. What is the key learning of this part? So we'll touch a real RF application. I will just let you play a bit with real radio link. I will provide you details regarding the implementation of the proprietary protocol on the top of the LORA modulation because we'll use only physical layer of LORA 1 specification, which is a radio link based on LORA modulation. Then I will show you the sequencer, which is kind of the low power framework for the WL application. I will also show you how to limit the overdue traffic using channel sensing algorithm. What is the target of our hands-on? We will build the multi-point to point network. In fact, this is the use case for the face-to-face training when trainer stands in front of the attendees in one room. So as it is remote training, we will implement the subset of this star network, the point-to-point application. Our point-to-point link consists of the node, which acts as a remote sensor and base station. Node periodically sends, if RF channel is free, the following real data. Node ID, it is one byte, then temperature, it is the temperature measured by internal junction temperature sensor, I mean internal WL junction temperature sensor. Then frame send counter and frame acknowledge counter. Those counters let you to indicate in quite easy way the quality of the link. All the debug output, the debug trace is redirected to virtual comport using UART and virtual comport is implemented on the top of the onboard ST-Link debugger. We will use 115 kilobits per second VOD rate for the UART connection and it is also possible to use alternative format of the payload. Instead of the data like temperature and frame counters, you can use user-defined text. On the base station side, the data are received and printed out using virtual comport and then after reception of the frame, the following action is to send to the sensor node the acknowledge frame. The acknowledge frame consists of three bytes, the ASCII characters A, C, K. And the TX event on the sensor board is followed by the blue LED blink. That's why I put this arrow in blue. And the reception of the acknowledge on the sensor board is followed by a green LED blink. So let's start our practice. First point is to prepare the base station. So for that we need to connect one NUCLEO WL board to our PC. So please do it. And we need to flash our board with relevant binary. So for that we will use one of the features of the onboard ST-Link debugger which is flash disk drive profile. So the only action to perform is to copy and paste the file from one location to another location. So please open the file explorer and put the first instance of the file explorer on the left side of the screen. Then go to the workshop repository, STM32 WLWS. And then enter the hands-on folder and then attend the resources. The file to be flashed on the base station board it is the SAP Gigahertz PHY base station bin here. But before we need to open the second instance of the file explorer let's put it on the right side of the screen. So the left instance of the file explorer it is our source. The right instance of the file explorer it is our destination. And let's navigate to the WL disk drive. On my PC it is disk drive D. And the label is NOD underscore WL55JC. And now the flashing of the board is really simple. So again we need to highlight the SAP Gigahertz PHY base station bin. Copy this file to the scratch part and then paste in WL disk drive. Okay that's all so we can close or minimize the file explorer. And the next action is to check if our base station is working. So for that please use terminal in example the TerraTerm terminal. So I will open TerraTerm terminal and then I need to connect the WL board. So file, new connection, serial and then I need to find the comport with label ST microelectronics as the link virtual comport. So I'm selecting this comport. And then because the bold rate of the UART is 115 I need to configure the serial port accordingly. So 115 kilobits per second. And then I can press reset which is located just under the USB connector of the STing on the WL nuclear board. Okay I can see that base station is working. So that's all regarding base station. Now please disconnect the USB cable of the base station nuclear WL board. But please keep the terminal open. Just minimize the the instance of the terminal. The target configuration is to use two instances of the terminal. One for the base station and the another for the sensor board. What are the parameters of the RF link we will use? We will practice. Those parameters are listed within the sub gigahertz PHY APP.H header file. I will provide you more details regarding the project structure later on. We will use the RF frequency which is covered by ISM band, Industrial Scientific Medical and it is sub gigahertz band and it is 868 megahertz here. Then I decided to use quite low TX output power, 10 mW just in order to reduce the transmitted RF power. So it is just a good practice to limit the TX power. Then Laura bandwidth is selected as 0, what means 125 kHz. And this bandwidth is in line with the Laura van specification. I selected this particular bandwidth because the link we are building is quite practical solution for the new Laura van users in order to test the performance of Laura modulation. I mean mainly in order to test the range of the communication. And that's why I selected Laura van bandwidth just to reflect the real condition of the target configuration. Then Laura spreading factor, I selected the lowest spreading factor, what means the lowest time on air in order to limit the over the air traffic. If you would like to test the maximum range of the communication, the performance of the Laura modulation RF link, I would suggest to increase this spreading factor to the maximum one supported by Laura van specification and it is 12. But please remember that selecting higher spreading factor, this means that you will increase the time on air and you will decrease the moderate. Then we have four parameters related to the channel sensing algorithm. For the channel sensing algorithm we are sensing the channel and if a radio channel is free we can transmit data. If the channel is occupied we need to wait round on time and then sense channel again in order to send data. So we cannot sense the channel continuously. We need to define the particular number of trials and in our case it is 5. Then we must define what does it mean that the channel is free. It is the received signal strength indicator threshold and I decide to put here minus 80 dBm. It means that if the integrated noise within the channel will be lower than minus 80 dBm the channel is free. We need to integrate the noise over the channel for some time. It is not momentary value. So there is a need to define the integration period. I selected 10 ms. And then as I mentioned between the trials there is a round on time and for this round on time we need to define kind of atomic channel sensing back off time unit and it is 20 ms. The sequencer. It is important point. The sequencer will be also used for the main hands-on of our workshop. I mean the Loravan hands-on. And as I mentioned in the beginning the sequencer is a kind of low power framework for the application which somehow unloads the application developer from this task. How does it work? After reset after start the first action to be done is to register the task. And task it is just a particular C function. So for example it can be function which covers all the application layer of the WL application. After registration of the task the sequencer starts and the call of the sequencer is placed within the main loop. So it is main loop. And for the low power application the most often state it is just an idle task. So if the sequencer has nothing to do it enters idle task. It is up to the user to define the behavior the action within the idle task. The most obvious implementation of the idle task is just to enter low power mode. How to execute user related action? The sequencer implements the event driven approach of the application control. So the sequencer waits for the event. The event can be asynchronous like event coming from the radio from the transceiver for example interrupt followed by reception of the data interrupt followed by end of transmission etc. The event can be also regular, periodic like expiration of the timer. So when the event appears from technical point of view it is just an external interrupt and following callback within this callback we need to increase the priority of the task which is so called set the task and this triggers the sequencer to execute this task only once. After execution the task is reset and then sequencer again enters idle task. Here you can see the sequencer API in practice for example how to register a task. This is the C function name covering the application process in our KCD sensor process and this is the kind of alias or label just a name of the task. Then here you can see how to run the sequencer. So this function, utility sequencer run must be called within the main loop of the application. Here you can see the example of the callback in particular it is on takes done callback which is triggered following the end of transmission event, over the transmission event. So within this callback we need to modify the internal state machine and we need to increase the priority of the task. And for the sequencer implementation the lower number means the higher priority so the priority 0 is the highest priority. This is the implementation of the idle task and as you can see the implementation is very simple because within the body of the function we are calling only one function and it is and we just entering low power mode. What about our application flow? This is quite simple application so there is an internal timer which periodically triggers the data transmission over the year. So it is regular periodic event which triggers the sequencer. So after timer expiration the internal finished state machine is changed to TX start what triggers the TX process and the application sends data over the air only if the channel is free so TX under channel sensing. And as you remember from the architectural part we have independent systems so the radio the transceiver is independent from the call. So if the transceiver is just started to TX the data the MCU can go sleep immediately and this way save the energy. After the end of the transmission the on TX down callback is triggered it is just an interrupt from the sucky the hertz transceiver and internal finished state machine change the state to Rx start waiting for the acknowledge from the base station. So again the MCU can go sleep immediately and the only active part of the WL it is the sucky the hertz transceiver in Rx state. After reception of the data after reception of the acknowledge from the base station so here is a callback relevant callback the RX down state is set and both RF part and MCU part can go sleep there are some errors application errors to be serviced for example the callback on Rx timeout on Rx error on Tx timeout and following those callbacks the relevant machine states are set and as an action companion action RF part goes sleep and the same for the MCU how the channel sensing mechanism works after start we need to integrate the received signal stretch indicator value so we need to integrate over the time of course then if RSSI is lower than the threshold as you remember the threshold is set to minus 80 dBms it means that the channel is free and we can transmit data if not and if there are still trials to be used to be utilized we are waiting back of time and this time is random and then integrate RSSI sending data or trying one more time. If there are all the trials are utilized we are just stop the algorithm and there is no Tx as channel is occupied ok so let's play with the sensor board now so please connect the second WL nuclear board this one acting as a sensor as you remember at this stage we need only one board connected to the PC and then please start the cube IDE environment ok it is opened now we need to open the project so file, open project from file system and let's point the target folder then workshop repository STM32 WLWS hands-on folder point-to-point PHY folder projects nuclear WL55 applications sub gigahertz PHY and now please be careful and do not mix point-to-point base station with point-to-point sensor the base station we have used the binary but as a homework you can analyze the source code of point-to-point base station application now we need to open the point-to-point sensor so please enter this folder and highlight STM32 cube IDE so now we can analyze the structure of the project the name sub gigahertz PHY ping pong has been taken from the cube WL application examples there is an application for the physical layer so called ping pong and I decide to simplify this application and add some real data like temperature to the payload so it is just a migrated application from ping pong ok we have folder like application and within this folder we have sub folders application file is located within app folder and it is sub gigahertz PHY app.c so please open this file by double clicking within the core sub folder you can see all the files which are related to the peripherals like ADC, DMA, RTC and main.c within drivers you can see the CMC's ARM drivers and you can see the HAL driver for the peripherals and sub gigahertz PHY you can see the drivers for the radio transceiver physical layer. Those drivers are split into two parts I will provide you more details during the next Loravan head zone and within utilities you can see the files like implementing for example TRAILS which implements the low power manager this is sequencer, this is the implementation of software timers, so just set of utilities but let's come back to our file so this is application file and you can see here for example the definition of frame counters, the receive signal strength indicator, the signal to noise ratio variables here you can see a set of software timers like timers which controls the LED this is our main timer, timer TX which triggers the regular TX process here you can see the variable which controls the channel occupation is channel 3 then you can see some callbacks related to the software timers to the events from radio like on TXDAN or RxDAN then you can see the function which implements the initialization of the application sensor init, so some creation of the timers initialization of the radio parts here you can see the initialization of radio callbacks of radio parameters, we are using cloramodulation and as you can see here the configuration is splitted for the TX path and Rx path, here you can see the registration of the task, the main task and in our case the only one task, the sensor process and the main application function is here, sensor process so as you can see here just filling up the buffer with the payload to be sent node ID, so the address of the node 1 byte, then temperature value also as a 1 byte, battery level we have USB power supply, so the battery level will be stable, but if you would use battery to power the board, you can see the battery level here, then the next values are frame counters it is also possible to by changing the prep processor to use the user defined text instead of the real data, up to you, I will keep the real data to be sent, then you can see the channel sensing algorithm, so we need to sense the channel up to the maximum number of trials if channel is free, we can set the selected radio frequency, then wait to stabilize for the tcxon oscillator and sense data then there is implementation of another finite state machine here start of the reception etc ok, let's modify something with this application, so please open the companion header file, this is subgluehertzphyapp.c and the companion header file is here subgluehertzphyapp.h, please put cursor here and press F3 so we just open the header file you can see some definitions like RF frequency like output power, the details of the modulations, spreading factor the timeouts both for Rx and Tx the periods for the LED blinking, then the parametrization of the channel sensing algorithm and here you can see the note ID modify the note ID, by default it is 1, let's change it to a different number let's put here 2 ok, then save the source code and build by taking a hammer ok, let's just build so we can start the back session by pressing the back button here ok, I need to select the project to be for the debug and for the debugger stage the only point to perform is to flash the board with the binary, so we need to wait for the download verified successfully message within the console and we can close the debug session by pressing terminate right button, then let's start the terminal session, so we need to open another terminal session because we have already opened the terminal session for the base station, so I will start the second instance of the Terra Term and put this Terra Term instance on the left side of the screen, then I need to connect, file new connection, search for the sd-microelectronics label, ok, and set so set up serial board the board rate 115 kbps and press reset ok, so the sensor note, the sensor board just started as you can see ID is 0,2 following our change and now let's finish our job by switching on the base station so please connect the base station usb cable to the pc and place the terminal of the base station on the right side this is our source, the sensor note and this is our destination base station and as you can see the communication takes place, we are sending temperature 20 degrees and here you can see 20 degrees as well, the channel sensing the channel noise is about minus 100 dBm so I would say quite clean quite quiet channel and the only point to consider is that the frame send counter 9 is not equal to the frame acknowledged counter, why? because the sensor board has been active while the base station has been disconnected so I will press reset on the Nucleo WL sensor board and now you can see the frame counters are equal and the ratio of difference between frame send counter and frame acknowledged counter can be used as a very basic very simple indicator of the link quality obviously the link is perfect then the counters are equal and in our case in my case I have both boards on the same table so the link is perfect ok, the link is working then let's come back to the slides, I already provided the explanation of the project for the structure then we made the modification of the node ID then I also provide you the explanation of the main application process the sensor process, here you can see also the examples of the callbacks, the callback of the main application timer, timer TX and within the callback of this timer we need to change the state of the finite state machine to the TX start because we want to start the RF transmission then because of the timer is one shot we need to restart the timer TX timer then we want to blink blue LED for a moment that's why we need to start the relevant timer for the blue LED and the main action of this callback is to set the task to the highest priority, what triggers the execution of the task by sequencer but only once, please remember about that here you can see on RX down callback, so the reception of the data as you remember the sensor receives the acknowledge from the base station 3 bytes ACK so we need to copy the payload to the buffer we need to assign the receive signal strange indicator and signal to noise ratio change the state of finite state machine to the RX down and again execute once the sensor process task here you can see the steps we have just performed building the source code, debugging but only in order to flash the application configuration of the terminal and the terminal log the trace on the sensor node and it is good practice to place the sensor node terminal on one side and base station on the opposite side of the screen thank you for your attention