title: Copying 16-bit data with DMA on the STM32
body: <p>How do I use DMA to copy ADC data into a 16-bit buffer? The STM32F373 has a 16-bit ADC that can be read using the HAL function:
  <code>HAL_StatusTypeDef HAL_SDADC_InjectedStart_DMA(SDADC_HandleTypeDef *hsdadc, uint32_t *pData, uint32_t Length)</code></p>
  <p>This DMA initializer wants a pointer to an array of <code>uint32_t</code> values. However, the ADC's native data format is <code>int16_t</code> so I want DMA to put the data into <code>int16_t adc_data[ADC_BUFFER_LENGTH]</code> by calling:</p>
  <p><code>HAL_SDADC_InjectedStart_DMA(&amp;hsdadc, adc_data, ADC_BUFFER_LENGTH);</code></p>
  <p>This seems to work fine but throws an incompatible pointer type warning. I am confused about the correct way to fix this. Should I passing <code>(uint32_t*)adc_data</code> instead? How does the DMA know the correct array step size for a 16-bit array vs a 32-bit array? What would have happened if I passed an <code>int32_t</code> array instead, would the data align correctly?</p>
  <p>When I dig into <code>HAL_SDADC_InjectedStart_DMA()</code> I find the call to: <code>HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)</code> which only takes generic uint32_t pointers without any reference to the step increment. This leaves me more confused about how this actually works.</p>
  <p>Note: While I am specifically trying to get this STM32 ADC to work I think this question is much more general. There are many times you might want to copy 16-bit data with DMA.</p>