{"id":1940,"date":"2023-08-23T07:14:42","date_gmt":"2023-08-23T07:14:42","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1940"},"modified":"2023-08-23T07:14:46","modified_gmt":"2023-08-23T07:14:46","slug":"building-board-support-package-bsp-for-stm32f411-nucleo64-part13-3-dma-memory-to-peripheral-mode","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1940","title":{"rendered":"Building Board Support Package (BSP) for STM32F411-Nucleo64 Part13.3: DMA Memory to Peripheral Mode"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-1024x683.jpeg\" alt=\"\" class=\"wp-image-1941\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-1024x683.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-300x200.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-768x512.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-1536x1024.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-2048x1365.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-1150x767.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-750x500.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-400x267.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/AdobeStock_128586024-4-250x167.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In this third section of the thirteenth part of board support package, we shall use the BSP of DMA to transfer data from the memory to peripheral which is SPI in this case.<\/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>Enabling DMA for SPI.<\/li><li>Configure the DMA.<\/li><li>Code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Enabling DMA for SPI:<\/h2>\n\n\n\n<p>Open spi_bsp.h header file and declare this enum:<\/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;}\">typedef enum\n{\n\tSPI_DMA_Disabled=0,\n\tSPI_DMA_Enable=1\n\n}SPI_DMATypedef;<\/pre><\/div>\n\n\n\n<p>This defines the DMA enabling process in the source code.<\/p>\n\n\n\n<p>Within SPI_ConfigTypedef include the following variable:<\/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;}\">uint8_t DMA_Enable;<\/pre><\/div>\n\n\n\n<p>This will either enable or disable the DMA.<\/p>\n\n\n\n<p>Hence, the updated data structure 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;}\">typedef struct\n{\n\tuint8_t mode;\n\tuint8_t dataFromat;\n\tuint8_t slaveManagement;\n\tuint8_t LSBFirst;\n\tuint8_t baud;\n\tuint8_t CPOL;\n\tuint8_t CPHA;\n\tuint8_t DMA_Enable;\n}SPI_ConfigTypedef;<\/pre><\/div>\n\n\n\n<p>Now, open spi_bsp.c source file.<\/p>\n\n\n\n<p>Within <strong>BSP_SPI_Config<\/strong> function, before starting the SPI: include the following line:<\/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;}\">\tif (con-&gt;DMA_Enable==SPI_DMA_Enable)\n\t{\n\t\tspi-&gt;CR2|=SPI_CR2_TXDMAEN|SPI_CR2_RXDMAEN;\n\t}<\/pre><\/div>\n\n\n\n<p>This will enable DMA for both, TX and RX part of SPI.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Hence, the updated <strong>BSP_SPI_Config<\/strong> 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 BSP_SPI_Config(SPI_TypeDef *spi, SPI_ConfigTypedef *con)\n{\n\n\tswitch (con-&gt;mode)\n\t{\n\n\t\t case Master_mode:  spi-&gt;CR1|=(1&lt;&lt;SPI_CR1_MSTR_Pos);\n\t\t \t break;\n\t\t case Slave_mode:   spi-&gt;CR1&amp;=~(1&lt;&lt;SPI_CR1_MSTR_Pos); break;\n\t\t default : break;\n\t}\n\n\tswitch (con-&gt;dataFromat)\n\t{\n\t\tcase MSB_First: spi-&gt;CR1&amp;=~(con-&gt;dataFromat&lt;&lt;SPI_CR1_LSBFIRST_Pos);\n\t\t\tbreak;\n\t\tcase LSB_First: spi-&gt;CR1|=(con-&gt;dataFromat&lt;&lt;SPI_CR1_LSBFIRST_Pos); break;\n\t\tdefault: break;\n\t}\n\n\tif(con-&gt;baud ==FCLK_2)\n\t{\n\t\tspi-&gt;CR1&amp;=~(SPI_CR1_BR_Msk&lt;&lt;SPI_CR1_BR_Pos);\n\t}\n\n\telse\n\t{\n\t\tspi-&gt;CR1|=(con-&gt;baud&lt;&lt;SPI_CR1_BR_Pos);\n\t}\n\n\n\n\tif (con-&gt;CPOL==CPOL0)\n\t{\n\t\tspi-&gt;CR1&amp;=~(1&lt;&lt;SPI_CR1_CPOL_Pos);\n\t}\n\telse\n\t{\n\t\tspi-&gt;CR1|=(con-&gt;CPOL&lt;&lt;SPI_CR1_CPOL_Pos);\n\t}\n\n\tif (con-&gt;CPHA==CPHA0)\n\t{\n\t\tspi-&gt;CR1&amp;=~(1&lt;&lt;SPI_CR1_CPHA_Pos);\n\t}\n\telse\n\t{\n\t\tspi-&gt;CR1|=(con-&gt;CPHA&lt;&lt;SPI_CR1_CPHA_Pos);\n\t}\n\n\n\n\tswitch (con-&gt;slaveManagement)\n\t{\n\t case software_slave: spi-&gt;CR1|=(1&lt;&lt;SPI_CR1_SSM_Pos)|(1&lt;&lt;SPI_CR1_SSI_Pos); break;\n\t case hardware_slave: spi-&gt;CR1&amp;=~((1&lt;&lt;SPI_CR1_SSM_Pos)|(1&lt;&lt;SPI_CR1_SSI_Pos)); break;\n\t default: break;\n\t}\n\n\tif (con-&gt;DMA_Enable==SPI_DMA_Enable)\n\t{\n\t\tspi-&gt;CR2|=SPI_CR2_TXDMAEN|SPI_CR2_RXDMAEN;\n\t}\n\n\tspi-&gt;CR1|=SPI_CR1_SPE;\n\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for enabling DMA for SPI.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Configuring the DMA:<\/h2>\n\n\n\n<p>In main.c:<\/p>\n\n\n\n<p>Declare a volatile to indicate that DMA finished transferring data and an array of 5 byte which holds the variable to be sent:<\/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;}\">volatile uint8_t finished=0;\n\n\nuint8_t SPI_TX[5]={0x00,0x22,0xFF,0x55,0x33};<\/pre><\/div>\n\n\n\n<p>Declare DMA configuration:<\/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_ConfigTypedef SPI_TX_DMA;<\/pre><\/div>\n\n\n\n<p>Declare CS pin:<\/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;}\">GPIO_Output_Typedef CS_Pin;<\/pre><\/div>\n\n\n\n<p>GPIO configuration for SPI and CS pins:<\/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;}\">GPIO_Configure_Typedef PA5_SPI,PA6_SPI,PA7_SPI;\n\n\tGPIOA_CLOCK_ENABLE();\n\n\tPA5_SPI.PinNumber=5;\n\tPA5_SPI.Mode=Alternate_function;\n\tPA5_SPI.AlternateType=AF5;\n\tPA5_SPI.OutPutspeed=High_Speed;\n\n\n\tPA6_SPI.PinNumber=6;\n\tPA6_SPI.Mode=Alternate_function;\n\tPA6_SPI.AlternateType=AF5;\n\tPA6_SPI.OutPutspeed=High_Speed;\n\n\tPA7_SPI.PinNumber=7;\n\tPA7_SPI.Mode=Alternate_function;\n\tPA7_SPI.AlternateType=AF5;\n\tPA6_SPI.OutPutspeed=High_Speed;\n\n\tGPIO_Initialization(GPIOA,&amp;PA5_SPI);\n\tGPIO_Initialization(GPIOA,&amp;PA6_SPI);\n\tGPIO_Initialization(GPIOA,&amp;PA7_SPI);\n\n\n\tGPIO_Configure_Typedef CS_Pin_Config;\n\n\tCS_Pin_Config.PinNumber=pin0;\n\tCS_Pin_Config.Mode=OUTPUT;\n\tCS_Pin_Config.OutPutspeed=High_Speed;\n\n\tGPIO_Initialization(GPIOA,&amp;CS_Pin_Config);\n\n\tGPIO_WritePin(GPIOA,&amp;CS_Pin,Set);<\/pre><\/div>\n\n\n\n<p>SPI configuration:<\/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;}\">\tSPI_Enable_Clock(spi1);\n\n\tSPI_ConfigTypedef cSPI1;\n\n\tcSPI1.mode=Master_mode;\n\tcSPI1.slaveManagement=software_slave;\n\tcSPI1.baud=FCLK_32;\n\tcSPI1.CPHA=CPHA0;\n\tcSPI1.CPOL=CPOL0;\n\tcSPI1.LSBFirst=MSB_First;\n\tcSPI1.DMA_Enable=SPI_DMA_Enable;\n\n\n\tBSP_SPI_Config(SPI1,&amp;cSPI1);<\/pre><\/div>\n\n\n\n<p>Similar to BSP for SPI with addition of DMA parameter only.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Since the required DMA is DMA2 Stream2 Channel2: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"557\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-1024x557.png\" alt=\"\" class=\"wp-image-1942\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-1024x557.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-300x163.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-768x418.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-1536x835.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-2048x1114.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-1150x625.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-750x408.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-400x217.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-10.08.23-AM-250x136.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The configuration as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Channel is 2.<\/li><li>Single Mode (Non circular).<\/li><li>Memory and Peripheral size is byte.<\/li><li>Memory increment mode.<\/li><li>Fixed peripheral address.<\/li><li>Transfer complete 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;}\">\t__BSP_DMA2__CLOCK_ENABLE();\n\n\tSPI_TX_DMA.DMA_Channel=Channel2;\n\tSPI_TX_DMA.CircularMode=SingleTransfer;\n\tSPI_TX_DMA.MemorySize=byte;\n\tSPI_TX_DMA.PerpheralSize=byte;\n\tSPI_TX_DMA.MemoryIncMode=incMode;\n\tSPI_TX_DMA.PeripheralIncMode=SingleTransfer;\n\tSPI_TX_DMA.Direction=memory2Peripheral;\n\tSPI_TX_DMA.InterruptEnable=InterruptEnbaled;\n\tSPI_TX_DMA.TransferCompleteInterrupt=TransferComplet;\n\tSPI_TX_DMA.DMAStream=dma2stream2;\n\tBSP_DMA_Init(DMA2_Stream2, &amp;SPI_TX_DMA);<\/pre><\/div>\n\n\n\n<p>For the interrupt handler:<\/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 DMA2_Stream2_handler(void)\n{\n\tif((DMA2-&gt;LISR &amp; DMA_LISR_TCIF2)==DMA_LISR_TCIF2)\n\t{\n\t\tfinished=1;\n\t}\n\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In while loop:<\/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;}\">GPIO_WritePin(GPIOA,&amp;CS_Pin,Reset);\n\n\t\tBSP_DMA_Transfer_Single_Buffer(DMA2_Stream2, &amp;SPI1-&gt;DR,(uint32_t)&amp;SPI_TX,5);\n\n\t\twhile(finished ==0){;}\n\n\t\tfinished=0;\n\n\t\tGPIO_WritePin(GPIOA,&amp;CS_Pin,Set);\n\n\t\tBSP_Delay(200);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3.Code:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>You may download the source code from here:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/BSP-STM32F411_Nucleo64-1.zip\">BSP-STM32F411_Nucleo64-1<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/BSP-STM32F411_Nucleo64-1.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Using logic analyzer, connect the channels to PA5 and PA7 and you should get the following which is the array declared in the code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"676\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM-1024x676.png\" alt=\"\" class=\"wp-image-1944\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM-1024x676.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM-300x198.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM-768x507.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM-1150x759.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM-750x495.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM-400x264.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM-250x165.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-23-at-9.33.22-AM.png 1412w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this third section of the thirteenth part of board support package, we shall use the BSP of DMA to transfer data from the memory to peripheral which is SPI in this case. In this guide, we shall cover the following: Enabling DMA for SPI. Configure the DMA. Code. Results. 1. Enabling DMA for SPI: [&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-1940","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\/1940"}],"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=1940"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1940\/revisions"}],"predecessor-version":[{"id":1945,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1940\/revisions\/1945"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}