 Let's start by connecting the USB cable to the sd-link USB connector, which is the right one viewed from the top and The second step is starting a kupamex So I will do this hands-on in parallel with you and switch in between the presentation and And the live view. So let me open kupamex And in the next step, we will create a new project We go to board selector and select the nuclear w55 When you create the project a window will pop up asking you if you want to initialize the peripheral in default mode and Click no because this will pre-configure some of the GPIOs according to the nuclear So there will be pre-configured GPIOs for the LEDs and also for the buttons But otherwise the the project will be completely empty and it's up to us to Initialize the peripherals and also the middlewares. So let me start the new project Okay so in the board selector you can type WB55RG and This is this is our target So we start by double-clicking and click no so first thing we can do is to inspect the documentation if you click on help and Docs and resources You will get a quick access to the user manual for the nuclear. So in there you will find also the schematics And in the MCU type you find the datasheet reference manual programming manual and a router sheet and also a list of application notes which are related to WB The first thing we need to do is to enable pull-up for the for the button So you see the part of the schematics of the button button one which is connected to PC PC 4 through a 1k resistor So we need to enable an internal pull-up to have a stable value So let's go Into the system core then GPIO and find the PC PC 4 and Let's enable the internal internal pull-up So right now we want to enable Well in the end we want to enable the Bluetooth middleware, which is right now great out If you hover the cursor on the on the great out of the pan middleware, you will see some contextual help So the cupa mix tries to guide you what to do. It shows you the dependencies So you see that the BLE stack and the BLE middleware can be enabled when we enable RF, RTC, IPCC, HSM, etc, etc so here You can see some sort of in program help and We will do these steps one by one So first in the RCC in the clock configuration We need to enable the external high-speed crystal and also loss external low-speed crystal The HSC 32 megahertz is a mandatory part for WB. It's directly used by the radio to generate the carrier And so is the low-speed clock which is used to time Things like connection interval or advertising interval So let me go to RCC and enable both external crystals So the next thing is hardware semaphores Hardware semaphore is a periphery which is used to synchronize the access by the two cores to shared peripheries Example of a shared periphery is is a sum registers in the clock tree or a random number generator So the HSM and under the system core We need to simply activate the periphery The next thing is the IPC the inter processor Communication controller and I'd like to spend a few words on this one because it's quite unique feature of WB As you know, the architecture is a dual core. There's a cortex M0 Which runs the RF stack and the user application is implemented on a separate Cortex M4 the two cores communicate through a shared part of memory in SRAM 2 and IPCC is a periphery Responsible for messaging mechanisms between the two cores So basically it can generate an interrupt for the receiving core that there is some message in the in the SRAM Or it can also generate an interrupt for the transmitting core that the message has been Received and the memory can be freed or used for something else in the Qpamax I will go to IPCC activate the periphery And also enable the interrupt for the Cortex M4 Next is RTC Real-time clock. In fact, RTC is required only for virtual timers It's a software component delivered by ST Which is built on top of real-time clock internal wake-up timer and it allows you to create up to 255 software timers for which you can use for whatever reason in your application We will not use this particular feature Nevertheless, it is a dependency for the Bluetooth middleware. So we need to enable it so let's go to the Timers tab and in the real-time clock activate the clock source and and internal wake-up timer And we might as well enable the interrupt in case we decide to use it So let's go to the next slide So the last periphery we need to enable is the with the RF so let's go to Qpamax and It's hidden in the connectivity tab RF and Let's activate it Now you've noticed that the vPan middleware is not grayed out anymore Which mean we can We can activate one of the one of the stacks. So let's enable the BLE And there is a set of options available By default, there is enabled the point-to-point server that I already discussed We could use it, but in fact we want to do it from from scratch So we will implement the same behavior, but based on the custom custom template which will allow us a better control of Of the services and also the characteristic. So the first step is to turn off the point-to-point server and enable the custom template and You notice there are more tabs appearing which will give us some more control of what's going on under the hood So next step In the BLE advertising tab we can actually control the content of the advertising packets So by default there is not much We can enable for example the complete name Which is something that we will see on the screen of the of the smartphone So please name it uniquely so that you can recognize your own device and do not connect to your neighbor In my case, I will I will call it I will first enable the complete local name and Define it to be my device 90 97 Next thing we will create our own BLE service. So let's go to the BLE gut tab and Let's enable we want to enable a single single service And Then we need to name it here. The uniqueness is not important. So you can call it whatever you like, I will call it my my svc and I use it both for the long can also the short name And you see there is another tab appearing which is in fact the definition of your service Go to the tab which is named after your service and There you see there is a single characteristic already predefined. We will need to name it and You also notice there is a field called UUID the universal unique identifier So when the when the gut client performs the service and characteristic discovery It's using these identifiers to recognize the service for the proprietor service. This these numbers are are random and They are 128 bits in length. So 16 16 bytes you notice that We are displaying only the The upper two which is the reduced reduced form of UUID the rest is Randomly generated, but if you want you can Select the type of UUID to full and then you can set it to what you can set it to whatever number you you want So let's let's do that in Kupa max So you see there is one characteristic already defined This is the the identifier of the service you can switch to full But we don't need to change this. In fact, it's just for your information Here we have to name our our characteristic I Will call it my correct my heart right Because in fact, I want the phone to be able to write to this characteristic And based on the right event processed by the application, we will toggle an LED So that's why we need to define this characteristic to be writable. So first the name and Then in the properties of this characteristic, we can enable the property right If you scroll to the very bottom, we want to disable all the events Generated by the L. E. Stack when there is some action performed on this particular characteristic And the only event we want to process is the right Whenever the phone writes to the characteristic the BLE stack will generate an event Which we will later process on the application side and In fact This this is it. We need one small change in the clock tree We want to clock the real-time clock from the low-speed external crystal and also The RF wake-up clock. So again, this is the clock used to time connection advertising intervals and and similar So When the in the presentation In the clock configuration tab we select the LSE as a source for the RTC and we use the same clock for the RF system wake-up and When you're done, you can go to the project manager name your project set the tool chain to be cube IDE and and Generate the project so I go to project manager. I will call my project term my Project WB for example and set the tool chain to cube IDE and Let's generate it Okay, so the project has been generated. I can open it in cube IDE. It has been imported successfully and As a quick test, we will build it and run it We did not implement any application behaviors. There will be not much to see but at least we will be able to connect to the target and See the service and see the characteristics So the build is successful. There are no errors just a few warnings that we can ignore for now So let's let's flash it and Here you see my nuclear board. I have The smartphone application STB le2 box Already, so I'll open it and you can you can see all the devices that are advertising around me You can sort by RSSI To have it to have your device on top My device 97 I can connect to it And here you see the BLE address on top the signal strength Minus 56 DB. There are three BLE services the first two They are added by default because every BLE device needs to have them the third one is in fact our proprietary service that we have just defined in the cube Mx and you can notice the UU ID In fact, we have seen the first two bytes of it in the cube Mx And if you click on it, you see a single characteristic, which is writable So in fact, you can write something to it nothing will happen as We didn't process the event yet, but anyway You can see that it's the application the application is directly Compilable and runnable on the target So the next step is to implement the event handler when the phone writes to the characteristic But before we do that, I would like to make a quick overview of the source source tree so you can see in the cube IDE that there is a folder core which includes the initialization of The of the microcontroller and also of the cm0 plus there are interrupt service routine main.c and similar kind of things then we have drivers for the cmsys and hl in Middleware folder you see the vpan which includes the BLE middleware and Then there is a folder stm32 underscore vpan which implements The BLE related application So we will modify for sure some of these file later on in the last folder the utilities you see the Low power manager. We will not touch that and Also a sequencer Which we will see a little bit later Just to remind you a sequencer. It's a very simple non preemptive scheduler That is integrated in most WB examples Basically, it's a while loop that schedules multiple tasks in a non preemptive manner Let's go to make some changes in the code The first one will be very simple. We need to locate the file custom underscore stm.c And in there you will find the event handler for the right transaction We first need to include the main.h to have the visibility of the macros that define the LED and Then online 148 we will toggle an LED on any right event. So notice that we are actually not parsing the value We are simply acting on the fact that the right transaction happened In fact, if you want to parse the value you can scroll down to the very bottom of the presentation And you will see a few lines of code to do this But we will keep this keep it simple we will simply Toggle an LED just based on on the right itself So let's go to st underscore vpan and then app and Then custom underscore stm.c First, let's include the header file Make sure that all the code you write is inside this user code sections. Otherwise next time you regenerate the kupa mix The code will disappear if it's in the user section the code will stay Let's include main.h and Online 148 You see this is the function that's responsible for handling the events and Here in this case we will toggle the LED You can use control tab for contextual help. So we want to toggle the GPIO and The green LED is called LD2 So the first argument is the port the second argument is Is the GPIO pen and that's it you can compile and Flash it so right now if I Again connect to my target Go to my service and my characteristic and write anything I think because the value is not Relevant in this application the green LED Will turn on and As you see it did If I write again It will switch off In fact, this is the end of the first part of this hands-on