EmbeddedRelated.com
Forums
Memfault Beyond the Launch

LPC812, WKT, deep power down mode: working only once...

Started by capiman26061973 March 8, 2013
Hello,

i am currently trying to get the LPC812 to use its
deep power down mode and wake up via WKT.

Here is what i am doing:

I start up the chip. UART is working.
LEDs are working.

When a certain key is pressed, i prepare deep power down mode
(see code 1 below before WFI) and enter deep power down
mode via WFI for around 10 seconds.

After around 10 seconds the chip wakes up
and jumps into WKT interrupt service routine.
(see code 2 below)

After returning from WKT ISR, the code after WFI
is continued, UART is working again, everything ok.
(see code 1 below again after WFI,
i removed code for UART and LEDs to make code more readable)

Now i do the same again: press the key,
go to deep power down mode, but the LPC812 does not stay
in deep power down, but immediately goes into WKT ISR.
After WKT ISR the code after WFI is not executed
(different than before).
I already printed a lot registers and compared them
between first and second run, but it seems i have not yet
found the right one...
Is there any additional register which i must clear?
Something like for the pending IRQ, which i already
cleared for WKT_IRQn.

Hardware is (cutted) LPCxpresso with LPC812.
I upload software via FlashMagic.
I have no JTAG/SWI connected.
I assume JTAG/SWI is not helpful,
because it is not working with deep power down mode.
Is this correct?

Has someone already done a similar thing?

Best regards,

Martin
Here are some code snippets:
(removed most UART and LED handling used for debugging)

(1) Code executed after key press:

// Needed?
NVIC_ClearPendingIRQ(WKT_IRQn);
NVIC_DisableIRQ(WKT_IRQn);

// Init self wakeup timer (WKT)

/* Enable clock for WKT */
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 9);

/* Reset WKT */
LPC_SYSCON->PRESETCTRL &= ~(1 << 9);
LPC_SYSCON->PRESETCTRL |= (1 << 9);

/* set LPOSCDPDEN and LPOSCEN to 1 */
LPC_PMU->DPDCTRL |= (3 << 2);

/* Enable Interrupt for WKT in NVIC */
NVIC_EnableIRQ(WKT_IRQn);

/* Config WKT */
LPC_WKT->CTRL = (1 << 2);
LPC_WKT->COUNT = 10 * 10000;
LPC_WKT->CTRL = 1;

/* Set wakeup config to same as run config */
LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG;

/* WKT can wake up */
LPC_SYSCON->STARTERP1 = (1 << 15);

/* Go to deep power down mode */
LPC_PMU->PCON = 0x3;
__WFI();

SystemCoreClockUpdate();

DebugInitPort(0, 9600);

DebugPutString("After WFI\n");
(2) WKT-ISR:

void WKT_IRQHandler(void)
{
uint32_t regVal;

// Needed?
if ( (LPC_PMU->PCON & (0x1<<11)) != 0x0 )
{
/* Check deep power down bits. If deep power down mode is entered,
clear the PCON bits. */
regVal = LPC_PMU->PCON;
regVal |= (0x1<<11);
LPC_PMU->PCON = regVal;
}

// Needed?
if ( (LPC_PMU->PCON & (0x1<<8)) != 0x0 )
{
/* Check sleep flag. If sleep flag is set,
clear the sleep flag. */
regVal = LPC_PMU->PCON;
regVal |= (0x1<<8);
LPC_PMU->PCON = regVal;
}

// Without this, WKT-ISR is entered endless...
NVIC_DisableIRQ(WKT_IRQn);
}

An Engineer's Guide to the LPC2100 Series

Inside WKT ISR

SCB->ICSR00001F

which seems to be correct because i am in ISR for WKT (31-16)

After ISR of WKT one bit

SCB->ICSR400000

remains set, even after

NVIC_ClearPendingIRQ(WKT_IRQn);
NVIC_DisableIRQ(WKT_IRQn);

Bit 2^22 means ISRPENDING

according to

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/Cihfaaha.html

Thanks to Mike on lpcware.com the following was missing in WKT ISR:

// Clearing the ALARMFLAG
LPC_WKT->CTRL = (1 << 1);

Now going to deep power mode and waking up via WKT
works multiple times.

Best regards,

Martin

Some additional hints:
(it was not yet going to deep power down mode)

- Register SCR in System Control Block was missing
#define NVIC_LP_SLEEPDEEP (0x04)
SCB->SCR |= NVIC_LP_SLEEPDEEP;

- WAKEUP pin (ISP TXD) must externally be connected to a pull-up (like mentioned in user manual)
(at least with my environment it woke up after around 3 seconds instead of time configured in WKT,
i have the pull up on TXD now additional to RS232 converter)

- Potentiometer on LPCxpresso consumed a lot power (~ 184 uA)

After these steps (and removing ISP connection) my multimeter showed a power consumption of ~ 0,3 uA (300 nA)
for the time, the LPC812 was in deep power down mode, till WKT times out or i put a signal on WAKEUP pin.


Memfault Beyond the Launch