Raspberry Pi as an AVR Programmer

Introduction

Recently, I got my hands on a Raspberry Pi and one of the first things I wanted to do with it was to turn it into my complete AVR development environment. As part of that I wanted to make avrdude be able to program an AVR directly from the Raspberry Pi with no programmer. I know there is this linuxgpio programmer type that was recently added, but it is so recent that it isn’t yet included in the repos and it also requires a compile-time option to enable it. I noticed that the Raspberry Pi happens to expose its SPI interface on its expansion header and so I thought to myself, “Why not use this thing instead of bitbanging GPIOs? Wouldn’t that be more efficient?” Thus, I began to decipher the avrdude code and write my addition. My hope is that things like this will allow the Raspberry Pi to be used to explore further embedded development for those who want to get into microcontrollers, but blew all their money on the Raspberry Pi. Also, in keeping with the purpose that the Raspberry Pi was originally designed for, using it like this makes it fairly simple for people in educational surroundings to expand into different aspects of small computer and embedded device programming.

As my addition to avrdude, I created a new programmer type called “linuxspi” which uses the userspace SPI drivers available since around Linux ~2.6 or so to talk to a programmer. It also requires an additional GPIO to operate as the reset. My initial thought was to use the chip select as the reset output, but sadly, the documentation for the SPI functions mentioned that the chip enable line is only held low so long as the transaction is going. While I guess I could compress all the transactions avrdude makes into one giant burst of data, this would be very error prone and isn’t compatible with avrdude’s program structure. So, the GPIO route was chosen. It just uses the sysfs endpoints found in /sys/class/gpio to manipulate a GPIO chosen in avrdude.conf into either being in a hi-z input state or an output low state. This way, the reset can be connected via a resistor to Vcc and then the Raspberry Pi just holds reset down when it needs to program the device. Another consequence which I will mention here of choosing to use the Linux SPI drivers is that this should actually be compatible with any Linux-based device that exposes its SPI or has an AVR connected to the SPI; not just the Raspberry Pi.

Programming an AVR

Raspberry Pi Programming an AVR

Usage

So, down to the nitty gritty: How can I use it? Well, at the moment it is in a github repository at https://github.com/kcuzner/avrdude. As with any project that uses the expansion header on the Raspberry Pi, there is a risk that a mistake could cause your Raspberry Pi to die (or let out the magic smoke, so to speak). I assume no responsibility for any damage that may occur as a result of following these directions or using my addition to avrdude. Just be careful when doing anything involving hooking stuff up to the expansion port and use common sense. Remember to measure twice and cut once. So, with that out of the way, I will proceed to outline here the basic steps for installation and usage.

Installation

The best option here until I bother creating packages for it is to  do a git clone directly into a directory on the Raspberry Pi and build it from there on the Raspberry Pi itself. I remember having to install the following packages to get it to compile (If I missed any, let me know):

  • bison
  • autoconf
  • make
  • gcc
  • flex

Also, if your system doesn’t have a header at “linux/spi/spidev.h” in your path, you probably need to install that driver. I was using Arch Linux and it already had the driver there, so for all I know its always installed. You also should take a look to make sure that “/dev/spidev0.0″ and “/dev/spidev0.1″ or something like that exist. Those are the sort of endpoints that are to be used with this. If they do not exist, try executing a “sudo modprobe spi_bcm2708″. If the endpoints still aren’t there after that, then SPI support probably isn’t installed or enabled for your kernel.

After cloning the repo and installing those packages, run the “./boostrap” script which is found in the avrdude directory. This will run all the autoconf things and create the build scripts. The next step is to run “./configure” and wait for it to complete. After the configure script, it should say whether or not “linuxspi” is enabled or disabled. If it is disabled, it was not able to find the header I mentioned before. Then run “make” and wait for it to complete. Remember that the Raspberry Pi is a single core ARM processor and so building may take a while. Afterwards, simply do “sudo make install” and you will magically have avrdude installed on your computer in /usr/local. It would probably be worthwhile to note here that you probably want to uninstall any avrdude you may have had installed previously either manually or through a package manager. The one here is built on top of the latest version (as of May 26th, 2013), so it should work quite well and be all up to date and stuff for just using it like a normal avrdude. I made no changes to any of the programmer types other than the one I added.

