 okay so now let's start the practical part and implementation of previously analyzed project so and we will use stn32 cube id tool for that so let me start my cube ibte so it is here and the first action is to start the project so new then stn32 project it will take a time it seems okay so now we can select our target just by entering the part number stn42 i mean the microcontroller on the top of the nuclear board stn32 l 476 rg and indeed here you can see the related comment of the associated board it is nuclear l 476 rg so let's highlight this microcontroller and then press next so next step is to add a project name stn32 l 476 atc let's say inter interrift and i select different than default location so maybe here and give me a moment please okay idc interlift it is here and let's say this sub folder of course you are free to select any sub folder for the project okay and finish so again we need to wait for the project creation okay so we have the project is opened now and let's start configuration of our project maybe the first step is to enable the debug lines so system core item and then sysperipherial and within debug selection let's select serial wire so here you can see pa14 pa14 lines to be active the lines are in green color okay then we need to add some debug output to our mcu application and the most maybe not the most but quite useful channel for that is the uart we have usert 2 or uart 2 so i'm selecting the asenhanos mode for usert 2 connected on nuclear board to the stlink debugger and one of the feature of the stlink debugger it is a virtual comport so we can redirect data from pins pa2 pa3 acting as a uart rx and tx uart 2 rx and tx to the virtual comport and this way we can observe data on the pc using any terminal let's keep the default parameters so 115 kilobits per second 8 bits character length without parity and one stop bit okay so we have debug pins for the debugger we have debug pins in order to redirect the printf output data stream then let's focus on the core activity of our application so the adc and configuration of the analog to digital converters yeah but it would be practical to select the particular pin of the nuclear board please remember we are going to use fast channels of the adc so let's see where are the fast channels in the datasheet so this is the datasheet here maybe i will magnify fast channels are pc0 pc1 pc2 pc3 and pa0 then we can go to the nuclear 64 description this is user manual 1724 you can also find this drawing this figure within the blister of the nuclear board let's say pa0 pa0 is here so let's use let's use pa0 pin for our application it is connected to pin number one of cn8 or it is connected to pin number 28 of cn7 so pa0 where is pa0 here it is here and it is indeed connected to the adc1 input 5 and adc2 input 5 because in order to perform the dual adc dual mode interleaved mode in particular we need to connect both adcs input to the same pin okay so adc1 let's select in 5 as a single-ended so pa0 pin is in green and adc2 in 5 single-ended okay so now pa0 is connected to the input 5 of adc1 and adc2 let's come back to the adc1 acting as a master adc so i can modify the screen a little bit okay so in 5 is activated let's start from the parameter setting tab and from the mode setting we want to configure the dual interleaved mode only here we want to have dma access so dma access enabled delay between two sampling phases it is three clock adc clock cycles clock press color that's the important point we want to connect we want to use the highest possible adc clock so synchronous clock mode divided by one but let's see what is the synchronous clock value so please switch to the clock configuration and we can see the system clock hclk is set to four megahertz while the maximum value it is 80 megahertz so let's change it just by entering here 80 megahertz and to automatically calculate the new settings okay so the new hclk and cclk clock value is set so we have msi as a input or base frequency for a pll unit here and 80 megahertz as a result okay then let's come back to the adc settings so we have 80 megahertz synchronous clock connected to the adc peripheral resolution 12 bits it is okay continuous conversion mode let's enable this because we need to or we want to continuously convert sample by sample as quick as possible then also we need to enable the dma continuous requests but it is currently impossible why because we need to configure the dma so let's add a channel and please remember we are going to use common data register so the data with is word the data size is instead of the half word the data size should be word and let's keep mode as a normal it is equivalent of single shot so the transfer stops when the buffer will be full the other option is a circular mode okay so let's come back to the parameter settings and enable dma continuous requests let's keep external trigger conversion source as a software and let's configure our rank so it is channel 5 but sampling time must be set to 6.5 adc clock cycles okay that's all regarding adc one and so it is our master so regarding adc two acting as a slave it is already set as dual interleaved mode dma access mode enabled delay between two sampling phases is three cycles synchronous clock is divided by one so that's okay continuous conversion enabled dma continuous request disabled because we don't have dma channel assigned to adc two we have common data register the only action on our side it is to configure the rank properly and we need the same sampling mode period so 6.5 clock cycles and that's all we can generate the source code okay and let's start our coding we are going to use printf function in order to send out to print out the user interface debug data the application so let's include the standard io file and as you remember when we are using kubemix to generate the source code it is good practice or i would say it is a must to put your user code between the code sections otherwise the the code will be deleted in case of regeneration of the source code so for the include the relevant section is here okay the next point it is to define the adc buffer size so the definition private define is here sorry and let's put here 20 why 20 because we want to acquire 40 samples we have interleaved mode so every transfer from the common data register means transfer of two adc's data register so in fact every item of the adc buffer consists of two results so we need to multiply 20 by 2 and then we get 40 items of the adc buffer okay we can save this then let's define the variables the user variables and the relevant section is here user code begin pv private variables so we have flag adc flag this flag will be active just after the end of dual conversion so just after the end of conversion of slave adc and this flag will be set within the dma and of transfer callback and the default value is of course reset then and it is volatile because it will be modified within interact callback the same for the variable i we need some index variable and we need the adc buffer okay the next point is to overwrite the default write function let's do it within the user code begin 0 section in fact this override of write underscore write function allows us to redirect the printf output data stream to the uart number two here okay next step it is important and it is practical hint for you that really first action when you are using adc on the top of stn32 microcontroller it is to calibrate the adc we have two adcs so we need to calibrate adc1 and adc2 we have single ended inputs for both then we can start our adc conversion and the api for that it is hull adc ex because ex means extended because this function is related to the l4 family the implementation of this function is related to l4 family multimode start multimode means that we are using more than one adc while the adc1 is a master adc so we need to point the master adc the buffer and the buffer size the next action is to enable the multi dma mode and configure this mode as a one shot here so the parameters are adc1 to 3 common it informs the function that we need we are using the common data register at 12 or 10 bits resolution then the next action it is to disable half transfer complete of dma interrupt this is quite practical hint for you when dma is active in hull library we have automatically enabled two interrupts dma transfer complete and dma hull transfer complete in our case we would like to increase the performance of our application and there is no need for half transfer complete dma from our application point of view we don't have dual buffer solution it is simple application so it makes sense to disable the enabled by default half transfer dma complete interrupt and this way save time increase the performance of application so the only interrupt from dma side we need it is the dma transfer complete okay and then we can add some welcome string like application started and that's all and this is all the activity before the main loop calibration of the adc start of dual mode or multi mode adc conversion configuration of the dma transfer so the n dma mode we are using single dma channel transferring data from common data register of adc in one shot mode some practical approach disable of half transfer complete dma interrupt in order to increase the application performance and then welcome string so let's implement main loop so i will copy all the main loop it is quite simple and it is good practice to put the main loop within the user code section number three as you can see it is between the brackets okay while one loop okay so what is behind if adc flag so it means when adc conversion is finished we are printing some separation string then we are printing out the adc buffer having in mind that lsb part of the world it is a master adc data register and msb part of the world it is a slave adc data register if you come back to the adc ex multi mode start dma api and this buffer adc buffer you can see that it is u in 32 type buffer so we have words in the buffer because of command data register so we are printing out the content of the adc buffer having in mind the organization of the command data register of adc then we are toggling the led and then we can reset back the adc flag and restart the dma multi mode adc conversion configure the mdma mode and disable the half transfer complete it seems i forgot to enable the gpio pin for the led so i can do it and this way i can show you how to regenerate the source code but before let's finish our main dot c modifications so here is the adc flag variable to be analyzed but we didn't modify this variable yet within the source code let's do it now and as i mentioned in the beginning this variable is modified within the callback so that i put i have just put the callback within the user code section number four this is the callback of the dma adc dma transfer complete and thanks to how dma transfer complete interrupt is linked to the adc conversion complete callback this is the power of the hardware abstraction layer and library so the only action here is to set the adc flag that's all okay so we can save and then let's come back to the our cuba mix and configure the relevant pin it is pa5 for the gpio before the led so i need to set gpio output and then regenerate the source code and thanks to the fact that i have put all my source code within the related source code sections i can still see my source code after regeneration so this is for example the callback just edit this is the main loop here and the user code section one more comment here so here you can see the alternative solution for the app of line so you can use ll api in order to configure the multimode dma or you can just write directly to the register using the related data structure but let's keep the low layer library this is equivalent so let's try to build our application okay and now we can start the back session and in the meantime i will open the terminal once again let's start the back session okay so application just build it then we can start the back session it is just finished download verified successfully so we can close the debug session because we are going to use terminal only in order to debug our application so this is terra term let's modify the settings starting from the font size to maximize the window and then let's change the serial port border to 115 okay okay we need to establish a connection first looking for the sd microelectronics virtual comport label here yeah so it is working now but it seems we need to maximize the size of the window in order to see all the buffer so that's it was the reason for the for for the separation string here just to separate following acquisitions okay so we can see some noise external noise voltage i will try to start the signal generator now this is the application to control the signal generation on my side so it is sinus output signal 500 kilohertz so the period is two microseconds amplitude is 1.5 volts offset is 1.5 volts so we have signal starting from zero up to three volts so let's start and see the terminal output so something has changed maybe let's stop the session and copy the data to the scratchpad so control c and now let's open the excel at paste data to the excel okay and then we can try to insert the chart okay and we see very nice sinus chart so it is working it is working i'm going to come back for a moment to the slides and show you the analyze of this sinus chart because this is exactly the same here as you remember the output data rate or something data rate the equivalent one for the interleaved mode it is eight mega samples per second what means 16 samples for two microseconds because for eight mega samples per second we have 125 nanoseconds per sample if we would divide the period of the 500 kilohertz which is two microseconds by the sampling period we will get 16 samples for the period so here we have 16 samples and just one period of the signal so thank you for your attention