UART4 DMA Rx Problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 4:21 AM
I cannot get into DMA mode, the code I wrote did not get into DMA interrupt. The code I wrote is as follows. Any advice?( my processor is STM32F103ZG)
uint8_t RxBuffer1[100]; /*UART - Pin Config*/ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; DMA_InitTypeDef DMA_InitStructure;; /* Clock configuration -------------------------------------------------------*/ RCC_APB2PeriphClockCmd( UART_GPIO_CLK_TX | UART_GPIO_CLK_RX | RCC_APB2Periph_AFIO, ENABLE); RCC_APB1PeriphClockCmd(UART_CLK , ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,ENABLE); /* Configure the GPIO ports( UART4 Transmit and Receive Lines) */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = UART_TxPin; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(UART_GPIO_TX, &GPIO_InitStructure); /* Configure the UART4_Rx as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = UART_RxPin ; GPIO_Init(UART_GPIO_RX, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 1200; USART_InitStructure.USART_WordLength = USART_WordLength_9b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Even; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* UART Guard Time set to 16 Bit */ USART_SetGuardTime(UART4, 8); USART_Init(UART4, &USART_InitStructure); /* Enable the UART4 */ USART_Cmd(UART4, ENABLE); /************************* DMA *****************************/ DMA_DeInit(DMA2_Channel3); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&UART4->DR; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)RxBuffer1; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // Receive DMA_InitStructure.DMA_BufferSize = 1; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA2_Channel3, &DMA_InitStructure); /* Enable the USART Rx DMA request */ USART_DMACmd(UART4, USART_DMAReq_Rx, ENABLE); /* Enable DMA Transfer Complete interrupt */ DMA_ITConfig(DMA2_Channel3, DMA_IT_TC, ENABLE); /* Enable the DMA RX Stream */ DMA_Cmd(DMA2_Channel3, ENABLE); /* Enable the UART4 RX DMA Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /*******************************************************************/ void DMA2_Channel3_IRQHandler(){ if(DMA_GetITStatus(DMA2_IT_TC3)){ Uart_Interrupt_Handler(); DMA_ClearITPendingBit(DMA2_IT_TC3); }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 4:40 AM
>
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // Receive
? JW- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 4:47 AM
Don't we choose ''DMA_DIR_PeripheralDST'' when interrupt comes Rx Pin ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 4:52 AM
Don't we choose ''DMA_DIR_PeripheralDST'' when interrupt comes Rx Pin ?
NO, you're configuring a DMA transaction, which you want to READ the Peripheral register, and WRITE to Memory, this would mean the Peripheral is the SOURCE (SRC), right?Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 5:00 AM
Is my BufferSize correct ?
I want to get into IRQ for each byte ?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 5:08 AM
I changed the DMA_DIR_PeripheralDST to DMA_DIR_PeripheralSRC .
But i cannot still get into the interrupt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 5:37 AM
If you use Normal mode you'll need to reinitialize the DMA on each interrupt
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 5:54 AM
I changed the DMA_InitStructure.DMA_Mode to DMA_Mode_Circular but the problem has not solved.
Is there an error on IRQ Configuring ?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 7:20 AM
to be migrated, sourceId: 40316:697285D7-A9CA-445D-B16C-F23BF0E3B1A3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-04 8:30 AM
The last version is following below. I cannot understand where is the wrong ?
A cursory review suggests the code is not unreasonable, although I honestly can't see the point of doing a one byte DMA, and how that's materially more useful than just doing an RXNE interrupt. Are you actually receiving any data? If you make a simple polled mode version, or echo back, does that actually work?
Up vote any posts that you find helpful, it shows what's working..
