NuMaker tickless example

Committer:
cyliang
Date:
Tue Feb 21 10:16:16 2023 +0000
Revision:
24:b9e5db00adbb
Parent:
20:759aab916d47
Update mbed os v6.16.0+ for M467 support

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 16:ed2c228cbc9c 9
ccli8 16:ed2c228cbc9c 10 - [NuMaker-PFM-NANO130](https://os.mbed.com/platforms/NuMaker-PFM-NANO130/)
ccli8 14:83b73695da8f 11 - [NuMaker-PFM-NUC472](https://os.mbed.com/platforms/Nuvoton-NUC472/)
ccli8 14:83b73695da8f 12 - [NuMaker-PFM-M453](https://os.mbed.com/platforms/Nuvoton-M453/)
ccli8 14:83b73695da8f 13 - [NuMaker-PFM-M487](https://os.mbed.com/platforms/NuMaker-PFM-M487/)
ccli8 20:759aab916d47 14 - [NuMaker-IoT-M487](https://os.mbed.com/platforms/NUMAKER-IOT-M487/)
ccli8 20:759aab916d47 15 - [NuMaker-IoT-M263A](https://os.mbed.com/platforms/NUMAKER-IOT-M263A/)
ccli8 20:759aab916d47 16 - NuMaker-M252KG
cyliang 24:b9e5db00adbb 17 - [NuMaker-IoT-M467](https://os.mbed.com/platforms/NUMAKER-IOT-M467/)
ccli8 20:759aab916d47 18
ccli8 20:759aab916d47 19 **Note**: With TrustZone, this example cannot support [NuMaker-PFM-M2351](https://os.mbed.com/platforms/NUMAKER-PFM-M2351/). But users can still achieve power saving goal through **tickless mode+tickless from lp_ticker** (see below).
ccli8 1:eb1da9d36e12 20
ccli8 1:eb1da9d36e12 21 ## Supported wake-up source
ccli8 1:eb1da9d36e12 22 - Button(s)
ccli8 1:eb1da9d36e12 23 - lp_ticker (internal with tickless)
ccli8 1:eb1da9d36e12 24 - WDT timeout
ccli8 1:eb1da9d36e12 25 - RTC alarm
ccli8 1:eb1da9d36e12 26 - UART CTS state change (TODO)
ccli8 1:eb1da9d36e12 27 - I2C address match (TODO)
ccli8 1:eb1da9d36e12 28
ccli8 14:83b73695da8f 29 ## Choose idle handler
ccli8 14:83b73695da8f 30 Application user can choose to use Mbed OS internal idle handler or customize its own one.
ccli8 16:ed2c228cbc9c 31 1. To use Mbed OS internal idle handler, ensure the `MBED_TICKLESS` macro is defined and `tickless-from-us-ticker` is configured to false in `mbed_app.json`.
ccli8 14:83b73695da8f 32
ccli8 16:ed2c228cbc9c 33 ```json
ccli8 14:83b73695da8f 34 "target_overrides": {
ccli8 16:ed2c228cbc9c 35 ......
ccli8 14:83b73695da8f 36 "NUMAKER_PFM_NUC472": {
ccli8 16:ed2c228cbc9c 37 "target.macros_add": ["MBED_TICKLESS"],
ccli8 16:ed2c228cbc9c 38 "target.tickless-from-us-ticker": false,
ccli8 16:ed2c228cbc9c 39 ......
ccli8 16:ed2c228cbc9c 40 ```
ccli8 16:ed2c228cbc9c 41
ccli8 16:ed2c228cbc9c 42 **Note**: To enable tickless on existent project, just define `MBED_TICKLESS` and configure `tickless-from-us-ticker` to false as above.
ccli8 16:ed2c228cbc9c 43
ccli8 16:ed2c228cbc9c 44 1. To customize idle handler, ensure the `MBED_TICKLESS` macro is not defined in `mbed_app.json`.
ccli8 16:ed2c228cbc9c 45 This gives flexibility for providing platform-dependent idle handler.
ccli8 16:ed2c228cbc9c 46 The `idle_hdlr` in `main.cpp` is a trivial example.
ccli8 14:83b73695da8f 47
ccli8 1:eb1da9d36e12 48 ## Execution
ccli8 1:eb1da9d36e12 49 To run this tickless example, target board must run with no ICE connected.
ccli8 1:eb1da9d36e12 50 With ICE connected, system will enter **Idle** mode (shallow sleep) rather than **Power-down** mode (deep sleep)
ccli8 16:ed2c228cbc9c 51 even though `CLK_PowerDown()` is called.
ccli8 1:eb1da9d36e12 52
ccli8 16:ed2c228cbc9c 53 **Note:** With old Nu-Link1 firmware version, ICE is unexpected connected in MASS mode. Update to the latest Nu-Link firmware version to fix the issue.
ccli8 1:eb1da9d36e12 54
ccli8 16:ed2c228cbc9c 55 ### Terminal output
ccli8 16:ed2c228cbc9c 56 With your terminal program configured with 115200/8-N-1, you would see output with:
ccli8 1:eb1da9d36e12 57 <pre>
ccli8 1:eb1da9d36e12 58 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 59 Wake up by WDT timeout from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 60
ccli8 1:eb1da9d36e12 61 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 62 Wake up by <b>Unidentified</b> from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 63
ccli8 1:eb1da9d36e12 64 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 65 Wake up by Button2 from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 66
ccli8 1:eb1da9d36e12 67 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 68 Wake up by RTC alarm from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 69
ccli8 1:eb1da9d36e12 70 I am going to shallow/deep sleep
ccli8 1:eb1da9d36e12 71 Wake up by Button1 from <b>deep sleep</b>
ccli8 1:eb1da9d36e12 72 </pre>
ccli8 1:eb1da9d36e12 73
ccli8 1:eb1da9d36e12 74 1. If you see `shallow sleep` rather than `deep sleep`, you just enter **Idle** mode (shallow sleep) rather than
ccli8 1:eb1da9d36e12 75 **Power-down** mode (deep sleep). And you need to check your environment.
ccli8 1:eb1da9d36e12 76 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 77 Usually it is `lp_ticker` which is internal with the tickless mechanism.
ccli8 1:eb1da9d36e12 78
ccli8 16:ed2c228cbc9c 79 ## Reference
ccli8 1:eb1da9d36e12 80
ccli8 16:ed2c228cbc9c 81 - [Tickless kernel](https://en.wikipedia.org/wiki/Tickless_kernel)
ccli8 16:ed2c228cbc9c 82 - [Mbed tickless](https://os.mbed.com/docs/mbed-os/v5.15/porting/tickless.html)