 Hello, in this video I will demonstrate to you how to use DMI multiplexer in practice with combination of timer in PWM mode and external interrupts. Requisites As a hardware I will use Nucleo C031C6 board which is equipped with STM32C031C6T microcontroller. You can use any other STM32-based board of the STM32 device which is equipped with DMI Mox. To connect the board to the PC I will use micro USB cable and as a software I will use STM32QPID and my version would be 1.11.1 but you can use any other version which is above 1.10.1. As a library I will use STM32C0QP library in version 1.0.0. On the picture you can see as well the location of green LED which we will mention in the further part of this exercise. Here on the screen you can see the simplified description of our final application. On the left side we can see the block diagram of the microcontroller and the main components which would be used during this part. So we can see the timer one which would work in PWM mode on its channel 1 with period 100 millisecond. This period will be constant and it will have the flexible deoticycle which will be modified by the DMA and those DMA transfers will be done from the internal SRAM buffer and will be synchronized by the signal coming from DMI Mox and those signals will be triggered by the events on PC13 line and this PC13 line will be controlled by the blue button on our board. On the right side of the screen we can see the final effect on our output channel of timer 1 which is connected to PA5 pin. So we can see the constant period and variable deoticycle. So the time when the LED will be turned on will differ on the different pulse selection and we should observe it on our green LED. Bit more details about the application. So the timer 1 will generate the signal of 10 Hz on its channel 1 which is connected to PA5 and with flexible deoticycle. This PA5 is used as well to connect green LED called LD4 so it's pretty convenient to observe the final effect without any special equipment. Timer 1 will have a signed DMA channel to transfer its deoticycle so called pulse values from internal SRAM buffer to timer 1 capture compare register 1 and DMA will be synchronized by the external interrupt XTI 13 signal triggered by the blue button press. Let's start the project using STM48EQPIDE. I will use this folder as a location of my workspace and within the workspace I would keep all of the examples related to DMA MOOCs which will follow within this video series. Now I can select this button, start a new STM48EQPIDE project. In case you do not have this information center window you can go to file new STM48EQPIDE project. Now we need to specify the part number I would like to use in our example. So in our case it is STM48EQC031C60 microcontroller which is located on the selected board. So we will use MCU selector tab over here and I would specify that part number using only C031C6 and then I can see the line with a selected nuclear board so this is our microcontroller I press next then I need to specify the project name so it will be dim underscore XTI underscore DMA MOOCs. I keep all of the default settings for the project and press just finish. Here is a warning that will switch to the configuration perspective which is in fact start of STM48EQPIDE which is integrated into STM48EQPIDE so I just press yes. Okay we've got our configuration application started so we can start from the clock configuration review so by default the microcontroller selected one so STM48EQC0 is clocked by HSI48MHz divided by 4 so the system clock is 12MHz without any PLL and all of the peripherals are using the same clock so 12MHz will be our clock for the timer in this exercise. We'll keep the default settings so let's come back to the pinoutend configuration and we will start from the timer selection so we'll go to timers timer one and now we need to specify the mode of this timer so it will be the only timer we will use of an hour microcontroller except the cystic which is for the time base so we will not use this master slave configuration neither trigger source we'll just specify the clock source as internal one and we need to configure the channel one to PWM mode so this configuration. No other settings will be done within the mode now we can switch to the configuration part of the window and select the parameter settings over here. By default the pre-scaler is set to zero and the counter period is set to 65000 which is the maximum value for 16-bit register so we need to have 10Hz signal at the end so having 12MHz on the input I would propose to divide it first by 12000 so we need to specify here 11999 because we are counting from zero so to the counter we'll put 1MHz signal so to have outside 10Hz we need to divide it additionally by 100 so again counting from zero we need to put here 99 there are no more settings we need to update here at the moment because pulse value will be modified by the DMA of an hour application so those two parameters are enough then we need to enable the DMA so let's switch to the DMA settings there is no DMA request so far so just press add select timer one channel one and we need to specify the direction not the default one from peripheral to memory but memory to peripheral because we'll transfer the numbers for the pulses from the memory buffer to our compare register of the channel one we'll specify the amount of the DMA as a circular will keep the memory incrementation and we will change the data size from half word to word on both sides then we need to configure as well the DMA mocks so we need to enable synchronization because you would like to have this transfers from memory to timer one channel one synchronized by the external channel external interrupt channel line which is PC 13 in fact so we cannot select yet the signal because it is not yet configured so let's switch to the pinout configuration and the first thing we need to change is the location of timer one channel one by default it is P0 but in our case you would like to use a different location in fact P5 and how to make this change one of the methods is that we can go with the mouse cursor over the selected pin then we need to press the control key on the keyboard and the left button on mouse and now we can see all of the alternative locations of this function and then just keeping pressed control button and left button on mouse we are just drag and drop this function over the desired pin in our case PA5 and then release control and left button on mouse we just made a remap of this pin to PA5 the next step would be configuration of PC 13 line to external interrupt mode so we'll go over this line select left button on mouse and we'll select the GPIO XT13 then we need to check this line configuration whether it is working in interrupt mode on rising edge and whether the interrupt is enabled and with an NVIC configuration so we go to system core GPIO select this PC 13 we can see that mode is correct so it's external interrupt mode in rising edge so this is what we would like to have then we go to NVIC tab and we see that interrupt that interrupt controller is not enabled so I will just click enable even if this interrupt will be not used in this exercise it is worth to remember that it is not enabled by default so let's come back to the timer one and now we can finish our configuration of DMA Moog so we go to this configuration DMA settings synchronization signal and now we can select XT13 as it is right now enabled and we will use the polarity rising edge now the project is ready to be generated so we just go to project manager name and location is already selected so we are ready to generate the project the easiest way is to use this gear icon but you can use as well the many project generate code or just save the project by Ctrl S after I trigger this project generation I can see another warning that will switch to different perspectives so set of windows related to the CC++ editor so just select remember my decision and press yes so now the project complete project would be generated and we can start with the code processing so as you can see that it is finalized on the screen we can see right now the main.c file before we will continue with the code processing I will just increase the size of the font for the better visibility so go to many preferences and then we need to go to general editors text editors colors and fonts text font and edit increase it to 14 and now we can continue the first thing we need to specify is a buffer which would contain different pulse values so I would specify this 32-bit unsigned I would call it pulses and let's assume that we'll have 10 components inside please remember that the period of our timer is set to 100 so the pulse value should not exceed this 100 so I would use just 10 so 0, 10, 20, 30, 40, 50, 60, 70, 80 and 90 please note that I put this definition of the table within this user code begin pv so private variable section to be sure that in the next code regeneration my modification would be untouched otherwise if I would put it somewhere else outside of any of the user code sections it will be deleted by the qbemmix or qbyd application the next point before we will continue with the code processing is verification whether the initialization process is correctly done by our tools so DMA should be always the first function before any other peripherals initialization which are working with DMA in our case timer one is working with DMA so it should be initialized after DMA is initialized so this is the proper flow at the moment so the next point would be to start a timer one in PWM mode on channel one and with usage of DMA so let's try to find the proper function we are using hull libraries so I will start from IJL prefix then we need to specify the peripheral group so it's timer underscore and now I can use control spice to check the proper function from the list so it should be something related to PWM and we'll start and DMA usage so this function looks pretty okay so just double click to select it we've got four arguments first one is a handler if the timer would like to use there's only one so I just select the timer one then the channel so it's timer underscore now if I am not sure what to put here I would just press control spice and I can select from the list so it should be something related to channel so it's pretty a lot definitions yes channel one so this is this one then the pointer to the buffer of the data so in our case it will be just name of the buffer so pulses and length is a number of those components within this buffer so it's 10 in case you will be not sure what to put as an arguments you can go to the function definition or just go with the cursor over this function and then you can have brief information about argument lists and possible values which you can put as an arguments this is the end of the coding process now we are ready to build a project so the easiest way is just to press this hammer icon over here you can use as well build option within this project menu we see zero error zero warnings and on the right side we have as well the information about the memory regions and the memory usage so the ram and flash ones and what we can see here is that we are using close to 15 percent of the ram and 37 percent of flash now it is a time to connect our board so i'm taking a micro usb cable and connecting my discovery board to pc the board is connected we are ready to start a debug session the easiest way is to clean this bug icon for the first time it is launching this edit configuration just to check whether everything is okay we will not modify anything within this debug configuration at the moment so i'll just press okay we can see another warning window informing us that will switch the perspective so the set of windows to the debug one so i will just select the remember my decision and click switch now application is ready to be run so here we can see this play button so called resume if i would press it my application is start working i can pause it anytime using this pause button or terminate using this square one we can have a look as well on the sfr registers sfr means special function registers and here we can put for example timer one and what would be interesting in our case it would be capture capture compare register as you can see there is error reading value because we need to pause the execution to have the the value at the moment started there so as you remember the default configuration of the pulse value was zero and each change on each button blue button press so at the moment i would press the button once and i would pause execution so there is no change so let's do it again now i press and i can see that there is a 10 inside this the reason i couldn't see anything on the first press of the button is that the first value is again zero so i changed zero to zero so the effect was not visible so let's do another test i will resume the execution i will press blue button twice this time and they pause it so now i can see one e which is 30 decimal value and it is in line with our expectations you can see as well in the in the meantime on the camera the effect which is visible on the green led so we can see the application is properly working each blue button press is causing the rising edge on the pc 13 line and this line is used as external interrupt 13 which is used as a trigger for dmimox to generate the synchronization signal which is transferring one word from the sram buffer to our timer one capture compare register and is changing the pwm generation signal at the end so now we can terminate execution of the code and we can go to the next exercise more information about dmimox you can find in those documents so dedicated application note an 52 24 which is fully dedicated for stm32 implementation of dma multiplexer then you can find some useful information about dma implementation in stm32 c0 g0 and the other lines with an application note 2548 and finally you can find more details of an dedicated reference manual for stm32 c0 family which is marked rm0490 thank you for your attention