other/dma2mem: Fix typos and coding-style.

This commit is contained in:
Uwe Hermann 2011-11-12 15:01:01 +01:00
parent 793bd23851
commit 61ff27cfbe
2 changed files with 25 additions and 18 deletions

View File

@ -2,7 +2,7 @@
README README
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
This program demonstrates a little DMA MEM2MEM transfer. A string is send out This program demonstrates a little DMA MEM2MEM transfer. A string is sent out
to USART1 and afterwards copied by DMA to another memory location. To check to USART1 and afterwards copied by DMA to another memory location. To check
if the transfer was successful we send the destination string also out to if the transfer was successful we send the destination string also out to
USART1. USART1.

View File

@ -57,7 +57,7 @@ void gpio_setup(void)
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7); GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
} }
void my_usart_print_string(u32 usart, char * s) void my_usart_print_string(u32 usart, char *s)
{ {
while (*s != 0) { while (*s != 0) {
usart_send(usart, *s); usart_send(usart, *s);
@ -67,8 +67,10 @@ void my_usart_print_string(u32 usart, char * s)
int main(void) int main(void)
{ {
/* Exactly 20 bytes including '0' at the end. /*
We want to transfer 32bit * 5 so it should fit */ * Exactly 20 bytes including '\0' at the end.
* We want to transfer 32bit * 5 so it should fit.
*/
char s1[20] = "Hello STM MEM2MEM\r\n"; char s1[20] = "Hello STM MEM2MEM\r\n";
char s2[20]; char s2[20];
@ -94,7 +96,10 @@ int main(void)
dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR1_MSIZE_32BIT); dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR1_MSIZE_32BIT);
dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR1_PSIZE_32BIT); dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR1_PSIZE_32BIT);
/* After each 32Bit we have to increase the addres because we use RAM. */ /*
* After every 32bits we have to increase the address because
* we use RAM.
*/
dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL1); dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL1);
dma_enable_peripheral_increment_mode(DMA1, DMA_CHANNEL1); dma_enable_peripheral_increment_mode(DMA1, DMA_CHANNEL1);
@ -102,23 +107,24 @@ int main(void)
dma_set_read_from_peripheral(DMA1, DMA_CHANNEL1); dma_set_read_from_peripheral(DMA1, DMA_CHANNEL1);
/* We want to transfer string s1. */ /* We want to transfer string s1. */
dma_set_peripheral_address(DMA1, DMA_CHANNEL1, (u32) &s1); dma_set_peripheral_address(DMA1, DMA_CHANNEL1, (u32)&s1);
/* Destination should be string s2. */ /* Destination should be string s2. */
dma_set_memory_address(DMA1, DMA_CHANNEL1, (u32) &s2); dma_set_memory_address(DMA1, DMA_CHANNEL1, (u32)&s2);
/* Set number of DATA to transfer. /*
Remember that this means not necessary bytes but MSIZE or PSIZE * Set number of DATA to transfer.
depending from your source device. */ * Remember that this means not necessary bytes but MSIZE or PSIZE
* depending on your source device.
*/
dma_set_number_of_data(DMA1, DMA_CHANNEL1, 5); dma_set_number_of_data(DMA1, DMA_CHANNEL1, 5);
/* Start DMA transfer. */ /* Start DMA transfer. */
dma_enable_channel(DMA1, DMA_CHANNEL1); dma_enable_channel(DMA1, DMA_CHANNEL1);
/* TODO: write a function to get the interrupt flags. */ /* TODO: Write a function to get the interrupt flags. */
while(!(DMA_ISR(DMA1) & 0x0000001)) while (!(DMA_ISR(DMA1) & 0x0000001))
{ ;
}
dma_disable_channel(DMA1, DMA_CHANNEL1); dma_disable_channel(DMA1, DMA_CHANNEL1);
@ -127,7 +133,8 @@ int main(void)
my_usart_print_string(USART1, s2); my_usart_print_string(USART1, s2);
gpio_clear(GPIOB, GPIO6); /* LED2 on */ gpio_clear(GPIOB, GPIO6); /* LED2 on */
while(1); /* Halt. */
while (1); /* Halt. */
return 0; return 0;
} }