STM32 Peripheral DMA Usage Summary:
1. Select Dam mode as required:
(1) cycle mode-dma_mode = Dma_mode_circular
(2) Normal mode-dma_mode = Dma_mode_normal
2. For DMA1 Chanel3, the corresponding peripheral is USART3 rx
Imagine: If the serial receive interrupt and the dam interrupt open simultaneously, how the CPU corresponds?
(1) Interrupt priority is different: this is to say, support for nested interrupts (NVIC) CORTEX-M3 Natural Priority Service Interrupt high priority
(2) interrupt priority is the same: processing principle, first to deal with, if at the same time, the interrupt number is low priority processing
the manual indicates that the DMA (IRQN number 13) will be processed by the CPU prior to USART3 (39)
3, set the DMA mode to cycle mode, then:
(1) DMA interrupt only, turn off peripheral interrupt, will only go in Once DMA service function
(2) Turn on DMA interrupt, turn on peripheral interrupt, just loop into DMA service function
4. When turning on multiple DMA interrupts, note the priority setting for each interrupt
5, in the interrupt function, disable DMA enable after you want to reset the DMA transfer data volume size and turn on the DMA
void Dma1_channel3_irqhandler (void) {if (Dma_getitstatus (DMA1_FLAG_TC3)) {dma_clearitpendingbit (DMA1_IT_GL3);/* Turn off DMA during data processing, prevent data tampering */dma_cmd (DMA1_CHANNEL3, DISABLE);/* Process data *//* Reset DMA transfer data size and turn on DMA */DMA1_CHANNEL3->CNDTR = DMA _CH3_RECV_BYTES;DMA1_CHANNEL3->CCR |= dma_ccr3_en;}}
6. DMA Configuration options:
typedef struct{/* Sets the peripheral base address of the DMA transmission, such as Usart DMA transmission, Base address (uint32_t) usart3-dr */uint32_t dma_peripheralbaseaddr;/* Sets the DMA memory base address, the memory address that holds the DMA transmits the data */uint32_t dma_memorybaseaddr;/* operation Peripheral is the source ground (takes data from the peripheral), the destination (sends the data to the peripheral) */uint32_t Dma_dir; /* The size of the data volume of the DMA transfer */uint32_t dma_buffersize; /* The peripheral address is automatically incremented, such as for Usart DMA transmission, the peripheral address is a fixed */uint32_t dma_peripheralinc; /* Ibid., except for memory address */uint32_t dma_memoryinc;/* Set peripheral data width, 8bits/16bits/31bits */uint32_t dma_peripheraldatasize; /* Ibid. */uint32_t dma_memorydatasize; /* Select dam mode, loop mode or Normal mode */uint32_t dma_mode;/* DMA Channel priority, Dma_priority_veryhigh,dma_priority_high,dma_priority_medium , Dma_priority_low *//* If multiple DMA channels are turned on, remember to set the appropriate value */uint32_t dma_priority;/* set DMA to mem mode */uint32_t dma_m2m;} Dma_inittypedef;
STM32 Peripheral DMA Usage Summary