diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb0c9b8..ee1cc57 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,4 +26,9 @@ jobs: run: | nextpnr-ecp5 --version yosys --version - pipenv run python3 ./sucrela.py --build \ No newline at end of file + pipenv run python3 ./sucrela.py --build + - name: Build the software + run: | + cd software/libuartbone + make + ./uartbone_cli -h diff --git a/software/libuartbone/linux_cli.c b/software/libuartbone/linux_cli.c index fc3a904..3be96b9 100644 --- a/software/libuartbone/linux_cli.c +++ b/software/libuartbone/linux_cli.c @@ -79,6 +79,10 @@ int get_reg_addr(FILE *csv, char *reg_name, uint32_t *res) { return 0; } +void print_usage(char *prog_name) { + printf("usage: %s uart_port [-V] [-b baudrate] [-r addr|reg_name] [-w addr|reg_name -v value] [-i] [-a addr_width]\n", prog_name); +} + int main(int argc, char **argv) { struct uartbone_ctx ctx; char ident_str[256]; @@ -95,13 +99,11 @@ int main(int argc, char **argv) { char *addr_string = NULL; uint32_t res, val; char *prog_name = argv[0]; - char *uart_port = argv[1]; + char *uart_port = NULL; char *csv_file = NULL; FILE *csv; - optind = 2; - - while ((opt = getopt(argc, argv, ":w:r:b:a:v:c:Vi")) != -1) { + while ((opt = getopt(argc, argv, ":w:r:b:a:v:c:u:Vih")) != -1) { switch (opt) { case 'r': char *endptr; @@ -124,32 +126,45 @@ int main(int argc, char **argv) { case 'b': baudrate = strtol(optarg, &endptr, 0); if (errno != 0 || endptr == optarg) - goto print_usage; + goto err_print_usage; break; case 'a': addr_width = strtol(optarg, &endptr, 0); if (errno != 0 || endptr == optarg) - goto print_usage; + goto err_print_usage; break; case 'c': csv_file = optarg; break; + case 'u': + uart_port = optarg; + break; case 'V': verbose = true; break; case 'v': val = strtol(optarg, &endptr, 0); if (errno != 0 || endptr == optarg) - goto print_usage; + goto err_print_usage; + break; + case 'h': + print_usage(prog_name); + return 0; break; case '?': default: - print_usage: - printf("usage: %s uart_port [-V] [-b baudrate] [-r addr|reg_name] [-w addr|reg_name -v value] [-i] [-a addr_width]\n", prog_name); + err_print_usage: + print_usage(prog_name); return -1; } } + if (!uart_port) { + printf("You must specify an uart port using -u uart_port\n"); + print_usage(prog_name); + return -1; + } + uartbone_unix_init(&ctx, uart_port, baudrate, addr_width); if (!ctx.open) {