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

Provide user config value "default_baudrate" (acc. discussion #1589) #1590

Merged
merged 5 commits into from
Dec 18, 2023

Conversation

Ho-Ro
Copy link
Contributor

@Ho-Ro Ho-Ro commented Dec 5, 2023

No description provided.

Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
@mcuee mcuee added the enhancement New feature or request label Dec 5, 2023
Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
@stefanrueger
Copy link
Collaborator

stefanrueger commented Dec 9, 2023

Thanks for the PR!

What happens if both a programmer default baudrate is set and the newly introduced one? And, more importantly, what should happen , ie, which one should prevail? In any case -b should win over both other methods. I guess the programmer-specific default baud rate should win over the newly introduced global one, but I have not thought about this deeply. This precedence ought to be documented better.

@Ho-Ro
Copy link
Contributor Author

Ho-Ro commented Dec 10, 2023

What happens if both a programmer default baudrate is set and the newly introduced one?

If both values are defined in ~/.avrduderc, then the global default_baudrate has priority over baudrate in a programmer entry. This seems confusing at first glance, but it is usually the case that a baudrate entry in the global config file is to be corrected.
So -b xxx has priority over default_baudrate, which in turn has priority over baudrate in the programmer entries.

@stefanrueger
Copy link
Collaborator

Thinking a bit more about that, if you have a programmer with a fixed hard-coded baudrate and a different favourite baudrate otherwise, would it not make more sense to only use the global default_baudrate if neither a command line -b is specified (highest prio) nor a programmer-specific default baudrate was specified (second prio)? Otherwise you'd have to explicitly use -b for your programmers with hard-coded baudrates once you use a global default_baudrate.

Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
@Ho-Ro
Copy link
Contributor Author

Ho-Ro commented Dec 12, 2023

Ok, changed the hierarchy:
baudrate (set by -b) has priority over pgm->baudrate which has priority over default_baudrate.

Please review.

EDIT:
I've thought about the verbosing of the baudrate values again and will suggest a better solution later - some programmers don't need a baudrate and it makes no sense to display it even if it's provided by -b, e.g.:

$ avrdude -pm328p -v -c atmelice_isp -b12345

avrdude: Version 7.2
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

         System wide configuration file is /home/horo/projects/AVR/avrdude-7.2/build_linux/src/avrdude.conf
         User configuration file is /home/horo/.avrduderc

         Using Port                    : usb
         Using Programmer              : atmelice_isp
         Overriding Baud Rate          : 12345

Maybe the best idea would be to drop the PR, no need for the parameter default_baudrate because you can always define your own programmer with a different baudrate in ~/.avrduderc, I do that for my nanoSTK with 500kbps for example.

Two steps forward and one step back - I can provide a new PR that displays Overriding Baud Rate only if it overrides a defined baud rate, i.e.

baudrate != 0 && pgm->baudrate !=0 && baudrate != pgm->baudrate

What's your opinion?

@stefanrueger
Copy link
Collaborator

you can always define your own programmer

I like this PR. It is an awful lot of work to add 140 private programmers just to express a default baud rate.

The only thing missing is the documentation that default_baudrate is only consulted in absence of programmer-specific default and in absence of -b.

And yes, displaying Overriding Baud Rate is kinda neater when it's actually overridden (though I can live with overclaiming that the baud rate was set to a different value when it wasn't).

Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
@Ho-Ro
Copy link
Contributor Author

Ho-Ro commented Dec 14, 2023

Ok, it's complete for my understanding - please have a look.
I checked:

default_baudrate pgm->baudrate -b display result
none none none 0
X none none Default baud rate X
none Y none Programmer baud rate Y
X Y none Programmer baud rate Y
none none Z Setting baud rate Z
X none Z Overriding baud rate Z
X none X Default baud rate X
none Y Z Overriding baud rate Z
none Y Y Programmer baud rate Y
X Y Z Overriding baud rate Z
X Y Y Programmer baud rate Y
X Y X Overriding baud rate X

X, Y, Z are three different baud rate values

avrdude.texi and avrdude.1 are updated accordingly

@stefanrueger
Copy link
Collaborator

Table looks great. Would be wonderful if there was some independent testing whether the implementation follows suit.

Thanks @Ho-Ro

@mcuee
Copy link
Collaborator

mcuee commented Dec 15, 2023

I should be able to give this PR some simple tests over the weekend when I have access to my HW.

@mcuee
Copy link
Collaborator

mcuee commented Dec 17, 2023

Hmm, I need to use another programmer to test this feature. I will carry out the test tomorrow using other programmers.
-c stk500v2 seems to support only baud rate of 115200.

