Hi,
I am migrating a project to NRF Connect SDK and an having an issue changing the RX/TX pins so that I can talk to s different device via same UART instance.
On previous SDK, this was quite simple and worked fine using nrf_libuarte_async_uninit(&libuarte);
However with NRF Connect SDK (I'm using 2.4.0), it is more complex. I have looked at the documentation here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/pinctrl/index.html#
And also posts such as:
How to switch uart pins while runtime using pinctrl (Zephyr) (nrf52832) ?
However, I am still unable to progress.
One issue is that when I try and define additional pinctrl states as per docs:
periph0: periph@0 {
...
/* state 0 ("default") */
pinctrl-0 = <...>;
...
/* state N ("mystate") */
pinctrl-N = <...>;
/* names for state 0 up to state N */
pinctrl-names = "default", ..., "mystate";
...
};
I get compilation errors.
For example the following works:
modem_uart: &uart1 {
status = "okay";
current-speed = <115200>;
// pinctrl-0 = <&uart1_default_alt>;
// pinctrl-1 = <&uart1_sleep_alt>;
pinctrl-0 = <&uart1_default>;
pinctrl-1 = <&uart1_sleep>;
pinctrl-names = "default","sleep";
//pinctrl-names = "default-alt","sleep-alt","default","sleep";
};
&pinctrl {
compatible = "nordic,nrf-pinctrl";
uart1_default_alt: uart1_default_alt {
group1 {
psels = <NRF_PSEL(UART_RX, 0, 30)>, <NRF_PSEL(UART_TX, 0, 31)>;
};
};
uart1_sleep_alt: uart1_sleep_alt {
group1 {
psels = <NRF_PSEL(UART_RX, 0, 30)>, <NRF_PSEL(UART_TX, 0, 31)>;
};
};
uart1_default: uart1_default {
group1 {
psels = <NRF_PSEL(UART_RX, 0, 8)>, <NRF_PSEL(UART_TX, 0, 7)>;
};
};
uart1_sleep: uart1_sleep {
group1 {
psels = <NRF_PSEL(UART_RX, 0, 8)>, <NRF_PSEL(UART_TX, 0, 7)>;
};
};
};
But if I try and add two more pinctrl states, the code no longer compiles:
modem_uart: &uart1 {
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart1_default_alt>;
pinctrl-1 = <&uart1_sleep_alt>;
pinctrl-2 = <&uart1_default>;
pinctrl-3 = <&uart1_sleep>;
//pinctrl-names = "default","sleep";
pinctrl-names = "default-alt","sleep-alt","default","sleep";
};
&pinctrl {
compatible = "nordic,nrf-pinctrl";
uart1_default_alt: uart1_default_alt {
group1 {
psels = <NRF_PSEL(UART_RX, 0, 30)>, <NRF_PSEL(UART_TX, 0, 31)>;
};
};
uart1_sleep_alt: uart1_sleep_alt {
group1 {
psels = <NRF_PSEL(UART_RX, 0, 30)>, <NRF_PSEL(UART_TX, 0, 31)>;
};
};
uart1_default: uart1_default {
group1 {
psels = <NRF_PSEL(UART_RX, 0, 8)>, <NRF_PSEL(UART_TX, 0, 7)>;
};
};
uart1_sleep: uart1_sleep {
group1 {
psels = <NRF_PSEL(UART_RX, 0, 8)>, <NRF_PSEL(UART_TX, 0, 7)>;
};
};
};
The error is:
/opt/nordic/ncs/v2.4.0/zephyr/include/zephyr/drivers/pinctrl.h:93:17: error: 'PINCTRL_STATE_DEFAULT_ALT' undeclared here (not in a function);
I have also tried using groups which compiles OK but unfortunately, only the last group is ever referenced - this seems to be a known limitation.
My plan (if I can get more than two states to work) is use the pause/resume approach:
// Suspend UART pm_device_action_run(modem_uart, PM_DEVICE_ACTION_SUSPEND); // Select state > 1U which hopefully maps to my new pin configs pinctrl_apply_state(config->pcfg, PINCTRL_STATE_PRIV_START); // Resume UART pm_device_action_run(modem_uart, PM_DEVICE_ACTION_RESUME);
Any help would be appreciated as I am out of ideas...
Nick