2019-12-11
04:50 AM
- last edited on
2024-02-09
04:22 AM
by
Lina DABASINSKAITE
hi, Dear, how can I use usart + dma? I make the project by stm32cubeMx and add some code in main function as below: but it run fail and show a dma transfer error(Show as addition files: RunHere.png). Looking for your reply , Thank you!
/* Infinite loop */
/* USER CODE BEGIN WHILE */
uint32_t ticko = 0;
uint32_t t = 0;
char buf[256];
while (1)
{
if (HAL_GetTick() - ticko > 1000) {
ticko = HAL_GetTick();
sprintf(buf, "test uart and dma: time:%d\n", t++);
HAL_UART_Transmit_DMA(&huart1, buf, strlen(buf));
//HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
//HAL_USART_Transmit_DMA(&huart1, buf, strlen(buf));
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2019-12-11 05:48 AM
You'd presumably need to use a callback to flag if the transfer completed. And then wait before sending again.
2019-12-11 05:19 PM
Are you meaning add a callback function like below:
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart == &huart1) {
ctlUart.f_TxBusy = FALSE;
#ifdef freeRtos_Enable
if (pdPASS != xSemaphoreGive(ctlUart.sema)) {
while (1);
}
#endif
}
}
2020-09-06 09:52 PM
I had a similar issue where only the first DMA transmission would work, and found the fix was to enable HAL_UART_IRQHandler()
See this thread for more details:
https://community.st.com/s/question/0D50X00009XkgtY/dma-uart-with-hal-remain-busy-bug