Skip to main content
AGarp.1
Associate II
December 25, 2019
Question

How to get UART DMA interrupt to work?

  • December 25, 2019
  • 3 replies
  • 1623 views

I have implemented the following code based on some examples on internet. It is supposed to trigger the DMA transfer complete callback put it does not. 99% of the code is generated using CubeMX IDE.

 The modified part of the code:

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	HAL_GPIO_TogglePin(GPIOA, LD2_Pin);
}
 
/* USER CODE END 0 */
 
/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{
 /* USER CODE BEGIN 1 */
 
 /* USER CODE END 1 */
 
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 
 /* USER CODE END Init */
 
 /* Configure the system clock */
 SystemClock_Config();
 
 /* USER CODE BEGIN SysInit */
 
 /* USER CODE END SysInit */
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_USART2_UART_Init();
 MX_DMA_Init();
 /* USER CODE BEGIN 2 */
 uint8_t pData[16];
 HAL_UART_Receive_DMA(&huart2, pData, 16);
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
 
 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}

Autogenerated DMA init:

static void MX_DMA_Init(void) 
{
 
 /* DMA controller clock enable */
 __HAL_RCC_DMA1_CLK_ENABLE();
 
 /* DMA interrupt init */
 /* DMA1_Channel6_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
 
}

What Im I doing wrong? The code I generate is basically the same as in examples across internet. I have a nuceo-L476RG board. Below is the CubeMX project attached:

Best,

Anders

This topic has been closed for replies.

3 replies

T J
Senior III
December 25, 2019

       (++) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA() and HAL_UART_Receive_DMA() APIs):

           (+++) Declare a DMA handle structure for the Tx/Rx channel.

           (+++) Enable the DMAx interface clock.

           (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.

           (+++) Configure the DMA Tx/Rx channel.

           (+++) Associate the initialized DMA handle to the UART DMA Tx/Rx handle.

           (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel.

AGarp.1
AGarp.1Author
Associate II
December 25, 2019

Thanks for the tip! Indeed it was the CubeMX placing the initialisation in the wrong order.