/* DMA Stream Enable Transfer Direction. 
Ensure that the stream is disabled otherwise the setting will not be changed. */
void dma_set_transfer_mode(uint32_t dma, uint8_t stream, uint32_t direction)
/* DMA Stream Enable Transfer Direction. 
Ensure that the stream is disabled otherwise the setting will not be changed. */
void dma_set_transfer_mode(uint32_t dma, uint8_t stream, uint32_t direction)
{
	uint32_t reg32 = (DMA_SCR(dma, stream) & ~DMA_SxCR_DIR_MASK);
	if (direction == DMA_SxCR_DIR_MEM_TO_MEM) {
		reg32 &= ~(DMA_SxCR_CIRC | DMA_SxCR_DBM);
	}
	DMA_SCR(dma, stream) = (reg32 | direction);
}