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.

Parents
  • 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

    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

  • Hm, not sure, maybe it was somehow mixed up:

    If "CONFIG_SERIAL=n" is used, then you don't need the "power_manager" stuff.

    So the part:

    #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

    must/may be switched off by "#if 0".

    If "CONFIG_SERIAL=y" is used, then you may use the "power_manager" stuff. But don't call "pm_device_state_set(uart_dev,PM_DEVICE_STATE_OFF);" unconditional. I would always guard that with

    if (device_is_ready(uart_dev)) {
      pm_device_state_set(uart_dev,PM_DEVICE_STATE_OFF);
    }

    that doesn't crash, even if "uart_dev" is NULL.

  • Achim

    I used the second method with CONFIG_SERIAL=y and pm_device_state_set(uart_dev,PM_DEVICE_STATE_OFF); it does disable the UARt and does not crash. The production application continues to run. Thank you very much. you can close this ticket.

Reply Children
Related