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

Wrong timings for ATmega328PB and other parts in avrdude.conf #976

Closed
stefanrueger opened this issue May 22, 2022 · 16 comments
Closed

Wrong timings for ATmega328PB and other parts in avrdude.conf #976

stefanrueger opened this issue May 22, 2022 · 16 comments
Labels
bug Something isn't working

Comments

@stefanrueger
Copy link
Collaborator

While designing a PCB with the ATmeg328PB I noticed that some timings are different from ATmega328P's, eg, chip erase delay is 10.5 ms, not 9 ms. avrdude.conf does not reflect that. Also noticed that chip erase delay misses for the ATmega406 (along possibly other timings).

Not sure these things are still relevant today for some programmers (as they could as well poll to establish the operation is finished).

In my experience, errors are more likely to happen in sections of a project that already have seen a few errors, so if these timings are relevant in avrdude.conf it's probably a good idea to review other parameters and parts, too.


328pb-wait-delay


328p-wait-delay


@mcuee
Copy link
Collaborator

mcuee commented May 23, 2022

I am a Hardware engineer by trade.
Take note the datasheet for the ATmega328PB says "Typical Wait Delay" and the datasheet for ATmega328P says "Minimum Wait Delay". So they are not exactly comparable.

@MCUdude
Copy link
Collaborator

MCUdude commented May 23, 2022

@stefanrueger feel free to create a PR for small issues like this. They can easily be merged right away.
I've seen cases where people are having trouble flashing their 324PB/328PB, where flash verification fails for mysterious reasons.

@stefanrueger
Copy link
Collaborator Author

I've seen cases where people are having trouble flashing their 324PB/328PB, where flash verification fails for mysterious reasons.

Good to know. So, the timings in .conf might still be relevant for today's programmers (I had imagined they poll if possible).

feel free to create a PR

Thanks, but no: I have stopped suggesting PRs on a number of small-ish issues for fear of putting too much pressure on the current PR queue and, hence, diluting the limited resources the project has. This issue can serve as a useful reminder, though, for me or anyone else later on.

small issues like this

Whilst the issue is small, the solution is not as easy as it may look: some of the timings are specific for memories, which avrdude.conf's grammar file zaps (not extends), so they need to be copied in their entirety before making changes.

A good case study illustrating some pitfalls is the history of ATmega64M1's entry in avrdude.conf. Recognising the wrong flash size triggered that change. Good. However, the change effected that the SPI programming ops and all other memory parameters were zapped. While a subsequent correction copied the memory descriptions over from the parent part, that in turn overlooked that the op address bits only catered for the parent device's smaller flash requiring a further intervention. Speaking of the ATmega64M1, its entry might still be wrong: it is inherited from ATmega328, so if even the ATmegega328PB differs in timings etc from it, how can we be confident that the ATmega64M1 shares its parameters (other than size-related)? Answering this question for this part, or any other part for that matter, including the mentioned ATmega324PB, is well above my expertise (and pay grade :).

@stefanrueger
Copy link
Collaborator Author

the datasheet for the ATmega328PB says "Typical Wait Delay"

