Hello everybody
I have installed the Arduino software on my Raspberry Pi and I want to program my chips (not Arduino boards) with the linuxspi (or even linuxgpio) programmer of avrdude
I have no problem using avrdude to access and flash my chips but I can't find anywhere* how to use it with the Arduino software
Does anybody know how to do this?
Thanks
well actually I saw people using the following with other purposes but it doesn't work (I get this error "Board at COM1 is not available")
pi_grammer.name=linuxspi
pi_grammer.protocol=linuxspi
pi_grammer.program.protocol=linuxspi
pi_grammer.program.tool=avrdude
pi_grammer.program.extra_params=-P /dev/spidev0.0 -b 2000000
pert
December 5, 2018, 2:12am
2
This is something I've spent some time looking into. The latest version of avrdude from Arduino (6.3.0-arduino14) does support linuxspi. Unfortunately, there is a bug in the linuxspi code used in that avrdude version, which causes failures when avrdude is not run as superuser. I submitted a patch for the bug which has been merged by both the author of of the linuxspi programmer patch:
kcuzner:master ← per1234:fopen-retry
opened 02:22PM - 25 Jul 18 UTC
Setting the reset pin direction immediately after export doesn't allow enough ti… me for the udev rule to give access rights to the gpio user group. This causes avrdude commands run as non-root to fail:
```
avrdude: linuxspi_gpio_op_wr(): Unable to open file /sys/class/gpio/gpio25/direction
```
This code is based on the patch in https://github.com/kcuzner/avrdude/issues/10 but it doesn't impose a fixed delay of 2 seconds. On my RPi 3 B+, I find a delay of 50 ms is all that's needed.
Your patch is currently being [beta tested](https://github.com/facchinm/avrdude/commits/b5f8cd7f7235e441dccd7541e5c8c66d0096cafa/avrdude/linuxspi.h) for inclusion in the [next release of the Arduino IDE/Arduino AVR Boards](https://github.com/arduino/toolchain-avr/pull/47) but this issue makes the linuxspi programmer not terribly useful to Arduino IDE users. So, even if things aren't moving forward quickly for merging your patch in mainline AVRDUDE, it would still be very helpful to get this issue resolved and the patch updated.
I welcome any suggestions for improvement of this code.
Fixes https://github.com/kcuzner/avrdude/issues/10
CC: @thinkingcow
as well as Arduino:
facchinm:master ← per1234:fopen-retry
opened 03:06PM - 06 Aug 18 UTC
Setting the reset pin direction immediately after export doesn't allow enough ti… me for the udev rule to give access rights to the gpio user group. This causes avrdude commands run as non-root to fail:
```
avrdude: linuxspi_gpio_op_wr(): Unable to open file /sys/class/gpio/gpio25/direction
```
This change has been accepted by the author of the linuxspi programmer code:
https://github.com/kcuzner/avrdude/pull/17
but Arduino has not made a new release since that time.
Once the new version of avrdude is released by Arduino, I'll see if they're willing to add a linuxspi programmer to Arduino AVR Boards. If they're not, I'll publish a 3rd party hardware package that can be used to add that programmer.
You can find documentation of my work here:
per1234:master ← per1234:add-pi_grammer
opened 03:59AM - 19 Jul 18 UTC
This adds a **Tools > Programmer > Pi_grammer** menu selection after installing … SparkFun AVR Boards, which allows the SPI pins of a Raspberry Pi to be used as an ISP programmer. More info [here](https://learn.sparkfun.com/tutorials/raspberry-pi-stand-alone-programmer).
#### Installation instructions:
1. Install the [hourly build of the Arduino IDE](https://www.arduino.cc/en/Main/Software#hourly). This is only a temporary requirement. Once Boards Manager support for this version of SparkFun AVR Boards is added, it will be usable with any modern version of the Arduino IDE.
1. Download the file [avrdude.zip](https://github.com/per1234/Arduino_Boards/files/2226696/avrdude.zip) (or if you prefer, build the modified AVRDUDE from source: https://github.com/per1234/avrdude/tree/linuxspi-retry)
1. Unzip the downloaded file.
1. Replace {Arduino IDE installation folder}/hardware/avr/bin/avrdude with the one from the unzipped file (required if you want to use Pi_grammer when the Arduino IDE is not run as root).
1. Download https://github.com/per1234/Arduino_Boards/archive/add-pi_grammer.zip (or clone https://github.com/per1234/Arduino_Boards.git and checkout the `add-pi_grammer` branch).
1. Unzip the downloaded file.
1. Copy the sparkfun subfolder to {sketchbook folder}/hardware. You can find the location of {sketchbook folder} in the Arduino IDE at **File > Preferences > Sketchbook location**.
1. Restart the Arduino IDE if it's running.
1. If you have previously installed SparkFun AVR Boards via Boards Manager then you need to remove it so the modified version will be used: **Tools > Board > Boards Manager**, click on "SparkFun AVR Boards", click "Remove".
#### Usage
1. Connect your Raspberry Pi to the target board:
RPi GPIO | Target
---|---
MOSI | MOSI
MISO | MISO
SCK | SCK
3V3 | Vcc
GND | GND
26 | RST
Powering a 16 MHz board at 3.3 V is out of spec and may lead to unstable operation. Connecting the RPi GPIO pins directly to a board running at 5 V can damage the RPi so you should use level shifters.
2. Enable SPI on the Raspberry Pi by following these instructions:
https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial#spi-on-pi
Note that I found the menu path to be a little different using the latest version of Raspian.
1. (In the Arduino IDE) Tools > Board > select one of the Sparkfun AVR Boards.
1. Tools > Programmer > Pi_grammer.
1. Open the sketch you want to upload to the target.
1. Sketch > Upload Using Programmer.
I've tested this working (every other time, see (1) below) with the SparkFun Digital Sandbox. I haven't tested the 16 MHz boards because I don't have level shifters to safely use my Raspberry Pi with boards running at 5 V.
To do:
- [x] 1. ~~Every other upload fails: `avrdude: linuxspi_gpio_op_wr(): Unable to open file /sys/class/gpio/gpio26/direction`.~~ (fixed by https://github.com/per1234/avrdude/commit/1b673007e0382564f50aedad8875036ca48de27c)
- [X] 2. ~~The SparkFun pi_program.sh script used for programming their products does a reset of the target between setting fuses and flashing (https://github.com/sparkfun/SparkFun_Pi_AVR_Programmer_HAT/blob/master/pi_program.sh#L29-L33). Due to (1) I have not been able to complete a Burn Bootloader to see if this is necessary. The alternative is to simply set fuses and burn bootloader in a single avrdude command. The two avrdude commands back to back have historically caused problems with the AVRISP mkII (`https://github.com/arduino/Arduino/issues/2986`) and reportedly continue to do so for the AVR Dragon (`https://github.com/arduino/ArduinoCore-avr/issues/9`).~~ (Doesn't appear to be necessary)
- [ ] 3. The change to platform.txt switches from using using the avrdude.conf bundled with Arduino's AVRDUDE tool to using the avrdude.conf bundled with SparkFun AVR Boards. As reported here: `https://github.com/sparkfun/Arduino_Boards/issues/21`, this is an outdated version of that file and so this avrdude.conf will need to be updated in order to ensure support for all newer programmers and parts. The current version of the file should be fine for any testing of the Pi_grammer programmer.
- [ ] 4. Determine whether there is official interest in adding this programmer to Arduino AVR Boards. Since the proposal comes from SparkFun, I've added the programmer to SparkFun AVR Boards but it could just as easily be done to Arduino AVR Boards instead.
- [ ] 5. The default reset pin, as set in the [kcuzner/avrdude patch](http://savannah.nongnu.org/patch/?8228) is GPIO 25. SparkFun uses 26 instead and this is the only reason the custom avrdude.conf file is necessary. With GPIO 25 as reset it's possible to use the avrdude.conf bundled with Arduino's avrdude tool and the change to platform.txt is not necessary. It seems like the change to 26 was solely due to the layout of SparkFun's custom hat, which is not likely to be used with Arduino or by general users anyway.
- [ ] 6. If this doesn't end up being accepted to Arduino AVR Boards, I think it would actually be more appropriate as a 3rd party package rather than part of SparkFun AVR Boards. This would need to wait for the retry fix to be made to avrdude, the fix to be picked up by Arduino, and Arduino to make a release of Arduino AVR Boards with the fixed AVRDUDE.
Reference:
https://github.com/arduino/Arduino/issues/7795
Other links of interest:
jackoyack:
I get this error "Board at COM1 is not available"
You definitely shouldn't be getting that error. Are you doing a Sketch > Upload Using Programmer , or a standard Upload? You should be doing the former.
I already looked at a couple of these links and they already helped me
The actual problem this time was I was indeed using standard upload
Thanks a lot for your help, for your answer here but also for your resources I found before asking on this forum!
pert
December 8, 2018, 10:12pm
4
You're very welcome. I'm glad to hear it's working now. Enjoy!
Per