Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In terminal only offer commands a programmer actually supports #1113

Merged
merged 7 commits into from
Oct 11, 2022

Conversation

stefanrueger
Copy link
Collaborator

Supposed to fix Issue #1104

@stefanrueger
Copy link
Collaborator Author

Here an example:

$ avrdude -qqt -c usbtiny -pm2560
avrdude> help
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> [<data>[,] {<data>[,]} | <len> <data>[,] {<data>[,]} ...]
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  part    : display the current part information
  send    : send a raw command: send <b1> <b2> <b3> <b4>
  sck     : set <SCK period>
  spi     : enter direct SPI mode
  pgm     : return to programming mode
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : help
  ?       : help
  quit    : quit after writing out cache for flash & EEPROM

Note that flash and EEPROM type memories are normally read and written
using a cache and paged r/w access; the cache is synchronised on quit.
Use the 'part' command to display valid memory types for use with the
'dump' and 'write' commands.

avrdude> parms
avrdude (cmd): invalid command parms
avrdude> 

Now that those commands that are not available are not called, we can remove all those lines such as

  if (pgm->set_sck_period == NULL) {
    terminal_message(MSG_INFO, "%s (sck): the %s programmer cannot set SCK period\n",
      progname, pgm->type);
    return -2;
  }

I am a big fan of recycling, so we can reuse the bytes saved here elsewhere ;)

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 7, 2022

Wow, that's a really clever solution to the problem! Much neater than what I probably would have done. Many thanks, @stefanrueger!

Tested with an USBasp and a pkobn_updi (Curiosity Nano), and seems to work perfectly.

@mcuee mcuee added the enhancement New feature or request label Oct 7, 2022
@mcuee
Copy link
Collaborator

mcuee commented Oct 7, 2022

@stefanrueger
This PR is good. But we have an issue now that we deprecate the original STK 500v1 HW and favor things like optiboot bootloader or "Arduino as ISP", but they do not actually have the capability of the STK500v1. Maybe we need to change something programmer capability of stk500v1 and arduino.

I think they will not support the following command.

  sig     : display device signature bytes
  parms   : display adjustable parameters (not meaningful)
  vtarg   : set <V[target]>
  varef   : set <V[aref]>
  fosc    : set <oscillator frequency>
  sck     : set <SCK period>

Run log:

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113 -qqt -c arduino -P COM5 -b 115200 -p m328p
avrdude> help
>>> help
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> [<data>[,] {<data>[,]} | <len> <data>[,] {<data>[,]} ...]
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  sig     : display device signature bytes
  part    : display the current part information
  send    : send a raw command: send <b1> <b2> <b3> <b4>
  parms   : display adjustable parameters
  vtarg   : set <V[target]>
  varef   : set <V[aref]>
  fosc    : set <oscillator frequency>
  sck     : set <SCK period>
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : help
  ?       : help
  quit    : quit after writing out cache for flash & EEPROM

Note that flash and EEPROM type memories are normally read and written
using a cache and paged r/w access; the cache is synchronised on quit.
Use the 'part' command to display valid memory types for use with the
'dump' and 'write' commands.

avrdude> parms
>>> parms
avrdude_pr1113.exe: stk500_recv(): programmer is not responding
avrdude_pr1113.exe: stk500_recv(): programmer is not responding
avrdude_pr1113.exe: stk500_recv(): programmer is not responding
avrdude_pr1113.exe: stk500_recv(): programmer is not responding
avrdude_pr1113.exe: stk500_recv(): programmer is not responding
Vtarget         : 0.0 V
Varef           : 85144128.0 V
Oscillator      : 0.003 Hz
SCK period      : 788.9 us

avrdude> sig
>>> sig
avrdude_pr1113.exe: error reading signature data for part "ATmega328P", rc=-1
avrdude_pr1113.exe (sig): error reading signature data, rc=-1
Device signature = 0xffffff

@mcuee
Copy link
Collaborator

mcuee commented Oct 7, 2022