You are not wrong but the table caption probably is: I fully expect tWD_XYZ to mean "unless polling the user must wait at least that time after XYZ", and that is how AVRDUDE uses tWD_ERASE. (Search where WD_ is used in Microchip's MCU datasheets.)

@stefanrueger
Copy link
Collaborator Author

I added a little spiel to my partdesc branch so that avrdude -p\* outputs its own understanding of wait delays.

For example, to find memory/part combination with unset wait delays, use

$ avrdude -p\* 2>&1 | grep ^.wd_".* "0.000.ms
.wd_eeprom 0.000 ms ATtiny11
.wd_flash 0.000 ms ATtiny11
.wd_lock 0.000 ms ATtiny11
.wd_fuse 0.000 ms ATtiny11
.wd_fuse 0.000 ms AT90S1200
.wd_fuse 0.000 ms AT90S4414
.wd_fuse 0.000 ms AT90S2313
.wd_fuse 0.000 ms AT90S8515
.wd_efuse 0.000 ms ATmega169
.wd_efuse 0.000 ms ATmega169A
.wd_efuse 0.000 ms ATmega169P
.wd_efuse 0.000 ms ATmega169PA
.wd_chip_erase 0.000 ms ATtiny28
.wd_flash 0.000 ms ATtiny28
.wd_lock 0.000 ms ATtiny28
.wd_fuse 0.000 ms ATtiny28
.wd_efuse 0.000 ms ATmega32M1
.wd_chip_erase 0.000 ms ATmega406
.wd_eeprom 0.000 ms ATmega406
.wd_flash 0.000 ms ATmega406
.wd_hfuse 0.000 ms ATmega406
.wd_lfuse 0.000 ms ATmega406
.wd_lockbits 0.000 ms ATmega406

Some of these will be legit and expected (I am guessing ATtiny11 and ATtiny28), others rarely noticed if at all (missing efuse write delay because that's likely the last fuse byte to be written), but some others might be significant. I cannot tell, though.

BTW, that technique is otherwise useful for debugging. For example,

$ avrdude -p\* 2>&1 | grep ^.desc | awk '{ x=and(strtonum($14), 48); if(x == 16) print $2; }'

shows the list of all parts, as AVRDUDE understands them, that have byte EEPROM commands but no paged EEPROM commands (needed in Issue #967). Another example is

$ avrdude -p\* 2>&1 | grep ^.desc | awk '{ if(strtonum($12) == 1) print $2; }' | tr "'\n" '` ' | xclip

that puts all parts with an EEPROM page size of 1 (relevant for Issue #970) on a mouse button for markdown issue reporting.

@stefanrueger stefanrueger changed the title Wrong timings for ATmega328PB in avrdude.conf Wrong timings for ATmega328PB and other parts in avrdude.conf May 24, 2022
@mcuee
Copy link
Collaborator

mcuee commented Jun 1, 2022

I just got two official Microchip boards (AVR128DB48 Curiosity Nano) and ATmega328PB-xmini.

avrdude seems to work fine with ATmega328PB. But I will try the updated timing as mentioned by @stefanrueger

C:\work\avr\binary\avrdude-v7.0-windows-x64> .\avrdude.exe -c xplainedmini -p m328pb 
-U flash:r:readout_m328pb.hex -vv

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

             System wide configuration file is "C:/work/avr/binary/avrdude-v7.0-windows-x64/avrdude.conf"

             Using Port                    : usb
             Using Programmer              : xplainedmini
avrdude.exe: stk500v2_jtag3_open()
avrdude.exe: Found CMSIS-DAP compliant device, using EDBG protocol
avrdude.exe: Sending sign-on command: 0x80 (3 bytes msg)
             AVR Part                      : ATmega328PB
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PC2
             RESET disposition             : dedicated
             RETRY pulse                   : SCK
             Serial program mode           : yes
             Parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                               Block Poll               Page                       Polled
               Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom                 65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
               flash                  65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
               lfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
               hfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
               lock                    0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
               calibration             0     0     0    0 no          1    1      0     0     0 0x00 0x00
               signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
               efuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00

             Programmer Type : JTAG3_ISP
             Description     : Atmel AVR XplainedMini in ISP mode
avrdude.exe: jtag3_getparm()
avrdude.exe: Sending get parameter (scope 0x01, section 1, parm 0) command: 0x84 (6 bytes msg)
             Vtarget         : 5.0 V
             SCK period      : 8.00 us

avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 0, parm 0) command: 0x80 (3 bytes msg)
avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 0, parm 1) command: 0x80 (3 bytes msg)
avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 1, parm 0) command: 0x80 (3 bytes msg)
avrdude.exe: AVR device initialized and ready to accept instructions

Reading |                                                   
 | 0% 0.00savrdude.exe: stk500isp_read_byte(.., signature, 0x0, ...)
avrdude.exe: stk500isp_read_byte(): 
Sending read memory command: avrdude.exe: stk500isp_read_byte(.., signature, 0x1, ...)
Reading | #################                                  
| 33% 0.03savrdude.exe: stk500isp_read_byte(.., signature, 0x2, ...)
Reading | ################################################## | 100% 0.05s

avrdude.exe: Device signature = 0x1e9516 (probably m328pb)
avrdude.exe: reading flash memory:

Reading | ################################################## | 100% 30.21s

avrdude.exe: writing output file "readout_m328pb.hex"
avrdude.exe: stk500v2_jtag3_close()
avrdude.exe: jtag3_close()
avrdude.exe: Sending AVR sign-off command: 0x80 (3 bytes msg)
avrdude.exe: Sending sign-off command: 0x80 (3 bytes msg)

avrdude.exe done.  Thank you.
C:\work\avr\binary\avrdude-v7.0-windows-x64> .\avrdude.exe -c xplainedmini -p m328pb 
-U flash:w:readout_m328pb.hex -vv

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

             System wide configuration file is "C:/work/avr/binary/avrdude-v7.0-windows-x64/avrdude.conf"

             Using Port                    : usb
             Using Programmer              : xplainedmini
avrdude.exe: stk500v2_jtag3_open()
avrdude.exe: Found CMSIS-DAP compliant device, using EDBG protocol
avrdude.exe: Sending sign-on command: 0x80 (3 bytes msg)
             AVR Part                      : ATmega328PB
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PC2
             RESET disposition             : dedicated
             RETRY pulse                   : SCK
             Serial program mode           : yes
             Parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                               Block Poll               Page                       Polled
               Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom                 65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
               flash                  65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
               lfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
               hfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
               lock                    0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
               calibration             0     0     0    0 no          1    1      0     0     0 0x00 0x00
               signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
               efuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00

             Programmer Type : JTAG3_ISP
             Description     : Atmel AVR XplainedMini in ISP mode
avrdude.exe: jtag3_getparm()
avrdude.exe: Sending get parameter (scope 0x01, section 1, parm 0) command: 0x84 (6 bytes msg)
             Vtarget         : 5.0 V
             SCK period      : 8.00 us

avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 0, parm 0) command: 0x80 (3 bytes msg)
avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 0, parm 1) command: 0x80 (3 bytes msg)
avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 1, parm 0) command: 0x80 (3 bytes msg)
avrdude.exe: AVR device initialized and ready to accept instructions