To check to see if the avrdude you have is the right one, you should see an output similar to the following if you run this command (tiny-tim is the name of my Raspberry Pi until I think of something better):

kcuzner@tiny-tim:~/avrdude/avrdude$ avrdude -c ?type

Valid programmer types are:
  arduino          = Arduino programmer
  avr910           = Serial programmers using protocol described in application note AVR910
  avrftdi          = Interface to the MPSSE Engine of FTDI Chips using libftdi.
  buspirate        = Using the Bus Pirate's SPI interface for programming
  buspirate_bb     = Using the Bus Pirate's bitbang interface for programming
  butterfly        = Atmel Butterfly evaluation board; Atmel AppNotes AVR109, AVR911
  butterfly_mk     = Mikrokopter.de Butterfly
  dragon_dw        = Atmel AVR Dragon in debugWire mode
  dragon_hvsp      = Atmel AVR Dragon in HVSP mode
  dragon_isp       = Atmel AVR Dragon in ISP mode
  dragon_jtag      = Atmel AVR Dragon in JTAG mode
  dragon_pdi       = Atmel AVR Dragon in PDI mode
  dragon_pp        = Atmel AVR Dragon in PP mode
  ftdi_syncbb      = FT245R/FT232R Synchronous BitBangMode Programmer
  jtagmki          = Atmel JTAG ICE mkI
  jtagmkii         = Atmel JTAG ICE mkII
  jtagmkii_avr32   = Atmel JTAG ICE mkII in AVR32 mode
  jtagmkii_dw      = Atmel JTAG ICE mkII in debugWire mode
  jtagmkii_isp     = Atmel JTAG ICE mkII in ISP mode
  jtagmkii_pdi     = Atmel JTAG ICE mkII in PDI mode
  jtagice3         = Atmel JTAGICE3
  jtagice3_pdi     = Atmel JTAGICE3 in PDI mode
  jtagice3_dw      = Atmel JTAGICE3 in debugWire mode
  jtagice3_isp     = Atmel JTAGICE3 in ISP mode
  linuxgpio        = GPIO bitbanging using the Linux sysfs interface (not available)
  linuxspi         = SPI using Linux spidev driver
  par              = Parallel port bitbanging
  pickit2          = Microchip's PICkit2 Programmer
  serbb            = Serial port bitbanging
  stk500           = Atmel STK500 Version 1.x firmware
  stk500generic    = Atmel STK500, autodetect firmware version
  stk500v2         = Atmel STK500 Version 2.x firmware
  stk500hvsp       = Atmel STK500 V2 in high-voltage serial programming mode
  stk500pp         = Atmel STK500 V2 in parallel programming mode
  stk600           = Atmel STK600
  stk600hvsp       = Atmel STK600 in high-voltage serial programming mode
  stk600pp         = Atmel STK600 in parallel programming mode
  usbasp           = USBasp programmer, see http://www.fischl.de/usbasp/
  usbtiny          = Driver for "usbtiny"-type programmers
  wiring           = http://wiring.org.co/, Basically STK500v2 protocol, with some glue to trigger the bootloader.

Note that right under “linuxgpio” there is now a “linuxspi” driver. If it says “(not available)” after the “linuxspi” description, “./configure” was not able to find the “linux/spi/spidev.h” file and did not compile the linuxspi programmer into avrdude.

Configuration

There is a little bit of configuration that happens here on the Raspberry Pi side before proceeding to wiring it up. You must now decide which GPIO to sacrifice to be the reset pin. I chose 25 because it is next to the normal chip enable pins, but it doesn’t matter which you choose. To change which pin is to be used, you need to edit “/usr/local/etc/avrdude.conf” (it will be just “/etc/avrdude.conf” if it wasn’t built and installed manually like above). Find the section of the file that looks like so:

