{"id":1241,"date":"2022-10-05T05:56:28","date_gmt":"2022-10-05T05:56:28","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1241"},"modified":"2022-10-05T05:56:31","modified_gmt":"2022-10-05T05:56:31","slug":"working-with-stm32f7-and-uart-part-4-full-duplex-using-dma","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1241","title":{"rendered":"Working with STM32F7 and UART part 4: Full Duplex using DMA"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"441\" height=\"259\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/08\/UART-BUS-between-two-devices.jpg\" alt=\"\" class=\"wp-image-330\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/08\/UART-BUS-between-two-devices.jpg 441w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/08\/UART-BUS-between-two-devices-300x176.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/08\/UART-BUS-between-two-devices-400x235.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/08\/UART-BUS-between-two-devices-250x147.jpg 250w\" sizes=\"(max-width: 441px) 100vw, 441px\" \/><\/figure><\/div>\n\n\n\n<p>In the previous guide (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=1233\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1233\" target=\"_blank\">here<\/a>), we took a look how to configure the UART to transmit data to PC using DMA. In this guide, we shall configure the UART to receive characters using DMA.<\/p>\n\n\n\n<p>This guide shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Configure UART for DMA RX<\/li><li>Configure DMA.<\/li><li>Support functions.<\/li><li>Code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Configure UART for DMA RX:<\/h2>\n\n\n\n<p>This section is continuation from the previous guide<\/p>\n\n\n\n<p>In order to configure the UART in RX mode with DMA, first we need to set PD9 to AF07 which is for USART3_RX pin 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;}\">GPIOD-&gt;MODER|=GPIO_MODER_MODER9_1;\n#define AF07 0x07\nGPIOD-&gt;AFR[1]|=(AF07&lt;&lt;4);<\/pre><\/div>\n\n\n\n<p>Now, we shall enable RX mode in CR1 of USART3:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"348\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-1024x348.png\" alt=\"\" class=\"wp-image-1242\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-1024x348.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-300x102.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-768x261.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-1536x523.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-2048x697.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-1150x391.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-750x255.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-400x136.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.26.18-AM-250x85.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\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;}\">USART3-&gt;CR1|=USART_CR1_RE; \/\/enable RX<\/pre><\/div>\n\n\n\n<p>Then enable DMAR in CR3:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"371\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-1024x371.png\" alt=\"\" class=\"wp-image-1243\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-1024x371.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-300x109.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-768x278.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-1536x556.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-2048x741.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-1150x416.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-750x271.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-400x145.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.34.31-AM-250x90.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Finally enable UART module:<\/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;}\">USART3-&gt;CR1|=USART_CR1_UE;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. DMA Configuration:<\/h2>\n\n\n\n<p>First we need which Stream and Channel of DMA1 is responsible for USART3_RX. From the reference manual, we can find it is Stream1 Channel 4<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"498\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-1024x498.png\" alt=\"\" class=\"wp-image-1244\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-1024x498.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-300x146.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-768x374.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-1536x748.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-2048x997.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-1150x560.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-750x365.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-400x195.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.37.11-AM-250x122.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Since the clock access is already enable, we shall first disable the stream and wait until the stream is disabled:<\/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_Stream1-&gt;CR &amp;=~(DMA_SxCR_EN);\n\twhile((DMA1_Stream1-&gt;CR &amp;(DMA_SxCR_EN)));<\/pre><\/div>\n\n\n\n<p>Then the configuration of the DMA as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Channel select is channel 4.<\/li><li>Memory increment mode.<\/li><li>Circular mode<\/li><li>Direction from peripheral to memory.<\/li><li>Transfer complete interrupt enabled.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"395\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-1024x395.png\" alt=\"\" class=\"wp-image-1246\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-1024x395.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-300x116.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-768x296.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-1536x592.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-2048x790.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-1150x443.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-750x289.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-400x154.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.42.03-AM-250x96.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\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 ch4 0x04\n\tDMA1_Stream1-&gt;CR|=(ch4&lt;&lt;25)|DMA_SxCR_MINC|DMA_SxCR_TCIE|DMA_SxCR_CIRC;<\/pre><\/div>\n\n\n\n<p>Set the peripheral address to be USART3-&gt;RDR:<\/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_Stream1-&gt;PAR=(uint32_t)&amp;USART3-&gt;RDR;<\/pre><\/div>\n\n\n\n<p>Enable DMA1_Stream1 interrupt in the NVIC:<\/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;}\">NVIC_EnableIRQ(DMA1_Stream1_IRQn);<\/pre><\/div>\n\n\n\n<p>For the DMA1_Channel1 interrupt handler:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Check if the source is from transfer complete<\/li><li>If it is from transfer complete, set rx_finshed to 1 and clear the pending interrupt.<\/li><\/ul>\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;}\">\n\nvoid DMA1_Stream1_IRQHandler(void)\n\t{\n\t\tif(DMA1-&gt;LISR &amp; DMA_LISR_TCIF1)\n\t\t\t{\n\t\t\t\trx_finished=1;\n\t\t\t\tDMA1-&gt;LIFCR=DMA_LIFCR_CTCIF1;\n\t\t\t}\n\n\t}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Support function:<\/h2>\n\n\n\n<p>For launching the DMA, we shall use a function that takes two arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Pointer to the buffer where the data shall be stored.<\/li><li>Length of the buffer.<\/li><\/ul>\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 launch_rx_dma(uint8_t * buffer, uint16_t length)<\/pre><\/div>\n\n\n\n<p>Within this function, set the memory address to be the buffer:<\/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_Stream1-&gt;M0AR= buffer;<\/pre><\/div>\n\n\n\n<p>Number of transfer to be the passed length:<\/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_Stream1-&gt;NDTR=length;<\/pre><\/div>\n\n\n\n<p>Finally, launch the DMA:<\/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_Stream1-&gt;CR|=DMA_SxCR_EN;<\/pre><\/div>\n\n\n\n<p>Within the header file, we shall use the following enumerated values:<\/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;}\">\ntypedef enum\n\t{\n\t\tbuffer_full=1,\n\t\tbuffer_empty=0\n\t}buffer_enums;\n<\/pre><\/div>\n\n\n\n<p>Also, check if the buffer is full:<\/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;}\">\nuint8_t isBufferFull()\n\t{\n\t\tif(rx_finished==0)\t{return buffer_empty;}\n\t\telse {rx_finished=0; return buffer_full;}\n\t}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Code:<\/h2>\n\n\n\n<p>Within main.c file:<\/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;uart.h&quot;\nchar uart_data_tx[40], uart_data_rx[5];\n\nuint8_t length;\n\nint main(void)\n\t{\n\t\tuart_tx_rx_dma_init();\n\t\tlaunch_rx_dma(&amp;uart_data_rx, 5);\n\t\twhile(1)\n\t\t\t{\n\t\t\t\tif(isBufferFull()){\n\t\t\t\tlength=sprintf(uart_data_tx,&quot;Received 5 characters are: %s\\r\\n&quot;,uart_data_rx);\n\t\t\t\tusart_dma_write(uart_data_tx,length);\n\t\t\t\t}\n\t\t\t}\n\t}\n<\/pre><\/div>\n\n\n\n<p>You may download the code from here:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/UART_RX_TX_DMA.zip\">UART_RX_TX_DMA<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/UART_RX_TX_DMA.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Results:<\/h2>\n\n\n\n<p>Open you serial terminal and set the baud rate to 115200 and send any five characters:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"715\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM-1024x715.png\" alt=\"\" class=\"wp-image-1248\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM-1024x715.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM-300x210.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM-768x536.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM-1150x803.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM-750x524.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM-400x279.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM-250x175.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-05-at-8.54.43-AM.png 1174w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\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 UART to transmit data to PC using DMA. In this guide, we shall configure the UART to receive characters using DMA. This guide shall cover the following: Configure UART for DMA RX Configure DMA. Support functions. Code. Results. 1. Configure UART for [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2,11,12],"tags":[],"class_list":["post-1241","post","type-post","status-publish","format-standard","hentry","category-data-structures","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1241"}],"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=1241"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1241\/revisions"}],"predecessor-version":[{"id":1249,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1241\/revisions\/1249"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}