2015-07-06 04:36 AM
hej,
can anyone tell me why dma is not working?...but the usart works...volatile uint8_t Buffer[32];uint8_t receiveword;/**************************************************************************************/void gpio_Usart(){ //enable the usart RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); //enabling the port for usart6 GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 |GPIO_Pin_7; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd =GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_PinAFConfig(GPIOC, GPIO_PinSource6 , GPIO_AF_USART6); GPIO_PinAFConfig(GPIOC, GPIO_PinSource7 , GPIO_AF_USART6); //enable usart configuration USART_InitTypeDef USART_InitStruct; USART_InitStruct.USART_BaudRate = 9600; USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None ; USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;; USART_InitStruct.USART_Parity = USART_Parity_No; USART_InitStruct.USART_StopBits = USART_StopBits_1; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_Init(USART6, &USART_InitStruct); //enable usart USART_Cmd( USART6, ENABLE); //clock for leds RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); //GPIO intialization for leds GPIO_InitTypeDef GPIO_IntStruct; GPIO_IntStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_IntStruct.GPIO_OType = GPIO_OType_PP ; GPIO_IntStruct.GPIO_Pin = GPIO_Pin_12 |GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 ; GPIO_IntStruct.GPIO_PuPd = GPIO_PuPd_UP ; GPIO_IntStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_IntStruct);}/**************************************************************************************/void DMA_Nvic_Configuration(void){ //clock for dma RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_DMA2, ENABLE); DMA_DeInit(DMA2_Stream1); DMA_InitTypeDef DMA_InitStruct; DMA_InitStruct.DMA_Channel = DMA_Channel_5; DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralToMemory; // Receive DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)Buffer; DMA_InitStruct.DMA_BufferSize = (uint16_t)sizeof(Buffer); DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&USART6->DR; DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStruct.DMA_Mode = DMA_Mode_Circular; DMA_InitStruct.DMA_Priority = DMA_Priority_High; DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream1, &DMA_InitStruct); //enable dma2 DMA_Cmd(DMA2_Stream1, ENABLE); //usart request USART_DMACmd(USART6, USART_DMAReq_Rx, ENABLE); //enable the dma interrupt DMA_ITConfig(DMA2_Stream1, DMA_IT_TC | DMA_IT_HT, ENABLE); //enable interrupt for dma NVIC_InitTypeDef NVIC_InitStruct; NVIC_InitStruct.NVIC_IRQChannel = DMA2_Stream1_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct);}void DMA2_Stream1_IRQHandler(void){ /* Test on DMA Stream Transfer Complete interrupt */ if (DMA_GetITStatus(DMA2_Stream1, DMA_IT_TCIF1)) { /* Clear DMA Stream Transfer Complete interrupt pending bit */ DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1); GPIO_SetBits(GPIOD, GPIO_Pin_12); } /* Test on DMA Stream Half Transfer interrupt */ if (DMA_GetITStatus(DMA2_Stream1, DMA_IT_HTIF1)) { /* Clear DMA Stream Half Transfer interrupt pending bit */ DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_HTIF1); GPIO_SetBits(GPIOD, GPIO_Pin_13); }}void receiveUsart(){ while(USART_GetFlagStatus(USART6, USART_FLAG_RXNE) != SET); receiveword = USART6->DR;}int main(void){ int decremt = 32; printf(''decremt %d\n'', decremt); gpio_Usart(); DMA_Nvic_Configuration(); while(decremt) { receiveUsart(); printf(''receiveword %c\n'', receiveword); decremt--; } return 0;}2015-07-06 06:42 AM
Hi m.dums,
What do you mean by ''DMA is not working but USART is woking''?How did you checked this?-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2015-07-06 06:51 AM
i checked usart seperately by toggling the bits and print the characters in semihosting. but half transfer and full transfer interrupt is not trigerring ....
Do you know why ?2015-07-06 07:01 AM
May be you should have the IRQ toggle the LED's
Not sure you're going to see RXNE if the DMA is servicing it correctly. Don't exit main(), only bad things can happen.2015-07-06 10:49 AM
Don't poll RXNE, don't enable the RXNE interrupt and most important of all DO NOT read the DR register when DMA is enabled. The DMA controller will trigger on the RXNE and read DR; you are interfering with the DMA hardware
In the DMA IRQ handler you also need to check for errors. If DMA stops the error flags will tell you why. Jack Peacock2015-07-07 01:42 AM
Hi,
I suggest you have a look to the example in the standard library (For STM32F4), folder: Project\STM32F4xx_StdPeriph_Examples\USART\USART_TwoBoards\USART_DataExchangeDMA.It may bring you some help.-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2015-07-07 02:58 AM
clive, i ahve tried what u told. but its not even going to interrupt handlar..
any idea to solve?2015-07-07 05:11 AM
Want to enable the DMA2 clock, not reset it
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_DMA2, ENABLE);
2015-07-07 06:24 AM
copied wrongly from coocox ....did not notice properly...
now it works....thank you :)