{"id":1779,"date":"2023-05-24T05:52:08","date_gmt":"2023-05-24T05:52:08","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1779"},"modified":"2023-05-24T05:52:12","modified_gmt":"2023-05-24T05:52:12","slug":"getting-started-with-stm32l053-pwm-update-with-dma","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1779","title":{"rendered":"Getting started with STM32L053: PWM Update with DMA"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"654\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-1024x654.jpeg\" alt=\"\" class=\"wp-image-1780\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-1024x654.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-300x192.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-768x491.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-1536x982.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-2048x1309.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-1150x735.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-750x479.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-400x256.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/AdobeStock_495094833-250x160.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In the previous guide (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=1012\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1012\" target=\"_blank\">here<\/a>), we took a look how to configure the timer to generate PWM signal and update the duty cycle in software. In this guide, we shall configure the time with PWM to update the duty cycle using DMA.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Configure timer in DMA mode.<\/li><li>Configure the DMA.<\/li><li>Test code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Configure timer in DMA mode:<\/h2>\n\n\n\n<p>Create new source and header file with name of tim.c and tim.h respectively.<\/p>\n\n\n\n<p>Within tim.h, include the guards:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef TIM_H_\n#define TIM_H_\n\n\n#endif \/* TIM_H_ *\/\n<\/pre><\/div>\n\n\n\n<p>Within the define and endif, include stdint.h as following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stdint.h&quot;<\/pre><\/div>\n\n\n\n<p>Declare the following function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void tim2_pwm(uint16_t *dutyData1, uint16_t *dutyData2, uint16_t  len1, uint16_t len2);<\/pre><\/div>\n\n\n\n<p>The function takes 4 parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Pointer to duty cycle array for channel1 and channel2.<\/li><li>Length of each array.<\/li><\/ul>\n\n\n\n<p>Hence, the header file as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef TIM_H_\n#define TIM_H_\n\n#include &quot;stdint.h&quot;\n\n\n\nvoid tim2_pwm(uint16_t *dutyData1, uint16_t *dutyData2, uint16_t  len1, uint16_t len2);\n\n\n\n#endif \/* TIM_H_ *\/\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the header file.<\/p>\n\n\n\n<p>Next in source file, tim.c include tim.h and stm32l0xx.h header file as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;tim.h&quot;\n\n#include &quot;stm32l0xx.h&quot;<\/pre><\/div>\n\n\n\n<p>Declare the function as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void tim2_pwm(uint16_t *dutyData1, uint16_t *dutyData2, uint16_t  len1, uint16_t len2)<\/pre><\/div>\n\n\n\n<p>within the function:<\/p>\n\n\n\n<p>The following is the same as the previous guide<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Enable clock access to GPIOA*\/\n\tRCC-&gt;IOPENR |= RCC_IOPENR_GPIOAEN;\n\t\/*Set PA0 and PA1 to alternate function*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE0_1|GPIO_MODER_MODE1_1;\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE0_0|GPIO_MODER_MODE1_0);\n\t\/*Select which alternate function*\/\n\tGPIOA-&gt;AFR[0]|=(TIM2_AF&lt;&lt;0)|(TIM2_AF&lt;&lt;4);\n\n\t\/**Configure timer 2 in PWM mode *\/\n\n\tRCC-&gt;APB1ENR|=RCC_APB1ENR_TIM2EN;\n\tTIM2-&gt;PSC=0;\n\tTIM2-&gt;ARR=1600;\n\tTIM2-&gt;CCMR1|=TIM_CCMR1_OC1M_2|TIM_CCMR1_OC1M_1|TIM_CCMR1_OC2M_2|TIM_CCMR1_OC2M_1;\n\tTIM2-&gt;CCER|=TIM_CCER_CC1E|TIM_CCER_CC2E;<\/pre><\/div>\n\n\n\n<p>Before enabling the timer, we shall enable Capture\/compare in DMA mode for both channel1 and channel2.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>To enable them, we need to enable Capture\/Compare  DMA request in TIMx DMA\/Interrupt enable register as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"261\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-1024x261.png\" alt=\"\" class=\"wp-image-1781\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-1024x261.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-300x76.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-768x196.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-1536x391.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-1150x293.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-750x191.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-400x102.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM-250x64.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.27.43-AM.png 1774w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Enable DMA for TIM2*\/\n\n\tTIM2-&gt;DIER|=TIM_DIER_CC1DE|TIM_DIER_CC2DE;<\/pre><\/div>\n\n\n\n<p>Don&#8217;t enable the timer yet.<\/p>\n\n\n\n<p>Thats all for timer configuration.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Configure the DMA:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>First we need to know which channel is responsible for TIM2_CH1 and TIM2_CH2:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"598\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-1024x598.png\" alt=\"\" class=\"wp-image-1782\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-1024x598.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-300x175.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-768x448.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-1536x897.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-2048x1196.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-1150x671.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-750x438.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-400x234.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.32.13-AM-250x146.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>From the table, we can find that Channel5 and Channel3 for TIM2_CH1 and TIM2_CH2 respectively.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>First, enable clock access to DMA1:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"642\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-1024x642.png\" alt=\"\" class=\"wp-image-1157\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-1024x642.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-300x188.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-768x482.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-1536x963.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-2048x1284.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-1150x721.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-750x470.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-400x251.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-17-at-7.26.00-AM-250x157.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>From block diagram, we can find that DMA1 is connected to AHB bus. Hence, we can enable clock access to DMA as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tRCC-&gt;AHBENR|=RCC_AHBENR_DMA1EN;<\/pre><\/div>\n\n\n\n<p>The DMA_Channel5 and Channel3 shall have the following configuration:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Memory and peripheral size to be 16-bit.<\/li><li>Memory increment mode.<\/li><li>Circular mode.<\/li><li>Direction, read from memory.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"598\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-1024x598.png\" alt=\"\" class=\"wp-image-1783\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-1024x598.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-300x175.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-768x448.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-1536x897.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-2048x1196.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-1150x671.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-750x438.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-400x234.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-24-at-8.39.44-AM-250x146.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>For DMA1_Channel5:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel5-&gt;CCR=DMA_CCR_MSIZE_0|DMA_CCR_PSIZE_0|DMA_CCR_MINC|DMA_CCR_CIRC\n\t\t\t|DMA_CCR_DIR;<\/pre><\/div>\n\n\n\n<p>For DMA1_Channel3:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tDMA1_Channel3-&gt;CCR=DMA_CCR_MSIZE_0|DMA_CCR_PSIZE_0|DMA_CCR_MINC|DMA_CCR_CIRC\n\t\t\t|DMA_CCR_DIR;<\/pre><\/div>\n\n\n\n<p>Set peripheral address to be TIM2-&gt;CCR1 and TIM2-&gt;CCR2 respectively:<\/p>\n\n\n\n<p>DMA1_Channel5:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel5-&gt;CPAR=(uint32_t)&amp;TIM2-&gt;CCR1;<\/pre><\/div>\n\n\n\n<p>DMA1_Channel3:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel3-&gt;CPAR=(uint32_t)&amp;TIM2-&gt;CCR2;<\/pre><\/div>\n\n\n\n<p>Set memory destination to be the array passed by the user:<\/p>\n\n\n\n<p>DMA1_Channel5:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel5-&gt;CMAR|=(uint32_t)dutyData1;<\/pre><\/div>\n\n\n\n<p>DMA1_Channel3:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel3-&gt;CMAR|=(uint32_t)dutyData2;<\/pre><\/div>\n\n\n\n<p>Set the length for both channel:<\/p>\n\n\n\n<p>DMA1_Channel5:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel5-&gt;CNDTR=len1;<\/pre><\/div>\n\n\n\n<p>DMA1_Channel3:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel3-&gt;CNDTR=len1;<\/pre><\/div>\n\n\n\n<p>Set the channel selection to be TIM2:<\/p>\n\n\n\n<p>Since this register doesn&#8217;t exist in the main header file, we shall create it as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define DMA_CSELR  (*(volatile unsigned int *)(0x400200a8))<\/pre><\/div>\n\n\n\n<p>DMA1_Channel5<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA_CSELR|=(0x08&lt;&lt;16);<\/pre><\/div>\n\n\n\n<p>DMA1_Channel3:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA_CSELR|=(0x08&lt;&lt;8);<\/pre><\/div>\n\n\n\n<p>Enable the DMA channels:<\/p>\n\n\n\n<p>DMA1_Channel5:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel5-&gt;CCR|=DMA_CCR_EN;<\/pre><\/div>\n\n\n\n<p>DMA1_Channel3:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">DMA1_Channel3-&gt;CCR|=DMA_CCR_EN;<\/pre><\/div>\n\n\n\n<p>Finally enable the timer:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">TIM2-&gt;CR1|=TIM_CR1_CEN;<\/pre><\/div>\n\n\n\n<p>Hence the source file as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;tim.h&quot;\n\n#include &quot;stm32l0xx.h&quot;\n\n#define TIM2_AF 0x02\n\n#define DMA_CSELR  (*(volatile unsigned int *)(0x400200a8))\n\nvoid tim2_pwm(uint16_t *dutyData1, uint16_t *dutyData2, uint16_t  len1, uint16_t len2)\n\t{\n\n\n\t\/*Enable clock access to GPIOA*\/\n\tRCC-&gt;IOPENR |= RCC_IOPENR_GPIOAEN;\n\t\/*Set PA0 and PA1 to alternate function*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE0_1|GPIO_MODER_MODE1_1;\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE0_0|GPIO_MODER_MODE1_0);\n\t\/*Select which alternate function*\/\n\tGPIOA-&gt;AFR[0]|=(TIM2_AF&lt;&lt;0)|(TIM2_AF&lt;&lt;4);\n\n\t\/**Configure timer 2 in PWM mode *\/\n\n\tRCC-&gt;APB1ENR|=RCC_APB1ENR_TIM2EN;\n\tTIM2-&gt;PSC=0;\n\tTIM2-&gt;ARR=1600;\n\tTIM2-&gt;CCMR1|=TIM_CCMR1_OC1M_2|TIM_CCMR1_OC1M_1|TIM_CCMR1_OC2M_2|TIM_CCMR1_OC2M_1;\n\tTIM2-&gt;CCER|=TIM_CCER_CC1E|TIM_CCER_CC2E;\n\n\t\/*Enable DMA for TIM2*\/\n\n\tTIM2-&gt;DIER|=TIM_DIER_CC1DE|TIM_DIER_CC2DE;\n\n\t\/*DMA Setup*\/\n\n\tRCC-&gt;AHBENR|=RCC_AHBENR_DMA1EN;\n\n\t\/*DMA1_CH5 is for TIM2_CH1\n\t * DMA1_CH3 is for TIM2_CH3\n\t * *\/\n\n\n\tDMA1_Channel5-&gt;CCR=DMA_CCR_MSIZE_0|DMA_CCR_PSIZE_0|DMA_CCR_MINC|DMA_CCR_CIRC\n\t\t\t|DMA_CCR_DIR;\n\n\tDMA1_Channel5-&gt;CPAR=(uint32_t)&amp;TIM2-&gt;CCR1;\n\n\tDMA1_Channel5-&gt;CMAR|=(uint32_t)dutyData1;\n\n\tDMA1_Channel5-&gt;CNDTR=len1;\n\n\tDMA_CSELR|=(0x08&lt;&lt;16);\n\n\tDMA1_Channel5-&gt;CCR|=DMA_CCR_EN;\n\n\n\tDMA1_Channel3-&gt;CCR=DMA_CCR_MSIZE_0|DMA_CCR_PSIZE_0|DMA_CCR_MINC|DMA_CCR_CIRC\n\t\t\t|DMA_CCR_DIR;\n\n\tDMA1_Channel3-&gt;CPAR=(uint32_t)&amp;TIM2-&gt;CCR2;\n\n\tDMA1_Channel3-&gt;CMAR|=(uint32_t)dutyData2;\n\n\tDMA1_Channel3-&gt;CNDTR=len1;\n\n\tDMA_CSELR|=(0x08&lt;&lt;8);\n\n\tDMA1_Channel3-&gt;CCR|=DMA_CCR_EN;\n\n\n\tTIM2-&gt;CR1|=TIM_CR1_CEN;\n\n\t}\n\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Test code:<\/h2>\n\n\n\n<p>Within main.c :<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;tim.h&quot;\n\nuint16_t lookUp1[] = {0,50 ,100 ,151 ,201 ,250 ,300 ,349 ,398 ,446 ,494 ,542 ,589 ,635 ,681\n\t,726 ,771 ,814 ,857 ,899 ,940 ,981 ,1020 ,1058 ,1095 ,1131 ,1166 ,1200 ,1233 ,1264\n\t,1294 ,1323 ,1351 ,1377 ,1402 ,1426 ,1448 ,1468 ,1488 ,1505 ,1522 ,1536 ,1550 ,1561\n\t,1572 ,1580 ,1587 ,1593 ,1597 ,1599 ,1600 ,1599 ,1597 ,1593 ,1587 ,1580 ,1572 ,1561\n\t,1550 ,1536 ,1522 ,1505 ,1488 ,1468 ,1448 ,1426 ,1402 ,1377 ,1351 ,1323 ,1294 ,1264\n\t,1233 ,1200 ,1166 ,1131 ,1095 ,1058 ,1020 ,981 ,940 ,899 ,857 ,814 ,771 ,726 ,681 ,635\n\t,589 ,542 ,494 ,446 ,398 ,349 ,300 ,250 ,201 ,151 ,100 ,50,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0\n\t,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0\n\t,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0\n\t,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0};\n\nuint16_t lookUp2[] = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0\n\t,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0\n\t,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0\n\t,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,50 ,100 ,151 ,201 ,250 ,300 ,349 ,398 ,446 ,494\n\t,542 ,589 ,635 ,681 ,726 ,771 ,814 ,857 ,899 ,940 ,981 ,1020 ,1058 ,1095 ,1131 ,1166 ,1200 ,1233\n\t,1264 ,1294 ,1323 ,1351 ,1377 ,1402 ,1426 ,1448 ,1468 ,1488 ,1505 ,1522 ,1536 ,1550 ,1561 ,1572 ,1580\n\t,1587 ,1593 ,1597 ,1599 ,1600 ,1599 ,1597 ,1593 ,1587 ,1580 ,1572 ,1561 ,1550 ,1536 ,1522 ,1505 ,1488\n\t,1468 ,1448 ,1426 ,1402 ,1377 ,1351 ,1323 ,1294 ,1264 ,1233 ,1200 ,1166 ,1131 ,1095 ,1058 ,1020 ,981\n\t,940 ,899 ,857 ,814 ,771 ,726 ,681 ,635 ,589 ,542 ,494 ,446 ,398 ,349 ,300 ,250 ,201 ,151 ,100 ,50 ,0,0};\n\n\n\nint main(void)\n{\n\ttim2_pwm(lookUp1,lookUp2, 200,200 );\n\n\twhile(1)\n\t{\n\n\n\t}\n\n}\n\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p>By probing PA0 and PA1 using oscilloscope, you should get the following results:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"480\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/DS1Z_QuickPrint5.png\" alt=\"\" class=\"wp-image-1784\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/DS1Z_QuickPrint5.png 800w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/DS1Z_QuickPrint5-300x180.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/DS1Z_QuickPrint5-768x461.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/DS1Z_QuickPrint5-750x450.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/DS1Z_QuickPrint5-400x240.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/05\/DS1Z_QuickPrint5-250x150.png 250w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous guide (here), we took a look how to configure the timer to generate PWM signal and update the duty cycle in software. In this guide, we shall configure the time with PWM to update the duty cycle using DMA. In this guide, we shall cover the following: Configure timer in DMA mode. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-1779","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1779"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1779"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1779\/revisions"}],"predecessor-version":[{"id":1785,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1779\/revisions\/1785"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}