From 39ac5e88b39b475326533503f092741c7cf98c09 Mon Sep 17 00:00:00 2001 From: stefanrueger Date: Tue, 11 Mar 2025 11:17:50 +0100 Subject: [PATCH] Self-document hvupdi_variant --- src/avrdude.conf.in | 4 ++-- src/doc/avrdude.texi | 4 ++-- src/jtag3.c | 4 ++-- src/jtag3_private.h | 2 +- src/libavrdude.h | 19 ++++++++++++++----- src/pickit5.c | 16 ++++++++-------- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index 31df9298..f44f2f37 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -49,7 +49,7 @@ avrdude_conf_version = "@AVRDUDE_FULL_VERSION@"; # usbvendor = ; # USB Vendor Name # usbproduct = ; # USB Product Name # usbsn = ; # USB Serial Number -# hvupdi_support = [, , ... ] ; # UPDI HV Variants Support +# hvupdi_support = [, , ... ] ; # HV support for enabling UPDI # ; # # # Notes @@ -110,7 +110,7 @@ avrdude_conf_version = "@AVRDUDE_FULL_VERSION@"; # n_page_erase = ; # if set, number of pages erased during SPM erase # n_boot_sections = ; # Number of boot sections # boot_section_size = ; # Size of (smallest) boot section, if any -# hvupdi_variant = ; # numeric -1 (n/a) or 0..2 +# hvupdi_variant = ; # numeric: -1 or 0..3; how to enable UPDI with HV # stk500_devcode = ; # numeric # avr910_devcode = ; # numeric # is_at90s1200 = ; # AT90S1200 part diff --git a/src/doc/avrdude.texi b/src/doc/avrdude.texi index 12a2901a..489fa944 100644 --- a/src/doc/avrdude.texi +++ b/src/doc/avrdude.texi @@ -3668,7 +3668,7 @@ programmer usbvendor = ; # USB Vendor Name usbproduct = ; # USB Product Name usbsn = ; # USB Serial Number - hvupdi_support = [, , ... ]; # UPDI HV Variants Support + hvupdi_support = [, , ... ]; # HV support for enabling UPDI ; @end smallexample @@ -3836,7 +3836,7 @@ part n_page_erase = ; # if set, number of pages erased during SPM erase n_boot_sections = ; # Number of boot sections boot_section_size = ; # Size of (smallest) boot section, if any - hvupdi_variant = ; # numeric -1 (n/a) or 0..2 + hvupdi_variant = ; # numeric: -1 or 0..3; how to enable UPDI with HV stk500_devcode = ; # numeric avr910_devcode = ; # numeric is_at90s1200 = ; # AT90S1200 part diff --git a/src/jtag3.c b/src/jtag3.c index a524f8a0..8021ce80 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1246,11 +1246,11 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) { } // Generate UPDI high-voltage pulse if user asks for it and hardware supports it - if(my.use_hvupdi == true && p->hvupdi_variant != HV_UPDI_VARIANT_1) { + if(my.use_hvupdi == true && p->hvupdi_variant != UPDI_ENABLE_ALWAYS) { parm[0] = PARM3_UPDI_HV_NONE; for(LNODEID ln = lfirst(pgm->hvupdi_support); ln; ln = lnext(ln)) { if(*(int *) ldata(ln) == p->hvupdi_variant) { - pmsg_notice("sending HV pulse to targets %s pin\n", p->hvupdi_variant == HV_UPDI_VARIANT_0? "UPDI": "RESET"); + pmsg_notice("sending HV pulse to targets %s pin\n", p->hvupdi_variant == UPDI_ENABLE_HV_UPDI? "UPDI": "RESET"); parm[0] = PARM3_UPDI_HV_SIMPLE_PULSE; break; } diff --git a/src/jtag3_private.h b/src/jtag3_private.h index 385f2b1c..491ac2bc 100644 --- a/src/jtag3_private.h +++ b/src/jtag3_private.h @@ -470,6 +470,6 @@ struct updi_device_desc { unsigned char address_mode; // 0x00 = 16-bit mode, 0x01 = 24-bit mode - unsigned char hvupdi_variant; // Indicates the target UPDI HV implementation + unsigned char hvupdi_variant; // How the target's UPDI can be enabled with HV }; #endif // JTAG3_PRIVATE_EXPORTED diff --git a/src/libavrdude.h b/src/libavrdude.h index 9bb35b99..3e0f70b2 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -19,6 +19,9 @@ #ifndef libavrdude_h #define libavrdude_h +// #define TO_BE_DEPRECATED_IN_2026 +// #define TO_BE_DEPRECATED_IN_2027 + #include #include #include @@ -280,9 +283,15 @@ typedef struct opcode { #define both_awire(pgm, p) (!!(joint_pm(pgm, p) & PM_aWire)) #define both_classic(pgm, p) (!!(joint_pm(pgm, p) & PM_Classic)) -#define HV_UPDI_VARIANT_0 0 // Shared UPDI/GPIO/RESET pin, HV on UPDI pin (tinyAVR0/1/2) -#define HV_UPDI_VARIANT_1 1 // Dedicated UPDI pin, no HV (megaAVR0/AVR-Dx) -#define HV_UPDI_VARIANT_2 2 // Shared UPDI pin, HV on _RESET (AVR-DD/AVR-Ex) +#define UPDI_ENABLE_HV_UPDI 0 // Shared UPDI/GPIO/RESET pin, HV on UPDI pin (tinyAVR0/1/2) +#define UPDI_ENABLE_ALWAYS 1 // Dedicated UPDI pin, no HV needed (megaAVR0/AVR-DA/DB) +#define UPDI_ENABLE_HV_RESET 2 // Shared UPDI/GPIO pin, HV on RESET (AVR-DD/DUEA/EB) + +#ifndef TO_BE_DEPRECATED_IN_2027 +#define HV_UPDI_VARIANT_0 UPDI_ENABLE_HV_UPDI +#define HV_UPDI_VARIANT_1 UPDI_ENABLE_ALWAYS +#define HV_UPDI_VARIANT_2 UPDI_ENABLE_HV_RESET +#endif #define HAS_SUFFER 1 #define HAS_VTARG_SWITCH 2 @@ -322,7 +331,7 @@ typedef struct avrpart { int n_page_erase; // If set, number of pages erased during NVM erase int n_boot_sections; // Number of boot sections int boot_section_size; // Size of (smallest) boot section, if any - int hvupdi_variant; // HV pulse on UPDI pin, no pin or RESET pin + int hvupdi_variant; // HV pulse: on UPDI pin (0), not needed (1), on RESET (2/3) int stk500_devcode; // Stk500 device code int avr910_devcode; // Avr910 device code int chip_erase_delay; // Microseconds @@ -989,7 +998,7 @@ typedef struct programmer { const char *usbsn; const char *usbvendor; const char *usbproduct; - LISTID hvupdi_support; // List of UPDI HV variants the tool supports, see HV_UPDI_VARIANT_x + LISTID hvupdi_support; // List of UPDI HV variants the tool supports, see UPDI_ENABLE_x // Values below are not set by config_gram.y; ensure fd is first for dev_pgm_raw() union filedescriptor fd; diff --git a/src/pickit5.c b/src/pickit5.c index 504322c1..b2db693c 100644 --- a/src/pickit5.c +++ b/src/pickit5.c @@ -830,9 +830,9 @@ static int pickit5_initialize(const PROGRAMMER *pgm, const AVRPART *p) { } if(my.hvupdi_enabled > 0) { - if(p->hvupdi_variant == 0) + if(p->hvupdi_variant == UPDI_ENABLE_HV_UPDI) pmsg_notice("high-voltage SYSCFG0 override on UPDI pin enabled\n"); - if(p->hvupdi_variant == 2) + if(p->hvupdi_variant == UPDI_ENABLE_HV_RESET) pmsg_notice("high-voltage SYSCFG0 override on RST pin enabled\n"); } @@ -937,11 +937,11 @@ static int pickit5_program_enable(const PROGRAMMER *pgm, const AVRPART *p) { const unsigned char *enter_prog = my.scripts.EnterProgMode; unsigned int enter_prog_len = my.scripts.EnterProgMode_len; - if(my.hvupdi_enabled && (my.pgm_type != PGM_TYPE_SNAP)) { // SNAP has no HV generation - if(p->hvupdi_variant == HV_UPDI_VARIANT_0) { // High voltage generation on UPDI line + if(my.hvupdi_enabled && (my.pgm_type != PGM_TYPE_SNAP)) { // SNAP has no HV generation + if(p->hvupdi_variant == UPDI_ENABLE_HV_UPDI) { // High voltage generation on UPDI line enter_prog = my.scripts.EnterProgModeHvSp; enter_prog_len = my.scripts.EnterProgModeHvSp_len; - } else if(p->hvupdi_variant == HV_UPDI_VARIANT_2) { // High voltage generation on RST line + } else if(p->hvupdi_variant == UPDI_ENABLE_HV_RESET) { // High voltage generation on RST line enter_prog = my.scripts.EnterProgModeHvSpRst; enter_prog_len = my.scripts.EnterProgModeHvSpRst_len; } @@ -1358,11 +1358,11 @@ static int pickit5_read_dev_id(const PROGRAMMER *pgm, const AVRPART *p) { if(len == 0x03 || len == 0x04) { // just DevId or UPDI with revision memcpy(my.devID, &my.rxBuf[24], len); } else { - if(my.hvupdi_enabled && p->hvupdi_variant == HV_UPDI_VARIANT_2) { - pmsg_info("failed to get DeviceID with activated HV Pulse on RST"); + if(my.hvupdi_enabled && p->hvupdi_variant == UPDI_ENABLE_HV_RESET) { + pmsg_info("failed to get DeviceID with activated HV Pulse on RST\n"); msg_info("if the wiring is correct, try connecting a 16 V, 1 uF cap between RST and GND\n"); } else { - pmsg_error("length (%u) mismatch of returned Device ID.\n", len); + pmsg_error("length (%u) mismatch of returned Device ID\n", len); } return -1; }