avrdudes / avrdude

AVRDUDE is a utility to program AVR microcontrollers
GNU General Public License v2.0
728 stars 137 forks source link

Pickit4 UPDI is writing at offset 0x4000 into flash instead of 0x0000. #892

Closed merlinblack closed 2 years ago

merlinblack commented 2 years ago

Compiled from latest source,on Linux. Have a small test program for a ATmega4809 that I've exported the hex file from Arduino IDE. Writing it using avrdude and a pickit4 in UPDI mode does not work as expected. The program is written but in the wrong place in flash.

Here's my command line and output:

#> ./avrdude -v -cpickit4_updi -pm4809 -Uflash:w:blinky.hex:i

avrdude: Version 6.99-20220221 (64cc54a)
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is "/home/nigel/prog/avr/avrdude/build_linux/src/avrdude.conf"
         User configuration file is "/home/nigel/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : pickit4_updi
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : ATmega4809
         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
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           prodsig                 0     0     0    0 no         61   61      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
           fuses                   0     0     0    0 no          9   10      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
           data                    0     0     0    0 no          0    1      0     0     0 0x00 0x00
           usersig     userrow     0     0     0    0 no         64   64      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      49152  128      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        256   64      0     0     0 0x00 0x00

         Programmer Type : JTAGICE3_UPDI
         Description     : MPLAB(R) PICkit 4 in UPDI mode
         ICE HW version  : 4
         ICE FW version  : 1.13 (rel. 236)
         Serial number   : 
         Vtarget         : 4.84 V
         JTAG clock megaAVR/program   : 1000 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz

avrdude: Partial Family_ID returned: "mega"
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x1e9651 (probably m4809)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "blinky.hex"
avrdude: writing flash (3048 bytes):

Writing | ################################################## | 100% 1.27s

avrdude: 3048 bytes of flash written
avrdude: verifying flash memory against blinky.hex:

Reading | ################################################## | 100% 0.65s

avrdude: 3048 bytes of flash verified

avrdude done.  Thank you.

From the above, it all looks like it's worked perfectly - but the LED is not blinking.

I tried using "pymcuprog" which did work, so I tried using pymcuprog to read back what avrdude does using:

#> pymcuprog -datmega4809 read -m flash -f dump.bin
Connecting to anything possible
Connected to MPLAB PICkit 4 CMSIS-DAP from Microchip Technology Incorporated (serial number BUR213372088)
Debugger firmware version 1.13.236
Debugger hardware revision 4
Pinging device...
Ping response: 1E9651
Reading...
Data written to binary file: 'dump_flash.bin'
Done.

And a dump of the file from hexdump looks like:

