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

Read sigrow for ATmega32[48]PB using ISP #1510

Merged
merged 7 commits into from
Oct 15, 2023

Conversation

stefanrueger
Copy link
Collaborator

@stefanrueger stefanrueger commented Oct 10, 2023

Fixes #1509 for ISP (well, a first shot anyway).

This PR introduces sigrow_pb memory, which needs a different name than sigrow (used for Attiny102/104) at least until Issue #1330 is addressed.

@mcuee mcuee added the enhancement New feature or request label Oct 10, 2023
@stefanrueger
Copy link
Collaborator Author

I think I have a simpler way of reading sigrow that does not require it to look like flash (though it might well be). Adding this memory should be sufficient I think:

    memory "sigrow"
        size               = 24;
        read               = "0 0 1 1 a0 0 0 0  0 0 0 0 0 0 0 0  0 0 0 0 a4 a3 a2 a1  o o o o o o o o";
    ;

@dl8dtl will like this if it works b/c it uses the vvv flexible way ISP command descriptions were designed. Such a memory might reveal undocumented calibration values in other parts, too.

@stefanrueger
Copy link
Collaborator Author

I tried this PR by adding a flash page's worth of sigrow memory for the ATmega2560:

diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in
index 1bf7e43a..f90d63ae 100644
--- a/src/avrdude.conf.in
+++ b/src/avrdude.conf.in
@@ -13249,6 +13249,11 @@ part
         read               = "0011.0000--xxxx.xxxx--xxxx.xxaa--oooo.oooo";
     ;
 
+    memory "sigrow"
+        size               = 256;
+        read               = "0 0 1 1 a0 0 0 0  0 0 0 0 0 0 0 0  0 a7 a6 a5 a4 a3 a2 a1  o o o o o o o o";
+    ;
+
     memory "calibration"
         size               = 1;
         read               = "0011.1000--xxxx.xxxx--0000.0000--oooo.oooo";

Then I can read signature and calibration memories through sigrow (interleaved); there is some (undocumented) further info in that page:

$ avrdude -qqpm2560 -T "read sigrow"
0000  1e a3 98 ff 01 ff ff ff  ed ff ff f7 ff ff 59 35  |..............Y5|
0010  34 33 30 38 ff 0b 11 03  17 08 12 07 13 07 ff ff  |4308. ..........|
0020  ff ff ff ff ff ff ff ff  ff ff ff ff 70 1c 7b 0c  |............p.{ |
0030  ed 26 d5 02 ef 0a 75 01  ff ff ff ff ff ff ff ff  |.&... u.........|
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 c3 54  |...............T|

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 10, 2023

Thanks for the PR! I'll see if I can give it a try tonight on both the 324PB and the 328PB. Will it work on an ATmega324PB using a JTAG programmer?

@stefanrueger
Copy link
Collaborator Author

Will it work on an ATmega324PB using a JTAG programmer?

I wouldn't have thought so! Jtag is your expertise, not? 😉

@mcuee
Copy link
Collaborator

mcuee commented Oct 11, 2023

It does not seem to work with my ATmega328PB-XMINI.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1510 -C .\avrdude_pr1510.conf -c xplainedmini_isp -p m328pb -qqt
avrdude> part
AVR Part                      : ATmega328PB
Chip Erase delay              : 10500 us
PAGEL                         : PD7
BS2                           : PC2
RESET disposition             : possible i/o
RETRY pulse                   : SCK
Serial program mode           : yes
Parallel program mode         : yes
Timeout                       : 200
StabDelay                     : 100
CmdexeDelay                   : 25
SyncLoops                     : 32
PollIndex                     : 3
PollValue                     : 0x53
Memory Detail                 :

                                  Block Poll               Page                       Polled
  Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
  ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
  eeprom                 65    20     4    0 no       1024    4      0  3600  3600 0x00 0x00
  flash                  65    10   128    0 yes     32768  128    256  4500  4500 0x00 0x00
  lfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
  hfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
  efuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
  lock                    0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
  signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
  calibration             0     0     0    0 no          1    1      0     0     0 0x00 0x00
  io                      0     0     0    0 no        224    1      0     0     0 0x00 0x00
  sigrow                  0     0     0    0 no         24    1      0     0     0 0x00 0x00
avrdude> read io
avrdude_pr1510 error: invalid operation AVR_OP_READ on io memory
avrdude_pr1510 error: (read) error reading io address 0x00000 of part ATmega328PB
                      read operation not supported on memory type io
avrdude> read calibration
0000  9a                                                |.               |
avrdude> read lfuse
0000  e0                                                |.               |
avrdude> read hfuse
0000  96                                                |.               |
avrdude> read efuse
0000  fd                                                |.               |
avrdude> read signature
0000  1e 95 16                                          |...             |
avrdude> read lock
0000  ff                                                |.               |
avrdude> read flash 0 0x10
0000  59 c0 00 00 5f c0 00 00  5d c0 00 00 5b c0 00 00  |Y..._...]...[...|
avrdude> read eeprom 0 0x10
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
avrdude> read sigrow
avrdude_pr1510 error: unknown command
avrdude_pr1510 error: timeout/error communicating with programmer
avrdude_pr1510 error: (read) error reading sigrow address 0x00000 of part ATmega328PB
                      read operation not supported on memory type sigrow
avrdude> quit

@stefanrueger
Copy link
Collaborator Author

The xplainedmini_isp uses a JTAG3 interface (via STK500v2 protocol?), so no that wouldn't work:

avrdude/src/avrdude.conf.in

Lines 2401 to 2409 in 55853eb

programmer
id = "xplainedmini", "xplainedmini_isp";
desc = "Atmel AVR XplainedMini in ISP mode";
type = "jtagice3_isp";
prog_modes = PM_ISP;
extra_features = HAS_SUFFER | HAS_VTARG_SWITCH;
connection_type = usb;
usbpid = 0x2145;
;

Have you tried usbtiny or usbasp?

@mcuee
Copy link
Collaborator

mcuee commented Oct 11, 2023

The xplainedmini_isp uses a JTAG3 interface (via STK500v2 protocol?), so no that wouldn't work:

Have you tried usbtiny or usbasp?

I see. -c usbasp seems to work fine.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1510 -C .\avrdude_pr1510.conf -c usbasp -p m328pb -qqt
avrdude> dump sigrow
0000  1e 8c 95 17 16 01 a5 a5  ff 8c ff fe ff 82 4c 30  |..............L0|
0010  42 36 4b 4a 69 08 27 28                           |B6KJi.'(        |
avrdude> quit

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1510 -C .\avrdude_pr1510.conf -c usbasp -p m328pb -qqT "read sigrow"
0000  1e 8c 95 17 16 01 a5 a5  ff 8c ff fe ff 82 4c 30  |..............L0|
0010  42 36 4b 4a 69 08 27 28                           |B6KJi.'(        |

@stefanrueger
Copy link
Collaborator Author

stefanrueger commented Oct 11, 2023

@mcuee Thanks for confirming that direct ISP programming elicits the sigrow contents in the terminal! I think -U sigrow:r:-:I should work, too. Pro tip: For command lines it helps if the (long) actual shell prompt is replaced with $:

$ avrdude_pr1510 -C .\avrdude_pr1510.conf -c usbasp -p m328pb -qqT "read sigrow"

instead of

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1510 -C .\avrdude_pr1510.conf -c usbasp -p m328pb -qqT "read sigrow"

I like that your examples use -qq as this makes the output shorter and less distracting.

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 11, 2023

The AVRISPmkII programmer can't read sigrow on the ATmega328PB:

$ ./avrdude -cavrispmkii -patmega328pb -Usigrow:r:-:h
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9516 (probably m328pb)

avrdude: processing -U sigrow:r:-:h
avrdude: reading sigrow memory ...
avrdude error: unknown command
avrdude error: timeout/error communicating with programmer
avrdude error: unable to read byte at address 0x0000
avrdude error: read operation not supported for memory sigrow
avrdude error: unable to read all of sigrow memory, rc=-2

avrdude done.  Thank you.

@stefanrueger
Copy link
Collaborator Author

stefanrueger commented Oct 11, 2023

The AVRISPmkII programmer can't read sigrow on the ATmega328PB

Did you expect this to work given that the PR targets direct ISP programming? AVRISPmkII uses the STK500v2 protocol, which does not appear to know sigrow. This needs some trickery in the STK500v2 communication where one pretends to read signature using CMD_READ_SIGNATURE_ISP but piggy-backs a different raw ISP command for actually reading sigrow. May or may not work depending on whether the programmer caches previous reads under CMD_READ_SIGNATURE_ISP. Could also try CMD_SPI_MULTI but apparently some Atmel programmers have decided not to implement this.

@stefanrueger
Copy link
Collaborator Author

ISP command for actually reading sigrow

So, looks like @mcuee's test with -c usbasp proves the approach of this PR correct, ie, the read command in avrdude.conf seems to work using direct ISP programming. I'd suggest testing direct ISP programming for this PR.

If tests are good, I suggest merging this PR and divide the work for AVRISP (myself?) and JTAG (@MCUdude?) for other PRs.

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 11, 2023

Did you expect this to work given that the PR targets direct ISP programming?

Not really. I thought I read in an email that we should try with a different stk500v2 programmer just to make sure, but that seemed to be just me making things up. Anyways it's great that it works with direct ISP commands, but this will make the sigrow memory one of very few (?) memories that can only be read by certain ISP programmers.

Could also try CMD_SPI_MULTI

Yes, they suddenly dropped support for this, so this won't work for all official ISP programmers.

Just for reference:

$ ./avrdude -cpowerdebugger_jtag -patmega324pb -Usigrow:r:-:h
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9517 (probably m324pb)

avrdude: processing -U sigrow:r:-:h
avrdude: reading sigrow memory ...
avrdude error: unable to read byte at address 0x0000
avrdude error: read operation not supported for memory sigrow
avrdude error: unable to read all of sigrow memory, rc=-2

avrdude done.  Thank you.


$ ./avrdude -cdragon_jtag -patmega324pb -Usigrow:r:-:h
avrdude warning: OCDEN fuse not programmed, single-byte EEPROM updates not possible
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9517 (probably m324pb)

avrdude: processing -U sigrow:r:-:h
avrdude: reading sigrow memory ...
avrdude: writing output file <stdout>
0xc,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94
avrdude error: bad response to leave progmode command: RSP_FAILED

avrdude done.  Thank you.

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 11, 2023

If tests are good, I suggest merging this PR and divide the work for AVRISP (myself?) and JTAG (@MCUdude?) for other PRs.

Do you mean a separate PR for using stk500v2 compatible programmers that does or does not support CMD_SPI_MULTI? The absolute best would be that the sigrow memory could be read with any ISP or JTAG programmer, regardless of the communication protocol, but I'm not qualified to tell whenever this would actually be possible or not

@stefanrueger
Copy link
Collaborator Author

we should try with a different stk500v2 programmer just to make sure

That was the other PR #1511 😄

separate PR for using stk500v2 compatible programmers

Yes, having looked at the protocol I have an idea how one might attempt this without using CMD_SPI_MULTI. But that requires we can read sigrow using direct ISP (ie, this current PR). However, my idea might still fold, and it needs experimentation.

JTAG

I still don't find my way around JTAG programmers in AVRDUDE code. So that would still be a different PR, and someone else would need to look into this.

@stefanrueger
Copy link
Collaborator Author

regardless of the communication protocol

Well, this is the problem. It could be that the protocol restricts what the host can ask the programmer to do. The CMD_SPI_MULTI was designed to give direct access to the SPI interface, and without it, it may or may not be possible to read sigrow depending on how the programmer's firmware has implemented the protocol.

@stefanrueger
Copy link
Collaborator Author

sigrow memory one of very few (?) memories that can only be read by certain ISP programmers

It may well be that Atmel's programmers are not intended to be able to read sigrow. Software archeologist will be able to date the birth of sigrow documentation long after Atmel produced, documented and sold their suite of programmers, but the sigrow memory existed all along well before its use was documented for the m324pb and m328pb. For example, I can read the sigrow memory in an ATmega2560. Also, the data sheets of neither m324pb nor m328pb explicitly list ISP commands for sigrow in the serial programming section.

@mcuee
Copy link
Collaborator

mcuee commented Oct 12, 2023

> $ ./avrdude -cdragon_jtag -patmega324pb -Usigrow:r:-:h
> avrdude warning: OCDEN fuse not programmed, single-byte EEPROM updates not possible
> avrdude: AVR device initialized and ready to accept instructions
> avrdude: device signature = 0x1e9517 (probably m324pb)
> 
> avrdude: processing -U sigrow:r:-:h
> avrdude: reading sigrow memory ...
> avrdude: writing output file <stdout>
> 0xc,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94,0x94
> avrdude error: bad response to leave progmode command: RSP_FAILED
> 
> avrdude done.  Thank you.
> 

@MCUdude

Interesting, this almost works. Have you tried to set the OCDEN fuse bit first?

@mcuee
Copy link
Collaborator

mcuee commented Oct 12, 2023

I'd suggest testing direct ISP programming for this PR.
If tests are good, I suggest merging this PR and divide the work for AVRISP (myself?) and JTAG (@MCUdude?) for other PRs.

I agree to merge this PR.

Just FYI, STK500v2 does not seem to work now. But I think you have the ideas of how to make it work later.

Strange thing is that AVRISP mkii does not work all, but there are some strange outputs from STK500v2. Both are clones but running official Atmel FW.

PS>.\avrdude_pr1510 -C .\avrdude_pr1510.conf -cavrisp2 -pm328pb -qq -T "read sigrow"
avrdude_pr1510 error: command failed
avrdude_pr1510 error: timeout/error communicating with programmer
avrdude_pr1510 error: (read) error reading sigrow address 0x00000 of part ATmega328PB
                      read operation not supported on memory type sigrow

PS>.\avrdude_pr1510 -C .\avrdude_pr1510.conf -cstk500v2 -PCOM13 -pm328pb -qq -T "read sigrow"
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
avrdude_pr1510 error: buffer too small, received 6 byte into 6 byte buffer
avrdude_pr1510 error: timeout
0000  bf bf bf bf bf bf bf bf  bf bf bf bf bf bf bf bf  |................|
0010  bf bf bf bf bf bf bf bf                           |........        |

PS>.\avrdude_pr1510 -C .\avrdude_pr1510.conf -cstk500v2 -PCOM13 -pm328pb -qq -T "read sigrow"
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
avrdude_pr1510 error: wrong checksum
0000  30 38 30 38 30 38 30 38  30 38 30 38 30 38 30 38  |0808080808080808|
0010  30 38 30 38 30 38 30 38                           |08080808        |

@stefanrueger
Copy link
Collaborator Author

I was just about to update the documentation for sigrow when I realised that this memory is called prodsig in parts with PDI and UPDI interfaces. The full name is production signature row.

Should we rename the sigrow memory to prodsig for this PR and also for the existing t102/t104 and alias sigrow to prodsig for the four parts t102, t104, m324pb and m328p? We could also alias sigrow to prodsig for all other 145 U/PDI parts. The only disadvantage of the name sigrow is that d s, d si and d sig become ambiguous in the terminal (signature/sigrow). @MCUdude @mcuee @dl8dtl What do you think?

@mcuee
Copy link
Collaborator

mcuee commented Oct 14, 2023

@stefanrueger

No objections from my side, including to alias sigrow to prodsig for all other 145 U/PDI parts.

@stefanrueger
Copy link
Collaborator Author

stefanrueger commented Oct 14, 2023

Have now also included the signature itself into the prodsig (aliased as sigrow) memory for ATtiny102 and ATtiny104. Both datasheet and .atdf files want this

Screenshot from 2023-10-14 20-35-04

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 15, 2023

Looks good to me! Thanks @stefanrueger!

@stefanrueger stefanrueger merged commit 40350be into avrdudes:main Oct 15, 2023
10 checks passed
@stefanrueger stefanrueger deleted the sigrow branch October 15, 2023 15:54
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.

Read ATmega324PB and ATmega328PB serial number
3 participants