How to use DMA in circular mode on STM32?
Using DMA in circular mode on STM32 basically means: “Keep filling the same buffer in RAM over and over, wrapping around when you reach the end.” This is perfect for continuous ADC sampling , UART RX streams , audio , etc. Here’s how to do it, in practical steps. 1. Basic idea Peripheral data register → DMA → RAM buffer. DMA writes: buf[0] … buf[N-1] then automatically wraps back to buf[0] and continues. Your code never restarts the DMA; it just reads from the buffer while DMA keeps filling it. 2. Create the buffer in RAM Example for an ADC (16-bit samples): # define ADC_BUF_LEN 256 uint16_t adc_buf[ADC_BUF_LEN]; Example for UART RX (8-bit): # define UART_RX_BUF_LEN 128 uint8_t uart_rx_buf[UART_RX_BUF_LEN]; Make sure the buffer is global or static so it stays allocated. 3. Configure DMA in circular mode (HAL example) Let’s say you’re using STM32Cube HAL. 3.1. In CubeMX / code, set: Direction : Peripheral → Memory Mode : DMA_...