Hi All.
I am working on imx8mn ddr3l system and changed console port with uart1 from default 2
see to check [imx8mn ddr3l evk] how to setup console port uart1 frm default uart2 - NXP Community
Now I am trying to read/write uart 2/3/4 on u-boot.
But I don't have idea how to read/write uart port on u-boot.
here is my trying example.
========================================================
#include <common.h>
#include <command.h>
#include <dm.h>
#include <serial.h>
#define UART_TIMEOUT_MS 10000
static int do_uart_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
const char *message;
const char *uart_base_str;
ulong uart_base;
if (argc != 3) {
printf("Usage: uart_test <uart_base> <message>\n");
return CMD_RET_USAGE;
}
/* UART base address */
uart_base_str = argv[1];
message = argv[2];
uart_base = simple_strtoul(uart_base_str, NULL, 16);
/* UART base address */
printf("Setting UART base address to 0x%lx\n", uart_base);
serial_setbrg(); // UART
printf("Sending message to UART at base address 0x%lx: %s\n", uart_base, message);
for (const char *p = message; *p; p++) {
serial_putc(*p);
}
serial_putc('\n');
printf("Message sent successfully.\n");
printf("Receiving data:\n");
ulong start_time = get_timer(0);
while (1) {
if (serial_tstc()) { // check if received data exist
char c = serial_getc();
if (c == '~') { // setup for exit condition with ~
break;
}
putc(c); // show received character
start_time = get_timer(0);
}
if (get_timer(start_time) > UART_TIMEOUT_MS) {
printf("\nTimeout: No data received for %d ms\n", UART_TIMEOUT_MS);
break;
}
}
printf("\nReception finished.\n");
return CMD_RET_SUCCESS;
}
U_BOOT_CMD(
uart_test, 3, 1, do_uart_test,
"Test UART communication ",
"<uart_base> <message>\n"
" - Send <message> to the specified UART at <uart_base>.\n"
" - Terminate reception on '~'."
);
========================================================
Let me know how to read/write uart on u-boot ?
-Best Regards-
HI.. it works now,
I got a useful link about the issue. Re: how to read/write uart 2/3/4 on u-boot with imx8mn ddr3l evk board ? - NXP Community
Now, I can tx via uart2.
HI @justin-inno!
Unfortunately we don't have examples reading UART from U-boot.
I recommend to consult the U-Boot Documentation for that.
Best Regards!
Chavira
Hi @justin-inno!
You can develop a program to run in u-boot, maybe you can develop your own driver.