Reading |                                                    
| 0% 0.00savrdude.exe: stk500isp_read_byte(.., signature, 0x0, ...)
avrdude.exe: stk500isp_read_byte(): 
Sending read memory command: avrdude.exe: stk500isp_read_byte(.., signature, 0x1, ...)
Reading | #################                                  
| 33% 0.03savrdude.exe: stk500isp_read_byte(.., signature, 0x2, ...)
Reading | ################################################## | 100% 0.05s

avrdude.exe: Device signature = 0x1e9516 (probably m328pb)
avrdude.exe: NOTE: "flash" memory has been specified, an erase cycle will be performed
             To disable this feature, specify the -D option.
avrdude.exe: erasing chip
avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 0, parm 0) command: 0x80 (3 bytes msg)
avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 0, parm 1) command: 0x80 (3 bytes msg)
avrdude.exe: jtag3_setparm()
avrdude.exe: Sending set parameter (scope 0x12, section 1, parm 0) command: 0x80 (3 bytes msg)
avrdude.exe: reading input file "readout_m328pb.hex"
avrdude.exe: input file readout_m328pb.hex auto detected as raw binary
avrdude.exe: writing flash (4674 bytes):

Writing | ################################################## | 100% 4.36s

avrdude.exe: 4674 bytes of flash written
avrdude.exe: verifying flash memory against readout_m328pb.hex:
avrdude.exe: load data flash data from input file readout_m328pb.hex:
avrdude.exe: input file readout_m328pb.hex auto detected as raw binary
avrdude.exe: input file readout_m328pb.hex contains 4674 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 4.36s

