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

Fix avrdoper header sequence for hidusb #1937

Merged
merged 1 commit into from
Dec 13, 2024
Merged

Conversation

alexjx
Copy link
Contributor

@alexjx alexjx commented Dec 10, 2024

This is my attempt to fix #1626. It seems there is a bug of the refactored code, which didn't initialize the report id. This patch should have fixed it.

@MCUdude
Copy link
Collaborator

MCUdude commented Dec 10, 2024

Thanks for spending time figuring out what the cause is, and provide a PR!
I don't have an AVR doper, but I'll assume this simple fix resolves the problem completely?

@alexjx
Copy link
Contributor Author

alexjx commented Dec 11, 2024

Glad to help. My AVR doper is working fiine now. I just used it to program my new board.

@mcuee
Copy link
Collaborator

mcuee commented Dec 12, 2024

I will carry out the test later, but the fix makes sense.

The HID report ID needs to be used as per the FW source code.
https://www.obdev.at/products/vusb/avrdoper.html
https://www.obdev.at/downloads/vusb/AVR-Doper.2012-12-08.zip

Relevant HID Report Descriptor from main.c.

const PROGMEM char usbDescriptorHidReport[60] = {
    0x06, 0x00, 0xff,              // USAGE_PAGE (Generic Desktop)
    0x09, 0x01,                    // USAGE (Vendor Usage 1)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //   REPORT_SIZE (8)

    0x85, 0x01,                    //   REPORT_ID (1)
    0x95, 0x0e,                    //   REPORT_COUNT (14)
    0x09, 0x00,                    //   USAGE (Undefined)
    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)

    0x85, 0x02,                    //   REPORT_ID (2)
    0x95, 0x1e,                    //   REPORT_COUNT (30)
    0x09, 0x00,                    //   USAGE (Undefined)
    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)

    0x85, 0x03,                    //   REPORT_ID (3)
    0x95, 0x3e,                    //   REPORT_COUNT (62)
    0x09, 0x00,                    //   USAGE (Undefined)
    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)

    0x85, 0x04,                    //   REPORT_ID (4)
    0x95, 0x7e,                    //   REPORT_COUNT (126)
    0x09, 0x00,                    //   USAGE (Undefined)
    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)

    0x85, 0x05,                    //   REPORT_ID (5) [for debug interface]
    0x95, 0x3e,                    //   REPORT_COUNT (62)
    0x09, 0x00,                    //   USAGE (Undefined)
    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)

    0xc0                           // END_COLLECTION
};
/* Note: REPORT_COUNT does not include report-ID byte */

@mcuee mcuee added the bug Something isn't working label Dec 12, 2024
@mcuee
Copy link
Collaborator

mcuee commented Dec 12, 2024

Good. FW test done and it is good.

avrdude git failed.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c stk500v2 -P avrdoper -p m8a -vvvv
$ 'C:\work\avr\avrdude_test\avrdude_bin\avrdude.exe' -c stk500v2 -P avrdoper -p m8a -vvvv
Avrdude version 8.0-20241125 (69c3293f)
Copyright see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

System wide configuration file is C:\work\avr\avrdude_test\avrdude_bin\avrdude.conf

Using port            : avrdoper
Using programmer      : stk500v2
Error usbGetReport() ser_avrdoper.c 125: unable to send message: Get Input/Feature Report DeviceIoControl: (0x00000057) The parameter is incorrect.
Error avrdoperFillBuffer() ser_avrdoper.c 265: USB I/O Error
Error main() main.c 1450: unable to open port avrdoper for programmer stk500v2
A possible candidate serial port is:
  -P COM3
Note that above port might not be connected to a target board or an AVR programmer.
Also note there may be other direct serial ports not listed above.

Avrdude done.  Thank you.

This PR is good.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1937 -c stk500v2 -P avrdoper -p m8a -vvvv
$ 'C:\work\avr\avrdude_test\avrdude_bin\avrdude_pr1937.exe' -c stk500v2 -P avrdoper -p m8a -vvvv
Avrdude_pr1937 version 8.0-20241210 (42d9cc43)
Copyright see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

System wide configuration file is C:\work\avr\avrdude_test\avrdude_bin\avrdude.conf
Warning main() main.c 1121: system wide configuration file version (8.0-20241125 (69c3293f))
does not match Avrdude build version (8.0-20241210 (42d9cc43))

