How do I power off the UART

I have a nRF9160 board that is running off batteries. I need to conserve power and I would like to power off the UART. In the field I do not need any printouts or listening to keystrokes. How do I completely power off the UART? There will not be a terminal connected in the field. The terminal would only be used at the factory for configuring the boards and saving the configuration to Flash.

  • AFAIK, there are two ways:

    static:

    - CONFIG_SERIAL=n

    dynamic:

    - CONFIG_PM_DEVICE=y

    #include "power_manager.h"
    static const struct device *const uart0_dev = DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_console));
    if (device_is_ready(uart0_dev)) {
    ret = pm_device_action_run(uart0_dev, PM_DEVICE_ACTION_SUSPEND);
    }
  • Hi Timothy

    I agree with the suggestions from Achim. 

    For further reading this blog has a lot of good input on power management in general. It is targeted for nRF5340 designs specifically, but a lot of the information in the blog will be relevant for other devices as well. 

    Best regards
    Torbjørn

  • Achim - I tried the static method by setting CONFIG_SERIAL=n in prj.conf and I got the following repeatedly.

    *** Booting Zephyr OS build v2.6.99-ncs1 ***
    I: Starting bootloader
    I: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x1
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000
    *** Booting Zephyr OS build v2.6.99-ncs1 ***
    I: Starting bootloader
    I: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x1
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000

    I tried the dynamic message and I got the following message

    ../src/jfet_files/jfet_init.c: fatal error: power_manager.h: No such file or directory

    any idea what I am missing or doing wrong in either case?

  • > v2.6.99-ncs1

    I use NCS 2.1.2 with v3.1.99-ncs1-1. I'm not sure, what that older version offers.

    > CONFIG_SERIAL=n

    I guess your code access that device "unconditional".

    > ../src/jfet_files/jfet_init.c: fatal error: power_manager.h: No such file or directory

    I guess, that requires a newer version, e.g. NCS 2.1.2

    Anyway, for a fast solution without update to NCS 2.1.2, I would recommend, that you try one of the samples, e.g. blinky with CONFIG_SERIAL=n and see, if that works. Or the nrf9160 udp sample.

    If so, the try to find, where your code access the uart.

    If the blinky doesn't work, then I'm not sure, if that's related to OS version.

  • Achim

    if I put this at the start of main

    void main(void)
    {
    int err;

    #if 1
    /*Option 3: by chosen node*/
    #define MY_SERIAL DT_CHOSEN(zephyr_console)
    const struct device *uart_dev = device_get_binding(DT_LABEL(MY_SERIAL));
    pm_device_state_set(uart_dev,PM_DEVICE_STATE_OFF);
    #endif
    LOG_INF("asset_tracker AWS V2 WSSC Started");

    *******************************

    I get the following repeated. I am not able to upgrade to a later version. There is a lot of customer and device driver code that would have to be ported.. so a lot of the printout is disabled but it is not running my program. it is just continually rebooting.

    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000
    I: Starting bootloadert image slot
    I: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x1
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000
    I: Starting bootloadert image slot
    I: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x1
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none

Related