NRF5340 UART completely turn off and turn on dynamically in app program

Hello

I am using NRF5340 as Soc in my project. In application program I have used uart0 for data transfer. At the same time the power consumption is really important for me

because the board is battery powered. So in idle times I turn off the uart0 by NRF_UARTE0->ENABLE = 0   command and turn it on again by NRF_UARTE0->ENABLE = 8

command. In this way I can reduce the current consumption from 1.5ma to 0.84ma. The problem is that when I add  CONFIG_SERIAL=n in the prj.conf file the current

reduces more and goes to 0.48ma. As far as I could understand from the dev zone studies the NRF_UARTE0->ENABLE = 0 command doesn't turn off the clock of uart0

but the command CONFIG_SERIAL=n does. Now I want to to know how can I completely turn off uart0 in my application program(not by prj.conf modification) and also

turn it on again. Thank you in advance for you support.

Parents
  • To enable/disable UART dynamically in your program you can set CONFIG_PM_DEVICE=y and use pm_device_action_run(). Check out the modem shell sample to see how to use this function.

    Best regards,

    Simon

  • Hi Simon

    I have added CONFIG_PM_DEVICE=y in the prj.config and also added the modem shell sample code in my program.

     I only used the code for uart0. But the sdk can not recognize pm_device_action_run() function and issued

    (undefined reference to `pm_device_action_run')

    static void uart0_set_enable(bool enable)
    {
    	const struct device *uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart0));
    
    	if (!device_is_ready(uart_dev)) {
    		return;
    	}
    
    	pm_device_action_run(uart_dev, enable ? PM_DEVICE_ACTION_RESUME : PM_DEVICE_ACTION_SUSPEND);
    }
    void disable_uarts(void)
    {
    	uart0_set_enable(false);
    	//uart1_set_enable(false);
    }
    
    void enable_uarts(void)
    {
    	uart0_set_enable(true);
    	//uart1_set_enable(true);
    }
    
    error.

Reply
  • Hi Simon

    I have added CONFIG_PM_DEVICE=y in the prj.config and also added the modem shell sample code in my program.

     I only used the code for uart0. But the sdk can not recognize pm_device_action_run() function and issued

    (undefined reference to `pm_device_action_run')

    static void uart0_set_enable(bool enable)
    {
    	const struct device *uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart0));
    
    	if (!device_is_ready(uart_dev)) {
    		return;
    	}
    
    	pm_device_action_run(uart_dev, enable ? PM_DEVICE_ACTION_RESUME : PM_DEVICE_ACTION_SUSPEND);
    }
    void disable_uarts(void)
    {
    	uart0_set_enable(false);
    	//uart1_set_enable(false);
    }
    
    void enable_uarts(void)
    {
    	uart0_set_enable(true);
    	//uart1_set_enable(true);
    }
    
    error.

Children
Related