2015-03-06 05:21 AM
Hi.
I am a newbe in STM32 microcontroles. I have problems with starting the DMA transfer to UART. This is my init for UART. /* * Helpers for DMA configuration */ static UART_HandleTypeDef *hRS232_handle=&RS232_handle; static DMA_HandleTypeDef RS232_RX_DMA_handle; static DMA_HandleTypeDef RS232_TX_DMA_handle; /* * GPIO UART pin configuration */ /* * GPIO Clock enable */ __GPIOA_CLK_ENABLE(); /* * Configure GPIO RX & TX Pins. * For UART2 TX - PA2 * For UART2 RX - PA3 */ GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF1_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* * USART port clock enable */ __USART2_CLK_ENABLE(); /* * Configure USART parameters */ RS232_handle.Instance = USART2; RS232_handle.Init.BaudRate = 300; RS232_handle.Init.WordLength = USART_WORDLENGTH_8B; RS232_handle.Init.StopBits = USART_STOPBITS_1; RS232_handle.Init.Parity = USART_PARITY_NONE; RS232_handle.Init.Mode = USART_MODE_TX_RX; RS232_handle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; /* * Configure DMA Clock */ __DMA1_CLK_ENABLE(); /* * Configure DMA RX Channel */ RS232_RX_DMA_handle.Instance = DMA1_Channel4; RS232_RX_DMA_handle.Init.Direction = DMA_PERIPH_TO_MEMORY; RS232_RX_DMA_handle.Init.PeriphInc = DMA_PINC_DISABLE; RS232_RX_DMA_handle.Init.MemInc = DMA_MINC_ENABLE; RS232_RX_DMA_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; RS232_RX_DMA_handle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; RS232_RX_DMA_handle.Init.Mode = DMA_NORMAL; RS232_RX_DMA_handle.Init.Priority = DMA_PRIORITY_LOW; HAL_DMA_Init(&RS232_RX_DMA_handle); __HAL_LINKDMA(hRS232_handle, hdmarx, RS232_RX_DMA_handle); /* * Interrupt for DMA TX channel. */ HAL_NVIC_SetPriority(DMA1_Channel4_5_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Channel4_5_IRQn); /* * Configure DMA TX Channel */ RS232_TX_DMA_handle.Instance = DMA1_Channel5; RS232_TX_DMA_handle.Init.Direction = DMA_MEMORY_TO_PERIPH; RS232_TX_DMA_handle.Init.PeriphInc = DMA_PINC_DISABLE; RS232_TX_DMA_handle.Init.MemInc = DMA_MINC_ENABLE; RS232_TX_DMA_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; RS232_TX_DMA_handle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; RS232_TX_DMA_handle.Init.Mode = DMA_NORMAL; RS232_TX_DMA_handle.Init.Priority = DMA_PRIORITY_HIGH; HAL_DMA_Init(&RS232_TX_DMA_handle); __HAL_LINKDMA(hRS232_handle, hdmatx, RS232_TX_DMA_handle); /* * Interrupt for DMA TX channel. */ HAL_NVIC_SetPriority(DMA1_Channel4_5_IRQn, 0, 1); HAL_NVIC_EnableIRQ(DMA1_Channel4_5_IRQn); /* * Configure Interrupt for UART */ HAL_NVIC_SetPriority(USART2_IRQn, 0, 1); HAL_NVIC_EnableIRQ(USART2_IRQn); /* * Initialize USART */ HAL_UART_Init(&RS232_handle); For DMA IRQ: void DMA1_Channel4_5_IRQHandler(void){ HAL_DMA_IRQHandler(RS232_handle.hdmatx); HAL_DMA_IRQHandler(RS232_handle.hdmarx); } Everything works fine when I am using the Polling mode - HAL_UART_Transmit But when I am trying to use HAL_UART_Transmit_DMA, I can not see any transfer form the UART. When I try to use breakpoint on IRQ, the breakpoint never stops the program.2015-03-24 04:59 AM
Solved.
The DMA Channels has been mixed up.For UART 2 TX the proper DMA Channel is 4For UART 2 TX the proper DMA Channel is 52015-03-24 05:00 AM
Found it.
The DMA channels has been mixed up.For UART 2 TX propper DMA channel is 4For UART 2 RX propper DMA channel is 5.