PS> ./avrdude_pr1590 -C ./avrdude_pr1590.conf -c stk500v2 -P COM41 -p m328pb -b  115200
avrdude_pr1590: AVR device initialized and ready to accept instructions
avrdude_pr1590: device signature = 0x1e9516 (probably m328pb)

avrdude_pr1590 done.  Thank you.

PS> ./avrdude_pr1590 -C ./avrdude_pr1590.conf -c stk500v2 -P COM41 -p m328pb -b  230400
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout communicating with programmer
avrdude_pr1590 error: unable to open port COM41 for programmer stk500v2
A possible candidate serial port is:
  -P COM41 or -P ch340
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_pr1590 done.  Thank you.

PS> ./avrdude_pr1590 -C ./avrdude_pr1590.conf -c stk500v2 -P COM41 -p m328pb -b 57600
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout
avrdude_pr1590 error: timeout communicating with programmer
avrdude_pr1590 error: unable to open port COM41 for programmer stk500v2
A possible candidate serial port is:
  -P COM41 or -P ch340
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_pr1590 done.  Thank you.

@Ho-Ro
Copy link
Contributor Author

Ho-Ro commented Dec 17, 2023

-c stk500v2 seems to support only baud rate of 115200.

Your observation is completely correct.
The setting -b only changes the baud rate of the PC, but the baud rate of the programmer is a constant value for this device that cannot be changed with a command from avrdude. The original STK500, for example, only uses 115200. If you set a different FW on the PC side, the communication will time out.

@stefanrueger stefanrueger merged commit ec96244 into avrdudes:main Dec 18, 2023
10 checks passed
@mcuee
Copy link
Collaborator

mcuee commented Dec 18, 2023

This PR should be okay as I can see that default_baudrate value in avrdude.rc is effective.

PS>cat avrdude.rc
# Overall avrdude defaults; suitable for avrdude.rc

default_serial     = "COM4";
default_baudrate     = 57600;

#programmer # dryrun
#    id                     = "my_dryrun";
#    desc                   = "Emulates programming without a programmer";
#    type                   = "dryrun";
#    prog_modes             = PM_TPI | PM_ISP | PM_HVSP | PM_HVPP;
#;

PS>./avrdude_pr1590 -C ./avrdude_pr1590.conf -c avrispmkii -p m328pb -v

avrdude_pr1590: Version 7.2-20231214 (2662a2dc)
                Copyright the AVRDUDE authors;
                see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

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

                Using port            : usb
                Using programmer      : avrispmkII
                Default baud rate     : 57600
                AVR Part              : ATmega328PB
                Programming modes     : ISP, HVPP, debugWIRE, SPM
                Programmer Type       : STK500V2
                Description           : Atmel AVR ISP mkII
                Programmer model      : AVRISP mkII
                HW version            : 1
                Serial number         : 001D2C990079
                FW Version Controller : 1.24
                Vtarget               : 4.8 V
                SCK period            : 4.0 us
avrdude_pr1590: AVR device initialized and ready to accept instructions
avrdude_pr1590: device signature = 0x1e9516 (probably m328pb)

avrdude_pr1590 done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Dec 21, 2023

Testing again with git main and serialupdi, and it is working fine.

C:\work\avr\avrdude_test\avrdude_bin> cat avrdude.rc
# Overall avrdude defaults; suitable for avrdude.rc

default_serial     = "COM4";
default_baudrate     = 230400;

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c serialupdi -P COM6 -p avr64dd32 -v

avrdude: Version 7.2-20231221 (06156d9c)
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

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

         Using port            : COM6
         Using programmer      : serialupdi
         Default baud rate     : 230400
         AVR Part              : AVR64DD32
         Programming modes     : UPDI, SPM
         Programmer Type       : serialupdi
         Description           : SerialUPDI
avrdude: device is in SLEEP mode
avrdude: NVM type 2: 24-bit, word oriented write
avrdude: entering NVM programming mode
avrdude: Chip silicon revision: 1.3
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e961a (probably avr64dd32)
avrdude: leaving NVM programming mode

avrdude done.  Thank you.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c serialupdi -P COM6 -p avr64dd32 -v -b 115200

avrdude: Version 7.2-20231221 (06156d9c)
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

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

         Using port            : COM6
         Using programmer      : serialupdi
         Overriding baud rate  : 115200
         AVR Part              : AVR64DD32
         Programming modes     : UPDI, SPM
         Programmer Type       : serialupdi
         Description           : SerialUPDI
avrdude: device is in SLEEP mode
avrdude: NVM type 2: 24-bit, word oriented write
avrdude: entering NVM programming mode
avrdude: Chip silicon revision: 1.3
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e961a (probably avr64dd32)
avrdude: leaving NVM programming mode

avrdude done.  Thank you.

@Ho-Ro Ho-Ro deleted the default_baudrate branch December 21, 2023 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants