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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/avrdude.1
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ avrdude -p m328p/S outputs AVRDUDE's understanding of ATmega328P MCU properties;
for more information run avrdude -p x/h.
.It Fl b Ar baudrate
Override the RS-232 connection baud rate specified in the respective
programmer's entry of the configuration file.
programmer's entry of the configuration file or defined by the default_baudrate
entry in your user configuration file
.Pa ${HOME}/.config/avrdude/avrdude.rc
or
.Pa ${HOME}/.avrduderc
if no baudrate was defined for this programmer.
.It Fl r
Opens the serial port at 1200 baud and immediately closes it, waits 400 ms
for each -r on the command line and then establishes communication with
Expand Down
1 change: 1 addition & 0 deletions src/avrdude.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ avrdude_conf_version = "@AVRDUDE_FULL_VERSION@";
default_parallel = "@DEFAULT_PAR_PORT@";
default_serial = "@DEFAULT_SER_PORT@";
default_spi = "@DEFAULT_SPI_PORT@";
# default_baudrate = 115200;
# default_bitclock = 2.5;
default_linuxgpio = "@DEFAULT_LINUXGPIO_PORT@";
allow_subshells = no;
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const char *default_programmer;
const char *default_parallel;
const char *default_serial;
const char *default_spi;
int default_baudrate;
double default_bitclock;
char const *default_linuxgpio;
int allow_subshells;
Expand Down
6 changes: 6 additions & 0 deletions src/config_gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static int pin_name;
%token K_BUFF
%token K_CONNTYPE
%token K_DEDICATED
%token K_DEFAULT_BAUDRATE
%token K_DEFAULT_BITCLOCK
%token K_DEFAULT_PARALLEL
%token K_DEFAULT_PROGRAMMER
Expand Down Expand Up @@ -239,6 +240,11 @@ def :
free_token($3);
} |

K_DEFAULT_BAUDRATE TKN_EQUAL TKN_NUMBER TKN_SEMI {
default_baudrate = $3->value.number;
free_token($3);
} |

K_DEFAULT_BITCLOCK TKN_EQUAL number_real TKN_SEMI {
default_bitclock = $3->value.number_real;
free_token($3);
Expand Down
1 change: 1 addition & 0 deletions src/developer_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ void dev_output_pgm_part(int dev_opt_c, const char *programmer, int dev_opt_p, c
dev_info("default_parallel = %s;\n", p = cfg_escape(default_parallel)); free(p);
dev_info("default_serial = %s;\n", p = cfg_escape(default_serial)); free(p);
dev_info("default_spi = %s;\n", p = cfg_escape(default_spi)); free(p);
dev_info("default_baudrate = %d;\n", default_baudrate);
dev_info("default_bitclock = %7.5f;\n", default_bitclock);
dev_info("default_linuxgpio = %s;\n", p = cfg_escape(default_linuxgpio)); free(p);
dev_info("allow_subshells = %s;\n", allow_subshells? "yes": "no");
Expand Down
10 changes: 9 additions & 1 deletion src/doc/avrdude.texi
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ ATmega328P MCU properties; for more information run @code{avrdude -p x/h}.

@item -b @var{baudrate}
Override the RS-232 connection baud rate specified in the respective
programmer's entry of the configuration file.
programmer's @code{baudrate} entry of the configuration file
or defined by the @code{default_baudrate} entry in your
@code{~/.config/avrdude/avrdude.rc} or @code{~/.avrduderc} configuration
file if no @code{baudrate} entry was provided for this programmer.

@item -B @var{bitclock}
Specify the bit clock period for the JTAG, PDI, TPI, UPDI, or ISP
Expand Down Expand Up @@ -2977,6 +2980,11 @@ using the @option{-P} option.
Assign the default programmer id. Can be overridden using the @option{-c}
option.

@item default_baudrate = "@var{default-baudrate}";
Assign the default baudrate value that will be used if the programmer doesn't
provide its specific @code{baudrate} entry. Can be overridden using the @option{-b}
option.

@item default_bitclock = "@var{default-bitclock}";
Assign the default bitclock value. Can be overridden using the @option{-B}
option.
Expand Down
1 change: 1 addition & 0 deletions src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ buff { yylval=NULL; ccap(); return K_BUFF; }
chip_erase { yylval=new_token(K_CHIP_ERASE); ccap(); return K_CHIP_ERASE; }
connection_type { yylval=NULL; ccap(); return K_CONNTYPE; }
dedicated { yylval=new_token(K_DEDICATED); return K_DEDICATED; }
default_baudrate { yylval=NULL; return K_DEFAULT_BAUDRATE; }
default_bitclock { yylval=NULL; return K_DEFAULT_BITCLOCK; }
default_parallel { yylval=NULL; return K_DEFAULT_PARALLEL; }
default_programmer { yylval=NULL; return K_DEFAULT_PROGRAMMER; }
Expand Down
1 change: 1 addition & 0 deletions src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ extern const char *default_programmer;
extern const char *default_parallel;
extern const char *default_serial;
extern const char *default_spi;
extern int default_baudrate;
extern double default_bitclock;
extern char const *default_linuxgpio;
extern int allow_subshells;
Expand Down
19 changes: 16 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ int main(int argc, char * argv [])
default_parallel = "";
default_serial = "";
default_spi = "";
default_baudrate = 0;
default_bitclock = 0.0;
default_linuxgpio = "";
allow_subshells = 0;
Expand Down Expand Up @@ -1289,14 +1290,26 @@ int main(int argc, char * argv [])
imsg_notice("Using programmer : %s\n", pgmid);
}

if (baudrate != 0) {
imsg_notice("Setting baud rate : %d\n", baudrate);
if (baudrate && !pgm->baudrate && !default_baudrate) { // none set
imsg_notice("Setting baud rate : %d\n", baudrate);
pgm->baudrate = baudrate;
}
else if (baudrate && ((pgm->baudrate && pgm->baudrate != baudrate)
|| (!pgm->baudrate && default_baudrate != baudrate))) {
imsg_notice("Overriding baud rate : %d\n", baudrate);
pgm->baudrate = baudrate;
}
else if (!pgm->baudrate && default_baudrate) {
imsg_notice("Default baud rate : %d\n", default_baudrate);
pgm->baudrate = default_baudrate;
}
else if (ser && ser->baudrate) {
imsg_notice("Default baud rate : %d\n", ser->baudrate);
imsg_notice("Serial baud rate : %d\n", ser->baudrate);
pgm->baudrate = ser->baudrate;
}
else if (pgm->baudrate != 0)
imsg_notice("Programmer baud rate : %d\n", pgm->baudrate);

if (bitclock != 0.0) {
imsg_notice("Setting bit clk period: %.1f us\n", bitclock);
pgm->bitclock = bitclock * 1e-6;
Expand Down