#> hexdump -C dump_flash.bin | head -n20
00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00004000  0c 94 70 00 0c 94 98 00  0c 94 98 00 0c 94 98 00  |..p.............|
00004010  0c 94 98 00 0c 94 98 00  0c 94 98 00 0c 94 98 00  |................|
*
00004040  0c 94 98 00 0c 94 9b 03  0c 94 75 03 0c 94 98 00  |..........u.....|
00004050  0c 94 98 00 0c 94 98 00  0c 94 98 00 0c 94 98 00  |................|
00004060  0c 94 98 00 0c 94 c9 03  0c 94 98 00 0c 94 98 00  |................|
00004070  0c 94 98 00 0c 94 98 00  0c 94 98 00 0c 94 98 00  |................|
*
000040a0  43 6f 6d 70 6c 69 65 64  3a 20 46 65 62 20 32 34  |Complied: Feb 24|
000040b0  20 32 30 32 32 2c 20 32  33 3a 32 31 3a 32 39 00  | 2022, 23:21:29.|
000040c0  42 6f 6f 74 69 6e 67 20  46 61 6e 63 79 20 42 6c  |Booting Fancy Bl|
000040d0  69 6e 6b 00 4d 69 6c 6c  69 73 3a 20 00 00 00 05  |ink.Millis: ....|
000040e0  11 24 1f be cf ef cd bf  df e3 de bf 18 e2 a0 e0  |.$..............|
000040f0  b8 e2 e5 ee fb e0 02 c0  05 90 0d 92 a2 30 b1 07  |.............0..|
00004100  d9 f7 28 e2 a2 e0 b8 e2  01 c0 1d 92 a8 3a b2 07  |..(..........:..|
00004110  e1 f7 10 e0 c0 e7 d0 e0  04 c0 21 97 fe 01 0e 94  |..........!.....|
00004120  71 05 cf 36 d1 07 c9 f7  0e 94 f1 03 0c 94 91 05  |q..6............|
00004130  0c 94 00 00 fc 01 50 8d  41 8d 25 2f 30 e0 84 2f  |......P.A.%/0../|

So you can see my program did get written - only at offset 0x4000. A dump from when it is working shows my program written at the beginning of the flash, i.e. offset 0x0000.

The offset in avrdude.conf for 'flash' for an ATmega4809 is 0x4000. Perhaps somehow this offset is being apply twice or something similar.

MCUdude commented 2 years ago

Can you paste the contests of the hex file you're trying to load? Maybe there's an addressing issue in there.

merlinblack commented 2 years ago

I thought that might be the case too, however it looks ok to me. If anyone wants to try it, this should toggle PA7 with a pattern, and output elapsed Millis on USART0. (On a Atmega4809 PDIP40)

:100000000C9470000C9498000C9498000C94980038
:100010000C9498000C9498000C9498000C94980000
:100020000C9498000C9498000C9498000C949800F0
:100030000C9498000C9498000C9498000C949800E0
:100040000C9498000C949B030C9475030C949800EA
:100050000C9498000C9498000C9498000C949800C0
:100060000C9498000C94C9030C9498000C9498007C
:100070000C9498000C9498000C9498000C949800A0
:100080000C9498000C9498000C9498000C94980090
:100090000C9498000C9498000C9498000C94980080
:1000A000436F6D706C6965643A2046656220323436
:1000B00020323032322C2032333A32313A32390067
:1000C000426F6F74696E672046616E637920426C7F
:1000D000696E6B004D696C6C69733A200000000515
:1000E00011241FBECFEFCDBFDFE3DEBF18E2A0E0DB
:1000F000B8E2E5EEFBE002C005900D92A230B10738
:10010000D9F728E2A2E0B8E201C01D92A83AB207EE
:10011000E1F710E0C0E7D0E004C02197FE010E94A3
:100120007105CF36D107C9F70E94F1030C949105F0
:100130000C940000FC01508D418D252F30E0842F60
:1001400090E0821B930B541710F0CF9608950197FF
:100150000895FC0196898789981761F0A789AE0FE9
:10016000BF2FB11D5D968C9197899F5F9F73978B71
:1001700090E008958FEF9FEF0895FC01968987899D
:10018000981731F08789E80FF11D858D90E008956B
:100190008FEF9FEF0895FC0196892789892F90E0C2
:1001A000805C9F4F821B91098F7399270895CF938D
:1001B000DF93EC01E881F9810680F781E02D099554
:1001C000EC85FD8586818F738683EC85FD85858131
:1001D0008F7585838F898E8B1D8ADF91CF910895CE
:1001E0008F929F92AF92BF92EF92FF920F931F93C5
:1001F000CF93DF93EC014A015B01E22E8D898823C6
:1002000039F0E881F9810688F789E02DCE0109955A
:100210000C8910E0FFB6F89460E070E281EA97E0A4
:10022000A50194010E94280549015A018FEF881AFF
:10023000980AA80AB80AB694A79497948794EC856C
:10024000FD8586818D7F8683EC85FD85868186830D
:100250001D8AA09123110A2E000CBB0BA50194014D
:100260000E94690520E034E040E050E00E944A0529
:10027000EC85FD85820E931EA41EB51E8086918698
:10028000EC85FD85E782EC85FD858681806C868323
:10029000EC85FD858581806885839091E2058B8959
:1002A000809589239801220F331FF901E00FF11F78
:1002B000EC0FFD1F9089892B8093E20586858132A2
:1002C00028F590E0FC01EF53F44B40814F3FF1F0F3
:1002D000FC01E056F44BA081E0E2AE9FD001112476
:1002E000BC5F8158944BFC015081F0E0E0E05F3F3F
:1002F00029F0CD014096FC01E50FF11D9FB7F89460
:1003000012964C938081886080839FBFF901E00F33
:10031000F11FEC0FFD1F8785813208F590E0FC018D
:10032000EF53F44B70817F3FD1F0FC01E25AF44B64
:10033000E081EE2331F0E130B1F118F0E63008F45D
:1003400046C0FC01E056F44BE08150E2E59FF0012D
:100350001124FC5F4081472309F443C07583020FD9
:10036000131FC00FD11F8F85813288F490E0FC01EC
:10037000EF53F44B20812F3F51F08056944BDC011A
:10038000EC91B0E2EB9FF0011124FC5F2183FFBEF2
:10039000DF91CF911F910F91FF90EF90BF90AF90A1
:1003A0009F908F900895FC01E158F44B6081633079
:1003B00008F06F5FE091010A41E050E001C0440F96
:1003C0006A95EAF740954E234093010ABACF40E17F
:1003D000E49FF0011124E05AF54F41814F7E4183A3
:1003E000B0CF8158944BDC018C91309761F08F3FF6
:1003F00051F07096E80FF11D9FB7F89480818860E6
:1004000080839FBFACCFF0E0E0E0F6CFFC0161302D
:1004100019F4648B81E00895148A6623D9F380E08F
:100420000895DC0154961C92549754968C915497DD
:100430008230A0F4282F30E0F901EE0FFF1FE20F09
:10044000F31FEA0FFB1F9785961303C09685941739
:1004500049F08F5F54968C935497E7CF54961C9233
:1004600080E0089581E00895CF93DF93FC01908DA3
:10047000818DC485D585981306C08D818F7D8D8330
:10048000DF91CF910895A18DAE0FBF2FB11DA35A5B
:10049000BF4F2C91818D90E001968F739927818FAA
:1004A00080E48C83A485B58512962C93908D818DE4
:1004B0009813E6CFA485B58515968C9115978F7DF9
:1004C00015968C93838D8823D9F2848D80931301A4
:1004D000138ED6CFDC011C96ED91FC910FB607FE72
:1004E00003C0258125FD04C0248125FD0C94340220
:1004F0000895EF92FF920F931F93CF93DF93EC0138
:1005000081E08D8B988D898D98131CC0AC85BD853D
:1005100014968C91149785FF15C012966C93AC8538
:10052000BD8580E414968C93EC85FD8585818F7D57
:10053000858381E090E0DF91CF911F910F91FF9033
:10054000EF9008958091110180FF08C08091130100
:100550008C8F8A8D8093130181E08B8FF62E088D0E
:1005600010E00F5F1F4F0F731127E02E898D8E1142
:1005700004C0CE010E946A02F9CFE88DEC0FFD2F76
:10058000F11DE35AFF4FF082088FEC85FD858581D0
:100590008062CECF0F931F93CF93DF938C01D0E077
:1005A000C0E0F801EC0FFD1F6491662341F08BE081
:1005B00098E20E947902892B11F02196F2CFCE01A8
:1005C000DF91CF911F910F910895CF93DF93FC019D
:1005D00025892223C9F0EC018091110180FF08C018
:1005E00080911301848F828D8093130181E0838F2A
:1005F000EC85FD85858185FD03C0848186FD04C071
:10060000CE010E946A02F4CFDF91CF9108958BE072
:1006100098E20E94CB0021E0892B09F420E0822F90
:10062000089580E090E0892B29F00E940703811152
:100630000E94000080E090E0892B49F080E090E08B
:10064000892B29F00E94000081110E94000080E0A7
:1006500090E0892B49F080E090E0892B29F00E94FE
:10066000000081110C9400000895AF92BF92CF92C8
:10067000DF92EF92FF920F931F93CF93DF936C0162
:100680007B018B01040F151FEB015E01AE18BF0843
:10069000C017D10759F06991D601ED91FC910190F5
:1006A000F081E02DC6010995892B79F7C501DF910D
:1006B000CF911F910F91FF90EF90DF90CF90BF905F
:1006C000AF90089581E00895DC01ED91FC910488DC
:1006D000F589E02D23E030E0099442E050E062EE3D
:1006E0007BE48BE098E20C9435031F920F920FB6D7
:1006F0000F9211242F933F934F935F936F937F93A8
:100700008F939F93AF93BF93EF93FF938BE098E208
:100710000E943402FF91EF91BF91AF919F918F9111
:100720007F916F915F914F913F912F910F900FBEED
:100730000F901F9018951F920F920FB60F921124D1
:100740002F938F939F93EF93FF93E0911728F0914E
:100750001828818181FD1BC09081809121288F5FA5
:100760008F7320912228821741F0E0912128F0E038
:10077000E55FF74D958F80932128FF91EF919F9131
:100780008F912F910F900FBE0F901F901895808121
:10079000F4CF1F920F920FB60F9211248F939F9355
:1007A000AF93BF938091022890910328A0910428D1
:1007B000B09105280196A11DB11D80930228909348
:1007C0000328A0930428B093052881E08093A60A0B
:1007D000BF91AF919F918F910F900FBE0F901F907F
:1007E0001895CF93DF93CDB7DEB7A197CDBFDEBF0E
:1007F00088ED90E084BF909361008091020686604E
:1008000080930206809100068160809300068091AB
:1008100002068F7C8065809302061092E20582E0DA
:100820008093E40581E08093030A8EEF8093270A8A
:100830008093260A80E880932D0A80932B0A809368
:10084000290A80932C0A80932A0A8093280A8BE035
:100850008093000A87E08093E505E0E8FAE037E05E
:100860002EEF90E885E0318324879587808370960A
:10087000E03C4AE0F407B9F71092A10A8FE79EE343
:100880008093AC0A9093AD0A8091A50A8160809311
:10089000A50A1092A00A8091A00A81608093A00A04
:1008A000789484E080933004809331048093320400
:1008B00080933304809334048093350480935604EA
:1008C0008093560440E052EC61E070E08BE098E2E7
:1008D0000E94640380EC90E00E94CA020E946D03B3
:1008E00080EA90E00E94CA020E946D038091000499
:1008F000806880930004BB24B3942AE0422E512CDC
:10090000612C712C8FB7F894C0900228D0900328E6
:10091000E0900428F09005288FBFE0910628809190
:10092000072890910828A0910928B0910A28B701BA
:10093000A601481B590B6A0B7B0BAE2FB0E0AA0F28
:10094000BB1FAC5BB44B8D919C91B0E0A0E08417D1
:100950009507A607B70708F04BC0C0920728D092AA
:100960000828E0920928F0920A28EF5FE093062811
:10097000F0E0EE0FFF1FEC5BF44B80819181892B3F
:1009800011F410920628809100288B25809300286E
:10099000882389F18091040480688093040484EDA5
:1009A00090E00E94CA0219A28E010F5D1F4FC7017D
:1009B000B601A30192010E94280569017A01605DD8
:1009C000F80162938F01C114D104E104F10479F7B5
:1009D000309761F001900020E9F73197AF01401B9B
:1009E000510BB8018BE098E20E9435030E946D0321
:1009F0000E94110387CF8091040410920404CFCF8A
:100A0000EBE0F8E21282138288EE93E0A0E0B0E01F
:100A100084839583A683B7838AE29BE48083918352
:100A200080E098E08487958781E086871786108A22
:100A300095E0918B94E0928B838B148A158A168AA9
:100A4000178A108E118E82E1828F138E148E089574
:100A5000A1E21A2EAA1BBB1BFD010DC0AA1FBB1FC2
:100A6000EE1FFF1FA217B307E407F50720F0A21B34
:100A7000B30BE40BF50B661F771F881F991F1A94A1
:100A800069F760957095809590959B01AC01BD01CB
:100A9000CF010895052E97FB1EF400940E94610576
:100AA00057FD07D00E94280507FC03D04EF40C9494
:100AB000610550954095309521953F4F4F4F5F4FC1
:100AC000089590958095709561957F4F8F4F9F4FBA
:100AD0000895B7FF0C9477050E947705821B930B4E
:100AE0000895EE0FFF1F0590F491E02D09940E94E8
:100AF0008205A59F900DB49F900DA49F800D911D20
:100B000011240895A29FB001B39FC001A39F700D4F
:100B1000811D1124911DB29F700D811D1124911D05
:060B20000895F894FFCFD8
:100B260000000000790235039A00E502CB00A90017
:100B3600BD00110206026403F000D7006203FA004A
:100B4600FA00FA00E80332003200320032003200C6
:100B560032003200D0070000000000000000000054
:100B66000101010101010000000000000000000079
:100B76000000000000000203000001020304050655
:100B8600070001020304050001020304050607002D
:100B96000102030001020304050600000000000034
:100BA600000002020202020203030303030303031B
:100BB60004040404050505050505050102040810DD
:100BC6002040800102040810200102040810204081
:0F0BD6008001020408010204081020400D0A00EB
:020BE50001000D
:00000001FF
MCUdude commented 2 years ago

I'm currently on winter vacation, but I'll see if I can reproduce the issue when I get home!

merlinblack commented 2 years ago

That would be great. I did try stepping through the code to see what I could find, however, nothing really stuck out. I thought perhaps the jtag3.c code at line 2467 might be suspect, but this same code works when reading the signature memory.

While hacking around, at one point for whatever reason MPLab IPE (on Linux) started writing to flash beginning at offset 0x2000. Power cycling the pickit did not fix it, but after using pymcuprog to erase and write it was back to normal. Perhaps there is a 'command' to set where in flash the Pickit4 operates, and pymcuprog sets this to 0x0000.

MCUdude commented 2 years ago

@merlinblack thanks for reporting! I can confirm that this is an issue on the Pickit4, SNAP and the Xplained Mini UPDI. probably all JTAG3 compatible programmers...

I can also confirm that this was not an issue with Avrdude 6.3

MCUdude commented 2 years ago

@merlinblack you're absolutely right about your assumptions, it's line 2467 that's causing the issue, and to be honest, it's my fault, sorry for that... However, I have no idea why this only applies to the flash memory and not the other ones!

https://github.com/avrdudes/avrdude/blob/64cc54ac3513fec863c439c9f87381fc45fc3706/src/jtag3.c#L2464-L2476

@dl8dtl do you know what the flash memory needs to be treated differently than the other memories?

This is a quick fix that works, but isn't very elegant:

  /*
   * Non-Xmega device.
   */
  if (p->flags & AVRPART_HAS_UPDI) {
    if (m->size == 1) {
      addr = m->offset;
    }
    else if (m->size > 1 && strcmp(m->desc, "flash") != 0) {
      addr += m->offset;
    }
  }
  return addr;
}
merlinblack commented 2 years ago

