UART function switching runtime on nRF5340

Hi,

In our projects, all of the digital interfaces have been assigned to different functions.

(2 group of I2C port with multiple sensors, 1 UART port for RS485 communication, 1 UART port for debug console) 

But we still need one extra UART port to read a low throughput sensor.

Hence, our plan is to conduct pin switching runtime between UART console and UART sensor.

We only need to read the sensor(~100bytes)  every 4 minutes.

Our planning as below:

1. uart0 assigned for uart console in device tree.  ie: gpio 0.20 and gpio 0.21

2. run uart0 suspend by pm_device_action_run(uart_dev, suspend)

3. reconfigure uart function to other pins by pinctrl_configure_pins

     ie: gpio 1.10 and gpio1.11 in our project

4. run uart0 resume by pm_device_action_run(uart_dev, resume)

5. read sensor data here

6. uart0 suspend

7. call pinctrl_configure_pins to set console pins. ie: gpio 0.20 and gpio 0.21

8. uart0 resume

9. uart debug console works

I will ignore the pinctrl_apply_state function from the uart suspend/resume functions.

Is there any problem in the uart pin switch flow?

  • Hi Jacob, 


    Could you let me know if you have implemented your planning steps or it's that you are asking if it's feasible ? 
    As far as I know Zephyr doesn't support pin re-configuration at run time after the peripheral has been initialized. Please take a look here: 
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/pinctrl/index.html#dynamic-pin-control

    Dynamic pin control should only be used on devices that have not been initialized. Changing pin configurations while a device is operating may lead to unexpected behavior. Since Zephyr does not support device de-initialization yet, this functionality should only be used during early boot stages.

    Have you consider using an extra UART, for example UART1 on the other pins ? 

  • Hi Hung,

    nRF-5340 only can run 4 digital interfaces simultaneously.

    We have assigned two I2C and two uart on different features.

    The digital interfaces are not enough and that's why I have to use this bad way to switch uart function dynamically.

    I have tried it on a test program and it seems to work.

    The uart device is put in suspend state that means it won't be running during pin switching.

    Then I can write the different psel into the register by NRF_PSEL_UART.

    My main concern is the stability, since this approach is not officially supported by NCS.

    Thanks,

    Jacob

  • Hi Jacob, 

    Our UART peripheral hardware does support changing the GPIO pins dynamically. And I believe nrfx library support it as well. However the higher level in Zephyr still mark it as not supported. 
    We can't give guarantee for something that haven't fully tested. 
    But from what I can see in the code nrfx does disable UART when you suspend the device via pm. Your approach would work I think. But as I mentioned, it's on your own to test the stability as this is not supported by Zephyr. 

Related