Added Restart(by RESET) function from Standby mode only for some Nucleo boards (STM32 series)

Dependencies:   LPC1114_WakeInterruptIn

Dependents:   Check_StandBy

Fork of WakeUp by Erik -

Example program using "Standby function" for Nucleo series is here.
/users/kenjiArai/code/Check_StandBy/

Committer:
Sissors
Date:
Wed Jun 14 08:56:55 2017 +0000
Revision:
23:69a0c843e4bd
Parent:
10:c41bc9154a7c
Child:
24:65c04a02ad45
Switched WakeUp to use the new callback system, to remove warnings during compilation.; ; Attached normal functions should still work the same. Attaching member functions is now:; WakeUp::attach(callback(&object, &Class::function));

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:fc439458a359 1 #include "mbed.h"
Sissors 0:fc439458a359 2
Sissors 0:fc439458a359 3 /**
Sissors 8:8d9a6ac0fba8 4 * Class to make wake up a microcontroller from deepsleep using a low-power timer.
Sissors 8:8d9a6ac0fba8 5 *
Sissors 8:8d9a6ac0fba8 6 * @code
Sissors 8:8d9a6ac0fba8 7 * // Depending on the LED connections either the LED is off the 2 seconds
Sissors 8:8d9a6ac0fba8 8 * // the target spends in deepsleep(), and on for the other second. Or it is inverted
Sissors 8:8d9a6ac0fba8 9 *
Sissors 8:8d9a6ac0fba8 10 * #include "mbed.h"
Sissors 8:8d9a6ac0fba8 11 * #include "WakeUp.h"
Sissors 8:8d9a6ac0fba8 12 *
Sissors 8:8d9a6ac0fba8 13 * DigitalOut myled(LED1);
Sissors 8:8d9a6ac0fba8 14 *
Sissors 8:8d9a6ac0fba8 15 * int main() {
Sissors 10:c41bc9154a7c 16 * wait(5);
Sissors 10:c41bc9154a7c 17 *
Sissors 8:8d9a6ac0fba8 18 * //The low-power oscillator can be quite inaccurate on some targets
Sissors 8:8d9a6ac0fba8 19 * //this function calibrates it against the main clock
Sissors 8:8d9a6ac0fba8 20 * WakeUp::calibrate();
Sissors 8:8d9a6ac0fba8 21 *
Sissors 8:8d9a6ac0fba8 22 * while(1) {
Sissors 8:8d9a6ac0fba8 23 * //Set LED to zero
Sissors 8:8d9a6ac0fba8 24 * myled = 0;
Sissors 8:8d9a6ac0fba8 25 *
Sissors 8:8d9a6ac0fba8 26 * //Set wakeup time for 2 seconds
Sissors 8:8d9a6ac0fba8 27 * WakeUp::set_ms(2000);
Sissors 8:8d9a6ac0fba8 28 *
Sissors 8:8d9a6ac0fba8 29 * //Enter deepsleep, the program won't go beyond this point until it is woken up
Sissors 8:8d9a6ac0fba8 30 * deepsleep();
Sissors 8:8d9a6ac0fba8 31 *
Sissors 8:8d9a6ac0fba8 32 * //Set LED for 1 second to one
Sissors 8:8d9a6ac0fba8 33 * myled = 1;
Sissors 8:8d9a6ac0fba8 34 * wait(1);
Sissors 8:8d9a6ac0fba8 35 * }
Sissors 8:8d9a6ac0fba8 36 * }
Sissors 8:8d9a6ac0fba8 37 * @endcode
Sissors 8:8d9a6ac0fba8 38 */
Sissors 0:fc439458a359 39 class WakeUp
Sissors 0:fc439458a359 40 {
Sissors 0:fc439458a359 41 public:
Sissors 0:fc439458a359 42 /**
Sissors 0:fc439458a359 43 * Set the timeout
Sissors 0:fc439458a359 44 *
Sissors 8:8d9a6ac0fba8 45 * @param s required time in seconds
Sissors 0:fc439458a359 46 */
Sissors 0:fc439458a359 47 static void set(uint32_t s) {
Sissors 0:fc439458a359 48 set_ms(1000 * s);
Sissors 0:fc439458a359 49 }
Sissors 0:fc439458a359 50
Sissors 0:fc439458a359 51 /**
Sissors 0:fc439458a359 52 * Set the timeout
Sissors 0:fc439458a359 53 *
Sissors 8:8d9a6ac0fba8 54 * @param ms required time in milliseconds
Sissors 0:fc439458a359 55 */
Sissors 0:fc439458a359 56 static void set_ms(uint32_t ms);
Sissors 0:fc439458a359 57
Sissors 0:fc439458a359 58 /**
Sissors 0:fc439458a359 59 * Attach a function to be called after timeout
Sissors 0:fc439458a359 60 *
Sissors 0:fc439458a359 61 * This is optional, if you just want to wake up you
Sissors 0:fc439458a359 62 * do not need to attach a function.
Sissors 0:fc439458a359 63 *
Sissors 8:8d9a6ac0fba8 64 * Important: Many targets will run the wake-up routine
Sissors 8:8d9a6ac0fba8 65 * at reduced clock speed, afterwards clock speed is restored.
Sissors 8:8d9a6ac0fba8 66 * This means that clock speed dependent functions, such as printf
Sissors 8:8d9a6ac0fba8 67 * might end up distorted.
Sissors 8:8d9a6ac0fba8 68 *
Sissors 23:69a0c843e4bd 69 * It uses the new Callback system to attach functions.
Sissors 0:fc439458a359 70 *
Sissors 8:8d9a6ac0fba8 71 * @param *function function to call
Sissors 0:fc439458a359 72 */
Sissors 23:69a0c843e4bd 73 static void attach(Callback<void()> function) {
Sissors 23:69a0c843e4bd 74 callback = function;
Sissors 0:fc439458a359 75 }
Sissors 0:fc439458a359 76
Sissors 0:fc439458a359 77 /**
Sissors 0:fc439458a359 78 * Calibrate the timer
Sissors 0:fc439458a359 79 *
Sissors 8:8d9a6ac0fba8 80 * Some of the low-power timers have very bad accuracy.
Sissors 8:8d9a6ac0fba8 81 * This function calibrates it against the main timer.
Sissors 0:fc439458a359 82 *
Sissors 0:fc439458a359 83 * Warning: Blocks for 100ms!
Sissors 0:fc439458a359 84 */
Sissors 0:fc439458a359 85 static void calibrate(void);
Sissors 0:fc439458a359 86
Sissors 0:fc439458a359 87
Sissors 0:fc439458a359 88 private:
Sissors 23:69a0c843e4bd 89 static Callback<void()> callback;
Sissors 0:fc439458a359 90 static void irq_handler(void);
Sissors 0:fc439458a359 91 static float cycles_per_ms;
Sissors 0:fc439458a359 92 };