How to enable/disable the UART with NCS/Zephyr

My BLE application needs to communicate with another µC using serial UART - so I started my app based on the sample in bluetooth/peripheral_Uart
I'm have a nRF52_DK board (52832) and a custome hardware with the same features for testing.
I'm currently using NCS 1.9.1 with SES - (I'm not planning to change to NCS 2.x.x or VS Code for many reasons !)

The app works fine - but we need to run the whole thing later on a CR2032 battery and the power consumption is too high.

The nordic chip consumes approx 2.4 mA while doing nothing - and I noticed this is caused by the UART. When I do not init the UART, the application runs at 0.12 mA - I measure current via P22 on the nRF52_DK board.

My application has 2 GPIO pins already connected to the other µC and so I'm able to handshake and determine when to enable/disable the UART - I just have no idea what would the preferred way to do this ... can someone please help ?

thanks, Matthias

Parents
  • I tried a code like this - but it causes a kernel crash:

    void uart_power_down()
    {
       int err;
       enum pm_device_state uart0_power_state;
       const struct device* dev;

       dev = device_get_binding(CONFIG_BT_NUS_UART_DEV);
       err = pm_device_state_get(dev, &uart0_power_state);
       if (uart0_power_state == PM_DEVICE_STATE_ACTIVE)
       {
          err = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);   <-- crash!
          if (err) error();
       }
    }

Reply
  • I tried a code like this - but it causes a kernel crash:

    void uart_power_down()
    {
       int err;
       enum pm_device_state uart0_power_state;
       const struct device* dev;

       dev = device_get_binding(CONFIG_BT_NUS_UART_DEV);
       err = pm_device_state_get(dev, &uart0_power_state);
       if (uart0_power_state == PM_DEVICE_STATE_ACTIVE)
       {
          err = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);   <-- crash!
          if (err) error();
       }
    }

Children
Related