Skip to content

Commit 96c0ae5

Browse files
author
Brian Daniels
committed
Added sleep and deepsleep for LPC11U68. Needs testing on board
1 parent 252d06b commit 96c0ae5

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define DEVICE_SEMIHOST 0
4545
#define DEVICE_LOCALFILESYSTEM 0
4646

47-
#define DEVICE_SLEEP 0
47+
#define DEVICE_SLEEP 1
4848

4949
#define DEVICE_DEBUG_AWARENESS 0
5050

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "sleep_api.h"
17+
#include "cmsis.h"
18+
#include "mbed_interface.h"
19+
20+
void sleep(void) {
21+
22+
#if (DEVICE_SEMIHOST == 1)
23+
// ensure debug is disconnected
24+
mbed_interface_disconnect();
25+
#endif
26+
27+
// PCON[PM] (bits 2:0) set to 0
28+
LPC_PMU->PCON &= ~0x03;
29+
30+
// SRC[SLEEPDEEP] set to 0 = sleep
31+
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
32+
33+
// wait for interrupt
34+
__WFI();
35+
}
36+
37+
38+
void deepsleep(void) {
39+
40+
#if (DEVICE_SEMIHOST == 1)
41+
// ensure debug is disconnected
42+
mbed_interface_disconnect();
43+
#endif
44+
45+
// PCON[PM] (bits 2:0) set to 1
46+
LPC_PMU->PCON &= ~0x03;
47+
LPC_PMU->PCON |= 0x01;
48+
49+
//According to user manual it is kinda picky about reserved bits, so we follow that nicely
50+
//Keep WDOSC and BOD in same state as they are now during deepsleep
51+
LPC_SYSCON->PDSLEEPCFG = 0x00000037 | (LPC_SYSCON->PDRUNCFG & (0x00000048));
52+
53+
// Power up same as before powerdown
54+
LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG;
55+
56+
// All interrupts can wake
57+
LPC_SYSCON->STARTERP0 = 0xFF;
58+
LPC_SYSCON->STARTERP1 = 0xFFFFFFFF;
59+
60+
// SRC[SLEEPDEEP] set to 1 = deep sleep
61+
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
62+
63+
// wait for interrupt
64+
__WFI();
65+
}

0 commit comments

Comments
 (0)