Same issue for stk500v2. wiring will certainly not support many of the features of the Real STK500 v2. Even AVRISP mkii will not support some commands of the STK500 v2. So things become quite complicated.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113 -qqt -c avrispmkii -p m328p
avrdude> help
>>> help
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> [<data>[,] {<data>[,]} | <len> <data>[,] {<data>[,]} ...]
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  sig     : display device signature bytes
  part    : display the current part information
  send    : send a raw command: send <b1> <b2> <b3> <b4>
  parms   : display adjustable parameters
  vtarg   : set <V[target]>
  varef   : set <V[aref]>
  fosc    : set <oscillator frequency>
  sck     : set <SCK period>
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : help
  ?       : help
  quit    : quit after writing out cache for flash & EEPROM

Note that flash and EEPROM type memories are normally read and written
using a cache and paged r/w access; the cache is synchronised on quit.
Use the 'part' command to display valid memory types for use with the
'dump' and 'write' commands.

avrdude> sig
>>> sig
Device signature = 0x1e950f

avrdude> parms
>>> parms
Vtarget         : 5.2 V
SCK period      : 8.00 us

avrdude> vtarg 3.3
>>> vtarg 3.3
avrdude_pr1113.exe: stk500v2_command(): command failed

avrdude_pr1113.exe: stk500v2_setparm(): failed to set parameter 0x94
avrdude_pr1113.exe (vtarg): failed to set V[target] (rc = -1)
avrdude> varef 1 3.3
>>> varef 1 3.3
avrdude_pr1113.exe: stk500v2_command(): command failed

avrdude_pr1113.exe: stk500v2_setparm(): failed to set parameter 0x95
avrdude_pr1113.exe (varef): failed to set V[aref] (rc = -1)
avrdude> quit
>>> quit

@mcuee
Copy link
Collaborator

mcuee commented Oct 7, 2022

@stefanrueger

Maybe adding a note will be good, something like Please take note derivative programmer may not support all the commands.

@mcuee
Copy link
Collaborator

mcuee commented Oct 7, 2022

For Arduino Nano Every, there is a known issue.

Interestingly using 'flush' and then quit is a bit different from directly using quit. But I think we can ignore this one as the FW seems to be problematic.

PS C:\work\avr\avrdude_test\avrdude_bin> mode COM12 baud=12 dtr=on > nul
PS C:\work\avr\avrdude_test\avrdude_bin> mode COM12 baud=12 dtr=off > nul
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113 -p atmega4809 -c jtag2updi -P COM12 -b115200 -qqt

avrdude> sig
>>> sig
Device signature = 0x1e9651

avrdude> parms
>>> parms
Vtarget         : 5.0 V

avrdude> dump eeprom 0x0 0x16
>>> dump eeprom 0x0 0x16
0000  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0010  66 6f 78 20 6a 75                                 |fox ju          |

avrdude> write eeprom 0x0 0xff 0xff 0xff 0xff
>>> write eeprom 0x0 0xff 0xff 0xff 0xff
avrdude> quit
>>> quit
avrdude_pr1113.exe: synching cache to device... avrdude_pr1113.exe: jtagmkII_paged_write(): 
timeout/error communicating with programmer (status -1)
avrdude_pr1113.exe: jtagmkII_paged_write(): timeout/error communicating with programmer (status -1)
avrdude_pr1113.exe: jtagmkII_paged_write(): timeout/error communicating with programmer (status -1)
avrdude_pr1113.exe: jtagmkII_paged_write(): timeout/error communicating with programmer (status -1)
<Ctrl-C>

PS C:\work\avr\avrdude_test\avrdude_bin> mode COM12 baud=12 dtr=on > nul
PS C:\work\avr\avrdude_test\avrdude_bin> mode COM12 baud=12 dtr=off > nul
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113 -p atmega4809 -c jtag2updi -P COM12 -b115200 -qqt
avrdude> sig
>>> sig
Device signature = 0x1e9651

avrdude> dump eeprom 0x0 0x16
>>> dump eeprom 0x0 0x16
0000  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0010  66 6f 78 20 6a 75                                 |fox ju          |

