UART time muxing in Zephyr

Hi!

I have a product based on nRF52832 with legacy code, that I would like to port to Zephyr.

It has 3 UART devices connected to the 3 pair of UART pins: GPS SOM on pins 6 and 7, LoRa SOM on pins 8 and 11, and an FTDI chip on pins 12 and 13.

The legacy firmware implements a "uart_select" function that re-configures UART on the fly.

My question is: what would be the proper way to implement this in Zephyr? Would it be possible to use pinmuxes? Or to write a UART mux driver?

Regards,

Eve

void uart_select(uint8_t Uart_Select)
{
    ret_code_t err_code;

    while(app_uart_send_in_progress());
    if(fUartOpen)
        app_uart_close();
    fUartOpen = 0;
    app_uart_comm_params_t comm_params =
    {
        .rx_pin_no    = 0,
        .tx_pin_no    = 0,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
        .baud_rate    = UARTE_BAUDRATE_BAUDRATE_Baud9600 //UART_BAUDRATE_BAUDRATE_Baud115200
    };

    if(Uart_Select == UART_LORA){
        nrf_gpio_cfg_default(RX_PIN_LORA);
        nrf_gpio_cfg_default(TX_PIN_LORA);
        comm_params.rx_pin_no = RX_PIN_LORA;
        comm_params.tx_pin_no = TX_PIN_LORA;
        comm_params.baud_rate = UART_LORA_BAUDRATE;
    }
    else if(Uart_Select == UART_GPS){
        nrf_gpio_cfg_default(RX_PIN_GPS);
        nrf_gpio_cfg_default(TX_PIN_GPS);
        comm_params.rx_pin_no = RX_PIN_GPS;
        comm_params.tx_pin_no = TX_PIN_GPS;
        comm_params.baud_rate = UART_GPS_BAUDRATE;
    }
    else{
        nrf_gpio_cfg_default(RX_PIN_FTDI);
        nrf_gpio_cfg_default(TX_PIN_FTDI);
        comm_params.rx_pin_no = RX_PIN_FTDI;
        comm_params.tx_pin_no = TX_PIN_FTDI;
        comm_params.baud_rate = UART_FTDI_BAUDRATE;
    }

    APP_UART_FIFO_INIT(&comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_event_handle,
                       UART_PRIORITY,
                       err_code);

    APP_ERROR_CHECK(err_code);

    fUartOpen = 1;
}

Related