Skip to content

Instantly share code, notes, and snippets.

@csrohit
Last active October 30, 2023 10:22
Show Gist options
  • Save csrohit/61e16ff03854c064b14b48f8120d2d9f to your computer and use it in GitHub Desktop.
Save csrohit/61e16ff03854c064b14b48f8120d2d9f to your computer and use it in GitHub Desktop.
Supporting gist for circular DMA operation
// enable circular mode
DMA1_Channel4->CCR |= DMA_CCR_CIRC;
// enable interrpt after full transfer
DMA1_Channel4->CCR |= DMA_CCR_TCIE;
const char * msg = "Hello world\r\n\0";
// set memory address to address of string
DMA1_Channel4->CMAR = (uint32_t)msg;
// set number od dma transactions
DMA1_Channel4->CNDTR = 13;
// USART TX is mapped to DMA1 channel 4
// set peripheral address to USART data register
DMA1_Channel4->CPAR = (uint32_t)&USART1->DR;
// Enable DMA mode for transmitter
USART1->CR3 |= USART_CR3_DMAT;
DMA1_Channel4->CCR |= DMA_CCR_EN;
int main(void)
{
dma1_clock_enable();
usart1_init();
dma_usart_tx_init();
dma_usart_tx_enable();
usart1_enable();
while (1);
}
// set priprity to lowest value
DMA1_Channel4->CCR &= ~(DMA_CCR_PL_0 | DMA_CCR_PL_1);
// set data transfer direction - memory -> peripheral
DMA1_Channel4->CCR |= DMA_CCR_DIR;
// set memory address size to 8 bits (Address is incremented by this much)
DMA1_Channel4->CCR &= ~(DMA_CCR_MSIZE_0 | DMA_CCR_MSIZE_0);
// set peripheral size to 8 bits (Has no effect as this is not incremented)
DMA1_Channel4->CCR &= ~(DMA_CCR_PSIZE_0 | DMA_CCR_PSIZE_0);
// set memory address incement by 1byte
DMA1_Channel4->CCR |= DMA_CCR_MINC;
// disable increment mode on peripheral address
DMA1_Channel4->CCR &= ~DMA_CCR_PINC;
@SoftHard-dev
Copy link

how it works?

@csrohit
Copy link
Author

csrohit commented Oct 30, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment