Best practice to re-configure uart/gpio at runtime in NCS v2.0.2

Hi,    
 
   
We are using NCS v2.0.2 on nRF52840.    
 
I have a question: what is the best practice to re-configure uart/gpio at runtime?    
 
What we need:    
 
1, Configure 2 IOs as UART TX/RX    
 
2, After ready to sleep, disable UARTE to save power, reconfigure the RX pin as a GPIO, and wait for interrupt.    
 
3, After new data coming from RX pin during sleep, the interrupt is triggered and wake up the system and then reconfigure IOs as UART TX/RX  (no need to worry about losing data during wake-up, the protocol on uart have a re-send mechanism to cover that)  
 
4, After data received/sent, ready to sleep and repeat step 2    
 
   
There are a lot of related functions from different layers:  Pin Control(Zephyr) / PRS(NCS) / nrfx_uart_* functions(nrf HAL) / using NRF_* registers directly  
Which is recommended? Using one of them or a combination of several?  

What I am planning to do:

a, set UARTE and GPIO in DeviceTree and set them as disabled    
 
b, set pin control dtsi to set default/sleep mode of uart/gpio  
 
c, During runtime,  
In step 2, call  
pm_device_action_run(uart_dev, PM_DEVICE_ACTION_SUSPEND);  
nrfx_uarte_uninit(&uart);
pm_device_action_run(gpio_dev, PM_DEVICE_ACTION_SUSPEND);  
gpio_pin_configure()  
gpio_pin_interrupt_configure(dev, DT_GPIO_PIN(RX0_NODE, gpios), GPIO_INT_EDGE_BOTH);  
 
in step 3, call  
gpio_pin_interrupt_configure(dev, DT_GPIO_PIN(RX0_NODE, gpios), GPIO_INT_DISABLE);  
pm_device_action_run(gpio_dev, PM_DEVICE_ACTION_RESUME);
nrfx_uarte_init()  
pm_device_action_run(uart_dev, PM_DEVICE_ACTION_RESUME);

Regards,

Anthony Yuan

Parents Reply Children
No Data
Related