@MCUdude Yeah the whole only affecting flash is weird. Or perhaps it just does not affect the signature memory. I haven't tried writing fuses.

Unfortunately, the quick fix does not work for me. Perhaps the offset is needed for some calls to jtag3_memaddr and not others?

If I use this - it puts my Pickit in a confused state where it does not even work for pymcuprog. Even power cycling does not get it back. Fortunately - doing a read in MPLab IPE corrects it.

Here's what I get from avrdude: with ./avrdude -v -cpickit4_updi -pm4809

avrdude: Version 6.99-20220221 (64cc54a)
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is "/home/nigel/prog/avr/avrdude/build_linux/src/avrdude.conf"
         User configuration file is "/home/nigel/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : pickit4_updi
avrdude: usbhid_open(): Unexpected reply to DAP_Info: 0x03 0x00
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
avrdude: jtag3_edbg_prepare(): unexpected response 0x00, 0x02
avrdude: jtag3_edbg_prepare(): unexpected response 0x02, 0x01
avrdude: jtag3_edbg_send(): Unexpected response 0x01, 0x00
avrdude: jtag3_edbg_recv(): Unexpected response 0x80
avrdude: opening programmer "pickit4_updi" on port "usb" failed

avrdude done.  Thank you.
merlinblack commented 2 years ago

