Sleeping and waking up from interrupts
Posted: Sat Sep 17, 2011 10:35 am
Hello again, after like 7 hours trying to make it work, I have faced a defeat. I have just received my Olimex STM32-P103 board and very happy about it, especially how easy the start with ChibiOS is, but got stuck with sleeping.
Deep sleep with waking up from RTC works great (although restarts the cpu on wakeup, I guess that is normal), adding
even makes the debugger (Olimex ARM-JTAG-EW) not crashing when the sleep is enabled.
On to the interrupts, I used the exti test app modified a bit
The interrupts are being called, working great, up to the moment I try to do any sleep:
crashes the debug into some vector tables code, nothing, even the RTC can wake it up from there
does not crash, button or data on the serial tx do nothing, RTC successfully wakes it up with restart
crashes again
All these are tested with and without chSysLock(); in advance, and with interrupt priorities in the mcuconfig ranging from 0 to 6, did experiments with various codes around and I know I'm missing something very basic, but can't figure out what is it. Ideally, I'd like to go into sleep with most peripherals disabled and wake up on usart, but sleeping tries so far have resulted in nothing but crashes. Can anyone give a hint?
Deep sleep with waking up from RTC works great (although restarts the cpu on wakeup, I guess that is normal), adding
Code: Select all
/* Keep debugger connection during SLEEP (debugging) */
DBGMCU_Config(DBGMCU_SLEEP, ENABLE);
DBGMCU_Config(DBGMCU_STOP, ENABLE);
DBGMCU_Config(DBGMCU_STANDBY, ENABLE);
/* IWDG stopped when core is halted (debugging) */
DBGMCU_Config(DBGMCU_IWDG_STOP, ENABLE);
even makes the debugger (Olimex ARM-JTAG-EW) not crashing when the sleep is enabled.
On to the interrupts, I used the exti test app modified a bit
Code: Select all
static const EXTConfig extcfg = {
{
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART, extcb1},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART, extcb3},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART, extcb3},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART, extcb2},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
},
EXT_MODE_EXTI(EXT_MODE_GPIOA,
EXT_MODE_GPIOA,
0,
EXT_MODE_GPIOA,
0,
0,
0,
0,
0,
0,
0,
0,
EXT_MODE_GPIOC,
0,
0,
0)
};
extStart(&EXTD1, &extcfg);
The interrupts are being called, working great, up to the moment I try to do any sleep:
Code: Select all
__WFI();
crashes the debug into some vector tables code, nothing, even the RTC can wake it up from there
Code: Select all
//RTC driver test code
PWR->CR |= (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__WFI();
does not crash, button or data on the serial tx do nothing, RTC successfully wakes it up with restart
Code: Select all
PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI);
crashes again
All these are tested with and without chSysLock(); in advance, and with interrupt priorities in the mcuconfig ranging from 0 to 6, did experiments with various codes around and I know I'm missing something very basic, but can't figure out what is it. Ideally, I'd like to go into sleep with most peripherals disabled and wake up on usart, but sleeping tries so far have resulted in nothing but crashes. Can anyone give a hint?