 Hands-on, simple BLE application generated from Qpamax. The purpose of this hands-on is to create a simple BLE application for STM32WBNucleo and we will use this application for further tests of security-related functions. We are going to create the project from scratch in Qpamax version 6.2.1 or later and we will compile the code in Qpide version 1.6.0 or later. You may need also the QProgrammer and to connect to the target application we will use a phone either Android or iOS with STBLE Toolbox app which is available on App Store and Google Store. To connect to the target we will need one micro USB cable. Make sure that your Nucleo is the latest revision that the microcontroller should be revision cut to 2.1. To check this you may open a QProgrammer and read location in the flash at the specified address and what you should see there is the Debug MCU ID code which has two fields revision ID and def ID and what you should see in the ref ID field is value 2001 in hex. Also make sure your Nucleo is flashed with the latest FUS and latest BLE stack. The installation procedure is described in the release note in the path specified on the slide. And last but not least we will use terminal app for example TerraTerm to observe the application traces. If you want to skip this part you can. The finished project is uploaded at GitHub. You may just forward to the end of this video where I will describe how to operate this app. On the STM32WB side we will implement a gut server. The second side of the connection will be the Android or iOS phone with the STBLE toolbox and it will act as a gut client. The gut server implements a custom BLE service with a single characteristic with a read property so it can be read by the gut client. The application outputs some useful traces on UART1 which is connected to the onboard ST link. An ST link is a composite device. It works as a debugger but also as a virtual comport so we may use a single USB cable to connect to the target application. All the steps that I will do in KUPA Max and later in KUPA IDE are described on this and the next slide. And you will also have access to PDF where this is all stated. I will do this live and provide some commentary as I go. So we will start by creating a new project from KUPA Max based on NUCLEO WB55RG. This allows us to see the actual connection as it is rooted on the board. So for example the connections to LEDs, buttons and also the UART connection to ST link. So when the window pop up asking us whether we want to initialize our peripherals in a default mode click yes. So the project will be pre-configured based on the actual schematics. So in the board selector tab let's search for WBNUCLEO. And by double clicking we can start the project and yes we want to initialize in the default mode. So as you see the project is partially configured with the LEDs, with the oscillators and with the debug pins. So let's just double check in the system core we must make sure that both HSE and LSE are enabled. This is correct. The hardware semaphore we must activate. And you see that the interrupts are automatically enabled. The next step is the IPCC which is the periphery responsible for communication between the two cores. We must activate it and enable the interrupts. You may also skip ahead. What we want to do in the final step is to enable the VPAN middleware. This is the middleware for the Bluetooth and possibly other RF stacks. And if you hover the mouse over this option you will see all the requirements. This is what we are doing right now. We are at the step of enabling the HSM and IPCC. The next step is enabling the RTC. So this will be in the timers RTC. And let's activate the clock and enable the internal wakeup timer. We also need to enable the interrupt for the wakeup timer. At this point we can go into the connectivity tab and enable the RF. So for the traces we need to enable and configure the wired one. So the board rate shall be 115,200 bits per second. That's okay. Let's make the word length 8 bits and no parity. To offload the CPU when outputting the traces we should also configure both DMA streams. One for the RX and the second one for the TX. And as a last step make sure that the UART global interrupt is enabled. Let's make this window larger. So at this point we can go to the Bluetooth middleware and enable it. So you see three tabs. Here on the first tab you see the most general configuration by default. The point-to-point server service is enabled. What we want is a custom service. So you see there are two more tabs that will allow us later on to configure the gut service, the gut characteristics and also the content of the advertising packets. But let's now focus on the application traces. To enable it let's go to the configuration tab. And here you see that we can enable it in the configuration hardware UART enabled. And you see this red message. Make sure that the project manager advanced settings, this function is not generated. So it should not be ticked and the visibility should be unticked. So if I go to project manager and go to this function we shall tick the do not generate and untick the visibility. This is because the initialization function is already implemented in one of the middleware and that's why it should not be generated by the MX. The DMATX supported. As you see it's enabled by default because we already set up the correct DMAT channels. So let's now go to the debug traces UART and let's select UART UART 1. And as a last step let's enable the application traces. This is all for the traces. So we can focus on the configuration of our advertisement data and our service. So let's go to the BLE advertising tab. And as you can see there are no fields currently in the advertising packet. And we shall enable at least one. And I suggest we enable the complete local name. And you may call, you may name your device as you wish. We will see that on the phone when the device is advertising. So I will call mine my BLE device. Let's go to the gut configuration tab. And let's create single service. We need to name it. So let's call it my custom service. And you may copy the long name and make it also the short name. You see there is another tab which relates to the service we have just created. So let's go in. You see there is one characteristic already predefined. We shall name it. Again you can name it as you wish. I will call it my my her. But you may also give it some more descriptive name for example temperature. The characteristic has certain properties. We want to read it from the phone. So by the gut client. So we shall enable the read property. And let's disable the default one, the broadcast. We should also disable the gut events related to this characteristic as we do not want to process it on the application side. So we disable the generation of these events. We are almost at the end. The last thing to check is the clock configuration tree. You see that both cores are running at 32 MHz which is fine. Remember there is a requirement for the BLE stack that the CM0 plus must run at 32 MHz exactly. Let's change the clock for the RTC. Let's make it the low speed external crystal. And let's also change the RF wake up clock again to LSE. Now we need to name the project. I will call mine BLE template. And as IDE I want to select stm32 cube IDE and I click generate. And now I will open the project. Now that we have the project open we have to make two small changes because of a bug in the generated code in current version of KUPA mix. Hopefully this will be fixed in the next version. So let's go to the main.c And on the line 25 let's include the header file for the sequencer. stm32 underscore sec.h And on line 121 inside the while one loop of the main function let's add the call to run the sequencer. So this is a util sequence run with the macro util default. So this will make sure the sequencer is run inside while loop. The next change relates to the application traces. So to make them work we need to make small change in the up entry file. And on line 84 let's add the call to appd init function. Always make sure that the code you add is inside the user section because this code will not be deleted when you regenerate the MX project. This was the case in the main.c and it's also the case here in the up entry.c. So this is all for the fixes. We should be able to compile the code without errors. And if this is the case we will load the binary into the target and make the first test. So I see no errors and two warnings which we will ignore for now. Now I will load the project. And on my Android phone I will open the STBLE toolbox application. And in parallel I open the traces. The connection parameters for this serial comport are the board rate is 115200. The data length is 8 bits and there is no parity. And we see the device is successfully advertising. So if I go to the STBLE toolbox and I sort by RSSI I will see the device on top as I'm very close to it. I can connect to it. And you see in the traces that the connection event have been received by the user application and the traces have been outputted over the UART. Here on the right side here is my custom BLE service with a single characteristic that can be read. And as you see it's read successfully and its value is zero. So this is the end of the hands-on. In the next one we will add some security related functionality.