I think is only flash that is affected. I've just tested wring to EEPROM and it works as expected. I used pymcuprog to verify the contents of EEPROM.

MCUdude commented 2 years ago

It's very strange that the fix didn't work for you, since this is was exactly how the code worked before I broke it in a previous PR.

Maybe @dl8dtl knows?

merlinblack commented 2 years ago

That error looks similar (perhaps the same) to what I was getting with a microUPDI setup. I'll have to try it again... sounds of tinkering No, different error I think.

./avrdude -v -cxplainedmini_updi -pm4809

avrdude: Version 6.99-20220221 (64cc54a)
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is "/home/nigel/prog/avr/avrdude/build_linux/src/avrdude.conf"
         User configuration file is "/home/nigel/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : xplainedmini_updi
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : ATmega4809
         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
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           prodsig                 0     0     0    0 no         61   61      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
           fuses                   0     0     0    0 no          9   10      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
           data                    0     0     0    0 no          0    1      0     0     0 0x00 0x00
           usersig     userrow     0     0     0    0 no         64   64      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      49152  128      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        256   64      0     0     0 0x00 0x00

         Programmer Type : JTAGICE3_UPDI
         Description     : Atmel AVR XplainedMini in UPDI mode
         ICE HW version  : 0
         ICE FW version  : 1.19 (rel. 57)
         Serial number   : MICROUPDIPROGRAMMERX
         Vtarget         : 3.30 V
