Last active
October 30, 2023 10:22
-
-
Save csrohit/61e16ff03854c064b14b48f8120d2d9f to your computer and use it in GitHub Desktop.
Supporting gist for circular DMA operation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// enable circular mode | |
DMA1_Channel4->CCR |= DMA_CCR_CIRC; | |
// enable interrpt after full transfer | |
DMA1_Channel4->CCR |= DMA_CCR_TCIE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char * msg = "Hello world\r\n\0"; | |
// set memory address to address of string | |
DMA1_Channel4->CMAR = (uint32_t)msg; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set number od dma transactions | |
DMA1_Channel4->CNDTR = 13; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// USART TX is mapped to DMA1 channel 4 | |
// set peripheral address to USART data register | |
DMA1_Channel4->CPAR = (uint32_t)&USART1->DR; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enable DMA mode for transmitter | |
USART1->CR3 |= USART_CR3_DMAT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DMA1_Channel4->CCR |= DMA_CCR_EN; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(void) | |
{ | |
dma1_clock_enable(); | |
usart1_init(); | |
dma_usart_tx_init(); | |
dma_usart_tx_enable(); | |
usart1_enable(); | |
while (1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set priprity to lowest value | |
DMA1_Channel4->CCR &= ~(DMA_CCR_PL_0 | DMA_CCR_PL_1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how it works?