Hello guys, this is (maybe) not exactly Keil specific but I'm trying here anyway ;) I have an application using Keil RTX running on a LPC1778.
My os_idle_demon() in RTX_Conf_CM.c looks like this:
__task void os_idle_demon (void) { /* The idle demon is a system task, running when no other task is ready */ /* to run. The 'os_xxx' function calls are not allowed from this task. */ int x; for (;;) { // Only enable sleep if not running in debugger if ((CoreDebug->DHCSR & 0x0001)==0) { LPC_SC->PCON = 0x00; SCB->SCR = 0x00; __WFI(); } } }
Basically this will put the CPU in Sleep when no task is ready to run. Works perfect.
I then added a call to CLKPWR_PowerDown() in a function (when a button is pressed). The CLKPWR_PowerDown() funtion looks like this:
/*********************************************************************//** * @brief Enter Power Down mode with co-operated instruction by the Cortex-M3. * @param[in] None * @return None **********************************************************************/ void CLKPWR_PowerDown(void) { /* Deep-Sleep Mode, set SLEEPDEEP bit */ SCB->SCR = 0x4; LPC_SC->PCON = 0x09; /* Power Down Mode*/ __WFI(); }
This function also works as supposed.
BUT!
If I activate the deepsleep mode, the CPU will correctly go to deepsleep and wake up when an enabled interrupt fires (another GPIO pin). Only one problem, when waking up the CPU resets itself! This ONLY occurs if I have the Sleep code enabled in the os_idle_demon() ! I I disable the sleep code in the os_idle_demon() and enable it maybe 10 seconds later (using another button) it will reset immediatly!
So, Sleep on it's own works, deepsleep on it's own work, but when doing deepsleep followed by sleep the CPU resets. The other way around it is ok, the system can run forever just using the sleep in the os_idle_demon() and it also works when activating deepsleep. It is only when exiting from deepsleep and then doing sleep at some point in time in os_idle_demon() that the system resets.....
Any ideas out there before I loose the rest of my hair ?