programmer
  id = "linuxspi";
  desc = "Use Linux SPI device in /dev/spidev*";
  type = "linuxspi";
  reset = 25;
;

The “reset = ” line needs to be changed to have the number of the GPIO that you have decided to turn into the reset pin for the programmer. The default is 25, but that’s just because of my selfishness in not wanting to set it to something more generic and having to then edit the file every time I re-installed avrdude. Perhaps a better default would be “0″ since that will cause the programmer to say that it hasn’t been set up yet.

Wiring

After setting up avrdude.conf to your desired configuration, you can now connect the appropriate wires from your Raspberry Pi’s header to your microchip. A word of extreme caution: The Raspberry Pi’s GPIOs are NOT 5V tolerant, and that includes the SPI pins. You must do either one of two things: a) Run the AVR and everything around it at 3.3V so that you never see 5V on ANY of the Raspberry Pi pins at any time (including after programming is completed and the device is running) or b) Use a level translator between the AVR and the SPI. I happen to have a level translator lying around (its a fun little TSSOP I soldered to a breakout board a few years back), but I decided to go the 3.3V route since I was trying to get this thing to work. If you have not ever had to hook up in-circuit serial programming to your AVR before, perhaps this would be a great time to learn. You need to consult the datasheet for your AVR and find the pins named RESET (bar above it), MOSI, MISO, and SCK. These 4 pins are connected so that RESET goes to your GPIO with a pullup resistor to the Vcc on your AVR, MOSI goes to the similarly named MOSI on the Raspberry Pi header, MISO goes to the like-named pin on the header, and SCK goes to the SPI clock pin (named SCLK on the diagram on elinux.org). After doing this and double checking to make sure 5V will never be present to the Raspberry Pi, you can power on your AVR and it should be able to be programmed through avrdude. Here is a demonstration of me loading a simple test program I made that flashes the PORTD LEDs:

kcuzner@tiny-tim:~/avrdude/avrdude$ sudo avrdude -c linuxspi -p m48 -P /dev/spidev0.0 -U flash:w:../blink.hex 
[sudo] password for kcuzner: 

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9205
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "../blink.hex"
avrdude: input file ../blink.hex auto detected as Intel Hex
avrdude: writing flash (2282 bytes):

Writing | ################################################## | 100% 0.75s

avrdude: 2282 bytes of flash written
avrdude: verifying flash memory against ../blink.hex:
avrdude: load data flash data from input file ../blink.hex:
avrdude: input file ../blink.hex auto detected as Intel Hex
avrdude: input file ../blink.hex contains 2282 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.56s

avrdude: verifying ...
avrdude: 2282 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

There are two major things to note here:

  • I set the programmer type (-c option) to be “linuxspi”. This tells avrdude to use my addition as the programming interface
  • I set the port (-P option) to be “/dev/spidev0.0″. On my Raspberry Pi, this maps to the SPI bus using CE0 as the chip select. Although we don’t actually use CE0 to connect to the AVR, it still gets used by the spidev interface and will toggle several times during normal avrdude operation. Your exact configuration may end up being different, but this is more or less how the SPI should be set. If the thing you point to isn’t an SPI device, avrdude should fail with a bunch of messages saying that it couldn’t send an SPI message.

Other than that, usage is pretty straightforward and should be the same as if you were using any other programmer type.

Future

As issues crop up, I hope to add improvements like changing the clock frequency and maybe someday adding TPI support (not sure if necessary since this is using the dedicated SPI and as far as I know, TPI doesn’t use SPI).

I hope that those using this can find it helpful in their fun and games with the Raspberry Pi. If there are any issues compiling and stuff, either open an issue on github or mention it in the comments here.

