From e1ba5288a88a26866b2c7ef7344bf31f11373177 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Wed, 8 Mar 2023 20:05:24 +0100 Subject: [PATCH 1/2] Make the start write address optional when writing data to a memory that's exactly one byte large --- src/term.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/term.c b/src/term.c index 0828e17e..5100a28e 100644 --- a/src/term.c +++ b/src/term.c @@ -406,10 +406,11 @@ static int is_mantissa_only(char *p) { static int cmd_write(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) { - if (argc < 4) { + if (argc < 3) { msg_error( "Usage: write [,] {[,]}\n" " write [,] {[,]} ...\n" + " write \n" "\n" "Ellipsis ... writes bytes padded by repeating the last item.\n" "\n" @@ -456,13 +457,23 @@ static int cmd_write(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) { } int maxsize = mem->size; - char *end_ptr; - int addr = strtoul(argv[2], &end_ptr, 0); - if (*end_ptr || (end_ptr == argv[2])) { - pmsg_error("(write) cannot parse address %s\n", argv[2]); + if (argc == 3 && maxsize > 1) { + pmsg_error("(write) no start address specified for memory %s\n" + "Please specify a start address for memories greater than 1 byte in size\n", + memtype); return -1; } + char *end_ptr; + int addr = 0; + if(argc >= 4) { + addr = strtoul(argv[2], &end_ptr, 0); + if (*end_ptr || (end_ptr == argv[2])) { + pmsg_error("(write) cannot parse address %s\n", argv[2]); + return -1; + } + } + if (addr < 0 || addr >= maxsize) { pmsg_error("(write) %s address 0x%05x is out of range [0, 0x%05x]\n", mem->desc, addr, maxsize-1); return -1; @@ -487,7 +498,12 @@ static int cmd_write(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) { } } else { write_mode = WRITE_MODE_STANDARD; - start_offset = 3; + // With no user specified start address, data starts at argv[2] + // With user specified start address, data starts at a argv[3] + if(argc == 3) + start_offset = 2; + else + start_offset = 3; len = argc - start_offset; } From 4311da6803819ca52d0446796ce4ff05711cbf9a Mon Sep 17 00:00:00 2001 From: MCUdude Date: Wed, 15 Mar 2023 20:14:32 +0100 Subject: [PATCH 2/2] Document terminal write feature where start addres isn't needed --- src/avrdude.1 | 5 +++++ src/doc/avrdude.texi | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/avrdude.1 b/src/avrdude.1 index eb8ab98d..158a5085 100644 --- a/src/avrdude.1 +++ b/src/avrdude.1 @@ -910,6 +910,11 @@ needs eight bytes as it is the same as 0xFFFFffffFFFFffffU. One trailing comma at the end of .Ar data items is ignored to facilitate copy & paste of lists. +.It Ar write memory data +The start address +.Ar addr +may be omitted if the size of the memory being written to is +1 byte in size. .It Ar write memory addr len data[,] {data[,]} ... The ellipsis ... form writes bytes padded by repeating the last .Ar data diff --git a/src/doc/avrdude.texi b/src/doc/avrdude.texi index 4a2197a9..944d1d03 100644 --- a/src/doc/avrdude.texi +++ b/src/doc/avrdude.texi @@ -1616,6 +1616,10 @@ eight bytes as it is the same as @code{0xFFFFffffFFFFffffU}. One trailing comma at the end of data items is ignored to facilitate copy and paste of lists. +@item write @var{memtype} @var{addr} @var{data} +The start address @code{addr} may be omitted if the size of the memory +being written to is 1 byte in size. + @item write @var{memtype} @var{addr} @var{length} @var{data[,]} @{@var{data[,]}@} @dots{} The ellipses form @dots{} of write is similar to above, but @var{length} byte of the memory are written. For that purpose, after writing the