0

I have STM32WLE5 series and I am trying to wake it up using hardware WKUP pin from STOP mode. That pin (PC13 = Wake-up 1 = PWR_WKUP2) is connected to my external button (automatically pulled down, button pulls it up).

After wakeup I read logic level of that pin and "reinit" it like CubeMX did:

GPIO_InitTypeDef GPIO_InitStructCOn = {0};
GPIO_InitTypeDef GPIO_InitStructCOff = {0};

GPIO_InitStructCOn.Pin = GPIO_PIN_13;
GPIO_InitStructCOn.Mode = GPIO_MODE_INPUT;
GPIO_InitStructCOn.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructCOn);

uint8_t caseOpen = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13);

GPIO_InitStructCOff.Pin = GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStructCOff.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructCOff.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructCOff);

Before entering STOP mode I do this to setup the pin (the pin is called 1 and 2 at once and I am unsure, what is correct, hence I enable both of them):

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2);

I enter stop mode with WFE like this (so everything can wake it up):

HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFE);

Reading it using INPUT mode works fine, so it is not hardware error. The power consumption is important to me, hence I do not use software EXTI.

Anybody knows, what I am doing wrong? I am also using RTC for auto wakeup and it works fine.

Foreen
  • 369
  • 2
  • 17
  • You are setting your pin as `GPIO_MODE_INPUT` - should it not be `GPIO_MODE_IT_RISING`? – pmacfarlane Apr 02 '23 at 14:26
  • That is just for reading the state of button when running (after wakeup) and it works fine. After readout I reset it to defaults, just like CubeMX did in MX_GPIO_Init hoping it will be set as WKUP pin from STOP mode – Foreen Apr 03 '23 at 12:03
  • 1
    FYI you can read the state of a GPIO pin no matter what it is configured as. Even if it is configured as an output, for example. You shouldn't need to reconfigure it to read its state. – pmacfarlane Apr 04 '23 at 19:11
  • Thanks for a tip. But do you know, what am I doing wrong with the wakeup? I still have not solved it :( – Foreen Jul 05 '23 at 18:13
  • Well you show configuring PC13 as an input, and then configuring PC14 and PC15 as analog. You don't show the configuration of PC13 back to an EXTI. Are you doing that? Can you show the code? – pmacfarlane Jul 05 '23 at 18:29
  • I am doing that exactly like MX did - MX just removed the pin from the initialization of C pins after setting the pin as WKUP. I do not configure PC13 as EXTI, because it uses a lot of energy (in MX for my STM series there are two ways how to configure the pin for the wakeup - using EXTI (SW - every pin) or WKUP (HW - just three pins) - second choice is the way I want to go) – Foreen Jul 05 '23 at 18:42
  • Does it work if you just do it the CubeMX way? Does wakeup work? i.e. if you remove your reconfiguration as an input etc. – pmacfarlane Jul 05 '23 at 18:47
  • No, it does not work – Foreen Jul 05 '23 at 19:01
  • Maybe you should make a simpler question that doesn't involve re-configuring the pin as an input then. That's a massive red-herring that is very confusing. If your problem is that you can't make wakeup work at all, just focus on that. Make a new project in CubeIDE that just does the one thing you want - enters STOP2 mode and wakes back up when you push the button. Then debug that, or ask about it. – pmacfarlane Jul 05 '23 at 19:06
  • Ok, thanks! I'll hide this question and create question with simplified example. – Foreen Jul 06 '23 at 08:26

0 Answers0