avrdude.exe: verifying ...
avrdude.exe: 4674 bytes of flash verified
avrdude.exe: stk500v2_jtag3_close()
avrdude.exe: jtag3_close()
avrdude.exe: Sending AVR sign-off command: 0x80 (3 bytes msg)
avrdude.exe: Sending sign-off command: 0x80 (3 bytes msg)

avrdude.exe done.  Thank you.

@MCUdude
Copy link
Collaborator

MCUdude commented Jun 19, 2022

@stefanrueger I had a look at the ATmega406 datasheet, and its ATDF file (attached below) that I've pulled from the most recent Microchip ATmega pack. To my surprise, I couldn't find any delays as I could in other ATDF files. Perhaps the avrdude.conf file is correct after all?

ATmega406.atdf.zip

@dl8dtl
Copy link
Contributor

dl8dtl commented Jun 19, 2022

the datasheet for the ATmega328PB says "Typical Wait Delay"

You are not wrong but the table caption probably is: I fully expect tWD_XYZ to mean "unless polling the user must wait at least that time after XYZ", and that is how AVRDUDE uses tWD_ERASE. (Search where WD_ is used in Microchip's MCU datasheets.)

I'm not so sure about yoir interpretation.

I read it as one table describing the delays to expect when using the polled algorithm, while the other one describes the minimal time you have to wait when not polling.

@stefanrueger
Copy link
Collaborator Author

couldn't find any delays [ATmega406] ... Perhaps the avrdude.conf file is correct after all?

You are not wrong, but do we want the programmers to sleep 0 µs for that chip where other chips require O(10 ms)? I would argue it makes sense to put some typical values in just to be on the safe side

one table describing the delays to expect

If it was expect to wait rather than min wait then avrdude.conf should hold an even higher value to be on the safe side, as AVRDUDE interprets that value as min wait needed for the programming to work.

I still think that the table captions are wrong: The page before the table says trice must wait at least. Technically tWD_ERASE is not mentioned in the text once, so in programming parlance a variable that is set but not used :), but other Atmel MCU data sheets that I read have WD_xxx as min delay. (I had verified in a couple of them with a text search for WD_ in the pdf.). Another fun fact: Both tables have captions saying typical delay. Only one table has a column heading with minimum delay. So, shoddy writing on part of Atmel/Microchip.

atmega328pb-wd_xxx-semantics

@mcuee mcuee added the bug Something isn't working label Jun 20, 2022
@mcuee
Copy link
Collaborator

mcuee commented Jun 20, 2022

I will label this as bug first, for the unset wait delays thingy and not necessarily for the ATmega328PB itself.

@stefanrueger
Copy link
Collaborator Author

@MCUdude You are right re the ATmega406: according to the data sheet it has JTAG programming, but no SPI programming, and therefore no tWD_... delays; looks like neither wd_chip_erase nor any other wd_... delays are needed.

I am guessing AVRDUDE does not need to know delays for JTAG programming as delegated to the (physical) programmer.

@stefanrueger
Copy link
Collaborator Author

Fixed in PR #1001 (thanks @MCUdude!)

stefanrueger added a commit that referenced this issue Jul 4, 2022
@mcuee
Copy link
Collaborator

mcuee commented Jul 17, 2022

Just tried the partdesc branch from @stefanrueger under Linux (Ubuntu 20.04) since it does not work for Windows.

mcuee@UbuntuSwift3:~/build/avr/avrdude_bin$ ./avrdude_partdesc -p\* 2>&1 | grep ^.wd_".* "0.000.ms
.wd_eeprom 0.000 ms ATtiny11
.wd_flash 0.000 ms ATtiny11
.wd_lock 0.000 ms ATtiny11
.wd_fuse 0.000 ms ATtiny11
.wd_fuse 0.000 ms AT90S1200
.wd_fuse 0.000 ms AT90S4414
.wd_fuse 0.000 ms AT90S2313
.wd_fuse 0.000 ms AT90S8515
.wd_chip_erase 0.000 ms ATtiny28
.wd_flash 0.000 ms ATtiny28
.wd_lock 0.000 ms ATtiny28
.wd_fuse 0.000 ms ATtiny28
.wd_chip_erase 0.000 ms ATmega406
.wd_eeprom 0.000 ms ATmega406
.wd_flash 0.000 ms ATmega406
.wd_hfuse 0.000 ms ATmega406
.wd_lfuse 0.000 ms ATmega406
.wd_lockbits 0.000 ms ATmega406

