Skip to content

Commit dd1255b

Browse files
committed
Improve defaults and documentation of linuxspi
* avrdude.conf.in: use @HAVE_LINUXGPIO_BEGIN/END@ and @HAVE_LINUXSPI_BEGIN/END@ brackets around respective config snippets; values were already set in configure.ac. * linuxspi.c (linuxspi_open): Provide a reasonable (for the Raspberry Pi) default for the -P option * avrdude.1: Extend linuxspi documentation * doc/avrdude.texi: (Dito.) git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1496 81a1dc3b-b13d-400b-aceb-764788c761c2
1 parent 18fe8ef commit dd1255b

File tree

6 files changed

+59
-31
lines changed

6 files changed

+59
-31
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2021-11-27 Joerg Wunsch <[email protected]>
2+
3+
Improve defaults and documentation of linuxspi
4+
* avrdude.conf.in: use @HAVE_LINUXGPIO_BEGIN/END@ and
5+
@HAVE_LINUXSPI_BEGIN/END@ brackets around respective config
6+
snippets; values were already set in configure.ac.
7+
* linuxspi.c (linuxspi_open): Provide a reasonable (for the
8+
Raspberry Pi) default for the -P option
9+
* avrdude.1: Extend linuxspi documentation
10+
* doc/avrdude.texi: (Dito.)
11+
112
2021-11-27 Joerg Wunsch <[email protected]>
213

314
Submitted by Alex Sverdlin:

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Current:
2020
- New configure option: -disable-libusb_1_0
2121
- extended UPDI device context (> 64 Ki flash)
2222
- major overhaul of ft245r driver (patch #9327/#9328)
23+
- some improvements in linuxspi driver
2324

2425
* New devices supported:
2526

@@ -122,6 +123,7 @@ Current:
122123
patch #10029: linuxspi: Report GPIO_GET_LINEHANDLE_IOCTL errors
123124
patch #10030: linuxspi: Support inverted GPIO pin
124125
patch #10031: linuxspi: Support GPIO uAPI v2
126+
(no-id): Improve documentation of linuxspi driver, provide portname default
125127

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

avrdude.1

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,10 @@ should be connected between the AVR's reset pin and Vcc. If Vcc is not
129129
the same as the SPI voltage, this should be done on the AVR side of
130130
the level translator to protect the hardware from damage.
131131
.Pp
132-
A commented-out template for this programmer is provided in the
133-
avrdude configuration file. To use it, clone that entry into the
134-
per-user configuration file, and configure the
135-
.Li reset
136-
GPIO
137-
number accordingly. Linuxspi can be used as follows:
138-
.Dl avrdude -c linuxspi -P /dev/spidev:/dev/gpiochip[:resetpin]
132+
The
133+
.Fl P Ar portname
134+
option for this programmer defaults to
135+
.Li /dev/spidev0.0:/dev/gpiochip0 .
139136
.Pp
140137
Atmel's STK500 programmer is also supported and connects to a serial
141138
port.

avrdude.conf.in

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,7 @@ programmer
15191519

15201520
@HAVE_PARPORT_END@
15211521

1522+
@HAVE_LINUXGPIO_BEGIN@
15221523
#This programmer bitbangs GPIO lines using the Linux sysfs GPIO interface
15231524
#
15241525
#To enable it set the configuration below to match the GPIO lines connected to the
@@ -1540,23 +1541,22 @@ programmer
15401541
# mosi = ?;
15411542
# miso = ?;
15421543
#;
1544+
@HAVE_LINUXGPIO_END@
15431545

15441546

1547+
@HAVE_LINUXSPI_BEGIN@
15451548
# This programmer uses the built in linux SPI bus devices to program an
1546-
# attached AVR. A GPIO accessed through the sysfs GPIO interface needs to
1547-
# be specified for a reset pin since the linux SPI userspace functions do
1548-
# not allow for control over the slave select/chip select signal.
1549+
# attached AVR. The reset pin must be attached to a GPIO pin that
1550+
# is otherwise unused (see gpioinfo(1)); the SPI bus CE pins are not
1551+
# suitable since they would release /RESET too early.
15491552
#
1550-
# To use it, copy this snippet into your ~/.avrduderc, make sure the
1551-
# 'reset' entry is configured correctly.
1552-
#
1553-
# programmer
1554-
# id = "linuxspi";
1555-
# desc = "Use Linux SPI device in /dev/spidev*";
1556-
# type = "linuxspi";
1557-
# reset = 25;
1558-
# baudrate=400000;
1559-
# ;
1553+
programmer
1554+
id = "linuxspi";
1555+
desc = "Use Linux SPI device in /dev/spidev*";
1556+
type = "linuxspi";
1557+
reset = 25; # Pi GPIO number - this is J8:22
1558+
;
1559+
@HAVE_LINUXSPI_END@
15601560

15611561
# some ultra cheap programmers use bitbanging on the
15621562
# serialport.

doc/avrdude.texi

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,30 @@ should be connected between the AVR's reset pin and Vcc. If Vcc is not
198198
the same as the SPI voltage, this should be done on the AVR side of
199199
the level translator to protect the hardware from damage.
200200

201-
A commented-out template for this programmer is provided in the
202-
avrdude configuration file. To use it, clone that entry into the
203-
per-user configuration file, and configure the @code{reset} GPIO
204-
number accordingly. Linuxspi can be used as follows:
201+
On a Raspberry Pi, header J8 provides access to the SPI and GPIO
202+
lines.
203+
204+
Typically, pins 19, 21, and 23 are SPI MOSI, MISO, and SCK, while
205+
pins 24 and 26 would serve as CE outputs. So, close to these pins
206+
is pin 22 as GPIO25 which can be used as /RESET, and pin 25 can
207+
be used as GND.
208+
209+
A typical programming cable would then look like:
210+
211+
@multitable @columnfractions .15 .15 .3
212+
@item @code{J8 pin} @tab @code{ISP pin} @tab @code{Name}
213+
@item @code{21} @tab @code{1} @tab @code{MISO}
214+
@item @code{-} @tab @code{2} @tab @code{Vcc - leave open}
215+
@item @code{23} @tab @code{3} @tab @code{SCK}
216+
@item @code{19} @tab @code{4} @tab @code{MOSI}
217+
@item @code{22} @tab @code{5} @tab @code{/RESET}
218+
@item @code{25} @tab @code{6} @tab @code{GND}
219+
@end multitable
205220

206-
@smallexample
207-
avrdude -c linuxspi -P /dev/spidev:/dev/gpiochip[:resetpin]
208-
@end smallexample
221+
(Mind the 3.3 V voltage level of the Raspberry Pi!)
222+
223+
The @code{-P @var{portname}} option defaults to
224+
@code{/dev/spidev0.0:/dev/gpiochip0} for this programmer.
209225

210226
The STK500, JTAG ICE, avr910, and avr109/butterfly use the serial port to communicate with the PC.
211227
The STK600, JTAG ICE mkII/3, AVRISP mkII, USBasp, avrftdi (and derivatives), and USBtinyISP

linuxspi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,16 @@ static int linuxspi_reset_mcu(PROGRAMMER *pgm, bool active)
131131

132132
static int linuxspi_open(PROGRAMMER *pgm, char *port)
133133
{
134-
const char *port_error = "%s: error: Unknown port specification. Please use the format /dev/spidev:/dev/gpiochip[:resetno]\n";
134+
const char *port_error =
135+
"%s: error: Unknown port specification. "
136+
"Please use the format /dev/spidev:/dev/gpiochip[:resetno]\n";
137+
char port_default[] = "/dev/spidev0.0:/dev/gpiochip0";
135138
char *spidev, *gpiochip, *reset_pin;
136139
struct gpiohandle_request req;
137140
int ret;
138141

139-
if (!port || !strcmp(port, "unknown")) {
140-
avrdude_message(MSG_INFO, "%s: error: No port specified. Port should point to an spidev device.\n", progname);
141-
return -1;
142+
if (!strcmp(port, "unknown")) {
143+
port = port_default;
142144
}
143145

144146
spidev = strtok(port, ":");

0 commit comments

Comments
 (0)