avrdude: Short read, read only 0 out of 64 bytes
avrdude: jtag3_edbg_recv(): Unexpected response 0x9c
avrdude: retrying with external reset applied
avrdude: jtag3_edbg_send(): Unexpected response 0x81, 0x11
avrdude: jtag3_edbg_recv(): Unexpected response 0x80
avrdude: retrying with external reset applied
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: jtag3_edbg_send(): Unexpected response 0x81, 0x11
avrdude: jtag3_edbg_recv(): Unexpected response 0x80
avrdude: jtag3_edbg_send(): Unexpected response 0x81, 0x11
avrdude: jtag3_edbg_recv(): Unexpected response 0x80

avrdude done.  Thank you.

It does work with the avrdude that comes with Arduino IDE - which led me to test the pickit4 with the arduino ide version of avrdude, but it doesn't work.

#> ./avrdude -v -cpickit4_updi -pm4809
avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "../etc/avrdude.conf"
         User configuration file is "/home/nigel/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : pickit4_updi
avrdude: usbdev_open(): Found MPLAB PICkit 4 CMSIS-DAP, serno: BUR213372088
avrdude: usbdev_open(): WARNING: failed to set configuration 1: Device or resource busy
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
avrdude: usbdev_send(): wrote -5 out of 912 bytes, err = Input/output error
avrdude: jtag3_edbg_prepare(): failed to send command to serial port

avrdude done.  Thank you.

Doing the same (./avrdude -v -cpickit4_updi -pm4809) with from source avrdude still works - just not the flashing.

Despite the Arduino version not working with my pickit, it does correctly flash my 4809 using my microUPD, so at least it's jtag updi code seems to work in that version.

dl8dtl commented 2 years ago

I thin PR #895 closes this as well.

merlinblack commented 2 years ago

Wonderfull! That works for me. It's only subtlely different to MCUdudes fix above, returning the addr unchanged regardless of m->size.

Anyhow - thanks all!