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

Clean up and simplify hvupdi handling, and set default hvupdi_variant… #3

Merged
merged 3 commits into from
Jul 12, 2022

Conversation

janegilruud
Copy link

… to -1.

Updated according to comments by @stefanrueger. (avrdudes#1015 (review))

Copy link

@stefanrueger stefanrueger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for considering my comments. I like the way that you removed the dependency of the programmer names with defaulting hvupdi to -1.

Could I ask you or @MCUdude do a final sanity check as to whether all still works as expected (I don't have the HW).

I have one remaining recommendation: If the user is not supposed to supply the hvupdi variant on the command line (and that makes perfect sense to me), then please consider replacing

   else if (matches(extended_param, "hvupdi")) {

with

   else if (strcmp(extended_param, "hvupdi") == 0) {

The reason is that match() is strncmp() in diguise, so -xhvupdi=3.1415, -xhvupdi=0 or -xhvupdi=-1 would all still match and trigger PDATA(pgm)->use_hvupdi = true; which seems counter-intuitive to me from a user point of view. The suggested strcmp() would only accept one string (as is documented).

If you decide to make this change, please remember I have done a "blind" review, ie, I have not compiled, let alone run the modified AVRDUDE. So, please test with a few command line options whether implementation matches documentation. Also imagine a user who hasn't read the documentation and predict whether or not they'd find the suggested command line logic reasonable. (From what you said earlier I understand this to be a "yes").

…The hvupdi type is implied by the part configuration.
@janegilruud
Copy link
Author

I do build it before I push the changes, so at least it compiles. But I do not have the HW setup easily available at the moment, so I hope @MCUdude can do some quick sanity checks on the latest changes.

Copy link

@stefanrueger stefanrueger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brill, over to @MCUdude - once confirmed working consider merging with AVRDUDE main straight away

@MCUdude
Copy link
Owner

MCUdude commented Jul 11, 2022

The PR works fine, but why change the behavior in jtag3_parseextparms? Not the -xhvupdi parameter is ignored when passed to a jtag3 programmer that doesn't support HVUPDI. An error should be thown instead.

$ ./avrdude -csnap_updi -pattiny1616 -xhvupdi -v

avrdude: Version 7.0-20220508
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is "/Users/hans/Downloads/avrdude/src/avrdude.conf"
         User configuration file is "/Users/hans/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : snap_updi
avrdude: usbhid_open(): No device found
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : ATtiny1616
         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
           userrow     usersig     0     0     0    0 no         32   32      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      16384   64      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        256   32      0     0     0 0x00 0x00

         Programmer Type : JTAGICE3_UPDI
         Description     : MPLAB(R) SNAP in UPDI mode
         ICE HW version  : 1
         ICE FW version  : 1.10 (rel. 249)
         Serial number   : 
         Vtarget         : 5.08 V
         JTAG clock megaAVR/program   : 1000 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz

avrdude: bad response to AVR sign-on command: 0xa0
avrdude: retrying with external reset applied
avrdude: bad response to AVR sign-on command: 0xa0
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 done.  Thank you.
-    else if ((matches(extended_param, "hvupdi") || matches(extended_param, "hvupdi=1")) &&
-       (matches(ldata(lfirst(pgm->id)), "pickit4_updi") || matches(ldata(lfirst(pgm->id)), "powerdebugger_updi"))) {
+     else if (strcmp(extended_param, "hvupdi") == 0) {
       PDATA(pgm)->use_hvupdi = true;
       continue;
     }

@janegilruud
Copy link
Author

why change the behavior in jtag3_parseextparms?

I don't think it is necessary to expose the user for hvupdi type. The type for the selected target is given in avrdude.conf, so Avrdude already has that information. The users then only has to choose if they want to use HVUPDI or not.

Not the -xhvupdi parameter is ignored when passed to a jtag3 programmer that doesn't support HVUPDI. An error should be thown instead.

Yes, Totally agree. Should do the check using hvupdi_support and not programmer name.

@janegilruud
Copy link
Author

janegilruud commented Jul 12, 2022

I guess there are several ways to check if the programmer supports HVUPDI. Here's one suggesting in jtag3_parseextparms():

    else if ((strcmp(extended_param, "hvupdi") == 0) &&
             (lsize(pgm->hvupdi_support) > 1)) {
      PDATA(pgm)->use_hvupdi = true;
      continue;
    }

For programmers that supports HVUPDI type 0 or 2 the hvupdi_support list is at least of size 2.

EDIT: But this throws no error... so a slight rewrite of this suggestion...
EDIT: Yes, it does throw an error. Please ignore my rambling.

@janegilruud
Copy link
Author

Do we want to add a return -1; after the message on jtag3.c:1270?

          avrdude_message(MSG_INFO, "%s: %s does not support sending HV pulse to target %s\n",
            progname, pgm->desc, p->desc);

@MCUdude
Copy link
Owner

MCUdude commented Jul 12, 2022

Do we want to add a return -1; after the message on jtag3.c:1270?

I don't think that's necessary. It will terminate before that code is even executed:

$ ./avrdude -csnap_updi -pattiny1616 -xhvupdi -v

avrdude: Version 7.0-20220508
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is "/Users/hans/Downloads/avrdude/src/avrdude.conf"
         User configuration file is "/Users/hans/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

avrdude: jtag3_parseextparms(): invalid extended parameter 'hvupdi'
avrdude: Error parsing extended parameter list

@MCUdude MCUdude merged commit dc6c10d into MCUdude:hv-updi Jul 12, 2022
@janegilruud
Copy link
Author

I don't think that's necessary. It will terminate before that code is even executed:

If you use a PowerDebugger and try to do hvupdi on a type 2 target, then you will get that message. Only case I can think of.

@janegilruud janegilruud deleted the hv-updi branch July 13, 2022 07:55
@MCUdude
Copy link
Owner

MCUdude commented Jul 13, 2022

If you use a PowerDebugger and try to do hvupdi on a type 2 target, then you will get that message. Only case I can think of.

It doesn't hurt to have it, so added return -1;in commit dde3501.

Off topic: Do you think Microchip would either donate or let one of us spare time Avrdude developers borrow some hardware to ensure that Avrdude properly supports the hardware? There's a few issues we can't work on without testing it on actual hardware:

  • The Power Debugger hasn't gotten much love, and there's a few features that could be added to Avrdude terminal mode.
  • Potential issue (#404) where xmegas with 256kB flash or more fails if the program is greater than 128kB in size
  • Unconfirmed issue with A4U devices (#289)
  • 256A3BU hangs, when programming or reading device signature (#337)

@janegilruud
Copy link
Author

I'll see what I can do...

MCUdude pushed a commit that referenced this pull request Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants