Deep power-down mode example program.

Dependencies:   mbed

LPC810のDeep power-downモードのテストプログラム。
LEDが消灯している時間はDeep power-downモードで作っています。

Warning

Deep power-downモードではリセットピンによるリセットは効きません。
フラッシュ書き込みにはISPモード(nISP=L)でパワーオンリセットして下さい。

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Thu Jul 10 04:26:53 2014 +0000
Child:
1:de1ba63f90b8
Commit message:
first commit

Changed in this revision

DeepPowerDown.h Show annotated file Show diff for this revision Revisions of this file
lpc810.s Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DeepPowerDown.h	Thu Jul 10 04:26:53 2014 +0000
@@ -0,0 +1,49 @@
+#pragma once
+
+class DeepPowerDown {
+public:
+    static void wakeupTimer(uint32_t delay_sec) {
+        wakeupTimer_ms(delay_sec * 1000);
+    }
+
+    static void wakeupTimer_ms(uint32_t delay_ms) {
+        LPC_PMU->DPDCTRL |= (1<<2)|(1<<3); // enable low-power oscillator
+        LPC_SYSCON->SYSAHBCLKCTRL |= 1<<9;
+        LPC_WKT->CTRL = 0x03; // low power clock(10kHz)
+        LPC_WKT->COUNT = delay_ms * (10000/1000);
+    }
+
+    static void wakeupPin(bool enable) {
+        if (enable) {
+            LPC_PMU->DPDCTRL &= ~(1<<1);
+        } else {
+            LPC_PMU->DPDCTRL |= (1<<1);
+        }
+    }
+
+    static void setData0(uint32_t data) { LPC_PMU->GPREG0 = data; }
+    static void setData1(uint32_t data) { LPC_PMU->GPREG1 = data; }
+    static void setData2(uint32_t data) { LPC_PMU->GPREG2 = data; }
+    static void setData3(uint32_t data) { LPC_PMU->GPREG3 = data; }
+
+    static uint32_t getData0() { return LPC_PMU->GPREG0; }
+    static uint32_t getData1() { return LPC_PMU->GPREG1; }
+    static uint32_t getData2() { return LPC_PMU->GPREG2; }
+    static uint32_t getData3() { return LPC_PMU->GPREG3; }
+
+    static void entry() {
+        LPC_PMU->PCON = 0x03|(1<<3); // Deep power-down mode setting
+        SCB->SCR = 1<<2; // Deep sleep for ARM core
+        __WFI();
+        /* NOTREACHED */
+    }
+
+    static bool is_entry() {
+        return (LPC_PMU->PCON & (1<<11)) ? true : false;
+    }
+
+    static void clear() {
+        LPC_PMU->PCON &= ~(1<<11); // clear DPDFLAG
+    }
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lpc810.s	Thu Jul 10 04:26:53 2014 +0000
@@ -0,0 +1,22 @@
+;patch for lpc810
+;
+                PRESERVE8
+                THUMB
+
+                AREA    |.text|, CODE, READONLY
+
+Reset_Handler   PROC
+                EXPORT  Reset_Handler
+                IMPORT  SystemInit
+                IMPORT  __main
+                LDR     R0, =0x10000400
+                MOV     SP,R0
+                LDR     R0, =SystemInit
+                BLX     R0
+                LDR     R0, =__main+4
+                BX      R0
+                ENDP
+
+                ALIGN
+
+                END
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 10 04:26:53 2014 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "DeepPowerDown.h"
+
+// LPC810 pinout
+#define dp1 P0_5  // nRESET
+#define dp2 P0_4  // WAKEUP
+#define dp3       // SWCLK
+#define dp4       // SWDIO
+#define dp5 P0_1  // nISP
+#define dp6       // VIN
+#define dp7       // GND
+#define dp8 P0_0
+
+DigitalOut led1(dp5);
+
+int main()
+{
+    led1 = 1;
+    wait_ms(3);
+    led1 = 0;
+
+    int ms = 500;
+    int cnt = DeepPowerDown::getData0();
+    if (++cnt >= 3) {
+        cnt = 0;
+        ms = 3*1000;
+    }
+    DeepPowerDown::setData0(cnt);
+    DeepPowerDown::wakeupTimer_ms(ms);
+    DeepPowerDown::wakeupPin(false);
+    DeepPowerDown::entry();
+    /* NOTREACHED */
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jul 10 04:26:53 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae
\ No newline at end of file