Skip to main content
BZhou.2
Associate
May 1, 2023
Solved

ADC DMA not restarting after exiting STOP mode

Hello!

I have my ADC DMA setup so that Timer 1 will trigger a conversion with a specific frequency. Both DMA continuous requests and Continuous conversions are disabled. DMA is set to Normal mode.

When the buffer is full and HAL_ADC_ConvCpltCallback is triggered, I stop the ADC with HAL_ADC_Stop_DMA, and some processing is performed on the DMA buffer. Once the processing is completed the ADC is restarted with HAL_ADC_Start_DMA.

This all works as expected until the MCU enters and exits from STOP mode. I'm unable to restart the ADC, the DMA buffer still contains the previous data, and HAL_ADC_ConvCpltCallback is never triggered.

Here's my code:

while (1) {
 /* USER CODE END WHILE */
 /* USER CODE BEGIN 3 */
 
 HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
 HAL_ADC_Start_DMA(&hadc1, (uint32_t*)sampleBuffer, samplesPerFrame);
 
 while (dataReadyFlag == 0)
 ;
 dataReadyFlag = 0;
 
 // TODO: Process sampleBuffer
 
 if ((uint32_t)(HAL_GetTick() - prevTime) > awakeTimer) {
 prevTime = HAL_GetTick();
 awakeTimer = 0;
 
 HAL_ADC_Stop_DMA(&hadc1);
 HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
 
 //			Enter STOP 1 mode.
 HAL_SuspendTick();
 HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x1999, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
 HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
 
 // Wake up
 HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
 SystemClock_Config();
 HAL_ResumeTick();
 
 awakeTimer += 10000;
 dataReadyFlag = 0;
 }
}

Is there something else I need to do? Do I need to restart the Timer somehow? Thanks!

MCU: STM32L432KC, Board Nucleo-L432KC

This topic has been closed for replies.
BZhou.2
BZhou.2Best answer
Associate
May 2, 2023

I'm able to resolve the issue by calling HAL_ADC_MspInit after wake up.

1 reply

BZhou.2
BZhou.2AuthorBest answer
Associate
May 2, 2023

I'm able to resolve the issue by calling HAL_ADC_MspInit after wake up.