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 avr_write_byte() #1897

Merged
merged 2 commits into from
Aug 23, 2024
Merged

Conversation

stefanrueger
Copy link
Collaborator

This PR should fix the problems with writing to fuse and lock of the t15 (and possibly other parts). The issue is that ISP programming via direct ISP commands pgm->cmd() does not necessarily read back from the fuse/lock what was written in case there are unused bits in the memory. These unused bits are set/read using the defaults of the read/write 4 byte commands and not via factory defaults.

The solution proposed here is to compare (read & bitmask) with (written & bitmask) as opposed to read with written.

While reviewing the function avr_write_byte_default(), which I think was responsible for the false alarm "cannot write" errors, I also found that fuse and lock writes would do polling with (unset default 0xff) readback values, which is wrong, and now no longer the case.

@MCUdude Please try that out.

@mcuee mcuee added the bug Something isn't working label Aug 22, 2024
@MCUdude
Copy link
Collaborator

MCUdude commented Aug 22, 2024

Seems to work well for the ATtiny15! Are there other parts/programmers I should test with to verify that this PR doesn't break anything else?

USBasp:

$ ./test8 -r1 usbasp attiny15 && ./test8 usbasp attiny15
Reading 1118 bytes for multiple memories from input file bak-usbasp-attiny15.hex
Writing 64 bytes to eeprom
Writing | ################################################## | 100% 0.60 s 
Reading | ################################################## | 100% 0.06 s 
64 bytes of eeprom verified
Writing 1024 bytes to flash
Writing | ################################################## | 100% 4.53 s 
 | ################################################## | 100% 1.26 s 
1024 bytes of flash verified
Writing 1 byte (0x5C) to fuse, 1 byte written, 1 verified
Writing 1 byte (0xFF) to lock, 1 byte written, 1 verified

Avrdude done.  Thank you.
test8: attiny15 initialised

Processing -U ALL:r:bak-usbasp-attiny15.hex:I
Reading multiple memories ...
 - eeprom         | ################################################## | 100% 0.06 s 
 - flash          | ################################################## | 100% 1.14 s 
 - fuse           | ################################################## | 100% 0.00 s 
 - lock           | ################################################## | 100% 0.00 s 
 - prodsig/sigrow | ################################################## | 100% 0.02 s 
 - sernum         | ################################################## | 100% 0.01 s 
 - signature      | ################################################## | 100% 0.00 s 
 - calibration    | ################################################## | 100% 0.00 s 
Writing 1128 bytes to output file bak-usbasp-attiny15.hex

Processing -T fact reset
performing chip erase; discarded pending writes to flash and EEPROM
Caching | ################################################## | 100% 0.07 s 
Caching | ################################################## | 100% 0.00 s 
after the next reset the part will have F_CPU = 1.600 MHz

Processing -U ALL:w:bak-usbasp-attiny15.hex:I
Reading 1118 bytes for multiple memories from input file bak-usbasp-attiny15.hex
Writing 64 bytes to eeprom
Writing | ################################################## | 100% 0.61 s 
Reading | ################################################## | 100% 0.09 s 
64 bytes of eeprom verified
Writing 1024 bytes to flash
Writing | ################################################## | 100% 3.58 s 
fd | ################################################## | 100% 0.82 s 
1024 bytes of flash verified
Writing 1 byte (0x50) to fuse, 1 byte written, 1 verified
Writing 1 byte (0x06) to lock, 1 byte written, 1 verified

Processing -U ALL:v:bak-usbasp-attiny15.hex:I
Verifying 1118 bytes of multiple memories against input file bak-usbasp-attiny15.hex
Reading | ################################################## | 100% 0.05 s 
64 bytes of eeprom verified
Reading | ################################################## | 100% 0.81 s 
1024 bytes of flash verified
1 byte of fuse verified
1 byte of lock verified
24 bytes of prodsig/sigrow verified
10 bytes of sernum verified
3 bytes of signature verified
1 byte of calibration verified