avrdude> write eeprom 0x0 0xff 0xff 0xff 0xff
>>> write eeprom 0x0 0xff 0xff 0xff 0xff
avrdude> flush
>>> flush
avrdude_pr1113.exe: synching cache to device... avrdude_pr1113.exe: jtagmkII_paged_write(): 
bad response to write memory command: RSP_ILLEGAL_MEMORY_TYPE
writeCachePage() eeprom write error at addr 0x0000
avrdude> quit
>>> quit
avrdude_pr1113.exe: synching cache to device... avrdude_pr1113.exe: jtagmkII_paged_write(): 
bad response to write memory command: RSP_ILLEGAL_MEMORY_TYPE
writeCachePage() eeprom write error at addr 0x0000

@mcuee
Copy link
Collaborator

mcuee commented Oct 7, 2022

Interestingly for my Arduino Nano ATmega4808, it can not write EEPROM in terminal mode.

SInce this has nothing to do with this PR, I have created a new issue.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113 -qqp atmega4808 -c jtag2updi -P COM13 -b115200 
-U eeprom:w:.\hex2\entest_128B.eep:i && echo OK
avrdude_pr1113.exe: jtagmkII_paged_write(): bad response to write memory command: RSP_ILLEGAL_MEMORY_TYPE
OK

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1112 -p atmega4808 -c jtag2updi -P COM13 -b115200 -qqt
avrdude> dump eeprom 0x0 0x10
>>> dump eeprom 0x0 0x10
0000  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |

avrdude> write eeprom 0x0 0xff 0xff 0xff 0xff
>>> write eeprom 0x0 0xff 0xff 0xff 0xff
avrdude> quit
>>> quit
avrdude_pr1112.exe: synching cache to device... avrdude_pr1112.exe: jtagmkII_paged_write(): 
bad response to write memory command: RSP_ILLEGAL_MEMORY_TYPE
writeCachePage() eeprom write error at addr 0x0000

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113 -qqp atmega4808 -c jtag2updi -P COM13 -b115200 
-U eeprom:w:.\hex2\detest_128B.eep:i && echo OK
avrdude_pr1113.exe: jtagmkII_paged_write(): bad response to write memory command: RSP_ILLEGAL_MEMORY_TYPE
OK

@stefanrueger
Copy link
Collaborator Author

stefanrueger commented Oct 7, 2022

Have just added a pgerase memory addr command to the terminal. It's slightly out of scope of this PR, but should be useful nevertheless

@mcuee
Copy link
Collaborator

mcuee commented Oct 8, 2022

Have just added a pgerase memory addr command to the terminal. It's slightly out of scope of this PR, but should be useful nevertheless

@stefanrueger
Which programmer or bootloader support this?

I tried to use optibioot (with eeprom support) and it does not seem to support this command.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113v1 -qq -p m328p -c arduino -P COM5 -b 115200 -t
avrdude> help
>>> help
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> [<data>[,] {<data>[,]} | <len> <data>[,] {<data>[,]} ...]
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  sig     : display device signature bytes
  part    : display the current part information
  send    : send a raw command: send <b1> <b2> <b3> <b4>
  parms   : display adjustable parameters
  vtarg   : set <V[target]>
  varef   : set <V[aref]>
  fosc    : set <oscillator frequency>
  sck     : set <SCK period>
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : help
  ?       : help
  quit    : quit after writing out cache for flash & EEPROM

Note that flash and EEPROM type memories are normally read and written
using a cache and paged r/w access; the cache is synchronised on quit.
Use the 'part' command to display valid memory types for use with the
'dump' and 'write' commands.

avrdude> quit
>>> quit

@mcuee
Copy link
Collaborator

mcuee commented Oct 8, 2022

jtag2updi seems to support pgerase for Flash but not for EEPROM. The EEPROM issue is probably the same as #1116.

@stefanrueger
The error message is not correct as this is not an xmega device.

>>> pgerase eeprom 0
avrdude_pr1113v1.exe: jtagmkII_page_erase(): 
bad response to xmega erase command: Unknown JTAG ICE mkII result code 0x34
avrdude_pr1113v1.exe (pgerase): eeprom page at 0x00000 could not be erased

