cancel
Showing results for 
Search instead for 
Did you mean: 

Going to STOP while waiting for UART TX DMA to complete

hmc
Associate III
Posted on July 04, 2016 at 04:06

Dear forum, I am trying to transfer a block of bytes from RAM to UART2 using DMA on STM32F042.  I found the HAL function HAL_UART_Transmit_DMA, so I want to go to stop right after that, like this:

    int_disable();

    while ((block = getBlock(&n))) { /* while not End-Of-Data... */

        int_enable();

        extern UART_HandleTypeDef huart2;

        HAL_UART_Transmit_DMA(&huart2, (uint8_t*)block, n);

        HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);

        int_disable();

    }

    int_enable();

I read the reference manual DMA section, but I cannot figure out whether I need to enable the UART2 before going to sleep.  I would imagine that going to WFI will work fine, since DMA interrupt is getting fired...

Thanks for reading.

#low-power #dma
2 REPLIES 2
Walid FTITI_O
Senior II
Posted on July 04, 2016 at 11:32

Hi choi.henry,

What you want to achieve exactly ? The problem that you faced is not clearly mentionned here. Please , reformulate to help you.

-Hannibal-

hmc
Associate III
Posted on July 04, 2016 at 21:38

Hi Hannibal, can you please confirm whether my code looks right for sending a block of bytes over UART2 using DMA?  I am the UART state is stuck at HAL_UART_STATE_BUSY_TX...

HAL_StatusTypeDef dma_status;

do {

   dma_status = HAL_UART_Transmit_DMA(&huart2, (uint8_t*)block, n);

   assert(dma_status == HAL_OK || dma_status == HAL_BUSY);

   HAL_UART_StateTypeDef uart_state;

   do { // <-- stuck in this loop

    HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);

    uart_state = HAL_UART_GetState(&huart2);

   } while (uart_state & (HAL_UART_STATE_BUSY | HAL_UART_STATE_ERROR));

} while (dma_status == HAL_BUSY);