0
\$\begingroup\$

I am attempting to wake an STM32L073RZ from stop mode using WAKEUP_PIN_1. I'm running MbedOS 5.11. Unfortunately throughout all of the documentation (Mbed/STM) I can't find a callback function to use. I.e. to wake from the RTC you will use the callback function: HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) but I cannot find an equivalent of this for WAKEUP pins.

I'm attempting to use pin PA0 (PWR_WAKEUP_PIN1) as my external interrupt. I attempt to configure it according to section A.7.2 of this reference material, my entire program looks like this:

#include "mbed.h"

#define LOG(...) pc.printf(__VA_ARGS__); pc.printf("\r\n");

Serial      pc(USBTX, USBRX);

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
    LOG("Handle interrupt here...");
}

int main()
{
    pc.baud(9600);

    /* Configure PA0 as External Interrupt */
    GPIOA->MODER &= ~( GPIO_MODER_MODE0 );  // PA0 is in Input mode
    EXTI->IMR |= EXTI_IMR_IM0;              // interrupt request from line 0 not masked
    EXTI->RTSR |= EXTI_RTSR_TR0;           // rising trigger enabled for input line 0

    // Enable interrupt in the NVIC
    NVIC_EnableIRQ(EXTI0_1_IRQn);
    NVIC_SetPriority(EXTI0_1_IRQn, 0x00);

    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE);
}

I believe this is all I need to do to detect an external rising edge interrupt on PA0, but the interrupt never gets called for me. Any insight as to why is greatly appreciated.

\$\endgroup\$
  • \$\begingroup\$ This depends on how you configure things and how you enter STOP mode, details which are missing from your question. Please see section 6.3 of the L0's reference manual \$\endgroup\$ – Chris Stratton Mar 14 at 16:07
  • \$\begingroup\$ Hi @ChrisStratton, I've progressed further since posting the question, though I'm still unable to trigger my callback. Question updated. \$\endgroup\$ – Adam Mitchell Mar 14 at 16:34
  • \$\begingroup\$ Your mixture of direct register access and HAL stuff is a bit odd, and your code fragments aren't really enough to tell if your setup is complete. \$\endgroup\$ – Chris Stratton Mar 14 at 16:37
  • \$\begingroup\$ I realised that the question became somewhat unruly, I've removed a lot of the extraneous garbage. The mixture between direct register access and the HAL is because I've been working/reading/copying from multiple different sources. \$\endgroup\$ – Adam Mitchell Mar 14 at 16:46
  • 1
    \$\begingroup\$ To leave sleep mode via the wakeup functionality you must configure the wakeup pin and not the EXTI (e.g. HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);). Also remember to activate the clock for the power module : __HAL_RCC_PWR_CLK_ENABLE(); \$\endgroup\$ – A.R.C. Mar 15 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.