[riot-notifications] [RIOT-OS/RIOT] kinetis: Implement low power modes (#11789)

Thomas Stilwell notifications at github.com
Thu Jul 4 08:03:21 CEST 2019


### Contribution description
Taken from #7897 

Implements low power modes using pm_layered with automatic blocking of modes depending on what peripherals are in use. Defaults to unblocking all low power modes otherwise.

The UART, I2C, LPTMR, and PIT peripheral drivers are updated to block power modes as appropriate. Other peripherals should continue working unaffected by this PR.

Kinetis boards that have a UART or LPUART configured need to add `uart_config.llwu_rx = LLWU_WAKEUP_PIN_UNDEF` to `periph_conf.h`. I think this PR updates them all but I didn't verify it. Missing this definition results in LLS mode being unblocked without any way to wake on UART activity.

Kinetis boards using LPTMR need to add `LPTMR.llwu = LLWU_WAKEUP_MODULE_LPTMR0` to `periph_conf.h`.

I only have kw41z to test this on but hopefully with some feedback it should be working on other platforms too. I'm not sure if I2C has ever been tested. It needed a blocker since it yields until an IRQ instead of spinning like other peripherals.

Since #7897 I fixed some problems with the blocking logic in the UART driver and it's possible that the issues observed on `pba-d-01-kw2x` are resolved now but I don't have this board to test with.

### Testing procedure
#11731 could be useful to help test this.

On `frdm-kw41z` with `STDIO_UART_BAUDRATE=115200` running `tests/periph_pm` should start up with mode 2 (`KINETIS_PM_STOP`) blocked and everything else unblocked:
```
main(): This is RIOT! (Version: 2019.07-devel-929-g881951-HEAD)
This application allows you to test the CPU power management.
The available power modes are 0 - 3. Lower-numbered power modes
save more power, but may require an event/interrupt to wake up
the CPU. Reset the CPU if needed.
mode 0 blockers: 0 
mode 1 blockers: 0 
mode 2 blockers: 1 
mode 3 blockers: 0 
lowest allowed mode: 3
>
```
Slow the baudrate with `CFLAGS+=-DSTDIO_UART_BAUDRATE=9600 make` to allow mode 2 unblocked:
```shell
mode 0 blockers: 0 
mode 1 blockers: 0 
mode 2 blockers: 0 
mode 3 blockers: 0 
lowest allowed mode: 0
>
```

After verifying that the shell continues working from mode 0, it should be safe to test blocking and forcing other modes and observe the current consumption in each mode without worry of breaking the shell or other bad things happening:
```shell
lowest allowed mode: 0
> block 0
Blocking power mode 0.
> block 1
Blocking power mode 1.
> pm show
mode 0 blockers: 1 
mode 1 blockers: 1 
mode 2 blockers: 0 
mode 3 blockers: 0 
lowest allowed mode: 2
> set 1
CPU is entering power mode 1.
Now waiting for a wakeup event... #enter pressed
CPU has returned from power mode 1.
> 
> 
```
Take care not to unblock a mode that isn't blocked as there's an assertion for that (#11731 prints a friendly error instead).

Aside from that, the shell should remain responsive no matter what, and it's a bug if it doesn't. That's assuming that it was verified that it stayed working from mode 0 to begin with. A board with a valid UART LLWU pin defined (<code>uart_config.llwu_rx <b>!=</b> LLWU_WAKEUP_PIN_UNDEF</code>) is required for this to work. Otherwise `uart_poweron()` will block mode 0 and if you unblock it manually or force mode 0 the shell will stop responding to input.

In case of an unresponsive shell on startup, change `cpu/kinetis/include/periph_cpu.h:PM_BLOCKER_INITIAL` to `{ .val_u32 = 0x01010101 }` to block all modes on startup and then manually unblock them to see which ones break.

### Issues/PRs references

This [comment](https://github.com/RIOT-OS/RIOT/pull/7897#issuecomment-504265108) has current consumption reference values as well as some information about PM usage and current measurement procedures.

You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/11789

-- Commit Summary --

  * boards/common/frdm: Set connect_assert_srst in default OpenOCD config
  * cpu/kinetis: Add low power support
  * boards: Add UART LLWU config to Kinetis boards
  * boards: Add LPTMR LLWU config to Kinetis boards
  * cpu/kinetis/uart: rework choosing of required PM blockers

-- File Changes --

    M boards/common/frdm/dist/openocd-klx.cfg (5)
    M boards/common/frdm/dist/openocd-kx.cfg (5)
    M boards/common/kw41z/include/periph_conf_common.h (26)
    M boards/frdm-k22f/include/periph_conf.h (18)
    M boards/frdm-k64f/include/periph_conf.h (18)
    M boards/mulle/include/periph_conf.h (21)
    M boards/pba-d-01-kw2x/include/periph_conf.h (2)
    M boards/teensy31/include/periph_conf.h (2)
    M cpu/kinetis/Makefile.features (2)
    M cpu/kinetis/Makefile.include (4)
    M cpu/kinetis/cpu.c (15)
    M cpu/kinetis/include/cpu_conf_kinetis.h (139)
    A cpu/kinetis/include/llwu.h (79)
    M cpu/kinetis/include/periph_cpu.h (45)
    M cpu/kinetis/periph/i2c.c (8)
    A cpu/kinetis/periph/llwu.c (106)
    M cpu/kinetis/periph/pm.c (69)
    M cpu/kinetis/periph/rtt.c (9)
    M cpu/kinetis/periph/timer.c (34)
    M cpu/kinetis/periph/uart.c (430)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/11789.patch
https://github.com/RIOT-OS/RIOT/pull/11789.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11789
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190703/5f0967e6/attachment.html>


More information about the notifications mailing list