mcuee@UbuntuSwift3:~/build/avr/avrdude_bin$ ./avrdude_partdesc -p\* 2>&1 | grep ^.desc |
 awk '{ x=and(strtonum($14), 48); if(x == 16) print $2; }'
'ATtiny12'
'ATtiny15'
'AT90S1200'
'AT90S4414'
'AT90S2313'
'AT90S2333'
'AT90S2343'
'AT90S4433'
'AT90S4434'
'AT90S8515'
'AT90S8535'
'ATmega103'
'ATmega64'
'ATmega64A'
'ATmega128'
'ATmega128A'
'ATmega163'
'ATmega161'
'ATmega8'
'ATmega8A'
'ATmega8515'
'ATmega8535'
'ATtiny26'

mcuee@UbuntuSwift3:~/build/avr/avrdude_bin$ ./avrdude_partdesc -p\* 2>&1 | grep ^.desc | 
gawk '{ if(strtonum($12) == 1) print $2; }' | tr "'\n" '` ' 
`ATtiny11` `ATtiny12` `ATtiny15` `AT90S1200` `AT90S4414` `AT90S2313` `AT90S2333` `AT90S2343` `AT90S4433` 
`AT90S4434` `AT90S8515` `AT90S8535` `ATmega103` `ATmega163` `ATmega161` `ATmega8515` `ATmega8535` 
`ATtiny26` `AVR32DA28` `AVR32DA32` `AVR32DA48` `AVR64DA28` `AVR64DA32` `AVR64DA48` `AVR64DA64` 
`AVR128DA28` `AVR128DA32` `AVR128DA48` `AVR128DA64` `AVR32DB28` `AVR32DB32` `AVR32DB48` 
`AVR64DB28` `AVR64DB32` `AVR64DB48` `AVR64DB64` `AVR128DB28` `AVR128DB32` `AVR128DB48` 
`AVR128DB64` `AVR16DD14` `AVR16DD20` `AVR16DD28` `AVR16DD32` `AVR32DD14` `AVR32DD20` 
`AVR32DD28` `AVR32DD32` `AVR64DD14` `AVR64DD20` `AVR64DD28` `AVR64DD32` 



@mcuee
Copy link
Collaborator

mcuee commented Jul 17, 2022

@stefanrueger and @MCUdude

The following may still be wrong, right?

.wd_chip_erase 0.000 ms ATmega406
.wd_eeprom 0.000 ms ATmega406
.wd_flash 0.000 ms ATmega406
.wd_hfuse 0.000 ms ATmega406
.wd_lfuse 0.000 ms ATmega406
.wd_lockbits 0.000 ms ATmega406

@MCUdude
Copy link
Collaborator

MCUdude commented Jul 17, 2022

The following may still be wrong, right?

Nope, it's correct. See @stefanrueger answer below. The ATmega406 doesn't have an ISP interface, only JTAG.

@MCUdude You are right re the ATmega406: according to the datasheet it has JTAG programming, but no SPI programming, and therefore no tWD_... delays; looks like neither wd_chip_erase nor any other wd_... delays are needed.

I am guessing AVRDUDE does not need to know delays for JTAG programming as delegated to the (physical) programmer.

@mcuee
Copy link
Collaborator

mcuee commented Jul 17, 2022

Nope, it's correct. See @stefanrueger answer below. The ATmega406 doesn't have an ISP interface, only JTAG.

I am guessing AVRDUDE does not need to know delays for JTAG programming as delegated to the (physical) programmer.

I see. Thanks for the explanation.

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

No branches or pull requests

4 participants