avrdude on RasPi Zero only works once

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I'm trying to set a Raspberry Pi Zero up as a mobile dev tool.

After a few false starts I have everything set up and I can program an ATTiny85 via SPI and the GPIO pins.

Once - it will flash the program once, and then fail with the error:

avrdude: verification error, first mismatch at byte 0x0000<br />
    0xff != 0x0e<br />
avrdude: verification error; content mismatch

If I reboot the Pi, it will work again, but still only once until another reboot.

All of my avrdude config files are default, I have a 1uF capacitor between GND & VCC, and 10k resistor between VCC and RESET on the ATTiny, calling avrdude with this:

<br />
$ sudo avrdude -P /dev/spidev0.0 -c linuxspi -p t85 -U flash:w:blinky.hex<br />

Any ideas?

Thanks
-Mike

This topic has a solution.
Last Edited: Mon. May 7, 2018 - 04:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there a way to do a devfs reset on just spidev?

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not sure, but I tried disabling it completely with raspi-config, and then re-enabling it and that had no effect - I got a different error after I disabled it (Unable to open SPI port..., as expected) and then the same error as before when I re-enabled it.

 

I also tried lsmod to find the spi module name (spidev), then rmmod spidev to remove it, mod probe spidev to put it back (which I think is the same as what raspi-config does anyway), still to no avail.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MalphasWats wrote:
I'm trying to set a Raspberry Pi Zero up as a mobile dev tool.
Also as headless and an AVR for real-time.

Have you considered Android?

Reasons :

  • AVRDUDE has been ported to Android
  • One or more threads here about AVR GCC toolchain on Android
  • Android apps on Chrome OS

 

YouTube

Zflasher AVR + USBtiny

https://www.youtube.com/watch?v=-Gh5i7FFv9k (1m44s)

Android app on AppBrain

ZFlasher AVR

https://www.appbrain.com/app/zflasher-avr/ru.zdevs.zflasheravr

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, unfortunately I'm all in on Apple - iPhone, iPad & iMac. Terminal app on all and a spare raspiPi. I'm trying to move away from the Arduino IDE and figured I'd set up a self contained system. This particular problem is particularly frustrating because it works! But then it doesn't :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

macOS -

AVRDUDE's on macOS, Microchip has an AVR GCC toolchain on macOS, and there's embedXcode and Microsoft Visual Studio Code with an AVR extension.

oh ... iMac is the desktop Mac.

 

iOS - that would be completely mobile.  May be worthwhile to search for AVR apps.

 

http://savannah.spinellicreations.com/avrdude/AtmelICE-kext-for-High-Sierra.readme.txt via http://download.savannah.gnu.org/releases/avrdude/

http://distribute.atmel.no/tools/opensource/Atmel-AVR-GNU-Toolchain/3.6.1/

https://embedxcode.weebly.com/

AVR Studio On Mac & Linux?

by ka7ehk

https://www.avrfreaks.net/forum/avr-studio-mac-linux

 

Edit: oh

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Sun. May 6, 2018 - 10:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MalphasWats wrote:
This particular problem is particularly frustrating because it works! But then it doesn't :(
Willing to move to linux gpio?

Reasons :

  • linuxspi may not be operated by many AVRDUDE operators (linuxspi may be defective)
  • linux gpio fixes in AVRDUDE

 

forthcoming AVRDUDE 6.4 :

http://svn.savannah.gnu.org/viewvc/avrdude/trunk/avrdude/NEWS?revision=1425&view=markup

...

* Bugfixes:
42 bug #47550: Linux GPIO broken

...

 

"Dare to be naïve." - Buckminster Fuller

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Solved it!

 

My hinky breadboard/jumper wires set up wasn't working at whatever default clock speed avrdude uses. I slowed it down with the -b parameter and it now works reliably (I only wish I'd tried this before I tried rebuilding the raspberry pi from a fresh image, but hey ho).

 

-b 19200 was too fast, but -b 14400 worked ok (I started at -b 2400 and worked my way up until it stopped working!)

 

so this works:

 

$ sudo avrdude -b 14400 -P /dev/spidev0.0 -c linuxspi -p t85 -U flash:w:blinky.hex

 

I have no idea why it would work once after reboot and then not again, but I'm not actually that clever anyway so it's not surprising.

 

Thank you for your efforts :)

Last Edited: Mon. May 7, 2018 - 04:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well done!

... and good to know (didn't know linuxspi existed)

MalphasWats wrote:
I slowed it down with the -b parameter and it now works reliably ...
SPI has very short rise and fall times so ground bounce and overshoot are likely; some AVR ISP have a 100 ohm resistor between the ISP AVR and the target AVR.

Another concern is a possible mis-match between the Raspberry Pi I/O voltage and the target AVR's VCC; for CMOS-to/from-CMOS, some mis-match is OK but not a lot.

Might consider adding a level translator between the Raspberry Pi and the AVR.

 

https://www.olimex.com/Products/AVR/Programmers/AVR-ISP-MK2/resources/AVR-ISP-MK2_sch.pdf (top center)

SparkFun Electronics

Level Shifters

https://www.sparkfun.com/categories/361

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks. I was thinking of getting a little board made up for this so I'll look into adding some 'protective' features. It probably doesn't help that the whole thing is breadboard and jumper wires at the moment!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MalphasWats wrote:
I was thinking of getting a little board made up for this so I'll look into adding some 'protective' features.
If I read it correctly, Raspberry Pi I/O is at 3.3V so a 5V AVR would be a problem.

MalphasWats wrote:
It probably doesn't help that the whole thing is breadboard and jumper wires at the moment!
There are Pi Hat protoboards.

 


Raspberry Pi Documentation

GPIO

https://www.raspberrypi.org/documentation/hardware/raspberrypi/gpio/README.md

...

 

Overview

...

Each of the three banks has its own VDD input pin. On Raspberry Pi, all GPIO banks are supplied from 3.3V. Connection of a GPIO to a voltage higher than 3.3V will likely destroy the GPIO block within the SoC.

...

Schmartboard, Inc.

Schmartboard

Raspberry Pi - Pi Zero Boards

http://schmartboard.com/raspberry-pi/pi-zero/

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

MalphasWats wrote:
It probably doesn't help that the whole thing is breadboard and jumper wires at the moment!

There are Pi Hat protoboards.

 

I bought one! And I soldered it all up and it works a treat - I experimented with the baud rate and it will mostly work at the default 400,000, but it needs the chip to be plugged into the socket really firmly and I always bend the pins taking it out again. 200,000 seems to be a little less picky and is still WAY faster than 14,000.

 

I've developed a new problem though. I've also since made a nice Makefile for my project and as part of that I realised that avrdude needed to run as sudo in order to access /dev/spidev0.0 and I wasn't completely comfortable hiding a sudo command in a Makefile, so I chmod'd /dev/spidev0.0 to give read/write to all users (before I realised I could have just added my user to the spi group).

 

This works, but only the second time I run avrdude. The first time I run it, I get this error:

 

avrdude: linuxspi_gpio_op_wr(): Unable to open file /sys/class/gpio/gpio25/direction

 

if I run it again, it works fine, then the next time I run it, it gives the error again. /sys/class/gpio/gpio25/direction doesn't exist, nor does the folder gpio25, so I assume it is being created and deleted by avrdude each run, so I set the permissions for /sys/class/gpio to give read/write access to all, but something changed it back again so that doesn't work. It's owned by root/gpio so I've made sure my user is in the gpio group but that didn't help.

 

Any ideas welcome, my linux foo is only yellow/gold belt, so I'm all out of 'em (well, I thought I could put the avrdude command in my Makefile twice, but that felt like a Bad idea).

 

EDIT: I've also just noticed that /dev/spidev0.0 has also had its permissions reset. Changing them back to 0666 hasn't helped.

Last Edited: Sat. May 12, 2018 - 08:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MalphasWats wrote:
... and I always bend the pins taking it out again.
DIP extractor, pull straight up, DIP pin straightener when goof the pull.

Consider a ZIF socket if programming "a lot".

fyi, late model AVR are SMD only; consider replacing DIP with SOIC as these also have sockets.

MalphasWats wrote:
if I run it again, it works fine, then the next time I run it, it gives the error again.
A guess is a defect in AVRDUDE; review its source code to confirm or deny the defect.

 


https://www.jameco.com/z/08-609-HT103A--IC-Extractor-DIP-Tool_16838.html (browse up one level to see the pin straightener)

http://www.proto-advantage.com/store/index.php?cPath=3600 (Socket to DIP) (PLCC, SOIC)

https://www.mouser.com/Connectors/IC-Component-Sockets/_/N-211lk?Keyword=Connectors+IC+Component+Sockets&FS=True (Product menu, scroll to ZIF)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rather than futz with the raspi's gpio, just get a cheapy usb isp adapter (usbasp). Level translation taken care of. Problem solved for probably $2 usd.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

At the risk of waking zombie threads, a solution to this (without rebuilding avrdude) is to export gpio25 before programming:

 

$ [ -d /sys/class/gpio/gpio25 ] || echo 25 >/sys/class/gpio/export
$ avrdude -P /dev/spidev0.0 -c linuxspi -p m164p

 

Good luck!

Chris