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

Add memory sram and remove memory data #1571

Merged
merged 4 commits into from
Nov 22, 2023
Merged

Conversation

stefanrueger
Copy link
Collaborator

@stefanrueger stefanrueger commented Nov 15, 2023

The memory data was introduced for the sole purpose to provide an nvm_data_offset for Microchip programmers. As an address offset it would tell programmers to read/write in data space. It so turned out that this nvm_data_offset always was 0x1000000 for PDI and UPDI parts.

This PR removes this artificial data memory and treats the data offset in the code as what it currently is: a constant.

At the same time the PR introduces an sram memory with offset and size for virtually all parts known to AVRDUDE.

Here a summary for the sram memory sizes and offsets (Issue #1559).

Known issues

  • The memory sram is not yet documented (but will be if this PR is accepted in principle)
  • The code base does not yet have code to r/w to the sram memory

The memory data was introduced for the sole purpose to provide an
nvm_data_offset for Microchip programmers. As an address offset it would
tell programmers to read/write in data space. It so turned out that this
nvm_data_offset always was 0x1000000 for PDI and UPDI parts.

This commit removes this artificial data memory and treats the data offset
in the code as what it currently is: a constant.

At the same time the commit introduces an sram memory with offset and size
for virtually all parts known to AVRDUDE.
@mcuee mcuee added the enhancement New feature or request label Nov 15, 2023
@stefanrueger
Copy link
Collaborator Author

Added handling of SRAM in the same way as IO is handled.

Some programmers need the additional offset of 0x1000000 to indicate it's SRAM. Interestingly, jtagmkII gets told the memory type is MTYPE_FLASH whilst that offset is added to the address. I wonder whether the change below is equivalent for IO/SRAM r/w.

diff --git a/src/jtagmkII.c b/src/jtagmkII.c
index c24d27cc..885aae16 100644
--- a/src/jtagmkII.c
+++ b/src/jtagmkII.c
@@ -2223,8 +2223,7 @@ static int jtagmkII_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR
     cmd[1] = MTYPE_PRODSIG;
     pmsg_notice2("in_sigrow addr 0x%05lx\n", addr);
   } else if (mem_is_io(mem) || mem_is_sram(mem)) {
-    cmd[1] = MTYPE_FLASH;
-    addr += avr_data_offset(p);
+    cmd[1] = MTYPE_SRAM;
   } else {
     pmsg_error("unknown memory %s\n", mem->desc);
     return -1;
@@ -2347,8 +2346,7 @@ static int jtagmkII_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AV
     if (pgm->flag & PGM_FL_IS_DW)
       unsupp = 1;
   } else if (mem_is_io(mem) || mem_is_sram(mem)) {
-    cmd[1] = MTYPE_FLASH; // Works with jtag2updi, does not work with any xmega
-    addr += avr_data_offset(p);
+    cmd[1] = MTYPE_SRAM;
   } else if(mem_is_readonly(mem)) {
     unsigned char is;
     if(pgm->read_byte(pgm, p, mem, addr, &is) >= 0 && is == data)

@askn37 @mcuee @MCUdude Could you test IO/SRAM read/write in this PR. If that turns out OK, could you make above change and try whether IO/SRAM access is still OK using jtagmkII type programmers?

@stefanrueger stefanrueger linked an issue Nov 16, 2023 that may be closed by this pull request
@askn37
Copy link
Contributor

askn37 commented Nov 16, 2023

Some programmers need the additional offset of 0x1000000 to indicate it's SRAM.

I think it was probably expanded for the XMEGA series (25bit BUS). This is because the area above 0x01000000 is treated as a data region, and the area below it is treated as a code region. This also applies to avr-gcc's internal calculations. (architecture numbers are 102, 103, 104)

Interestingly, jtagmkII gets told the memory type is MTYPE_FLASH whilst that offset is added to the address.

That's what I discovered while testing FWV=7. avr-gcc compiles the UPDI architecture the same way it compiles the XMEGA architecture. Until then 0x10000000 is indeed a data region. Then, when creating the HEX from ELF, accurately remap the addresses for the UPDI device. The UPDI architecture no longer uses 0x10000000 to indicate a data region.

As a result, MTYPE_SRAM and MTYPE_FLASH appear to have been swapped. Furthermore, small flash memories such as BOOTROW are now embedded in the data region. Nothing definitive yet, but since this belongs to a different region (separately from MTYPE_FLASH) it may be necessary to assign MTYPE_FLASH_PAGE.

I wonder whether the change below is equivalent for IO/SRAM r/w.

confirm. Please wait.

@mcuee
Copy link
Collaborator

mcuee commented Nov 16, 2023

First simple test with -c dryrun.

PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c dryrun -P usb -p m4809 -qqt
avrdude> dump sram 0 0x10
0000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> write sram 0 0xaa 0x55 0xaa 0x55
avrdude> flush
avrdude> dump sram 0 0x10
0000  aa 55 aa 55 00 00 00 00  00 00 00 00 00 00 00 00  |.U.U............|
avrdude> write sram 0 0x55 0xaa 0x55 0xaa
avrdude> flush
avrdude> dump sram 0 0x10
0000  55 aa 55 aa 00 00 00 00  00 00 00 00 00 00 00 00  |U.U.............|
avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Nov 16, 2023

There seems to be no support of SRAM by ATmega328PB, using either usbasp or AVRISP mkII. -c dryrun works though. I am not so sure which real programer will support SRAM Read/Write of ATmega328PB SRAM.

PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c dryrun -P usb -p m328pb -qqt
avrdude> dump sram 0 0x10
0000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> write sram 0 0xaa 0x55 0xaa 0x55
avrdude> flush
avrdude> dump sram 0 0x10
0000  aa 55 aa 55 00 00 00 00  00 00 00 00 00 00 00 00  |.U.U............|
avrdude> quit

PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c usbasp -P usb -p m328p -qqt
avrdude_pr1571 error: expected signature for ATmega328P is 1E 95 0F
               double check chip or use -F to override this check
PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c usbasp -P usb -p m328pb -qqt
avrdude> dump sram 0 0x10
avrdude_pr1571 error: (dump) error reading sram address 0x00000 of part ATmega328PB
                      read operation not supported on memory sram
avrdude> quit

PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c avrispmkii -P usb -p m328pb -qqt
avrdude> dump sram 0 0x10
avrdude_pr1571 error: unsupported memory sram
avrdude_pr1571 error: (dump) error reading sram address 0x00000 of part ATmega328PB
                      read operation not supported on memory sram
avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Nov 16, 2023

No issues with ATtiny817 using Xplained Pro built-in UPDI programmer.

PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c xplainedpro_updi  -P usb -p t817 -qqt
avrdude> dump sram
0000  b0 02 54 ec 00 00 9f 21  01 00 bf f7 73 97 c4 0f  |..T....!....s...|
0010  13 67 67 1d 5f 4b 55 91  97 4b 5b 36 b7 63 bf fb  |.gg._KU..K[6.c..|
0020  77 35 19 1e 4b d6 e1 e6  79 69 35 1e 3b ad dd 45  |w5..K...yi5.;..E|
0030  d5 33 ef 85 c7 f7 84 bb  35 87 32 3f 9f bc f5 ad  |.3......5.2?....|
0040  a0 b8 f7 ef f2 fb ed 44  af df 6f d7 14 be 7d ff  |.......D..o...}.|
0050  a2 6a 4f 0f 64 f9 a9 2f  e1 d7 67 f1 3f ba b1 fd  |.jO.d../..g.?...|
0060  73 4f 5e 7f ba 76 76 64  bb 7e 57 bf f6 9e 7b f7  |sO^..vvd.~W...{.|
0070  3b 77 d7 99 9b 32 9f 53  ff ab 19 d5 de f5 c7 7d  |;w...2.S.......}|
0080  c4 1f 9b 59 06 59 d7 47  5a 0c 8b 06 6e d6 c4 e8  |...Y.Y.GZ ..n...|
0090  cd 1c fd be 4e e5 f1 84  e8 77 37 f7 5b fd c3 a3  |....N....w7.[...|
00a0  3c f9 e7 df 3d 3d 2e 39  d4 88 bd b9 fe 19 28 3d  |<...==.9......(=|
00b0  f1 ef fa f9 dc 6a b1 7d  bf 7f 95 f4 2d 1d d9 bf  |.....j.}....-...|
00c0  ab 61 6f ec 7f cd 57 f7  b7 5f b1 ee af d6 7b ee  |.ao...W.._....{.|
00d0  49 f7 c7 ac 24 0b e3 55  fb db d7 ff 2f f3 fd dc  |I...$ .U..../...|
00e0  7b ff e1 52 e6 bf f3 ee  a8 9f 6d 6b eb ea f7 27  |{..R......mk...'|
00f0  84 be 8d de ce 9f 9f 0d  c7 cd 99 61 ff fa eb 1e  |....... ...a....|
avrdude> write sram 0 0xaa 0x55 0xaa 0x55
avrdude> flush
avrdude> dump sram 0 0x10
0000  aa 55 aa 55 00 00 9f 21  01 00 bf f7 73 97 c4 0f  |.U.U...!....s...|
avrdude> dump sram
0010  13 67 67 1d 5f 4b 55 91  97 4b 5b 36 b7 63 bf fb  |.gg._KU..K[6.c..|
avrdude> quit

PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c xplainedpro_updi  -P usb -p t817 -qqt
avrdude> dump sram
0000  20 01 5e 9b 00 00 67 be  00 00 bf f7 73 97 c4 0f  | .^...g.....s...|
0010  13 67 67 1d 5f 4b 55 91  97 4b 5b 36 b7 63 bf fb  |.gg._KU..K[6.c..|
0020  77 35 19 1e 4b d6 e1 e6  79 69 35 1e 3b ad dd 45  |w5..K...yi5.;..E|
0030  d5 33 ef 85 c7 f7 84 bb  35 87 32 3f 9f bc f5 ad  |.3......5.2?....|
0040  a0 b8 f7 ef f2 fb ed 44  af df 6f d7 14 be 7d ff  |.......D..o...}.|
0050  a2 6a 4f 0f 64 f9 a9 2f  e1 d7 67 f1 3f ba b1 fd  |.jO.d../..g.?...|
0060  73 4f 5e 7f ba 76 76 64  bb 7e 57 bf f6 9e 7b f7  |sO^..vvd.~W...{.|
0070  3b 77 d7 99 9b 32 9f 53  ff ab 19 d5 de f5 c7 7d  |;w...2.S.......}|
0080  c4 1f 9b 59 06 59 d7 47  5a 0c 8b 06 6e d6 c4 e8  |...Y.Y.GZ ..n...|
0090  cd 1c fd be 4e e5 f1 84  e8 77 37 f7 5b fd c3 a3  |....N....w7.[...|
00a0  3c f9 e7 df 3d 3d 2e 39  d4 88 bd b9 fe 19 28 3d  |<...==.9......(=|
00b0  f1 ef fa f9 dc 6a b1 7d  bf 7f 95 f4 2d 1d d9 bf  |.....j.}....-...|
00c0  ab 61 6f ec 7f cd 57 f7  b7 5f b1 ee af d6 7b ee  |.ao...W.._....{.|
00d0  49 f7 c7 ac 24 0b e3 55  fb db d7 ff 2f f3 fd dc  |I...$ .U..../...|
00e0  7b ff e1 52 e6 bf f3 ee  a8 9f 6d 6b eb ea f7 27  |{..R......mk...'|
00f0  84 be 8d de ce 9f 9f 0d  c7 cd 99 61 ff fa eb 1e  |....... ...a....|
avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Nov 16, 2023

AVRISPmkII does not seem to be able to dump SRAM for ATxmega32A4U.

PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c avrispmkii -P usb -p x32a4u -qqt
avrdude> dump sram
avrdude_pr1571 error: CMD_XPROG: Timeout
avrdude_pr1571 error: XPRG_CMD_READ_MEM failed
avrdude_pr1571 error: (dump) error reading sram address 0x00000 of part ATxmega32A4U
                      read operation not supported on memory sram
avrdude> quit

PS>.\avrdude_pr1571.exe -C .\avrdude_pr1571.conf -c dryrun -P usb -p x32a4u -qqt
avrdude> dump sram 0 0x10
0000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> write sram 0 0xaa 0x55 0xaa 0x55
avrdude> flush
avrdude> dump sram 0 0x10
0000  aa 55 aa 55 00 00 00 00  00 00 00 00 00 00 00 00  |.U.U............|
avrdude> quit

@askn37
Copy link
Contributor

askn37 commented Nov 17, 2023

I tried using JTAG2UPDI.

The JTAGICEmkII compatible implementation of JTAG2UPDI does not distinguish between memory types in the read direction at all. Simply read the specified 24-bit address (ignoring the 4th octet). The write direction identifies whether the memory type is flash or other. Since NVMCTRL_STATUS is not checked, memory write errors are not returned (if the device is normal, no results other than timeout/USB packet lost on the AVRDUDE side will be returned). Currently, if MTYPE_SRAM is passed, reading is possible, but writing returns RSP_ILLEGAL_MEMORY_TYPE.

avrdude: jtagmkII_read_byte(.., sram, 0x1, ...)
avrdude: jtagmkII_read_byte(): sending read memory command: 
avrdude: jtagmkII_send(): sending 10 bytes
avrdude: ser_send: . [1b] . [0f] . [00] . [0a] . [00] . [00] . [00] . [0e] 
. [05] . [c0]                 // CMND_READ_MEMORY : MTYPE_FLASH
. [01] . [00] . [00] . [00]   // read length = 1
. [01] ` [60] . [00] . [01]   // read address = $(01)00:6001
; [3b] . [92]
avrdude: jtagmkII_recv():
avrdude: ser_recv: . [1b]
avrdude: ser_recv: . [0f]
avrdude: ser_recv: . [00]
avrdude: ser_recv: . [02]
avrdude: ser_recv: . [00]
avrdude: ser_recv: . [00]
avrdude: ser_recv: . [00]
avrdude: ser_recv: . [0e]
avrdude: ser_recv: . [82] . [ff]
avrdude: ser_recv: . [19]
avrdude: ser_recv: R [52]

avrdude: jtagmkII_recv(): got message seqno 15 (command_sequence == 15)
avrdude: jtagmkII_recv: . [82] . [ff]

Raw message:
0x82 0xff 
memory contents:
0xff  

SRAM reads are passed from AVRDUDE as MTYPE_FLASH. Her fourth octet of the address field contains an invalid value. It's very slow because it's in bytes rather than bulk transfer, but it loads fine.

avrdude: writing 32 bytes sram ...
avrdude: jtagmkII_write_byte(.., sram, 0x0, ...)
avrdude: jtagmkII_write_byte(): sending write memory command: 
avrdude: jtagmkII_send(): sending 11 bytes
avrdude: ser_send: . [1b] . [11] @ [40] . [0b] . [00] . [00] . [00] . [0e] 
. [04] . [c0]                 // CMND_WRITE_MEMORY : MTYPE_FLASH
. [01] . [00] . [00] . [00]   // write length = 1
. [00] ` [60] . [00] . [01]   // write address = $(01)00:6000
. [ff]                        // write data = 0xFF
K [4b] x [78]
avrdude: jtagmkII_recv():
avrdude: ser_recv: . [1b]
avrdude: ser_recv: . [11]
avrdude: ser_recv: @ [40]
avrdude: ser_recv: . [01]
avrdude: ser_recv: . [00]
avrdude: ser_recv: . [00]
avrdude: ser_recv: . [00]
avrdude: ser_recv: . [0e]
avrdude: ser_recv: . [80]
avrdude: ser_recv: . [b3]
avrdude: ser_recv: . [1f]

avrdude: jtagmkII_recv(): got message seqno 16401 (command_sequence == 16401)
avrdude: jtagmkII_recv: . [80]

Raw message:
0x80 
OK

SRAM writes were passed as MTYPE_FLASH from AVRDUDE. Her fourth octet of the address field contains an invalid value. The flash update routine runs byte by byte instead of all at once, so the transfer is much slower, but AVRDUDE does not return an error. (The result of NVMCTRL itself is an update error)


Check how the SRAM changes when writing USERROW using a JTAG2UPDI clone modified to support AVR_EA and USERROW key writing. If the implementation is as described in the data sheet, you should be able to observe that a copy of the written USERROW appears at the beginning of the SRAM immediately after writing the USERROW. I used AVR64DD32 as the target (which happened to be connected).

+/Users/askn/Collaborator/avrdude_main/build_darwin/src/avrdude -xrtsdtr=high -p avr64dd32 -c jtag2updi -P /dev/cu.usbmodem1201 -q

avrdude: forcing serial DTR/RTS handshake lines HIGH
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e961a (probably avr64dd32)

avrdude: processing -T dump sram 0 64
0000  cf 99 2d 3c fa 6f d7 0f  0d c1 3b 14 90 47 ef df  |..-<.o.. .;..G..|
0010  53 82 ac 16 3e e0 72 e6  2e 8c a6 cc 1d e5 8b c9  |S...>.r.........|
0020  e1 1c b6 3c 1a 1e 16 5a  2c b4 37 5e ff 5e 76 b8  |...<...Z,.7^.^v.|
0030  d0 be cd 81 ef 99 c2 62  a6 06 47 56 7a 33 f5 69  |.......b..GVz3.i|

avrdude: processing -T dump userrow 0 64
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  |................|

avrdude: processing -U userrow:w:avr64dd32/UP.hex:i
avrdude: reading input file avr64dd32/UP.hex for userrow/usersig
         with 32 bytes in 1 section within [0, 0x1f]
         using 1 page and 0 pad bytes
avrdude: writing 32 bytes userrow/usersig ...
avrdude: 32 bytes of userrow/usersig written
avrdude: verifying userrow/usersig memory against avr64dd32/UP.hex
avrdude: 32 bytes of userrow/usersig verified

avrdude: processing -T dump sram 0 64
0000  02 c0 f8 95 08 95 11 24  80 91 40 00 81 11 05 c0  |.......$..@.....|
0010  98 ed 21 e0 94 bf 20 93  41 00 83 fd 02 c0 82 30  |..!... .A......0|
0020  e1 1c b6 3c 1a 1e 16 5a  2c b4 37 5e ff 5e 76 b8  |...<...Z,.7^.^v.|
0030  d0 be cd 81 ef 99 c2 62  a6 06 47 56 7a 33 f5 69  |.......b..GVz3.i|

avrdude: processing -T dump userrow 0 64
0000  02 c0 f8 95 08 95 11 24  80 91 40 00 81 11 05 c0  |.......$..@.....|
0010  98 ed 21 e0 94 bf 20 93  41 00 83 fd 02 c0 82 30  |..!... .A......0|

avrdude: processing -U userrow:w:avr64dd32/UnUSERROW.hex:i
avrdude: reading input file avr64dd32/UnUSERROW.hex for userrow/usersig
         with 32 bytes in 1 section within [0, 0x1f]
         using 1 page and 0 pad bytes
avrdude: writing 32 bytes userrow/usersig ...
avrdude: 32 bytes of userrow/usersig written
avrdude: verifying userrow/usersig memory against avr64dd32/UnUSERROW.hex
avrdude: 32 bytes of userrow/usersig verified

avrdude: processing -T dump sram 0 64
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  e1 1c b6 3c 1a 1e 16 5a  2c b4 37 5e ff 5e 76 b8  |...<...Z,.7^.^v.|
0030  d0 be cd 81 ef 99 c2 62  a6 06 47 56 7a 33 f5 69  |.......b..GVz3.i|

avrdude: processing -T dump userrow 0 64
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  |................|
avrdude: releasing DTR/RTS handshake lines

avrdude done.  Thank you.

It seems that the results were as per the specifications.

@stefanrueger
Copy link
Collaborator Author

Added a commit to sort all memories of parts in canonical order. This was done here rather than in PR #1568 to avoid merge conflicts.

$ avrdude -cdryrun -pt3216 -Tpart
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9521 (probably t3216)

avrdude: processing -T part
AVR Part                      : ATtiny3216
RESET disposition             : dedicated
RETRY pulse                   : SCK
Serial program mode           : yes
Parallel program mode         : yes
Memory Detail                 :

                                  Block Poll               Page                       Polled
  Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
  ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
  eeprom                  0     0     0    0 no        256   64      0     0     0 0x00 0x00
  flash                   0     0     0    0 no      32768  128      0     0     0 0x00 0x00
  fuses                   0     0     0    0 no         10    1      0     0     0 0x00 0x00
  fuse0       wdtcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
  fuse1       bodcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
  fuse2       osccfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
  fuse4       tcd0cfg     0     0     0    0 no          1    1      0     0     0 0x00 0x00
  fuse5       syscfg0     0     0     0    0 no          1    1      0     0     0 0x00 0x00
  fuse6       syscfg1     0     0     0    0 no          1    1      0     0     0 0x00 0x00
  fuse7       append      0     0     0    0 no          1    1      0     0     0 0x00 0x00
  fuse8       bootend     0     0     0    0 no          1    1      0     0     0 0x00 0x00
  lock                    0     0     0    0 no          1    1      0     0     0 0x00 0x00
  prodsig     sigrow      0     0     0    0 no         64   64      0     0     0 0x00 0x00
  signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
  sernum                  0     0     0    0 no         10    1      0     0     0 0x00 0x00
  osccal16                0     0     0    0 no          2    1      0     0     0 0x00 0x00
  osccal20                0     0     0    0 no          2    1      0     0     0 0x00 0x00
  tempsense               0     0     0    0 no          2    1      0     0     0 0x00 0x00
  osc16err                0     0     0    0 no          2    1      0     0     0 0x00 0x00
  osc20err                0     0     0    0 no          2    1      0     0     0 0x00 0x00
  userrow     usersig     0     0     0    0 no         64   64      0     0     0 0x00 0x00
  io                      0     0     0    0 no       4352    1      0     0     0 0x00 0x00
  sram                    0     0     0    0 no       2048    1      0     0     0 0x00 0x00
  sib                     0     0     0    0 no         32    1      0     0     0 0x00 0x00

avrdude done.  Thank you.

@askn37
Copy link
Contributor

askn37 commented Nov 17, 2023

Testing with serialupdi and AVR64EA32.

+cat avr64ea32/UP.hex
:200000000DC009C09DE994BF80930010809106108370E1F70895FC016083089511248091FC
:200020004000811105C098ED21E094BF2093410083FD02C0823021F4809340008CBBE0C019
:00000001FF
+cat avr64ea32/UnUSERROW.hex
:20000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0
:00000001FF
+/Users/askn/Collaborator/avrdude_main/build_darwin/src/avrdude -xrtsdtr=high -p avr64ea32 -c serialupdi -P /dev/cu.usbserial-230 -q -v


avrdude: Version 7.2-20231116 (1b9d0870)
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

         System wide configuration file is /Users/askn/Collaborator/avrdude_main/build_darwin/src/avrdude.conf
         User configuration file is /Users/askn/.avrduderc

         Using Port                    : /dev/cu.usbserial-230
         Using Programmer              : serialupdi
         AVR Part                      : AVR64EA32
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         Serial program mode           : yes
         Parallel program mode         : yes
         Memory Detail                 :

                                           Block Poll               Page                       Polled
           Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           fuses                   0     0     0    0 no         16    1      0     0     0 0x00 0x00
           fuse0       wdtcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse1       bodcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse2       osccfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse5       syscfg0     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse6       syscfg1     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse7       codesize    0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse8       bootsize    0     0     0    0 no          1    1      0     0     0 0x00 0x00
           lock                    0     0     0    0 no          4    1      0     0     0 0x00 0x00
           prodsig     sigrow      0     0     0    0 no        128  128      0     0     0 0x00 0x00
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           tempsense               0     0     0    0 no          4    1      0     0     0 0x00 0x00
           sernum                  0     0     0    0 no         16    1      0     0     0 0x00 0x00
           userrow     usersig     0     0     0    0 no         64   64      0     0     0 0x00 0x00
           io                      0     0     0    0 no       4160    1      0     0     0 0x00 0x00
           sib                     0     0     0    0 no         32    1      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        512    8      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      65536  128      0     0     0 0x00 0x00
           sram                    0     0     0    0 no       6144    1      0     0     0 0x00 0x00

         Programmer Type : serialupdi
         Description     : SerialUPDI
avrdude: forcing serial DTR/RTS handshake lines HIGH
avrdude: NVM type 3: 24-bit, page oriented
avrdude: entering NVM programming mode
avrdude serialupdi_enter_progmode() error: key was not accepted
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e961f (probably avr64ea32)

avrdude: processing -T dump sram 0 64
0000  00 00 00 00 a5 01 69 6f  61 76 72 36 34 65 61 33  |......ioavr64ea3|
0010  32 2e 68 00 0d 0a 00 00  04 68 00 08 00 94 02 ff  |2.h.  ...h......|
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  |................|

avrdude: processing -T dump usersig 0 64
0000  0d c0 09 c0 9d e9 94 bf  80 93 00 10 80 91 06 10  | . .............|
0010  83 70 e1 f7 08 95 fc 01  60 83 08 95 11 24 80 91  |.p......`....$..|
0020  40 00 81 11 05 c0 98 ed  21 e0 94 bf 20 93 41 00  |@.......!... .A.|
0030  83 fd 02 c0 82 30 21 f4  80 93 40 00 8c bb e0 c0  |.....0!...@.....|

avrdude: processing -U userrow:w:avr64ea32/UP.hex:i
avrdude: reading input file avr64ea32/UP.hex for userrow/usersig
         with 64 bytes in 1 section within [0, 0x3f]
         using 1 page and 0 pad bytes
avrdude: writing 64 bytes userrow/usersig ...
avrdude: 64 bytes of userrow/usersig written
avrdude: verifying userrow/usersig memory against avr64ea32/UP.hex
avrdude: 64 bytes of userrow/usersig verified

avrdude: processing -T dump sram 0 64
0000  0d c0 09 c0 9d e9 94 bf  80 93 00 10 80 91 06 10  | . .............|
0010  83 70 e1 f7 08 95 fc 01  60 83 08 95 11 24 80 91  |.p......`....$..|
0020  40 00 81 11 05 c0 98 ed  21 e0 94 bf 20 93 41 00  |@.......!... .A.|
0030  83 fd 02 c0 82 30 21 f4  80 93 40 00 8c bb e0 c0  |.....0!...@.....|

avrdude: processing -T dump usersig 0 64
0000  0d c0 09 c0 9d e9 94 bf  80 93 00 10 80 91 06 10  | . .............|
0010  83 70 e1 f7 08 95 fc 01  60 83 08 95 11 24 80 91  |.p......`....$..|
0020  40 00 81 11 05 c0 98 ed  21 e0 94 bf 20 93 41 00  |@.......!... .A.|
0030  83 fd 02 c0 82 30 21 f4  80 93 40 00 8c bb e0 c0  |.....0!...@.....|

avrdude: processing -U userrow:w:avr64ea32/UnUSERROW.hex:i
avrdude: reading input file avr64ea32/UnUSERROW.hex for userrow/usersig
         with 64 bytes in 1 section within [0, 0x3f]
         using 1 page and 0 pad bytes
avrdude: writing 64 bytes userrow/usersig ...
avrdude: 64 bytes of userrow/usersig written
avrdude: verifying userrow/usersig memory against avr64ea32/UnUSERROW.hex
avrdude: 64 bytes of userrow/usersig verified

avrdude: processing -T dump sram 0 64
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  |................|

avrdude: processing -T dump usersig 0 64
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  |................|
avrdude: leaving NVM programming mode
avrdude: releasing DTR/RTS handshake lines

avrdude done.  Thank you.

There is no problem with this SRAM operation.

@stefanrueger
Copy link
Collaborator Author

@askn37 @mcuee Thanks for testing!

As a result, MTYPE_SRAM and MTYPE_FLASH appear to have been swapped. Furthermore, small flash memories such as BOOTROW are now embedded in the data region. Nothing definitive yet, but since this belongs to a different region (separately from MTYPE_FLASH) it may be necessary to assign MTYPE_FLASH_PAGE.

Do you have a suggestion for how AVRDUDE should handle this for XMEGAs and modern (UPDI) parts? I am not convinced that AVRDUDE got it's handling right. Do you want to suggest a patch or a PR for correct io/sram handling?

no support of SRAM by ATmega328PB, using either usbasp or AVRISP mkII.

Correct; there is no method other than bootloaders that can access io or sram in classic parts. And I actually don't know of a single bootloader that allows you to do so.

@askn37
Copy link
Contributor

askn37 commented Nov 17, 2023

Do you have a suggestion for how AVRDUDE should handle this for XMEGAs and modern (UPDI) parts? I am not convinced that AVRDUDE got it's handling right. Do you want to suggest a patch or a PR for correct io/sram handling?

I don't have a clear opinion either. However, I understand that there are some things that need to be done differently with PDI and UPDI. For example, this requires careful consideration.

https://github.com/avrdudes/avrdude/blob/c82fec9c4b65ad029d44e173f5905f0644fb54ff/src/jtagmkII.c#L2608C1-L2617

Correct; there is no method other than bootloaders that can access io or sram in classic parts. And I actually don't know of a single bootloader that allows you to do so.

UPDI also includes OCD functionality, allowing access to SRAM and IO registers. Perhaps that's the difference.

@stefanrueger
Copy link
Collaborator Author

@mcuee @MCUdude @askn37 In absence of a clear steer I propose to consider this PR finished. I realise there might be some inconsistency in how AVRDUDE sets the memory type but

  • We don't have reported issued by users
  • Programmers may well have adopted to the way AVRDUDE communicates memory types

Sooo, I'll merge this PR at the next mergefest unless I hear otherwise

@mcuee
Copy link
Collaborator

mcuee commented Nov 18, 2023

I agree to merge this PR.

@askn37
Copy link
Contributor

askn37 commented Nov 18, 2023

I have no objection either. I think I have cleared this theme.

@stefanrueger stefanrueger merged commit 6df3f98 into avrdudes:main Nov 22, 2023
10 checks passed
@stefanrueger stefanrueger deleted the sram branch November 22, 2023 10:39
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.

[Proposal] Addition of memory "sram" directive
3 participants