2016-07-03 07:06 PM
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 #dma2016-07-04 02:32 AM
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-2016-07-04 12:38 PM
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);