Skip to content

Commit

Permalink
TESTING: Support switching baud rate
Browse files Browse the repository at this point in the history
  • Loading branch information
goodspeed34 committed Oct 8, 2024
1 parent 748ceab commit a5f0301
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/ws63defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const static struct cmddef WS63E_FLASHINFO[CMD_END] = {
},
[CMD_SETBAUDR] = {
.cmd = 0x5a,
.dat = {0x00, 0x10, 0x0e, 0x00, /* BAUD, 921600 */
0x08, 0x01, 0x00, 0x00}, /* MAGC, 0x0108 */
.dat = {0x00, 0x10, 0x0e, 0x00, /* BAUD */
0x08, 0x01, 0x00, 0x00}, /* MAGC, 8N1? */
.len = 8,
},
[CMD_DOWNLOADI] = {
Expand Down
55 changes: 51 additions & 4 deletions src/ws63flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <config.h>

#include "baud.h"
#include "ws63defs.h"
#include "ymodem.h"
#include "fwpkg.h"
Expand Down Expand Up @@ -61,7 +62,7 @@ static struct argp_option options[] = {
static struct args {
char *args[MAX_PARTITION_CNT+3];
int verbose;
long baud;
int baud;
} arguments;

static error_t parse_opt(int key, char *arg, struct argp_state *state)
Expand All @@ -72,8 +73,28 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 'b':
if (!arg)
argp_usage(state);
fprintf(stderr, "Warning: specifying a baudrate is buggy!\n");
args->baud = atol(arg);

int baud = atoi(arg), speed_found = 0;

for (int i = 0; i < AVAIL_BAUD_N; i++) {
struct baud_ipair baud_pair = avail_baud_tbl[i];
if (baud_pair.baud != baud) continue;
speed_found = 1;
break;
}

if (!speed_found) {
fprintf(stderr,
"Target baud %d not found,"
" maybe not supported by OS?\n"
"Available Baud: ", baud);
for (int i = 0; i < AVAIL_BAUD_N; i++)
printf("%d ", avail_baud_tbl[i].baud);
putchar('\n');
exit(EXIT_FAILURE);
}

args->baud = baud;
break;
case 'v':
args->verbose++;
Expand Down Expand Up @@ -264,8 +285,28 @@ int main (int argc, char **argv)

uart_read_until_magic(fd, arguments.verbose);

/* Xfer other files */
/* Set baud if neccessary */

if (arguments.baud == 115200) goto baud_done;

printf("Switching baud... ");
fflush(stdout);

struct cmddef baudcmd = WS63E_FLASHINFO[CMD_SETBAUDR];
*((uint32_t *) baudcmd.dat) = htole32(arguments.baud);

ret = ws63_send_cmddef(fd, baudcmd, arguments.verbose);
if (ret < 0)
return EXIT_FAILURE;

uart_read_until_magic(fd, arguments.verbose);
uart_open(&fd, NULL, arguments.baud);

printf("%d\n", arguments.baud);
uart_read_until_magic(fd, arguments.verbose);

/* Xfer other files */
baud_done:
for (int i = 0; i < header->cnt; i++) {
struct fwpkg_bin_info *bin = &bins[i];
if (bin->type_2 != 1) continue;
Expand All @@ -292,6 +333,9 @@ int main (int argc, char **argv)
return EXIT_FAILURE;
}

ret = ws63_send_cmddef(fd, baudcmd, arguments.verbose);
if (ret < 0)
return EXIT_FAILURE;
ret = ymodem_xfer(fd, fw,
bin->name, bin->length,
arguments.verbose);
Expand All @@ -303,5 +347,8 @@ int main (int argc, char **argv)
ws63_send_cmddef(fd, WS63E_FLASHINFO[CMD_RST], arguments.verbose);

uart_read_until_magic(fd, arguments.verbose);

/* Reset TTY to 115200 baud/s */
uart_open(&fd, NULL, 115200);
return EXIT_SUCCESS;
}

0 comments on commit a5f0301

Please sign in to comment.