Page 1 of 1

Add macro to read DMA Current Target (CR:CT) on STM32

Posted: Thu Jul 27, 2017 10:15 am
by FXCoder
When using DMA double buffer mode, changing MxAR is allowed for the non-active MxAR.
The non-active MxAR is determined by reading the CT bit of the CR.
A macro to read the CT bit could be added in os\hal\ports\STM32\LLD\DMAv2\stm32_dma.h and become part of the standard Chibios DMA macro set.
Suggested implementation...

Code: Select all

/**
 * @brief   DMA stream current target.
 * @note    This function can be invoked in both ISR or thread context.
 * @pre     The stream must have been allocated using @p dmaStreamAllocate().
 * @post    After use the stream can be released using @p dmaStreamRelease().
 *
 * @param[in] dmastp    pointer to a stm32_dma_stream_t structure
 * @return  Current memory target index
 *
 * @special
 */
#define dmaStreamGetCurrentTarget(dmastp)                                              \
    ((uint8_t)(((dmastp)->stream->CR >> DMA_SxCR_CT_Pos) & 1U))

Re: Add macro to read DMA Current Target (CR:CT) on STM32

Posted: Sun Sep 24, 2017 4:27 pm
by Giovanni
Hi,

Added to trunk but I removed the cast to uint8_t, those can make code slower on ARM.

Giovanni