cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect DMA transfer when address isn't aligned.

OGhis
Senior

Hi,

We using the HAL_ADC_Start_DMA() function and this function works very fine when the pData pointer is aligned to 4. (data transfer is DMA_PDATAALIGN_WORD)

Unaligned data can be happen when the *pData is defined as a structure and the structure is packed " __attribute__((pack(1)))"

The function HAL_ADC_Start_DMA() returns always HAL_OK even when the buffer address is incorrect and than are other memory locations override.

I suggest to add to HAL function an ASSERT at least.

ex.:

  if (hadc->DMA_Handle->Init.PeriphDataAlignment == DMA_PDATAALIGN_WORD) {
    assert_param((((uint32_t)pData) & 0x03uL) == 0);
  } else if (hadc->DMA_Handle->Init.PeriphDataAlignment == DMA_PDATAALIGN_HALFWORD) {
    assert_param((((uint32_t)pData) & 0x01uL) == 0);
  }

0 REPLIES 0