AnsweredAssumed Answered

(HAL) Sending UART strings using DMA

Question asked by h.hammer on Feb 12, 2015
Latest reply on Feb 12, 2015 by Clive One
Hi, I'm having a problem that when calling HAL_UART_TRANSMIT_DMA() I require a delay between consecutive calls of the function for it to accept new data into the DMA. I've found adding a HAL_Delay between calls fixes the problem so I must be trying to call the transmit too often.

How do I go about creating a while(dma_busy_flag){} for the DMA here? I'm using these settings:

stm32f4xx_hal_msp.c (some code not shown)

   extern DMA_HandleTypeDef hdma_usart1_tx;

   hdma_usart1_tx.Instance = DMA2_Stream7;
   hdma_usart1_tx.Init.Channel = DMA_CHANNEL_4;
   hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
   hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
   hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;
   hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
   hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
   hdma_usart1_tx.Init.Mode = DMA_NORMAL;
   hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;
   hdma_usart1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
   hdma_usart1_tx.Init.MemBurst = DMA_MBURST_SINGLE;
   hdma_usart1_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;

   __HAL_LINKDMA(huart, hdmatx, hdma_usart1_tx);

stm32f4xx_it.c (some code not shown)

   void DMA2_Stream7_IRQHandler(void)

serial.c  (some code not shown)

   HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 5, 0);

   /* Prints the supplied string to uart */ void print(char string[])
        // Do we need a "while(dma_busy){}"?     
        HAL_UART_Transmit_DMA(&huart1, (uint8_t*)string, strlen(string));

   /* UART TX complete callback */
   void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
        // Do we need a "clear_dma_busy_flag"?

I've tried using the macros:

__HAL_DMA_GET_FLAG(&hdma_usart1_tx, DMA_FLAG_TCIF3_7)
__HAL_DMA_CLEAR_FLAG(&hdma_usart1_tx, DMA_FLAG_TCIF3_7)

but haven't had any luck. Is there somewhere I'm messing up?

(Also unrelated, how do i format posts on this forum for code?)