 Hello and welcome to the STM32L4 MOOC online training. My name is André Barata and this is the dedicated session for the microcontroller core. The aim of this hands-on is not to go deep into the architecture of the core.xm, but to see core from the application point of view. We propose in this session to evaluate the influence of the ART Accelerator in the overall speed or execution of the program. ART Accelerator is ST's naming for its cache memory protocol. In this hands-on we will preform two independent runs of the same program, one with the ART Accelerator on and the other with this feature off. The algorithm we plan to implement is a simple prime number calculator, nothing too complex as the main goal is just to see the improvements of such feature has on the execution time of the program. We will now open STM32QBMX to configure our peripherals and generate our code. As a first step we click on New Project. On the new open window we will type our part number STM32L476VG and we will double click on the desired part. In this project we will just initialize two LEDs to signalize the different states of the program. The red LED connected to the PB2 pin will be used to indicate that the microcontroller is performing the counting of the prime numbers. The green LED connected to the PE8 pin will be used to indicate that the microcontroller just finished counting the prime numbers. Now we will go to the clock configuration tab and we will modify the speed to 80MHz. On the configuration tab we will leave everything as default. As everything is set we can save our project and generate the code using systemworkbench for STM32 as our IDE. After the code is generated by STM32QBMX and our project is loaded in systemworkbench for STM32 we will open our main.c file stored inside the source folder. In main.c file you can see the initialization of all peripherals defined in STM32QBMX. We will start by initializing the prototype of a function who will put the code to test. In this case the function will check if the number is a prime number or not. The function will be initialized as unsigned int8 type and called isPrimeNumber. It will expect a 32-bit long input number and the return value will be a true or false. So it will logically return zero if it's not a prime number or one if it's a prime number. Let's now implement the prime number checking function on the user code begin for section. So the isPrimeNumber function will be like. If the number is less than 2 we can return the zero or false value. For higher values we will create a for loop to check each value individually. A prime number can be divided evenly only by one or itself. It must be a whole number greater than one. We will now type the algorithm and I would suggest you to copy the exact same implementation. Now on the private variables section we need to initialize variables that will be unsigned 32-bit long. We will need two variables for the timestamps. One for the start of the computation and one for the end. Based on these two variables we will be able to calculate the computation duration. We will also initialize a prime number total counter. So through the timestamps created we will be able to know how much time it took to verify the exact amount of prime numbers there were on a given range. This value will be stored on the counter variable. Let's move now to the user code begin to and start by activating the red LED as this LED will be turned on during the computation phase. So we will use the function hl underscore GPIO underscore write pin on GPIO port B pin number 2 and the state will be set. As we are going to use c-stick as our time-base unit we copy the actual c-stick value to our start timestamp variable, t-start. Let's proceed to code a for loop that searches for the total number of prime numbers in a given interval. In this case the loop will call the is prime number function between the intervals starting in 400k and ending in 500k. If the return value of the is prime number function is different than zero we will increment our prime number total counter. In the end of the loop we will copy the actual c-stick value to our stop timestamp variable, t-stop. With these two timestamps we will be able to calculate the computation period. After the period is calculated let's switch off the red LED and light up the green LED which is connected to the port E pin 8. The first coding moment is finished so we can build the project and if no error appears let's launch our debugging session. After entering the debug mode let's open the watch expression tab and we will add the calculation period and the total of prime numbers calculated variables. If we press the resume button the program will run till the end and we are supposed to see the red LED on and when the calculation is finished the green LED will be turned on. If we press pause we will be able to see the amount of time it took to calculate the number of prime numbers and how many there were in the selected interval. So to wrap up the computation period took 1258 milliseconds and 7778 prime numbers were found between 400k and 500k which was our selected interval. The art accelerator is active by default so to be able to analyze the improvement that it brings to the duration of the program run time we need to turn it off by using two macros. One is hl underscore flash underscore instruction underscore cache underscore disable and the second is hl underscore flash underscore dot underscore cache underscore disable. And now it's time to build our application once more and start the debugging. We will repeat the whole process and when the green LED is back on we will pause the program. As you can see the computation time is now 1 976 milliseconds comparing to the 1.2 milliseconds when the cache was active. So we can conclude now that the cache greatly improves the performance of the microcontroller. We just finished our core hands-on. Thank you for your attention.