cancel
Showing results for 
Search instead for 
Did you mean: 

DMA2 RX stream5 CM4 not working

PVaaz.1
Associate III

Hello ,

I am trying to configure RX (only) with dma. I am using DMA2 stream5 on usart3

I have connected USB to UART bridge (4 wire) on 40 pin headers RX,TX,VDD(3) and GND on CN7. Whenever I am trying to send any data from the comport (teraterm ) from windows PC , nothing happens (on the RX side) on the CM4 of MPU.

My code :

  /* Peripheral clock enable */

  __HAL_RCC_USART3_CLK_ENABLE();

  __HAL_RCC_GPIOB_CLK_ENABLE();

  /**USART3 GPIO Configuration

  PB10   ------> USART3_TX

  PB12   ------> USART3_RX

  */

  GPIO_InitStruct.Pin = GPIO_PIN_10;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF7_USART3;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_12;

  GPIO_InitStruct.Mode = GPIO_MODE_AF;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Alternate = GPIO_AF8_USART3;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* USART3 DMA Init */

  /* USART3_RX Init */

  hdma_usart3_rx.Instance = DMA2_Stream5;

  hdma_usart3_rx.Init.Request = DMA_REQUEST_USART3_RX;

  hdma_usart3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;

  hdma_usart3_rx.Init.PeriphInc = DMA_PINC_DISABLE;

  hdma_usart3_rx.Init.MemInc = DMA_MINC_ENABLE;

  hdma_usart3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

  hdma_usart3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

  hdma_usart3_rx.Init.Mode = DMA_NORMAL;

  hdma_usart3_rx.Init.Priority = DMA_PRIORITY_LOW;

  hdma_usart3_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

  if (HAL_DMA_Init(&hdma_usart3_rx) != HAL_OK)

  {

   Error_Handler();

  }

  __HAL_LINKDMA(huart,hdmarx,hdma_usart3_rx);

  /* USART3 interrupt Init */

  HAL_NVIC_SetPriority(USART3_IRQn, 1, 0);

  HAL_NVIC_EnableIRQ(USART3_IRQn);

 /* USER CODE BEGIN USART3_MspInit 1 */

it.c :

void USART3_IRQHandler(void)

{

 /* USER CODE BEGIN USART3_IRQn 0 */

 /* USER CODE END USART3_IRQn 0 */

 HAL_UART_IRQHandler(&huart3);

 /* USER CODE BEGIN USART3_IRQn 1 */

 /* USER CODE END USART3_IRQn 1 */

}

/**

 * @brief This function handles DMA2 stream5 global interrupt.

 */

void DMA2_Stream5_IRQHandler(void)

{

 /* USER CODE BEGIN DMA2_Stream5_IRQn 0 */

 /* USER CODE END DMA2_Stream5_IRQn 0 */

 HAL_DMA_IRQHandler(&hdma_usart3_rx);

 /* USER CODE BEGIN DMA2_Stream5_IRQn 1 */

 /* USER CODE END DMA2_Stream5_IRQn 1 */

}

I am polling : (__HAL_DMA_GET_FLAG(handle_dma, __HAL_DMA_GET_TE_FLAG_INDEX(handle_dma))

but getting the counter always 1.

> baudrates and reversing Rx,Tx I have already done.

Can you please assist where else I can debug?

Regards,

2 REPLIES 2
ASega.1
Associate III

Hi,

I have only a suggestion. Check if the DMA_Init is before UART3_Init in the main.c.

Sorry for so poor information. Good luck.

Best Regards,

Andrea

Thaks Andrea, this is a good suggestion. I will try this out and update here

Regards