 Hello, in this video I will demonstrate to you how to use DMA multiplexer in combination with EOSart external interrupts and timers in STM32-C0 microcontroller. Pre-requisites We'll use Nucleo C031-C6 board and we'll connect this board to PC using micro USB cable. On surrounding software we'll need STM32-Cube IDE in version 1.10.1 at least and STM32-C0-Cube library in version 1.0.0. Here is a simple description of our lab. So on the left side we can see the block diagram of the complete system. So we'll use Timer 1 in WM mode on its channel 1 with period set to 100 milliseconds and flexible duty cycle. The output of this channel 1 will be redirected to PA5 pin where we can see as well the green LED connected on the board and pulse value of this timer which is stored in CAPTCOMPER RERISTER 1 CCR1 will be transferred from internal SRAM buffer using DMA to this register on the synchronization signal coming from DMA multiplexer which would be triggered by external pulses coming from PC13 pin. This PC13 is a place where we have blue button connected on our board. At the end of this DMA transfer between SRAM buffer and Timer 1 we'll have another synchronization signal which would synchronize another DMA transfer this time from the TX buffer located again in the SRAM memory to USART2 in order to display some text messages. It will be DC space number of the percent of duty cycle which is currently visible on this PA5 pin. The interesting thing is that this transfer synchronized by DMA multiplexer will contain always 9 characters so complete row from this TX buffer and it is a new feature coming from this DMA multiplexer implementation which is available with an STM32 C0. So let's have a look on more details about the application so Timer 1 will be configured in PWM mode to work in 10Hz output signal on its channel 1 redirected to PA5 with programmable duty cycle which is marked as Pulse. We can observe it on our green LED on the board. All the transfers between SRAM buffer to Timer 1 capture compare register 1 will be synchronized by the external interrupt 13 signal coming from the blue button. So each blue button press will trigger the copying of the new pulse value from the SRAM buffer to Timer 1 capture compare register 1. At the end of this transfer DMA multiplexer will generate an event which would trigger another transfer from SRAM buffer to USART2 and USART2 will be configured as asynchronous interface on PA2 PA3 pins connected to our onboard STA link so it will be possible to observe the data via the virtual comport and the parameters it will be 115,000 bits per second, a bit data, one bit stop and no parity. Those are the default settings in Qubemix and Qube IDE. Let's create a new project with an STM32 Qube IDE. I will use this path in some workspace location and I need to create a new project so I will go to file, new, STM32 project. As you can see there is already some existing project so we can have a multitude of projects within one workspace which is pretty convenient to switch from one to the other. So we need to specify the part number. It is STM32C031C6T microcontroller so I will specify C031C6 and now we can see that our nuclear board is over here so this is our part number. I click next. I need to specify the name so I would propose TIM underscore XTI underscore USART underscore DMA MOX and press finish. Let's start from the pinout configuration so PC13 it would be our trigger of the DMA transfer from SRAM to TIMER1 so I would just click left button on mouse over this pin and select the last option GPIO underscore XTI13 then from system and core I will select GPIO and this line and I will check whether it is external interrupt mode with rising edge trigger detection which is our desired configuration. Everything is correct so I will not change it and then with an NVIC and from the NVIC configuration I need to enable this interrupt. Then let's switch to the TIMER1 configuration so I go to the TIMERs, TIMER1 it will be standalone timer so we don't need to take care about the slave mode trigger source we just need to configure the clock source to internal clock and channel 1 to PWM generation. Then with DMA settings I would add TIMER1 channel 1 transfer and I would change it to circular I would change this direction to the opposite one so from memory to peripheral because we will transfer some values to the timer from the memory and I will change the data size from half word to word on both sides and I would keep this memory incrementation address. Then in DMA mocks below we need to enable synchronization coming from this XTI13 so this synchronization signal should be XTI13 rising edge and then we need to enable the event so we need to generate the signal which would trigger another DMA transfer from SRAM buffer to USART2 which will take care a bit later on. So we've got the proper configuration of the DMA for TIMER1 now we can configure its parameters so within parameter settings we need to configure its work to 10 Hz output signal. The timer one is clocked by the default clock which is 12 MHz coming from HSI48 MHz divided by 4 so we need to divide those 12 MHz for example by 12 000 so we'll use prescalar as 11999 because we are counting from 0 and we'll set the period to 100 so we need to write 99 because we are counting from 0 so in this case when we use those two components we'll have 10 Hz signal as an output of the TIMER1 on its channel 1 pulse value I would keep 0 as we'll modify it via DMA from the SRAM buffer. So all of the settings of TIMER1 are done now we need to do some pin up pin remapping because PA0 is not our desired pin we would like to have this function on PA5 where our green LED is connected. To make a remap I need to go with the cursor of mouse over the pin press the control on the keyboard left button on mouse and now I can see the alternate location then I need to drag this function to desired pin in my case PA5 and release control and then left button on mouse remap is done. The last point from the configuration is a configuration of the USART2 so I need to go to connectivity USART2 I need to select the mode as asynchronous those two pins are correct PA2 and PA3 those ones are connected to S-telling on our nuclear board. I need to configure the DMA settings click add we will send the data over UART so I will select USART2 RTX direction only it will be from memory to peripheral so it's correct we will use circular mode we will use bytes and incrementation on memory side and again we need to configure somehow the DMA mux so we will use synchronization coming from the DMA transfer between USART2 cut we will use a synchronization from the DMA transfer between SRAM buffer and timer 1 so as a signal I will select DMA1 channel 1 it is pretty easy to find it because it is the only active we can check whether it is exactly this one time DMA1 channel 1 yes so we've got the source of synchronism and we need to specify the request number so the number of the transfer which would be as an effect of this trigger so it will be it will be 9 it is the length of the single row of text we would like to display on the USART on each update on timer 1 plus value okay so this DMA configuration is done we can have a look on the parameter settings but we will keep all of the default ones so 115 000 bits per second 8-bit data no parity at 1 stop bit we are ready to generate the project so we can go to project manager just to verify whether everything is okay in case no change on the project name on its location we can generate it for example by clicking this gear icon when it's done we can specify some variables which we'll use within this exercise so the first one would be that table which would contain the pulse values for the timer 1 so 10 0 10 20 30 40 50 60 70 80 and 90 and then we need to specify the table which would contain the data which would like to send over the USART so tx underscore data it will be to to D table 10 rows 9 characters each and now we need to specify the first row and then we'll use the copy paste so we can send something like this dc 0 percent and then new line carriage return and then we need to copy it 10 times 9 times in fact one two three four five six seven eight nine and they just change this one space into the proper value of the duty cycle 50 40 30 let's have a look once again 40 50 60 70 80 and 90 this one is not here so this is those are the variables we would like to use please have a look that i located them into the user code section otherwise those would be deleted in case of any project regeneration the next point on our site is verification whether the initialization of the peripherals are properly done by the QPID DMA should be the first one above all of other peripherals which are working with DMA so timer one and USART2 and this is the case so everything is correct and we are ready to activate the preference as timer one will in fact somehow trigger the DMA transfers from SRAM to USART2 we can start from USART so how underscore UART in fact underscore T because we would like to transmit the data and now we need to select the function of the DMA USART2 then the data so this is TX data and the size we can use so this is the first one and the second one concerning timer so how the timer PWM counter space start with DMA timer one channel one pulses and 10 and that's it in case you are lost in case cut in case you do not know which arguments you should put into the function you can just go of the mouse cursor over the function name and you can see the brief description of the arguments needed so the coding is done I can compile the code using this hammer icon no errors no warnings we can see as well the usage of the memory RAM is 17% and flash is more or less 48% almost now we are ready to start a debug session so I click on this back icon my board is already connected I click okay and now before we start let's configure the internal terminal window so we can observe the data coming from our virtual comfort so to do this I will go below and I would select from this open console window common shell console as a connection type I would select the serial port connection name we will specify the new one so let's put labs underscore terminal serial port it should be the one which has been assigned to our virtual comfort on ester link usually it is the highest possible number mode rate as we kept default it is exactly the same 115k 8-bit data no parity and one stop bit I press finish and I press okay now we can see below the console the terminal is connected it's ready here on the right side we can see two new icons connect which is disabled because it's already connected and disconnected so we can disconnect our terminal from the the comport so now we are fully ready to run the application so I would just press resume and now if I would press the low button I can see different string displayed and again I can see some activities of my led so this is the duty cycle changed from 0% up to 90% so I can see that at 90% is almost constantly on while on 0% is completely off 10% is visibly blinking so all is working properly as expected so we can close this application at the moment so thank you very much for your attention