Run log:

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113v1 -qq -p m4808 -c jtag2updi -P COM13 -b 115200 -t
avrdude> help
>>> help
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> [<data>[,] {<data>[,]} | <len> <data>[,] {<data>[,]} ...]
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  pgerase : pgerase <memory> <addr>
  sig     : display device signature bytes
  part    : display the current part information
  parms   : display adjustable parameters
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : help
  ?       : help
  quit    : quit after writing out cache for flash & EEPROM

Note that flash and EEPROM type memories are normally read and written
using a cache and paged r/w access; the cache is synchronised on quit.
Use the 'part' command to display valid memory types for use with the
'dump' and 'write' commands.

avrdude> dump eeprom
>>> dump eeprom
0000  5a 20 6a 61 67 74 20 69  6d 20 6b 6f 6d 70 6c 65  |Z jagt im komple|
0010  74 74 20 76 65 72 77 61  68 72 6c 6f 73 74 65 6e  |tt verwahrlosten|
0020  20 54 61 78 69 20 71 75  65 72 20 64 75 72 63 68  | Taxi quer durch|
0030  20 42 61 79 65 72 6e 0a  5a 20 6a 61 67 74 20 69  | Bayern Z jagt i|
0040  6d 20 6b 6f 6d 70 6c 65  74 74 20 76 65 72 77 61  |m komplett verwa|
0050  68 72 6c 6f 73 74 65 6e  20 54 61 78 69 20 71 75  |hrlosten Taxi qu|
0060  65 72 20 64 75 72 63 68  20 42 61 79 65 72 6e 0a  |er durch Bayern |
0070  5a 20 6a 61 67 74 20 69  6d 20 6b 6f 6d 70 6c 65  |Z jagt im komple|
0080  64 6f 67 0a 54 68 65 20  71 75 69 63 6b 20 62 72  |dog The quick br|
0090  6f 77 6e 20 66 6f 78 20  6a 75 6d 70 73 20 6f 76  |own fox jumps ov|
00a0  65 72 20 74 68 65 20 6c  61 7a 79 20 64 6f 67 0a  |er the lazy dog |
00b0  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
00c0  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
00d0  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
00e0  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 6f 78 20  |quick brown fox |
00f0  6a 75 6d 70 73 20 6f 76  65 72 20 74 68 65 20 6c  |jumps over the l|

avrdude> pgerase eeprom 0
>>> pgerase eeprom 0
avrdude_pr1113v1.exe: jtagmkII_page_erase(): 
bad response to xmega erase command: Unknown JTAG ICE mkII result code 0x34
avrdude_pr1113v1.exe (pgerase): eeprom page at 0x00000 could not be erased
avrdude> dump flash
>>> dump flash
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

>>> write flash 0 "Hello world!"
avrdude> flush
>>> flush
avrdude_pr1113v1.exe: synching cache to device... done
avrdude> dump flash 0 0x10
>>> dump flash 0 0x10
0000  48 65 6c 6c 6f 20 77 6f  72 6c 64 21 00 ff ff ff  |Hello world!....|

avrdude> pgerase flash 0
>>> pgerase flash 0
avrdude> flush
>>> flush
avrdude> dump flash 0 0x10
>>> dump flash 0 0x10
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> quit
>>> quit

@mcuee
Copy link
Collaborator

mcuee commented Oct 8, 2022

Some problem with AVRISP mkii as well.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1113v1 -qq -p m328p -c avrispmkii -t
avrdude> help
>>> help
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> [<data>[,] {<data>[,]} | <len> <data>[,] {<data>[,]} ...]
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  pgerase : pgerase <memory> <addr>
  sig     : display device signature bytes
  part    : display the current part information
  send    : send a raw command: send <b1> <b2> <b3> <b4>
  parms   : display adjustable parameters
  vtarg   : set <V[target]>
  varef   : set <V[aref]>
  fosc    : set <oscillator frequency>
  sck     : set <SCK period>
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : help
  ?       : help
  quit    : quit after writing out cache for flash & EEPROM

