NuMaker tickless example

Committer:
ccli8
Date:
Tue Sep 12 16:16:43 2017 +0800
Revision:
1:eb1da9d36e12
Child:
8:acff1b7adc39
Support NUC472/M453/M487

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ccli8 1:eb1da9d36e12 1 # Example for tickless support on Nuvoton targets
ccli8 1:eb1da9d36e12 2
ccli8 1:eb1da9d36e12 3 This is an example to demonstrate [tickless](https://en.wikipedia.org/wiki/Tickless_kernel) support on
ccli8 1:eb1da9d36e12 4 Nuvoton Mbed-enabled boards.
ccli8 1:eb1da9d36e12 5 With tickless support, user program would enter **Idle** mode (shallow sleep) or **Power-down** mode (deep sleep)
ccli8 1:eb1da9d36e12 6 automatically when CPU is idle.
ccli8 1:eb1da9d36e12 7
ccli8 1:eb1da9d36e12 8 ## Supported platforms
ccli8 1:eb1da9d36e12 9 - [NuMaker-PFM-NUC472](https://developer.mbed.org/platforms/Nuvoton-NUC472/)
ccli8 1:eb1da9d36e12 10 - [NuMaker-PFM-M453](https://developer.mbed.org/platforms/Nuvoton-M453/)
ccli8 1:eb1da9d36e12 11 - [NuMaker-PFM-M487](https://developer.mbed.org/platforms/NUMAKER-PFM-M487/)
ccli8 1:eb1da9d36e12 12
ccli8 1:eb1da9d36e12 13 ## Supported wake-up source
ccli8 1:eb1da9d36e12 14 - Button(s)
ccli8 1:eb1da9d36e12 15 - lp_ticker (internal with tickless)
ccli8 1:eb1da9d36e12 16 - WDT timeout
ccli8 1:eb1da9d36e12 17 - RTC alarm
ccli8 1:eb1da9d36e12 18 - UART CTS state change (TODO)
ccli8 1:eb1da9d36e12 19 - I2C address match (TODO)
ccli8 1:eb1da9d36e12 20
ccli8 1:eb1da9d36e12 21 ## Execution
ccli8 1:eb1da9d36e12 22 To run this tickless example, target board must run with no ICE connected.
ccli8 1:eb1da9d36e12 23 With ICE connected, system will enter **Idle** mode (shallow sleep) rather than **Power-down** mode (deep sleep)
ccli8 1:eb1da9d36e12 24 even though `deepsleep()` is called.
ccli8 1:eb1da9d36e12 25
ccli8 1:eb1da9d36e12 26 ### Modes
ccli8 1:eb1da9d36e12 27 There are two modes on Nuvoton Mbed-enabled boards:
ccli8 1:eb1da9d36e12 28
ccli8 1:eb1da9d36e12 29 #### MASS mode
ccli8 1:eb1da9d36e12 30 This mode supports drap-n-drop programming and VCOM. For retrieving chip information, ICE is connected and system cannot enter
ccli8 1:eb1da9d36e12 31 **Power-down** mode.
ccli8 1:eb1da9d36e12 32
ccli8 1:eb1da9d36e12 33 #### Debug mode
ccli8 1:eb1da9d36e12 34 This mode supports debugger and VCOM. But without entering debug session for debugging, ICE isn't connected and system can enter
ccli8 1:eb1da9d36e12 35 **Power-down** mode (deep sleep).
ccli8 1:eb1da9d36e12 36
ccli8 1:eb1da9d36e12 37 So to run this tickless example, user must switch to **MASS** mode first for drag-n-drop programming and
ccli8 1:eb1da9d36e12 38 then switch to **Debug** mode without entering debug session for running the code.
ccli8 1:eb1da9d36e12 39
ccli8 1:eb1da9d36e12 40 ### Note for terminal output
ccli8 1:eb1da9d36e12 41 With your terminal program configured with 9600/8-N-1, you would see output with:
ccli8 1:eb1da9d36e12 42 <pre>
ccli8 1:eb1da9d36e12 43 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 44 Wake up by WDT timeout from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 45
ccli8 1:eb1da9d36e12 46 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 47 Wake up by <b>Unidentified</b> from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 48
ccli8 1:eb1da9d36e12 49 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 50 Wake up by Button2 from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 51
ccli8 1:eb1da9d36e12 52 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 53 Wake up by RTC alarm from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 54
ccli8 1:eb1da9d36e12 55 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 56 Wake up by Button1 from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 57 </pre>
ccli8 1:eb1da9d36e12 58
ccli8 1:eb1da9d36e12 59 1. If you see `shallow sleep` rather than `deep sleep`, you just enter **Idle** mode (shallow sleep) rather than
ccli8 1:eb1da9d36e12 60 **Power-down** mode (deep sleep). And you need to check your environment.
ccli8 1:eb1da9d36e12 61 1. If you see `Unidentified`, it means chip is waken up from **Power-down** mode but its wake-up source is unidentified.
ccli8 1:eb1da9d36e12 62 Usually it is `lp_ticker` which is internal with the tickless mechanism.
ccli8 1:eb1da9d36e12 63
ccli8 1:eb1da9d36e12 64 ## Known issues
ccli8 1:eb1da9d36e12 65 1. `Ticker`, `Timeout`, and `Timer` will misbehave with this example. These timers rely on
ccli8 1:eb1da9d36e12 66 internal `us_ticker`, which rely on high-res clocks HXT/HIRC, which are stopped in idle time to save power.
ccli8 1:eb1da9d36e12 67 The issue is to be addressed in next mbed OS version.
ccli8 1:eb1da9d36e12 68
ccli8 1:eb1da9d36e12 69 1. Interrupt callback and asynchronous transfer in `Serial`, `SPI`, `CAN`, etc. won't work with this example.
ccli8 1:eb1da9d36e12 70 These peripherals rely on high-res clocks HXT/HIRC to operate, which are stopped in idle time to save power.
ccli8 1:eb1da9d36e12 71 Same as above, the issue will be addressed in next mbed OS version.