cancel
Showing results for 
Search instead for 
Did you mean: 

Not generating PWM signal after wake up from STOP2

JNowa.4
Associate III

I'm working with STM32WL and trying to be able to generate PWM signal after wake up from STOP2 to control RGB LED. Before going to STOP2 I deinitialize PWM channel pin and disable timer clock. MCU wakes up on button press. After wake up timer clock is beeing enabled and channel pin is reinitialized. Despite that the LED is off. What else should I do to make it work or what I've done wrong?

  /* USER CODE BEGIN 2 */
 
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  /* Green LED on */
  HAL_TIMEx_PWMN_Start(&htim16, TIM_CHANNEL_1);
  __HAL_TIM_SET_COMPARE(&htim16, TIM_CHANNEL_1, 1000);
 
  HAL_Delay(500);
 
  /* DeInit of LED pin, disable TIM16 clock */
  HAL_TIMEx_PWMN_Stop(&htim16, TIM_CHANNEL_1);
  HAL_GPIO_DeInit(LED_G_CH_GPIO_Port, LED_G_CH_Pin);
  __HAL_RCC_TIM16_CLK_DISABLE();
 
  /* Enter STOP2 */
  HAL_SuspendTick();
  HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
 
  /* Wake up from STOP2 on button press */
  SystemClock_Config();
  HAL_ResumeTick();
 
  /* Enable TIM16 clock */
  __HAL_RCC_TIM16_CLK_ENABLE();
 
  /* ReInit of LED pin */
  __HAL_RCC_GPIOB_CLK_ENABLE();
  GPIO_InitStruct.Pin = LED_G_CH_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF14_TIM16;
  HAL_GPIO_Init(LED_G_CH_GPIO_Port, &GPIO_InitStruct);
 
  /* Green LED on */
  HAL_TIMEx_PWMN_Start(&htim16, TIM_CHANNEL_1);
  __HAL_TIM_SET_COMPARE(&htim16, TIM_CHANNEL_1, 1000);
 
  /* USER CODE END 2 */

1 ACCEPTED SOLUTION

Accepted Solutions
JNowa.4
Associate III

I've removed clock disabling before going to sleep and changed procedure after wake up. The code after wake up looks like that:

  /* Wake up from STOP2 on button press */
  SystemClock_Config();
  HAL_ResumeTick();
  MX_TIM16_Init();

With just MX_TIM16_Init() function everything works as expected.

View solution in original post

2 REPLIES 2

Read out and check/compare/post content of TIM and relevant GPIO registers for working and non-working cases.

JW

JNowa.4
Associate III

I've removed clock disabling before going to sleep and changed procedure after wake up. The code after wake up looks like that:

  /* Wake up from STOP2 on button press */
  SystemClock_Config();
  HAL_ResumeTick();
  MX_TIM16_Init();

With just MX_TIM16_Init() function everything works as expected.