Trying to use UART2 witn custom nrf9151 board non secure

Hi all,

I'm trying to use uart2 on my custom nrf9151 board, but I'm stuck. As I understand, I use i2c1 so I can't use uart1 and i2c1in parallel, so here is why I wnt to use uart2. 

Here is my configufration: I use P0.23 and P0.24 in my dtsi file

	uart2_default: uart2_default {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 23)>,
				<NRF_PSEL(UART_RX, 0, 24)>;
		};
	};

	uart2_sleep: uart2_sleep {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 23)>,
				<NRF_PSEL(UART_RX, 0, 24)>;
			low-power-enable;
		};
	};

And in overlay file

&uart2 {
    status = "okay";
    current-speed = <115200>;
    pinctrl-0 = <&uart2_default>;
    pinctrl-1 = <&uart2_sleep>;
    pinctrl-names = "default", "sleep";
};

and I've added CONFIG_UART_ASYNC_API=y in my prj.conf. So after all thaht setup I've write uart_async.c file (inspired by devacedemy here)

#define UART_NODE DT_NODELABEL(uart2)
#define RX_BUF_SIZE 64
#define RX_TIMEOUT 100

static const struct device *uart_dev;
static uint8_t rx_buf[RX_BUF_SIZE];

struct tx_msg {
	uint8_t data[64];
	size_t len;
};


static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data) {
	switch (evt->type) {

	case UART_TX_DONE:
		LOG_DBG("TX done (%d bytes)", evt->data.tx.len);
		break;

	case UART_TX_ABORTED:
		LOG_ERR("TX aborted");
		break;

	case UART_RX_RDY:
		if (evt->data.rx.len > 0) {
			LOG_INF("RX");
			LOG_HEXDUMP_INF(&evt->data.rx.buf[evt->data.rx.offset],
			                evt->data.rx.len,
			                "RX Data");

			for (size_t i = evt->data.rx.offset; i < evt->data.rx.offset + evt->data.rx.len; i++) {
				if (rx_buf[i] == '\n') {
					LOG_INF("End of message detected");
				}
			}
		}
		break;

	case UART_RX_DISABLED:
		LOG_WRN("RX disabled, re-enabling");
		uart_rx_enable(dev, rx_buf, sizeof(rx_buf), RX_TIMEOUT);
		break;

	case UART_RX_BUF_REQUEST:
		// RX buffer management not used in this basic example
		break;

	case UART_RX_BUF_RELEASED:
		// RX buffer management not used in this basic example
		break;

	case UART_RX_STOPPED:
		LOG_ERR("RX stopped due to error %d", evt->data.rx_stop.reason);
		break;

	default:
		break;
	}
}

int uart_init(void) {
	uart_dev = DEVICE_DT_GET(UART_NODE);
	if (!device_is_ready(uart_dev)) {
		LOG_ERR("UART device not ready");
		return -ENODEV;
	}

	const struct uart_config uart_cfg = {
		.baudrate = 115200,
		.parity = UART_CFG_PARITY_NONE,
		.stop_bits = UART_CFG_STOP_BITS_1,
		.data_bits = UART_CFG_DATA_BITS_8,
		.flow_ctrl = UART_CFG_FLOW_CTRL_NONE
	};

	int ret = uart_configure(uart_dev, &uart_cfg);

	if (ret == -ENOSYS) {
		return -ENOSYS;
	}


	ret = uart_rx_enable(uart_dev, rx_buf, sizeof(rx_buf), RX_TIMEOUT);
	if (ret) {
		LOG_ERR("Failed to enable UART RX (%d)", ret);
		return ret;
	}

	LOG_INF("UART initialized");
	return 0;
}

int uart_send_data(const uint8_t *data, size_t len) {
	int ret = uart_tx(uart_dev, data, len, SYS_FOREVER_MS);
	if (ret) {
		LOG_ERR("UART TX failed (%d)", ret);
		return ret;
	}
	return 0;
}

and my main

	uart_init();


	static uint8_t tx_buf[] = {
		"nRF Connect SDK Fundamentals Course\r\n"
	};

	uart_send_data(tx_buf, sizeof(tx_buf));
	....

Everything build but when my board boot, I receive my tx data but after thaht my board seem to be freeze nothing happen. If I boot my board without cp21 connected to P0.23/24 my board boot and run normaly, but if I try to send data through my cp21 i receive nothing...

Is there other configuration I missed in non secure to use uart2? It's seem RX pin to somthing, if I unplung it from mycp2102 my board boot normally

Related