Note that flash and EEPROM type memories are normally read and written
using a cache and paged r/w access; the cache is synchronised on quit.
Use the 'part' command to display valid memory types for use with the
'dump' and 'write' commands.

avrdude> dump eeprom
>>> dump eeprom
0000  ff 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |.he quick brown |
0010  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0020  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
0030  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 6f 78 20  |quick brown fox |
0040  6a 75 6d 70 73 20 6f 76  65 72 20 74 68 65 20 6c  |jumps over the l|
0050  61 7a 79 20 64 6f 67 0a  54 68 65 20 71 75 69 63  |azy dog The quic|
0060  6b 20 62 72 6f 77 6e 20  66 6f 78 20 6a 75 6d 70  |k brown fox jump|
0070  73 20 6f 76 65 72 20 74  68 65 20 6c 61 7a 79 20  |s over the lazy |
0080  64 6f 67 0a 54 68 65 20  71 75 69 63 6b 20 62 72  |dog The quick br|
0090  6f 77 6e 20 66 6f 78 20  6a 75 6d 70 73 20 6f 76  |own fox jumps ov|
00a0  65 72 20 74 68 65 20 6c  61 7a 79 20 64 6f 67 0a  |er the lazy dog |
00b0  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
00c0  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
00d0  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
00e0  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 6f 78 20  |quick brown fox |
00f0  6a 75 6d 70 73 20 6f 76  65 72 20 74 68 65 20 6c  |jumps over the l|

avrdude> pgerase eeprom 0
>>> pgerase eeprom 0
avrdude_pr1113v1.exe: stk500v2_page_erase(): this function must never be called
avrdude_pr1113v1.exe (pgerase): eeprom page at 0x00000 could not be erased

>>> dump flash 0
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

>>> write flash 0 "Hello World!"
avrdude> flush
>>> flush
avrdude_pr1113v1.exe: synching cache to device... done
avrdude> dump flash 0 0x10
>>> dump flash 0 0x10
0000  48 65 6c 6c 6f 20 57 6f  72 6c 64 21 00 ff ff ff  |Hello World!....|

avrdude> pgerase flash 0
>>> pgerase flash 0
avrdude_pr1113v1.exe: stk500v2_page_erase(): this function must never be called
avrdude_pr1113v1.exe (pgerase): flash page at 0x00000 could not be erased
avrdude> quit
>>> quit

@mcuee
Copy link
Collaborator

mcuee commented Oct 8, 2022

#1112 can be merged and then pgerase memory addr terminal command for JTAG3 UPDI programmers. Right now it is not supported.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1112 -qq -p t817 -c xplainedmini_updi -t
                    Vtarget                      : 5.00 V
avrdude> help
>>> help
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> [<data>[,] {<data>[,]} | <len> <data>[,] {<data>[,]} ...]
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  sig     : display device signature bytes
  part    : display the current part information
  send    : send a raw command: send <b1> <b2> <b3> <b4>
  parms   : display adjustable parameters (STK500 and Curiosity Nano only)
  vtarg   : set <V[target]> (STK500 and Curiosity Nano only)
  varef   : set <V[aref]> (STK500 only)
  fosc    : set <oscillator frequency> (STK500 only)
  sck     : set <SCK period> (STK500 only)
  spi     : enter direct SPI mode
  pgm     : return to programming mode
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : help
  ?       : help
  quit    : quit after writing out cache for flash & EEPROM

Note that flash and EEPROM type memories are normally read and written
using a cache and paged r/w access; the cache is synchronised on quit.
Use the 'part' command to display valid memory types for use with the
'dump' and 'write' commands.


@MCUdude
Copy link
Collaborator

MCUdude commented Oct 9, 2022

Perhaps we'll have to add something like prog_features in avrdude.conf, and fall back to this PR if no data is provided?
The issue @mcuee points out is mostly related to bootloader implementations of protocols like stk500v1 and stk500v2.

@mcuee
Copy link
Collaborator

mcuee commented Oct 10, 2022