Avrdude done.  Thank you.

$ avrdude -cusbasp -pattiny15 -Ufuse:r:-:h -Ulock:r:-:h

Processing -U fuse:r:-:h
Reading fuse memory ...
Writing 1 byte to output file <stdout>
0x50

Processing -U lock:r:-:h
Reading lock memory ...
Writing 1 byte to output file <stdout>
0x6

Avrdude done.  Thank you.

USBtiny:

$ ./test8 -r1 usbtiny attiny15 && ./test8 usbtiny attiny15
Reading 1118 bytes for multiple memories from input file bak-usbtiny-attiny15.hex
Writing 64 bytes to eeprom
Writing | ################################################## | 100% 0.73 s 
Reading | ################################################## | 100% 0.11 s 
64 bytes of eeprom verified
Writing 1024 bytes to flash
Writing | ################################################## | 100% 5.42 s 
0x188 | ################################################## | 100% 1.66 s 
1024 bytes of flash verified
Writing 1 byte (0x5C) to fuse, 1 byte written, 1 verified
Writing 1 byte (0xFF) to lock, 1 byte written, 1 verified

Avrdude done.  Thank you.
test8: attiny15 initialised

Processing -U ALL:r:bak-usbtiny-attiny15.hex:I
Reading multiple memories ...
 - eeprom         | ################################################## | 100% 0.11 s 
 - flash          | ################################################## | 100% 1.66 s 
 - fuse           | ################################################## | 100% 0.00 s 
 - lock           | ################################################## | 100% 0.00 s 
 - prodsig/sigrow | ################################################## | 100% 0.04 s 
 - sernum         | ################################################## | 100% 0.02 s 
 - signature      | ################################################## | 100% 0.01 s 
 - calibration    | ################################################## | 100% 0.00 s 
Writing 1128 bytes to output file bak-usbtiny-attiny15.hex

Processing -T fact reset
performing chip erase; discarded pending writes to flash and EEPROM
Caching | ################################################## | 100% 0.11 s 
Caching | ################################################## | 100% 0.00 s 
after the next reset the part will have F_CPU = 1.600 MHz

Processing -U ALL:w:bak-usbtiny-attiny15.hex:I
Reading 1118 bytes for multiple memories from input file bak-usbtiny-attiny15.hex
Writing 64 bytes to eeprom
Writing | ################################################## | 100% 0.73 s 
Reading | ################################################## | 100% 0.11 s 
64 bytes of eeprom verified
Writing 1024 bytes to flash
Writing | ################################################## | 100% 5.41 s 
30e | ################################################## | 100% 1.67 s 
1024 bytes of flash verified
Writing 1 byte (0x50) to fuse, 1 byte written, 1 verified
Writing 1 byte (0x06) to lock, 1 byte written, 1 verified

Processing -U ALL:v:bak-usbtiny-attiny15.hex:I
Verifying 1118 bytes of multiple memories against input file bak-usbtiny-attiny15.hex
Reading | ################################################## | 100% 0.11 s 
64 bytes of eeprom verified
Reading | ################################################## | 100% 1.66 s 
1024 bytes of flash verified
1 byte of fuse verified
1 byte of lock verified
24 bytes of prodsig/sigrow verified
10 bytes of sernum verified
3 bytes of signature verified
1 byte of calibration verified

Avrdude done.  Thank you.

$ avrdude -cusbtiny -pattiny15 -Ufuse:r:-:h -Ulock:r:-:h

Processing -U fuse:r:-:h
Reading fuse memory ...
Writing 1 byte to output file <stdout>
0x50

Processing -U lock:r:-:h
Reading lock memory ...
Writing 1 byte to output file <stdout>
0x6

Avrdude done.  Thank you.

@stefanrueger stefanrueger merged commit 284612f into avrdudes:main Aug 23, 2024
12 checks passed
@stefanrueger stefanrueger deleted the avr_write_byte_default branch August 23, 2024 01:22
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.

3 participants