This is an old revision of the document!
Direct Memory Access
The two DMA controller can be used to quickly transfer data between two peripherals (or memory) without any CPU interaction.
Features
- 8 streams for each DMA controller, up to 8 channels per stream.
- 4 (32 bit wide) FIFO buffer per stream.
- Programmable priority.
Programming Example
The code snippet bellow shows how to configure and use the DMA controller.
#include "reg_stm32f4xx.h" RCC->AHBENR[0] |= (0x1 << 22u); /* Enable DMA2 clock */ /* Configure DMA2 controller. */ DMA2->STREAM[0].CR |= (2u << 25u); /* Setup channel. */ DMA2->STREAM[0].CR |= (0x0 << 6u); /* Setup direction. */ DMA2->STREAM[0].CR |= (0x1 << 8u); /* Setup circular mode. */ DMA2->STREAM[0].NDTR |= 1u; /* Setup nr of transfers. */ /* Setup source and destination. */ DMA2->STREAM[0].PAR |= (uint32_t) &(ADC3->DR); DMA2->STREAM[0].M0AR |= (uint32_t) &(TIM3->CCR[0]); /* Setup buffer size. */ DMA2->STREAM[0].CR |= (0x1 << 11u); /* PSIZE */ DMA2->STREAM[0].CR |= (0x1 << 13u); /* MSIZE */ /* Start DMA transfer. */ DMA2->STREAM[0].CR |= (0x1 << 0u);
Configuration Registers
CRx
CR1
Configuration register 1
(not used in I²S mode)
MSTR | 0 | Slave mode (reset state) | ||
1 | Master mode | |||
BR | 000 | BR ⇒ fPCLK2 / 2 (reset state) | 100 | BR ⇒ fPCLK2 / 32 |
001 | BR ⇒ fPCLK2 / 4 | 101 | BR ⇒ fPCLK2 / 64 | |
010 | BR ⇒ fPCLK2 / 8 | 110 | BR ⇒ fPCLK2 / 128 | |
011 | BR ⇒ fPCLK2 / 16 | 111 | BR ⇒ fPCLK2 / 256 | |
SPE | 0 | SPI disabled (reset state) | ||
1 | SPI enabled | |||
LSBFIRST | 0 | MSB transmitted first (reset state) | ||
1 | LSB transmitted first | |||
SSM | 0 | Slave management by hw (reset state) | ||
1 | Slave management by sw | |||
DFF | 0 | Data frame: 8 bit (reset state) | ||
1 | Data frame: 16 bit |