cancel
Showing results for 
Search instead for 
Did you mean: 

Circular DMA seems to "doublebuffer" (STM32F427)

turboscrew
Senior III

What is it that I've been missing...

I set a timer to trig 7-channel ADC with DMA. The DMA is set to make 7 16-bit to 16-bit transfers circularly. It seemed to work fine, but some data started to corrupt. So I made the 7x16-bit buffer 4-fold (28 16-bit numbers) and it got half-written. It looks like the data is stored in two 7x16-bit blocks.

The actual doublebuffering was not used and the DMA_S0M1AR was zero.

(Checked in the Atollic debugger special register view.)

24 REPLIES 24
turboscrew
Senior III

I found out. It was bad way of starting the DMA, but really can't blame the original writer:

/**

 * @brief Enables ADC DMA request after last transfer (Single-ADC mode) and enables ADC peripheral 

 * @param hadc pointer to a ADC_HandleTypeDef structure that contains

 *        the configuration information for the specified ADC.

 * @param pData The destination Buffer address.

 * @param Length The length of data to be transferred from ADC peripheral to memory.

 * @retval HAL status

 */

HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)

The guy had set length to "sizeof(uint16_t) * NUMBER_OF_ADC_CHANNELS".

Turned out that the parameter should be number of transfers, not data size in bytes.

What I still don't understand is, why did the debugger show "7" in the special register view. When I set breakpoint in the transfer complete interrupt handler before I started the program, then I saw 0x0e there instead of 7.

HAL description could be better, but it's still that guy's fault. When you read "length", you should immediately ask yourself: "In what units?" 🙂

Not really: if its byte thansfers, the "length" is bigger than if it was word transfers. So 10 bytes with byte transfers is "longer" (10) than 16 bytes with word transfer (4). Transfer count is not really an unit of length or size. It's not even "length in time"-unit.

It it's still that guy's fault. When you read "HAL", you should immediately ask yourself: "Why?" 😉

JW

:D :D :D