Using port            : avrdoper
Using programmer      : stk500v2
Received 29 bytes data chunk of total 0
Send: 7 bytes: 1b 01 00 01 0e 01 14  "......."
Sending 7 bytes data chunk
Received 29 bytes data chunk of total 17
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 01  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 0b  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 01  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 08  "."
Receive: 1 bytes: 53  "S"
Receive: 1 bytes: 54  "T"
Receive: 1 bytes: 4b  "K"
Receive: 1 bytes: 35  "5"
Receive: 1 bytes: 30  "0"
Receive: 1 bytes: 30  "0"
Receive: 1 bytes: 5f  "_"
Receive: 1 bytes: 32  "2"
Receive: 1 bytes: 02  "."
Stk500v2_getsync(): found STK500 programmer
Received 29 bytes data chunk of total 0
AVR part              : ATmega8A
Programming modes     : SPM, ISP, HVPP

Memory          Size  Pg size
-----------------------------
eeprom           512        4
flash           8192       64
lfuse              1        1
hfuse              1        1
lock               1        1
prodsig/sigrow    24        1
sernum            10        1
io                64        1
sram            1024        1
calibration        4        1
signature          3        1

Variants      Package  F max   T range        V range
------------------------------------------------------------
ATmega8A      N/A      16 MHz  [N/A,    N/A]  [2.7 V, 5.5 V]
ATmega8A-AN   TQFP32   16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-ANR  TQFP32   16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-AU   TQFP32   16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-AUR  TQFP32   16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-MN   QFN32    16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-MNR  VQFN32   16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-MU   VQFN32   16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-MUR  QFN32    16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-PN   PDIP28   16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]
ATmega8A-PU   PDIP28   16 MHz  [-40 C, 85 C]  [2.7 V, 5.5 V]

Programmer type       : STK500V2
Description           : Atmel STK500 v2
Programmer model      : STK500
Send: 8 bytes: 1b 02 00 02 0e 03 90 86  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 02  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 01  "."
Receive: 1 bytes: 16  "."
Send: 8 bytes: 1b 03 00 02 0e 03 91 86  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 02  "."
Receive: 1 bytes: 14  "."
Send: 8 bytes: 1b 04 00 02 0e 03 92 82  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 04  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 04  "."
Receive: 1 bytes: 15  "."
HW version            : 1
FW Version Controller : 2.04
Send: 8 bytes: 1b 05 00 02 0e 03 9a 8b  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 05  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: aa  "."
Receive: 1 bytes: ba  "."
Topcard               : STK501
Send: 8 bytes: 1b 06 00 02 0e 03 94 86  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 06  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 32  "2"
Receive: 1 bytes: 21  "!"
Vtarget               : 5.0 V
Send: 8 bytes: 1b 07 00 02 0e 03 95 86  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 07  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 12  "."
Varef                 : 0.0 V
Oscillator            : Send: 8 bytes: 1b 08 00 02 0e 03 96 8a  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 08  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 1d  "."
Send: 8 bytes: 1b 09 00 02 0e 03 97 8a  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 09  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 1c  "."
Off
Send: 8 bytes: 1b 0a 00 02 0e 03 98 86  "........"
Sending 8 bytes data chunk
Received 29 bytes data chunk of total 9
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 0a  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 03  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 02  "."
Receive: 1 bytes: 1d  "."
SCK period            : 8.7 us
XTAL frequency        : 7.372800 MHz
Send: 9 bytes:
1b 0b 00 03 0e 02 9e 01  80                        "........."
Sending 9 bytes data chunk
Received 29 bytes data chunk of total 8
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 0b  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 02  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 02  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 1e  "."
Send: 18 bytes:
1b 0c 00 0c 0e 10 c8 64  19 20 00 53 03 ac 53 00   ".......d. .S..S."
00 3f                                              ".?"
Sending 18 bytes data chunk
Received 29 bytes data chunk of total 8
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 0c  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 02  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 10  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 0b  "."

