Uploading to AVR using Raspberry Pi GPIO (avrdude GPIO reset)

Please read docs Redirecting...

You need upload_protocol.

I am try with

“upload_protocol = -P /dev/spidev0.0 -c linuxspi -b 10000”

but next error:
avrdude: Can't find programmer id "-P

Do you have any example of upload_protocol?

Thanks

What are you doing? Please read docs and examples below:

upload_protocol = linuxspi
upload_speed = 10000

and etc… See upload_flags

See program examples Atmel AVR — PlatformIO v6.1 documentation

[env:attiny85]
platform = atmelavr
framework = arduino
board = attiny85
board_f_cpu = 1000000
upload_flags = -P$UPLOAD_PORT

upload_protocol = linuxspi
upload_speed = 10000
upload_port = /dev/spidev0.0

and use pio run -t program.

I am try with

upload_flags = -P /dev/spidev0.0
upload_protocol = linuxspi
upload_speed = 10000

I am doing programming attiny85 with Raspberry Pi, similar to

http://www.instructables.com/id/Programming-the-ATtiny85-from-Raspberry-Pi/ in the step 3

Try this

[env:attiny85]
platform = atmelavr
framework = arduino
board = attiny85
board_mcu = t85
board_f_cpu = 1000000
upload_flags = -P$UPLOAD_PORT

upload_protocol = linuxspi
upload_speed = 10000
upload_port = /dev/spidev0.0
extra_script = extra_script.py

However, that is not enough. You need to make software reset. See

sudo gpio -g mode 22 out
sudo gpio -g write 22 0

We have this software reset on other pins for raspduino and emonpi. Nevertheless, you can write custom extra_script and 2 hooks. Do you familiar with Python?

See my answer here

extra_script.py

Place it on the same level as platformio.ini

Import("env")

def _rpi_sysgpio(path, value):
    with open(path, "w") as f:
        f.write(str(value))

def before_upload(source, target, env):
    _rpi_sysgpio("/sys/class/gpio/export", 22)
    _rpi_sysgpio("/sys/class/gpio/gpio22/direction", "out")
    _rpi_sysgpio("/sys/class/gpio/gpio22value", 0)


def after_upload(source, target, env):
    _rpi_sysgpio("/sys/class/gpio/gpio22/direction", "out")
    _rpi_sysgpio("/sys/class/gpio/gpio22value", 1)

env.AddPreAction("program", before_upload)
env.AddPostAction("program", after_upload)

P.S: Need to run with sudo. RPi requires it.

I have the next error:

scons: *** Import of non-existent variable ''env''

Please switch to PlatformIO 3.0 Redirecting...

Done

I have the same error with programmer:

avrdude: Can't find programmer id "linuxspi"

it may be that the version of avrdude of platformio does not support this type of controller

I can use the default avrdude the raspberry ?

You need special avrdude. See instruction that you gave me:

git clone GitHub - kcuzner/avrdude: avrdude with a Linux SPI programmer type
cd avrdude/avrdude
./bootstrap && ./configure && sudo make install

Then, need to force PlatformIO use this avrdude. Please edit extra_script.py and before_upload function

def before_upload(source, target, env):
    _rpi_sysgpio("/sys/class/gpio/export", 22)
    _rpi_sysgpio("/sys/class/gpio/gpio22/direction", "out")
    _rpi_sysgpio("/sys/class/gpio/gpio22value", 0)
    env.Replace(UPLOADER="/path/to/hacked/avrdude")

I am trying with

env.Replace(UPLOADER="/usr/bin/avrdude")

that is the version avrdude default for raspberry pi and linuxspi programmer if it is available, but platformio does not detect it

I’ve just checked and it works for me

pio run -t program -v
[Fri Aug 26 16:22:00 2016] Processing uno (extra_script: extra_script.py, platform: atmelavr, board: uno, framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Framework incompatible library /Users/ikravets/.platformio/lib/MODSERIAL_ID218
Framework incompatible library /Users/ikravets/.platformio/lib/Servo
Framework incompatible library /Users/ikravets/.platformio/lib/TextLCD
More details about "Library Compatibility Mode": http://docs.platformio.org/en/latest/librarymanager/ldf.html#ldf-compat-mode
Collected 37 compatible libraries
Looking for dependencies...
Project does not have dependencies
Current build targets ['program']
before_upload(["program"], [".pioenvs/uno/firmware.hex"])
before_upload
BeforeUpload(["program"], [".pioenvs/uno/firmware.hex"])
/path/to/hacked/avrdude -v -p atmega328p -C "/Users/ikravets/.platformio/packages/tool-avrdude/avrdude.conf" -c arduino -U flash:w:.pioenvs/uno/firmware.hex:i
sh: /path/to/hacked/avrdude: No such file or directory
scons: *** [program] Error 127
  1. Please verify that you use extra_script.py above
  2. You should use program target
  3. The script should contain env.AddPreAction("program", before_upload).
  4. Try uploading with --verbose.

Working, but I have the next error

scons: *** [program] /sys/class/gpio/gpio22value: Permission denied

I am run with sudo

sudo pio run -t program -v

Could you try to restart RPi?

Yes, if not restart i have the next error

scons: *** [program] Device or resource busy

Please try to disable “after” uploading

# env.AddPostAction("program", after_upload)

Same error
scons: *** [program] /sys/class/gpio/gpio22value: Permission denied

Could you flash this board without PIO?

Working!!

My platformio.ini is:

[env:attiny85]
platform = atmelavr
framework = arduino
board = attiny85
board_f_cpu = 800000
upload_flags = -C /etc/avrdude.conf -P$UPLOAD_PORT -b 10000
upload_protocol = linuxspi
upload_port = /dev/spidev0.0
extra_script = extra_script.py

Thanks!

Aaaaa /etc/avrdude.conf :slight_smile: Yep, the config also should be used a correct.

My congrats! That was really interesting for me to resolve this task with PlatformIO. Now I understand how is PlatformIO powerfull :blush: