Unable to disable UART at runtime NCS v2.2.0

Hi,

I have the following minimal example:

main.c

#include ...

#define LOG_MODULE_NAME hci_uart
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#if defined(CONFIG_SERIAL)
static const struct device *hci_uart_dev =
    DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_c2h_uart));
#endif

static const struct device *led;

#define LED_NODE_ID DT_INST(0, gpio_leds)
#define LED_DEV_NAME DEVICE_DT_NAME(LED_NODE_ID)

void main(void) {
  led = device_get_binding(LED_DEV_NAME);

#if defined(CONFIG_SERIAL)
  int err=0;
  //err = pm_device_action_run(hci_uart_dev, PM_DEVICE_ACTION_SUSPEND);
  if (err) {
    led_on(led, 1);
  }
#endif

  int blink_status = 0;
  while (1) {
    if ((++blink_status) % 2) {
      led_on(led, 0);
    } else {
      led_off(led, 0);
    }

    k_sleep(K_SECONDS(1));
  }
}

proj.conf:

CONFIG_CONSOLE=n

CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y
CONFIG_LED=y
CONFIG_LED_GPIO=y

CONFIG_PM=y
CONFIG_PM_DEVICE=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512

Now, when setting CONFIG_SERIAL=n my nRF52840DK drains about 3-4 µA, when setting CONFIG_SERIAL=y it drains about 520 µA. That seems reasonable. Now I want to disable the UART at runtime, therefore I remove the comments in line 21. But this has no effect regarding the current. The return value is 0, so no error is reported. I read almost every thread regarding "disable UART" here in devzone, but no solution solved my problem. Any hints or ideas what I am missing?

What is confusing me is that the same appears to happen in the system_off sample. Maybe just my assumption is wrong that disabling the UART at runtime should lead to the same current consumption as CONFIG_SERIAL=n?

Regards,
Oliver

Parents
  • Fyi: I edited my code example. In line 21 it must be PM_DEVICE_ACTION_SUSPEND instead of PM_DEVICE_ACTION_TURN_OFF. 

  • Hi,

    For an example on how to disable UART, see the modem shell sample.

    How much current draw are you measuring after calling pm_device_action_run?

    Could it be that you suspend the wrong device?

    Try to suspend "uart0" as in the modem shell sample, and see if you can see any difference?

    Regards,
    Sigurd Hellesvik

  • Got it! Your hint regarding the modem shell sample led me to the right direction. It was not a wrong device, it was just one device too few. I have to disable uart1 too. I just overlooked that uart1 is enabled in the boards device tree and thus was enabled by CONFIG_SERIAL=y too. I added 

    &uart1 {
    	compatible = "nordic,nrf-uart";
    	status = "disabled";
    };
    

    in my board overlay file. This leads to about 3,5 µA which is perfect.

    Thanks and regards,
    Oliver

  • Hi,

    I want to let the current of nrf5340(now is 580ua) be much lower in hello world sample,

    I tried to disable UART using the code in the sample but there is a build error.

    it says "undefined reference to `__device_dts_ord_142'"

    How can I solve this?

    prj.conf

    CONFIG_PM=y
    CONFIG_PM_DEVICE=y
    CONFIG_PM_DEVICE_RUNTIME=y
    
    #config RTT
    CONFIG_LOG=n
    CONFIG_LOG_PRINTK=n
    # CONFIG_LOG_MODE_DEFERRED=y
    CONFIG_CONSOLE=n
    CONFIG_SERIAL=n
    CONFIG_UART_CONSOLE=n
    CONFIG_USE_SEGGER_RTT=n
    CONFIG_RTT_CONSOLE=n
    CONFIG_LOG_BACKEND_RTT=n
    CONFIG_LOG_BACKEND_UART=n
    
    # CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=4096
    # CONFIG_LOG_BUFFER_SIZE=4096
    
    # Disable internal DCDC
    CONFIG_BOARD_ENABLE_DCDC_APP=n
    CONFIG_BOARD_ENABLE_DCDC_NET=n
    CONFIG_BOARD_ENABLE_DCDC_HV=n
    
    # Use internal capacitor for 32M xtal and set capacitor value to 8.5pF 
    # (ranging from 7.0 pF to 20.0 pF in 0.5 pF steps
    # can be enabled on pins XC1 and XC2. This option specifies doubled
    # capacitance value for the two capacitors. Set it to 14 to get 7.0 pF
    # for each capacitor, 15 to get 7.5 pF, and so on.
    # )
    CONFIG_SOC_HFXO_CAP_INTERNAL=y
    CONFIG_SOC_HFXO_CAP_INT_VALUE_X2=17
     
    #  Use internal capacitor for 32k xtal and set capacitor value to 7pF 
    # (only 4 options of internal capacitor value settings for 32k xtal
    #   -INT_6PF
    #   -INT_7PF
    #   -INT_9PF
    #   - USE external capacitor)
    CONFIG_SOC_ENABLE_LFXO=y
    CONFIG_SOC_LFXO_CAP_INT_7PF=y

    Regards,

    Allen

Reply
  • Hi,

    I want to let the current of nrf5340(now is 580ua) be much lower in hello world sample,

    I tried to disable UART using the code in the sample but there is a build error.

    it says "undefined reference to `__device_dts_ord_142'"

    How can I solve this?

    prj.conf

    CONFIG_PM=y
    CONFIG_PM_DEVICE=y
    CONFIG_PM_DEVICE_RUNTIME=y
    
    #config RTT
    CONFIG_LOG=n
    CONFIG_LOG_PRINTK=n
    # CONFIG_LOG_MODE_DEFERRED=y
    CONFIG_CONSOLE=n
    CONFIG_SERIAL=n
    CONFIG_UART_CONSOLE=n
    CONFIG_USE_SEGGER_RTT=n
    CONFIG_RTT_CONSOLE=n
    CONFIG_LOG_BACKEND_RTT=n
    CONFIG_LOG_BACKEND_UART=n
    
    # CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=4096
    # CONFIG_LOG_BUFFER_SIZE=4096
    
    # Disable internal DCDC
    CONFIG_BOARD_ENABLE_DCDC_APP=n
    CONFIG_BOARD_ENABLE_DCDC_NET=n
    CONFIG_BOARD_ENABLE_DCDC_HV=n
    
    # Use internal capacitor for 32M xtal and set capacitor value to 8.5pF 
    # (ranging from 7.0 pF to 20.0 pF in 0.5 pF steps
    # can be enabled on pins XC1 and XC2. This option specifies doubled
    # capacitance value for the two capacitors. Set it to 14 to get 7.0 pF
    # for each capacitor, 15 to get 7.5 pF, and so on.
    # )
    CONFIG_SOC_HFXO_CAP_INTERNAL=y
    CONFIG_SOC_HFXO_CAP_INT_VALUE_X2=17
     
    #  Use internal capacitor for 32k xtal and set capacitor value to 7pF 
    # (only 4 options of internal capacitor value settings for 32k xtal
    #   -INT_6PF
    #   -INT_7PF
    #   -INT_9PF
    #   - USE external capacitor)
    CONFIG_SOC_ENABLE_LFXO=y
    CONFIG_SOC_LFXO_CAP_INT_7PF=y

    Regards,

    Allen

Children
No Data
Related