AVR device initialized and ready to accept instructions
Avr_signature(stk500v2, m8a)
Reading |                                                    | 0% 0.00 s
Avr_read_mem(stk500v2, m8a, signature, NULL)
Stk500isp_read_byte(.., signature, 0x0, ...)
Stk500isp_read_byte(): sending read memory command: Send: 12 bytes:
1b 0d 00 06 0e 1b 04 30  00 00 00 31               ".......0...1"
Sending 12 bytes data chunk
Received 29 bytes data chunk of total 10
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 0d  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 04  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 1e  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 19  "."
Stk500isp_read_byte(.., signature, 0x1, ...)
Stk500isp_read_byte(): sending read memory command: Send: 12 bytes:
1b 0e 00 06 0e 1b 04 30  00 01 00 33               ".......0...3"
Sending 12 bytes data chunk
Received 29 bytes data chunk of total 10
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 04  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 93  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 97  "."
Reading | #################                                  | 33% 0.07 s
Stk500isp_read_byte(.., signature, 0x2, ...)
Stk500isp_read_byte(): sending read memory command: Send: 12 bytes:
1b 0f 00 06 0e 1b 04 30  00 02 00 31               ".......0...1"
Sending 12 bytes data chunk
Received 29 bytes data chunk of total 10
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 0f  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 04  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 07  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 02  "."
Reading | ################################################## | 100% 0.12 s
Device signature = 1E 93 07 (ATmega8, ATmega8A)
Send: 9 bytes:
1b 10 00 03 0e 11 01 01  17                        "........."
Sending 9 bytes data chunk
Received 29 bytes data chunk of total 8
Receive: 1 bytes: 1b  "."
Receive: 1 bytes: 10  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 02  "."
Receive: 1 bytes: 0e  "."
Receive: 1 bytes: 11  "."
Receive: 1 bytes: 00  "."
Receive: 1 bytes: 16  "."

Avrdude_pr1937 done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Dec 12, 2024

One more test: it is good.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1937 -C .\avrdude_pr1937.conf -c stk500v2 -P avrdoper -p m8a -U .\avrdoper_usbasp.hex
Reading 4774 bytes for flash from input file avrdoper_usbasp.hex
Writing 4774 bytes to flash
Writing | ################################################## | 100% 8.69 s
Reading | ################################################## | 100% 6.02 s
4774 bytes of flash verified

Avrdude_pr1937 done.  Thank you.

@alexjx
Copy link
Contributor Author

alexjx commented Dec 12, 2024

Thank you for spending time on testing.

@mcuee
Copy link
Collaborator

mcuee commented Dec 12, 2024

Just one more test.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1937 -C .\avrdude_pr1937.conf -c stk500v2 -P avrdoper -p m328p -U .\hex\Blink_m328p_EEPROM_fuse.ino.ino_atmega328p_16000000L.hex
Reading 1052 bytes for flash from input file Blink_m328p_EEPROM_fuse.ino.ino_atmega328p_16000000L.hex
Writing 1052 bytes to flash
Writing | ################################################## | 100% 1.55 s
Reading | ################################################## | 100% 1.32 s
1052 bytes of flash verified

Avrdude_pr1937 done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Dec 12, 2024

Since we have not done test for this programmers, so I carry out one more test to make sure it works.

MINGW64 /c/work/avr/avrdude_test/avrdude_pr1937/tools
$ ./test-avrdude -e ../build_mingw64_nt-10.0-19045/src/avrdude.exe -t . -d 0 -p "-c stk500v2 -P avrdoper -p m328p"
Testing ../build_mingw64_nt-10.0-19045/src/avrdude.exe 8.0-20241210 (42d9cc43)
Prepare "-c stk500v2 -P avrdoper -p m328p" and press 'enter' or 'space' to continue. Press any other key to skip
✅   0.835 s: fuse access: clear, set and read eesave fuse bit
✅   1.986 s: fuse access: set eesave fusebit to delete EEPROM on chip erase
✅   1.472 s: chip erase
✅  16.147 s: flash -U write/verify holes_rjmp_loops_32768B.hex
✅   7.342 s: flash -T write/verify holes_rjmp_loops_32768B.hex
✅   0.775 s: eeprom check whether programmer can flip 0s to 1s
✅   2.362 s: eeprom -U write/verify holes_pack_my_box_1024B.hex
✅   4.696 s: eeprom -T write/verify holes_{the_five_boxing_wizards,pack_my_box}_1024B.hex
✅   8.001 s: chip erase and spot check flash is actually erased
✅   1.310 s: spot check eeprom is erased, too

@mcuee
Copy link
Collaborator

mcuee commented Dec 12, 2024

@stefanrueger

I think this PR is good to go. I have reviewed the code changes and carried out the tests.

@stefanrueger stefanrueger changed the title fix avrdoper after 6.4 Fix avrdoper header sequence for hidusb Dec 13, 2024
@stefanrueger
Copy link
Collaborator

Many thanks all round for testing @MCee and fixing @alexjx. Merging...

@stefanrueger stefanrueger merged commit d732f74 into avrdudes:main Dec 13, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AVR-Doper support is broken since version 6.4
4 participants