cancel
Showing results for 
Search instead for 
Did you mean: 

DMA USART callback function

ilyaz yilmaz
Associate III

Hello,

Stm32 F401RE Hal Library 2016 Works.

Stm32 F401RE Hal Library 2017(last version) DOESNT Works.

For Test purpose only I use USART DMA Send function. Main.C is like that...

Also This StMicroelectrincs youtube vide work 2016 HAL Library but it doesnt work 2017 Hal Library. Video is very simple actually. I test it maybe 10 times. but 2017 Hal Library doesnt work.

https://www.youtube.com/watch?v=BxFYmBYBmaU

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

uint8_t data_tx[5] = {0x41 , 0x42 ,0x43 ,0x44 , 0x45};

/* 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_DMA_Init();

 MX_USART2_UART_Init();

 MX_USART1_UART_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

   /* USER CODE END WHILE */

   /* USER CODE BEGIN 3 */

    HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

    HAL_UART_Transmit_DMA(&huart1, data_tx, 5);

    HAL_Delay(500);

 }

 /* USER CODE END 3 */

}

/* USER CODE BEGIN 4 */

uint64_t cnt1;

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)

{

   cnt1++;

}

/* USER CODE END 4 */

I Will also add interrupt file

extern DMA_HandleTypeDef hdma_usart1_rx;

extern DMA_HandleTypeDef hdma_usart1_tx;

/* USER CODE BEGIN EV */

/* USER CODE END EV */

/******************************************************************************/

/*          Cortex-M4 Processor Interruption and Exception Handlers         */

/******************************************************************************/

/**

 * @brief This function handles Non maskable interrupt.

 */

void NMI_Handler(void)

{

 /* USER CODE BEGIN NonMaskableInt_IRQn 0 */

 /* USER CODE END NonMaskableInt_IRQn 0 */

 /* USER CODE BEGIN NonMaskableInt_IRQn 1 */

 /* USER CODE END NonMaskableInt_IRQn 1 */

}

/**

 * @brief This function handles Hard fault interrupt.

 */

void HardFault_Handler(void)

{

 /* USER CODE BEGIN HardFault_IRQn 0 */

 /* USER CODE END HardFault_IRQn 0 */

 while (1)

 {

   /* USER CODE BEGIN W1_HardFault_IRQn 0 */

   /* USER CODE END W1_HardFault_IRQn 0 */

 }

}

/**

 * @brief This function handles Memory management fault.

 */

void MemManage_Handler(void)

{

 /* USER CODE BEGIN MemoryManagement_IRQn 0 */

 /* USER CODE END MemoryManagement_IRQn 0 */

 while (1)

 {

   /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */

   /* USER CODE END W1_MemoryManagement_IRQn 0 */

 }

}

/**

 * @brief This function handles Pre-fetch fault, memory access fault.

 */

void BusFault_Handler(void)

{

 /* USER CODE BEGIN BusFault_IRQn 0 */

 /* USER CODE END BusFault_IRQn 0 */

 while (1)

 {

   /* USER CODE BEGIN W1_BusFault_IRQn 0 */

   /* USER CODE END W1_BusFault_IRQn 0 */

 }

}

/**

 * @brief This function handles Undefined instruction or illegal state.

 */

void UsageFault_Handler(void)

{

 /* USER CODE BEGIN UsageFault_IRQn 0 */

 /* USER CODE END UsageFault_IRQn 0 */

 while (1)

 {

   /* USER CODE BEGIN W1_UsageFault_IRQn 0 */

   /* USER CODE END W1_UsageFault_IRQn 0 */

 }

}

/**

 * @brief This function handles System service call via SWI instruction.

 */

void SVC_Handler(void)

{

 /* USER CODE BEGIN SVCall_IRQn 0 */

 /* USER CODE END SVCall_IRQn 0 */

 /* USER CODE BEGIN SVCall_IRQn 1 */

 /* USER CODE END SVCall_IRQn 1 */

}

/**

 * @brief This function handles Debug monitor.

 */

void DebugMon_Handler(void)

{

 /* USER CODE BEGIN DebugMonitor_IRQn 0 */

 /* USER CODE END DebugMonitor_IRQn 0 */

 /* USER CODE BEGIN DebugMonitor_IRQn 1 */

 /* USER CODE END DebugMonitor_IRQn 1 */

}

/**

 * @brief This function handles Pendable request for system service.

 */

void PendSV_Handler(void)

{

 /* USER CODE BEGIN PendSV_IRQn 0 */

 /* USER CODE END PendSV_IRQn 0 */

 /* USER CODE BEGIN PendSV_IRQn 1 */

 /* USER CODE END PendSV_IRQn 1 */

}

/**

 * @brief This function handles System tick timer.

 */

void SysTick_Handler(void)

{

 /* USER CODE BEGIN SysTick_IRQn 0 */

 /* USER CODE END SysTick_IRQn 0 */

 HAL_IncTick();

 /* USER CODE BEGIN SysTick_IRQn 1 */

 /* USER CODE END SysTick_IRQn 1 */

}

/******************************************************************************/

/* STM32F4xx Peripheral Interrupt Handlers                                   */

/* Add here the Interrupt Handlers for the used peripherals.                 */

/* For the available peripheral interrupt handler names,                     */

/* please refer to the startup file (startup_stm32f4xx.s).                   */

/******************************************************************************/

/**

 * @brief This function handles DMA2 stream2 global interrupt.

 */

void DMA2_Stream2_IRQHandler(void)

{

 /* USER CODE BEGIN DMA2_Stream2_IRQn 0 */

 /* USER CODE END DMA2_Stream2_IRQn 0 */

 HAL_DMA_IRQHandler(&hdma_usart1_rx);

 /* USER CODE BEGIN DMA2_Stream2_IRQn 1 */

 /* USER CODE END DMA2_Stream2_IRQn 1 */

}

/**

 * @brief This function handles DMA2 stream7 global interrupt.

 */

void DMA2_Stream7_IRQHandler(void)

{

 /* USER CODE BEGIN DMA2_Stream7_IRQn 0 */

 /* USER CODE END DMA2_Stream7_IRQn 0 */

 HAL_DMA_IRQHandler(&hdma_usart1_tx);

 /* USER CODE BEGIN DMA2_Stream7_IRQn 1 */

 /* USER CODE END DMA2_Stream7_IRQn 1 */

}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

11 REPLIES 11
ilyaz yilmaz
Associate III

In firmware version 1.25 usart tx DMA in normal mode doesnt call usart_tx_completed callback function.(But in old firmware it was called)

I dont know the solution is true or not. But when enable usart global interrupt it call the function.

Old and new HAL library works different. Maybe it's bug or new way I dont know.

We will understand if ST make example with new firmware DMA and usart.

Thanks for reply Everyone...

Hi,

Dma counter must be re-initailized in order to transmit again.

Best regards...

FEN