Skip to content

Commit 2aee540

Browse files
committed
Use -B <bitclock> rather than -b <baudrate> to specify the clock rate
in linuxspi driver. This offers the additional advantage of being able to parse kHz and MHz values (in main.c). git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1497 81a1dc3b-b13d-400b-aceb-764788c761c2
1 parent dd1255b commit 2aee540

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2021-11-27 Joerg Wunsch <[email protected]>
2+
3+
* linuxspi.c: Use -B <bitclock> rather than -b <baudrate>
4+
to specify the clock rate
5+
16
2021-11-27 Joerg Wunsch <[email protected]>
27

38
Improve defaults and documentation of linuxspi

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Current:
2121
- extended UPDI device context (> 64 Ki flash)
2222
- major overhaul of ft245r driver (patch #9327/#9328)
2323
- some improvements in linuxspi driver
24+
- Use -B <bitclock> rather than -b <baudrate> for linuxspi driver
2425

2526
* New devices supported:
2627

@@ -124,6 +125,7 @@ Current:
124125
patch #10030: linuxspi: Support inverted GPIO pin
125126
patch #10031: linuxspi: Support GPIO uAPI v2
126127
(no-id): Improve documentation of linuxspi driver, provide portname default
128+
(no-id): Use -B <bitclock> rather than -b <baudrate> for linuxspi driver
127129

128130
* Internals:
129131
- New avrdude.conf keyword "family_id", used to verify SIB attributes

linuxspi.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ static int linuxspi_spi_duplex(PROGRAMMER *pgm, const unsigned char *tx, unsigne
7878
.rx_buf = (unsigned long)rx,
7979
.len = len,
8080
.delay_usecs = 1,
81-
//should settle around 400Khz, a standard SPI speed. Adjust using baud parameter (-b)
82-
.speed_hz = pgm->baudrate == 0 ? 400000 : pgm->baudrate,
81+
.speed_hz = 1.0 / pgm->bitclock, // seconds to Hz
8382
.bits_per_word = 8,
8483
};
8584

@@ -213,6 +212,19 @@ static int linuxspi_open(PROGRAMMER *pgm, char *port)
213212
if (ret)
214213
goto close_out;
215214

215+
if (pgm->baudrate != 0) {
216+
avrdude_message(MSG_INFO,
217+
"%s: obsolete use of -b <clock> option for bit clock; use -B <clock>\n",
218+
progname);
219+
pgm->bitclock = 1E6 / pgm->baudrate;
220+
}
221+
if (pgm->bitclock == 0) {
222+
avrdude_message(MSG_NOTICE,
223+
"%s: defaulting bit clock to 200 kHz\n",
224+
progname);
225+
pgm->bitclock = 5E-6; // 200 kHz - 5 µs
226+
}
227+
216228
return 0;
217229

218230
close_out:
@@ -306,7 +318,7 @@ static int linuxspi_program_enable(PROGRAMMER *pgm, AVRPART *p)
306318
*/
307319
if (linuxspi_reset_mcu(pgm, false))
308320
return -1;
309-
usleep(3 + (pgm->baudrate ? 500000 / pgm->baudrate : 1));
321+
usleep(5);
310322
if (linuxspi_reset_mcu(pgm, true))
311323
return -1;
312324
usleep(20000);

0 commit comments

Comments
 (0)