How to use GPIO programmer on the Raspberry Pi to flash AVR chip

Hi guys,

I have a GrovePi attached to the Raspberry Pi, which I want to flash remotely through a remote agent. Thing is, the GrovePi can only be flashed with the gpio programmer, which unfortunately doesn’t seem to be an option when triggering the flashing process within PIO IDE. When I choose the gpio option within PIO IDE I get:

avrdude: Can't find programmer id "gpio"

Also, there’s a custom set of fuses I need to set and there isn’t much on your documentation to help me understand how I can override the defaults within an extra_script.py file.

Just so you know, this is how I flash the firmware onto the GrovePi using a Raspberry Pi:

avrdude -c gpio -p m328p -U lfuse:w:0xFF:m
avrdude -c gpio -p m328p -U hfuse:w:0xDA:m
avrdude -c gpio -p m328p -U efuse:w:0x05:m
avrdude -c gpio -p m328p -U flash:w:grove_pi_firmware.hex

And the configuration file for gpio programmer, which I’ve extracted from /etc/avrdude.conf, looks like this:

programmer
  id    = "gpio";
  desc  = "Use sysfs interface to bitbang GPIO lines";
  type  = gpio;
  reset = 8;
  sck   = 11;
  mosi  = 10;
  miso  = 9;
;

I looked over other posts here on this community, but it didn’t help me understand what needs to be done and how. Could anyone show me exactly what is needed to get this going?

Thank you!

I’ve been playing with it a bit more and I changed the programmer to a custom one and it still doesn’t work.

platformio.ini file looks like this:

[env:env_custom_grovepi_uploader]
platform = atmelavr
board = uno
framework = arduino
; upload_port = /dev/ttyAMA0
upload_protocol = gpio
extra_scripts = extra_script.py

And extra_script.py script is this one:

from os.path import join
from SCons.Script import DefaultEnvironment

env = DefaultEnvironment()

env.Replace(
    MYUPLOADERFLAGS=[
        "-v",
        "-p", "$BOARD_MCU",
        "-C", "/etc/avrdude.conf"
        "-c", "$UPLOAD_PROTOCOL",
        "-b", "$UPLOAD_SPEED",
        "-U", "lfuse:w:0xFF:m",
        "-U", "hfuse:w:0xDA:m",
        "-U", "efuse:w:0x05:m"
     ],
    UPLOADHEXCMD='"$UPLOADER" $MYUPLOADERFLAGS -U flash:w:$SOURCES:i'
)

Next up, when I click on uploading to the board remotely, I get the following error:

Uploading firmware remotely
Upon execvpe platformio ['platformio', '--force', 'run', '-d', '/home/pi/.platformio/remote/projects/grovepi-6f9dc7ed31469c2c3401534a9e4085c14371614d', '-t', 'upload', '-t', 'nobuild', '--d
isable-auto-clean'] in environment id 1971024352
:Traceback (most recent call last):
  File "/home/pi/.platformio/packages/contrib-pysite/twisted/internet/process.py", line 445, in _fork

    environment)
  File "/home/pi/.platformio/packages/contrib-pysite/twisted/internet/process.py", line 523, in _execChild
    os.execvpe(executable, args, environment)
  File "/usr/lib/python2.7/os.py", line 355, in execvpe
    _execvpe(file, args, env)
  File "/usr/lib/python2.7/os.py", line 382, in _execvpe
    func(fullname, *argrest)
OSError: [Errno 2] No such file or directory

Also, it seems like I cannot import from SCons.Script import DefaultEnvironment on the host machine (my laptop) on which the PIO IDE is installed. And I also have installed scons==3.0.1 package on the virtual environment of the IDE.

Does anyone know what I’m missing?

Thank you!