43 thoughts on “Raspberry Pi as an AVR Programmer

  1. James

    THANK YOU this tutorial is extremely helpful. My cohort and I are doing some AVR flashing and I don’t have an AVR asp usb controller like he does. He came back to the lab yesterday and said “I flashed all my ATmega 232s,” so i need to figure a semi permanent avr programing solution for myself :)… The Pi is more then capable. Ill make a new SD installation for the Pi that’s just for interfacing with micro’s

    TY

    -James

    Reply
  2. Pieter-Jan

    Sorry to have to reply again but to be able to compile on raspbian I also had to install flex (sudo apt-get install flex)

    Reply
  3. admin Post author

    Thanks for the note about flex. I was compiling this on arch and was rapidly installing packages, so I thought it was likely I would miss a couple. I will add it to the list.

    Reply
  4. Mark "mikroskeem"

    What should i do? i’m using Attiny85
    sudo avrdude -F -p t85 -P /dev/spidev0.0 -c linuxspi

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.00s

    avrdude: Device signature = 0x1e930b
    avrdude: safemode: Verify error – unable to read lfuse properly. Programmer may not be reliable.
    avrdude: safemode: To protect your AVR the programming will be aborted

    avrdude done. Thank you.

    Reply
    1. admin Post author

      Whenever avrdude reads the fuses, it actually reads them 3 times. What is is saying there is that it didn’t read the same thing each time. I would check your connections since that could be a symptom of faulty connections. You will want to try programming it with another programmer to verify that it isn’t the avr causing the problem as well. Another possibility is that your clock speed is too high for the voltage you have it running at.

      Reply
          1. admin Post author

            The baud rate can be changed using the -b switch. This is actually the same for any programmer type in avrdude that supports variable baud rates.

  5. Campbell

    I really appreciate this addition to the avrdude code. It has been working great for loading application code into a new design I have (based on an ATTiny167).

    However, I am trying to place some code higher up in flash using –section-start=.text=0×3980 (the code will fit between there and 0x3fff). It fails on verification but I have pulled the flash off and the code is being uploaded but to the wrong addresses it is in the 0×2… range (sorry I am not on my pi right now). Any idea why this would be happening? Could you point me to where in code I might be able to see which address is being written (to put some printfs in to see where the problem is occuring, whether on my end, linuxspi or avrdude)?

    Reply
    1. admin Post author

      Hmm…I never tested that functionality. I would imagine something is being truncated somewhere. Since avrdude dictates exactly what to send to the avr, you can put a printf (or breakpoint, whatever) somewhere in linuxspi_spi_duplex (linuxspi.c:104-133) after it does the transfer (linuxspi.c:123-124). That should let you intercept everything that gets sent via spi so you can see if the raw command order is correct. It is possible that either the way I am calling the linuxspi driver is truncating things or this functionality is broken in avrdude itself, so I would also test on another programmer to make sure it is indeed my programmer type that is causing problems.

      Reply
  6. Pieter-Jan

    How do I get the spidev files if they don’t exist on my system? I get this error:

    avrdude: error: Unable to open SPI port /dev/spidev0.0

    Reply
    1. admin Post author

      Two things to check first, make sure that if that file actually exists at that location in your system and try running avrdude with sudo. Sometimes the devices are not readable to anyone but root. If the file /dev/spidev0.0 doesn’t exist, try running lsmod and see if “spidev” is listed. If not, do a sudo modprobe spidev to attempt to load it. If this fails, check to see if /usr/include/linux/spi/spidev.h exists in your system. If it does not, you may have a version of the linux kernel that does not have those drivers installed.

      Reply
  7. joedu12

    Thanks ! It worked for me !
    But now I want to program my 328P with arduino code and I don’t know how to do this. I’ve already installed the arduino bootloader inside but, now, how to send “.ino” files to the AVR ?

    Reply
  8. Ettore_M

    Indeed, a sudo modprobe_bcm2708 is necessary to proceed to programming the AVR. But ok, this was easy to solve. ;)
    I use a ATTiny85. I compiled the .c file with -mcu=attiny85, and finally used “sudo avrdude -c linuxspi -p t85 -P /dev/spidev0.0 -U flash:w:..blink.hex”.
    But all I get is “avrdude: Yikes! Invalid device signature”. The MCU I’m using is brand new. Could this be a wiring issue? I’m not sure about that: RESET (MCU) to CE0 (Raspberry Pi) and a pull-up resistor to 3V3. That’s what I did.
    What do you think is the problem here?

    Thank you!
    -Hector

    Reply
    1. Ettore_M

      I also run this with the -F option, too, and then I get “avrdude: verification error; content mismatch”. Do you think it’s the chip?

      -Hector

      Reply
    2. admin Post author

      It might not be the chip. Try lowering the baud rate to something like 200000-100000. The default is 400000 and that may be a little high for devices running slower. The switch is -b. Also, be careful using -F…if you are programming fuses or anything like that, you could brick the chip. Also, if you have an alternate programmer, I would try using that just to verify that the chip is indeed working.

      Reply
      1. Ettore_M

        I just tried to change the baud rate, bou again I get the same message.
        Is it the wiring? I’ve done this: (RPi to MCU) 3V3 to Vcc, GND to GND, MOSI to MOSI, MISO to MISO, SCLK to SCK and CE0 to RESET, with a resistor to 3V3 (I used a 1k resistor).
        I’m afraid I don’t have an alternate programmer, so I hope the chip is not bricked.
        If it isn’t any of this, should I try another chip? I have a ATiny 2313.

        -Hector

        Reply
        1. admin Post author

          Those connections sound about right. The CE pin you use would depend on which spidev you use. Using /dev/spidev0.0 will give CE0 and /dev/spidev0.1 will give CE1. What is the invalid device signature exactly? Is it different every time? 0xFFFFFF? If you have a scope, it might be useful to read it out. If it is random each time, that is either a symptom of the chip not getting power or its clock is not working right for the speed of the spi bus. If it is FFFFFF each time, that means that the data lines are probably not connected correctly. As for wiring, if there are multiple ground and power connections, make sure to connect all of them to 3V3/GND (that’s my most common error myself). Also, a small capacitor (.1uF or so should do it) close to the chip across gnd and vcc to act as a decoupling capacitor may help. I would also try the other chip, provided that you are sure that everything is connected correctly. I have destroyed a chip (not bricked, destroyed) by connecting the power backwards in a fit of confusion (it was my poor attiny84…power on bottom and gnd on top which is backwards from the 7400 logic I was working with just before hooking it up).

          Reply
          1. Ettore_M

            I use spidev0.0, so I use CE0. And the invalid signature is every time the same: 0×000000. The connections seem right, so what it could be?

            -Hector

  9. Fr4nky

    Hi!

    Thanks for this nice addition to avrdude!
    I want to use this to program an AVR on my RPi expansion board.
    However, the problem is that the AVR’s reset pin is connected to GPIO 25 via a transistor (to get a 5V high level on the reset pin), so I somehow have to tell avrdude to output high instead of low on GPIO 25 to get the AVR into “programming mode”.

    I have tried to use the line “reset = ~25;” in the avrdude.conf, but it gives me this error:
    avrdude: linuxspi_gpio_op_wr(): Unable to open file /sys/class/gpio/gpio-2147483623/directionavrdude: linuxspi_gpio_op_wr(): Unable to open file /sys/class/gpio/gpio-2147483623/direction

    Is there a way to do that (ideally without changing the source-code)?

    Thanks and Regards,
    Daniel

    Reply
    1. admin Post author

      The avrdude.conf file is very simply parsed and can’t handle things like bitwise inversion (or any transformation of the sort). At the moment, the only way to do this is via changing the source code, but it is a simple, two line change on linuxspi.c:233-234. A patch describing the change is here: http://pastebin.com/GgGnunEv

      Reply
  10. Ronald Teune

    Hi! This is just what I am looking for, for interfacing my rpi to an attiny2313, while having the possibility to reprogram it when I like. However… it does not work.
    - I have a “blink led” program on it, and it resets when I start programming, so the programmer reset does work
    - I checked the RESET, SCK, MOSI and MISO lines one by one using the ‘pigpiod’ library and my multimeter
    - I lowered the baud rate to 40000, even to 40.
    - I get 0x90nnnn device id’s (e.g. 0x90f230) when doing sudo avrdude -y -c linuxspi -p t2313 -P /dev/spidev0.1 -F
    - I have no xtal, and a 1 uF capacitor
    - the attiny2313 can still be programmed by another programmer (5V though)

    As a last resort, I tried linuxgpio, but it doesn’t seem to recognize the pins, it says: “Can’t export GPIO 0, already exported/busy?: Device or resource busy”

    Any ideas? :-$ Does it just not work with the ATTiny2313?

    Reply
    1. Ronald Teune

      (edited)

      Hi! This is just what I am looking for, for interfacing my rpi to an attiny2313, while having the possibility to reprogram it when I like. However… it does not work.
      - I have a “blink led” program on it, and it resets when I start programming, so the programmer reset does work
      - I checked the RESET, SCK, MOSI and MISO lines one by one using the ‘pigpiod’ library and my multimeter
      - I lowered the baud rate to 40000, even to 40.
      - I get 0x90nnnn device id’s (e.g. 0x90f230) when doing sudo avrdude -y -c linuxspi -p t2313 -P /dev/spidev0.1 -F
      - I have no xtal, and a 1 uF capacitor
      - the attiny2313 can still be programmed by another programmer (5V though)
      - I have not connected CE0 and CE1 since I understood that it would not be neccesary anymore.

      As a last resort, I tried linuxgpio, but it doesn’t seem to recognize the pins, it says: “Can’t export GPIO 0, already exported/busy?: Device or resource busy”

      Any ideas? :-$ Does it just not work with the ATTiny2313?

      Reply
      1. Ronald Teune

        …with an ATTiny45 it also does not work. Same errors.
        This might be an answer to my and Ettore_M’s question if it’s the ATTiny2313.
        Could it work at baud rates like 40?

        Reply
      2. admin Post author

        Is your AVCC connected as well as your VCC? The datasheet for that particular chip has a tiny tiny note in the serial programming section that says it needs to be within 0.3V of VCC.

        Reply
        1. Ronald

          Hey Kevin,

          Thanks for your efforts and reply. Since while programming with my other programmer, I had no problems, I figured that would not be the problem (and I think the tiny45 does not have an AVCC?).
          Anyway, after leaving the project abandoned for a few weeks, today I took up the courage to try again. I now use stevemarple’s GPIO bit banging driver on the same pins, which does work for me. So I’m happy now, but… still need to figure out how then to use the SPI to talk to the device after programming. :)
          I thought it might be the system’s spi drivers, but updating did not seem to help. I’ll let you know if I find out what the problem is.

          Kind regards,
          Ronald

          Reply
  11. Luke

    Hi, sorry if this is a dumb question, my electronics knowledge is only very basic.
    Is there a specific reason you’re using a pull-up resistor on the GPIO reset?
    The Raspberry PI has pull-up and pull-down resistors built in, why not use those?

    Thanks!

    Reply
    1. admin Post author

      I felt like it was more reliable that having the software have to set that up each time. I’m sure it would be ok to have used the internal pull-ups, but I wanted to be sure that I wouldn’t leave the AVR in reset mode if I had exported the pin and set it as an input, but somehow not enabled the pull-up resistor. So in other words, I could have gone either way, but I ended up going the external route and it would probably work just as well had I used the internal pull up.

      Reply
  12. Adam Dodman

    Hi There,
    I’ve been following your guide to try and flash a new bootloader onto a bricked atmega328p, but i can’t seem to start avrdude..
    The error that comes up when I try to run it is:
    avrdude: error: AVR device not responding
    avrdude: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.
    Any ideas?
    Many thanks,
    Adam

    Reply
    1. admin Post author

      I would first check your connections. I have found that this is the issue for me most of the time. If it turns out you do have it hooked up fully, then its time to test it on another programmer. If the chip cannot be programmed using another programmer, it is most likely damaged. If you have access to a high voltage programmer, it might be worthwhile to try programming it with that.

      I mention the possibility of the AVR being damaged because you mentioned that it is bricked and used to have a bootloader on it. If the bootloader simply stopped responding one day, something probably happened to the chip itself (unless its been running for 30 years or has rewritten itself 100,000 times and exceeded the life of the flash).

      I once broke an attiny84 when I had an accident involving a wire and a heatsink on a regulator. It was only for a fraction of a second that it was overvolted, but of course it was enough to damage it. Could something like this have happened?

      Reply
  13. ebswift

    Hey, this is awesome! I went from not knowing what an ATmega8 was yesterday to having one programmed today without having to buy an expensive programmer! Some of the comments were very helpful too for getting things working. Thank you, now I can go and get this capacitive humidity sensor working and talking to the raspberry pi.

    Reply
  14. Alexandre

    Hello Kevin
    Following your tuto I succeeded in programming a ATtiny85 using the arduino software.
    The only problem I am faced to is to directly program it from the GUI.
    It is ending with error while executing avrdude:
    linuxspi_gpio_op_wr(): Unable to open file /sys/class/gpio/gpio25/directionavrdude: linuxspi_gpio_op_wr(): Unable to open file /sys/class/gpio/gpio25/direction
    But, if I reexecute the avrdude command behind a sudo, all works well and the AVR is set and running as expected.

    Hence my question:
    what do I need to set-up on the raspberry pi system in order to be allowed to run avrdude from any plain (not root) user?
    All my users (including root) stand in the additional “dialout” group, but it is not enough.
    Could you please give me an hint?
    Regards

    Reply
  15. Kit

    Hi,
    I’m trying to make this work with beaglebone. But, I can’t build the source of your avrdude. I got stuck with flex. I have flex installed already as well as the other requirements.

    /bin/sh ./ylwrap lexer.l lex.yy.c lexer.c — flex
    flex: fatal internal error, exec failed
    make: *** [lexer.c] Error 141

    do you have any idea on this? I’m thinking that we are using different flex or something.

    thanks

    Reply
    1. admin Post author

      That could be the case, although they generally try to make things backwards compatible. What does “flex -V” say (it should give you your version number)?

      Reply
      1. Kit

        Hi,
        Thanks for the reply. The Flex version on my beaglebone black is 2.5.35. Have you tried this on beaglebone? I’m using Angstrom Linux from the Beaglebone site. The september something version.

        Reply
        1. admin Post author

          Sadly, I do not have access to a beaglebone to try this on. Have you tried a different distribution?

          Reply
  16. Damgot

    I try to run avrdude on my own board (with a ARM9 CPU) to program a ATtiny44 but I have the following message :

    avrdude -c linuxspi -p t44 -P /dev/spidev1.0
    avrdude: error: Unable to send SPI message

    If I put a scope on the SPI bus, and run avrdude command I have nothing on the bus. But if I do echo “Hello” > /dev/spidev1.0, I can see my “hello” on the bus.

    Reply
    1. admin Post author

      Have you tried running the command under sudo? I’m not sure it would help, but its worth a try. What does ls -l say about /dev/spidev1.0? Also, as a FYI, that error will be shown when ioctl reports that it did not send the same number of bytes that avrdude wanted it to send (see linuxspi.c line 128).

      Reply
  17. Josef Larsson

    Many thanks. Managed to fix my corrupted bootloader on my Printrboard thanks to this guide (using a bi-directional level converter).

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current month ye@r day *