Commit 6447b1c4 authored by Alberto Escolar Piedras's avatar Alberto Escolar Piedras Committed by Carles Cufi
Browse files

drivers/serial/uart_nrfx_uarte2: Fix for simulation

Just like for the old driver, for simulation, we cannot
get the UART regiter address for the pinctrl config structure
from DT, as that cannot match the one allocated at build time.
So let's override it at runtime with the correct address
which is stored in the UART config structure.

Also, do improve the condition for the busy wait during the poll_out,
for simulation, so we only busy wait if we will loop/the
Tx was busy.

Signed-off-by: default avatarAlberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
parent a4ed3994
Loading
Loading
Loading
Loading
+10 −3
Changes for drivers/serial/uart_nrfx_uarte2.c: 10 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -562,11 +562,13 @@ static void api_poll_out(const struct device *dev, unsigned char out_char)
		err = nrfx_uarte_tx(nrfx_dev, &out_char, 1, NRFX_UARTE_TX_EARLY_RETURN);
		__ASSERT(err != NRFX_ERROR_INVALID_ADDR, "Invalid address of the buffer");

		if (err == NRFX_ERROR_BUSY &&
		    IS_ENABLED(CONFIG_MULTITHREADING) && k_is_preempt_thread()) {
		if (err == NRFX_ERROR_BUSY) {
			if (IS_ENABLED(CONFIG_MULTITHREADING) && k_is_preempt_thread()) {
				k_msleep(1);
		}
			} else {
				Z_SPIN_DELAY(3);
			}
		}
	} while (err == NRFX_ERROR_BUSY);
}

@@ -789,6 +791,11 @@ static int uarte_nrfx_init(const struct device *dev)
	const struct uarte_nrfx_config *cfg = dev->config;
	struct uarte_nrfx_data *data = dev->data;

#ifdef CONFIG_ARCH_POSIX
	/* For simulation the DT provided peripheral address needs to be corrected */
	((struct pinctrl_dev_config *)cfg->pcfg)->reg = (uintptr_t)nrfx_dev->p_reg;
#endif

	err = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
	if (err < 0) {
		return err;