Perhaps we'll have to add something like prog_features in avrdude.conf, and fall back to this PR if no data is provided? The issue @mcuee points out is mostly related to bootloader implementations of protocols like stk500v1 and stk500v2.

@MCUdude and @stefanrueger
Yes I agree with the above proposal as the long term solution. But for the purpose of this PR, I think just adding a note will be good enough as the short term solution.
Please take note derivative programmer may not support all the commands.

As for pgerase memory addr command, it is very useful. It will be good to add a note that some programmer may not support it. Or maybe this is not necessary. I am okay to leave it as it is.

As for the pgerase error message for jtag2updi, I think it is okay to leave it as it is. It may not be wrong since updi devices may have similar architecute as xmega.

avrdude_pr1113v1.exe: jtagmkII_page_erase(): 
bad response to xmega erase command: Unknown JTAG ICE mkII result code 0x34
avrdude_pr1113v1.exe (pgerase): eeprom page at 0x00000 could not be erased

@mcuee
Copy link
Collaborator

mcuee commented Oct 10, 2022

@stefanrueger and @MCUdude

Actually for STK500 v1 and STK 500 v2, the current git message is actually good, just adding "STK500 only" in the end and we are done. There are too many derivative programmer from them so that it is hard to get everything right.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_git -p atmega4808 -c jtag2updi -P COM13 -b115200 -qq -t
avrdude> help
>>> help
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> [<data>[,] {<data>[,]} | <len> <data>[,] {<data>[,]} ...]
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  sig     : display device signature bytes
  part    : display the current part information
  send    : send a raw command: send <b1> <b2> <b3> <b4>
  parms   : display adjustable parameters (STK500 and Curiosity Nano only)
  vtarg   : set <V[target]> (STK500 and Curiosity Nano only)
  varef   : set <V[aref]> (STK500 only)
  fosc    : set <oscillator frequency> (STK500 only)
  sck     : set <SCK period> (STK500 only)
  spi     : enter direct SPI mode
  pgm     : return to programming mode
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : help
  ?       : help
  quit    : quit after writing out cache for flash & EEPROM

Note that flash and EEPROM type memories are normally read and written
using a cache and paged r/w access; the cache is synchronised on quit.
Use the 'part' command to display valid memory types for use with the
'dump' and 'write' commands.

avrdude> quit
>>> quit


@MCUdude
Copy link
Collaborator

MCUdude commented Oct 10, 2022

It's easy to remove terminal commands from the most popular bootloader implementations.

In arduino.c, we just need to clear some function pointers after stk500_initpgm(pgm).

avrdude/src/arduino.c

Lines 119 to 132 in 44fe5be

void arduino_initpgm(PROGRAMMER *pgm) {
/* This is mostly a STK500; just the signature is read
differently than on real STK500v1
and the DTR signal is set when opening the serial port
for the Auto-Reset feature */
stk500_initpgm(pgm);
strcpy(pgm->type, "Arduino");
pgm->read_sig_bytes = arduino_read_sig_bytes;
pgm->open = arduino_open;
pgm->close = arduino_close;
disable_trailing_ff_removal(); /* so that arduino bootloader can ignore chip erase */
}

The same goes for wiring.c

avrdude/src/wiring.c

Lines 206 to 218 in 44fe5be

void wiring_initpgm(PROGRAMMER *pgm) {
/* The Wiring bootloader uses a near-complete STK500v2 protocol. */
stk500v2_initpgm(pgm);
strcpy(pgm->type, "Wiring");
pgm->open = wiring_open;
pgm->close = wiring_close;
pgm->setup = wiring_setup;
pgm->teardown = wiring_teardown;
pgm->parseextparams = wiring_parseextparms;
}

@stefanrueger
Copy link
Collaborator Author

In arduino.c, we just need to clear some function pointers after stk500_initpgm(pgm)

Trouble is, we don't know what the bootloader does. It may not be optiboot, and it could be a bootloader that implements everything that is promised by stk500.

@stefanrueger stefanrueger merged commit d3a3257 into avrdudes:main Oct 11, 2022
@stefanrueger stefanrueger deleted the term_help branch October 11, 2022 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants