2022-10-30 10:54 PM
2022-10-31 01:17 AM
Hi @fgeldenh,
you have not activated pull-up on PA0, like you did on the other EXTI pins. Is the switch pulled-up externally?
BR,
Jaroslav
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-10-31 01:37 AM
Hi – This one has an external pullup. See attached.
Regards
Francois Geldenhuys
[edit: contact details removed from this public thread]
2022-10-31 03:47 AM
I can see only the CubeMX project, no schematics. Could you please upload it, or at least some clipping with the pin wiring and the pull-up? Also, have you changed anything in the generated code?
BR,
Jaroslav
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-10-31 03:58 AM
Here are the schematics. I have not modified the generated code except for adding the main entrypoint and hooks that allow calls to MX_GPIO_Init() andMX_I2C1_Init();
This is my code for going to sleep and restoring from sleep
/** EXTERNALS ********************************************************/
extern FLAGS sysStat; // state flags
extern I2C_HandleTypeDef hi2c1;
/** P R I V A T E P R O T O T Y P E S & CODE ***************************************/
void fixGpio(void); // call to reinit gpio
void SwitchTo32MHz(void);
void SwitchTo32kHz(void);
void fixI2C(void); // call to reinit I2C
void doSleep(void)
{
HAL_Delay(1000);
// turn off radio
sysStat.rfsleep = 1; // say we have disabled RF
HAL_I2C_DeInit(&hi2c1);
HAL_GPIO_DeInit(GPIOA, 0x93f2);
HAL_GPIO_DeInit(GPIOB, 0xffee);
HAL_SuspendTick();
SwitchTo32kHz();
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
SwitchTo32MHz();
fixGpio();
fixI2C();
HAL_ResumeTick();
PWR->CR |= PWR_CR_CWUF;
}
void SwitchTo32MHz(void)
{
/* (1) Select Vcore voltage range 1 (1.8V) */
/* (2) Enable 1 read WS on FLASH */
/* (3) Enable prefetch buffer */
/* (4) Enable HSI */
/* (5) Wait for HSI ready flag and HSIDIV flag */
/* (6) Set PLL on HSI, multiply by 4 and divided by 2 */
/* (7) Enable the PLL */
/* (8) Wait for PLL ready flag */
/* (9) Select PLL as system clock */
/* (10) Wait for clock switched on PLL */
/* (11) Disable MSI (unused) */
/* (12) Set SYSCLK prescaler to 1 */
PWR->CR = (PWR->CR & ~(PWR_CR_VOS)) | PWR_CR_VOS_0; /* (1) */
FLASH->ACR |= FLASH_ACR_LATENCY; /* (2) */
FLASH->ACR |= FLASH_ACR_PRFTEN; /* (3) */
RCC->CR |= RCC_CR_HSION; /* (4) */
while ((RCC->CR & RCC_CR_HSIRDY) != RCC_CR_HSIRDY) /* (5) */
{
}
RCC->CFGR |= RCC_CFGR_PLLSRC_HSI | RCC_CFGR_PLLMUL4 | RCC_CFGR_PLLDIV2; /* (6) */
RCC->CR |= RCC_CR_PLLON; /* (7) */
while ((RCC->CR & RCC_CR_PLLRDY) == 0) /* (8) */
{
}
RCC->CFGR = ((RCC->CFGR & ~(RCC_CFGR_SW)) | RCC_CFGR_SW_PLL); /* (9) */
while ((RCC->CFGR & RCC_CFGR_SWS_PLL) != RCC_CFGR_SWS_PLL) /* (10) */
{
}
RCC->CR &= ~RCC_CR_MSION; /* (11) */
RCC->CFGR = ((RCC->CFGR & ~(RCC_CFGR_HPRE)) | RCC_CFGR_HPRE_DIV1); /* (12) */
}
void SwitchTo32kHz(void)
{
/* (1) Enable MSI */
/* (2) Wait for MSI ready flag */
/* (3) Select MSI Range 0 (65kHz) */
/* (4) Select MSI as system clock */
/* (5) Wait for clock switched on MSI */
/* (6) Set SYSCLK prescaler to 2 */
/* (7) Disable HSI (unused) */
/* (8) Disable PLL (unused) */
/* (9) Disable prefetch buffer (not needed) */
/* (10) Disable 1 read WS on FLASH (not needed) */
/* (11) Select Vcore voltage range 3 (1.2V) */
RCC->CR |= RCC_CR_MSION; /* (1) */
while ((RCC->CR & RCC_CR_MSIRDY) != RCC_CR_MSIRDY) /* (2) */
{
}
RCC->ICSCR = ((RCC->ICSCR & ~(RCC_ICSCR_MSIRANGE)) | RCC_ICSCR_MSIRANGE_0); /* (3) */
RCC->CFGR = ((RCC->CFGR & ~(RCC_CFGR_SW)) | RCC_CFGR_SW_MSI); /* (4) */
while ((RCC->CFGR & RCC_CFGR_SWS_MSI) != RCC_CFGR_SWS_MSI) /* (5) */
{
}
RCC->CFGR = ((RCC->CFGR & ~(RCC_CFGR_HPRE)) | RCC_CFGR_HPRE_DIV2); /* (6) */
RCC->CR &= ~RCC_CR_PLLON; /* (7) */
RCC->CR &= ~RCC_CR_HSION; /* (8) */
FLASH->ACR &= ~FLASH_ACR_PRFTEN; /* (9) */
FLASH->ACR &= ~FLASH_ACR_LATENCY; /* (10) */
PWR->CR = (PWR->CR & ~(PWR_CR_VOS)); /* (11) */
}
2022-11-01 01:12 AM
Hi again,
I don't see any issue with your schematics. I even tested your code on Nucleo L053R8 and the interrupt was raised properly.
Please try to debug your application and check that the pin & the interrupt are configured properly before entering the sleep mode.
BR,
Jaroslav
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-11-01 08:12 PM
Thank you for your help. I am sure I will find the issue. You can close this case now.
2022-11-02 12:38 PM
I just wanted to add, that a common theme we see here is "I have it in code but it doesn't work" and "I have it in schematics but it doesn't work". While one is SW and other HW, the point is the same: source code and schematics are detached from reality by the implementation.
In HW, the reality check is continuity measurement, or, if possible, turning the mcu pin to GPIO output and wiggling it in software while measuring on the outermost point of the whole path.
SW is usually much more complicated and there are more possible points of failure. The starting point is always reading out related registers' content and checking against expectation (according to RM). For interrupts, a (possibly incomplete) checklist is here. You can also simplify on the observation side, by toggling a pin in the ISR.
JW