# DMA Init code for ADC sampled data

I am trying to figure out how this DMA Initialization code is used to sample following 4 ADC channels and save data in 'adc_data'.

ADC1: channel 1 & channel 3.
ADC2: channel 2 & channel 4.


To me it looks like incomplete code as it is only initializing ADC1 but not ADC2. My MCU is STM32L476.

extern volatile uint32_t adc_data[];

RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN; // DMA1
// Wait a bit
nop(); nop(); nop(); nop(); nop(); nop();
DMA1_Channel1->CNDTR = 2;
DMA1_Channel1->CCR = DMA_CCR_MSIZE_1 | DMA_CCR_PSIZE_1 | DMA_CCR_MINC |
DMA_CCR_CIRC | DMA_CCR_TCIE | DMA_CCR_EN;

• It is incomplete code indeed. You need to see where adc_data is allocated. Somewhere someone must tell the linker what adc_data is and where it is allocated. This is one of many reasons why we should never do spaghetti programming with extern. – Lundin Apr 16 '19 at 10:39

In the code to use the samples they should get extracted from the adc_data[] as they won't be useful as a single uint32_t.