ncs1.61 peripheral_uart : enable uart when connected and disable uart when disconnected

Hi,

I work with win10 laptop, Toolchain  nrf Connect SDK 1.6.1 on a nrf5340dk.

On peripheral_uart sample, I would like to enable uart when a device is connected and I want to disable uart when device is disconnected to reduce consumption.

There is the consumption mesure by PPK2:

It's seem that between two advertisings the consumption is due to the enable uart.

I need to have the lowest consumption when the nrf5340dk is advertising.

First step, I tryed to disable uart from prj.conf:

CONFIG_SERIAL=n & CONFIG_LOG=n

but after build and download the 4 led were ON and the was no more advertising.

Second step, I tryed to disable uart from the overlay file:

&uart0 {
    status = "disable";

};

but after build and download there was no led on and no more advertising.

There is my project:

5040.peripheral_uart.zip

Could you give me, please,  an example how to enable uart when a device is connected and disable uart when device is disconnected ?

Best regards,

Rob.

Parents
  • Additionnal information:

    Hi,

    I found this ticket "UART Enable/Disable with sdk v1.3.0": https://devzone.nordicsemi.com/f/nordic-q-a/63714/uart-enable-disable-with-sdk-v1-3-0

    I tryed to use this code:

    "

    void uart_0_disable(void)
    {
       struct device *uart0_dev = device_get_binding("UART_0");
        device_set_power_state(uart0_dev, DEVICE_PM_OFF_STATE, NULL, NULL);
        
        gpio_pin_configure(gpio_dev, PIN_UART_0_RX, GPIO_OUTPUT);
        gpio_pin_set(gpio_dev, PIN_UART_0_RX, 0);

        gpio_pin_configure(gpio_dev, PIN_UART_0_TX, GPIO_OUTPUT);
        gpio_pin_set(gpio_dev, PIN_UART_0_TX, 0);
    }

    void uart_0_enable(void)
    {
        struct device *uart0_dev = device_get_binding("UART_0");
        device_set_power_state(uart0_dev, DEVICE_PM_ACTIVE_STATE, NULL, NULL);
    }

    "

    I modified the code for sdk 1.6.1 like this:

    "

    #include <pm/state.h>
    #include <pm/device.h>
    #include <pm/pm.h>

    #include <drivers/gpio.h>

    void uart_0_disable(void)

       uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
       pm_device_state_set(uart, PM_DEVICE_STATE_OFF, NULL, NULL);

       gpio_pin_configure(uart, 22, GPIO_DISCONNECTED);
       gpio_pin_set(uart, 22, 0);

       gpio_pin_configure(uart, 20, GPIO_DISCONNECTED);
       gpio_pin_set(uart, 20, 0);
       
    }

    void uart_0_enable(void)
    {
        uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
        pm_device_state_set(uart, PM_STATE_ACTIVE, NULL, NULL);
    }

    "

    But I still have this error: 

    /main.c:116: 'undefined reference to `pm_device_state_set'

    collect2.exe: error: ld returned 1 exit status

    Could anyone help me to resolve this error, please ?

    Best Regards,

    Rob.

Reply
  • Additionnal information:

    Hi,

    I found this ticket "UART Enable/Disable with sdk v1.3.0": https://devzone.nordicsemi.com/f/nordic-q-a/63714/uart-enable-disable-with-sdk-v1-3-0

    I tryed to use this code:

    "

    void uart_0_disable(void)
    {
       struct device *uart0_dev = device_get_binding("UART_0");
        device_set_power_state(uart0_dev, DEVICE_PM_OFF_STATE, NULL, NULL);
        
        gpio_pin_configure(gpio_dev, PIN_UART_0_RX, GPIO_OUTPUT);
        gpio_pin_set(gpio_dev, PIN_UART_0_RX, 0);

        gpio_pin_configure(gpio_dev, PIN_UART_0_TX, GPIO_OUTPUT);
        gpio_pin_set(gpio_dev, PIN_UART_0_TX, 0);
    }

    void uart_0_enable(void)
    {
        struct device *uart0_dev = device_get_binding("UART_0");
        device_set_power_state(uart0_dev, DEVICE_PM_ACTIVE_STATE, NULL, NULL);
    }

    "

    I modified the code for sdk 1.6.1 like this:

    "

    #include <pm/state.h>
    #include <pm/device.h>
    #include <pm/pm.h>

    #include <drivers/gpio.h>

    void uart_0_disable(void)

       uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
       pm_device_state_set(uart, PM_DEVICE_STATE_OFF, NULL, NULL);

       gpio_pin_configure(uart, 22, GPIO_DISCONNECTED);
       gpio_pin_set(uart, 22, 0);

       gpio_pin_configure(uart, 20, GPIO_DISCONNECTED);
       gpio_pin_set(uart, 20, 0);
       
    }

    void uart_0_enable(void)
    {
        uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
        pm_device_state_set(uart, PM_STATE_ACTIVE, NULL, NULL);
    }

    "

    But I still have this error: 

    /main.c:116: 'undefined reference to `pm_device_state_set'

    collect2.exe: error: ld returned 1 exit status

    Could anyone help me to resolve this error, please ?

    Best Regards,

    Rob.

Children
No Data
Related