Custom variables in plaform.ini?

Hi, I want to burn bootloader on my Arduino Uno with another Arduino Uno. I’ve looked up on how to do it in wiki and there’s written that I should do it with custom upload script, which I’ve done.

I want to flash Optiboot8 and Arduino IDE uses 2 commands to set it up (from what I understand first set’s fuses, unlock bit; second flashes the bootloader and sets lock bit). The problem is that I need some variables for the command (so I can easily change it without going over that long one liner), but I just cannot access them in the command (I can only do $UPLOAD_FLAGS) but if they’re not ones that I can find in the settings, they’re just blank.

Here’s the code:

[env:optiboot_uno]
build_type = debug

platform = atmelavr
framework = arduino

board_build.mcu = atmega328p
board_build.f_cpu = 16000000L
board_hardware.uart = uart0
board_hardware.oscillator = external

board_bootloader.file = /home/jirka/.arduino15/packages/Optiboot/hardware/avr/0.8.0/bootloaders/optiboot/optiboot_atmega328.hex

lfuse = 0xF7
hfuse = 0xDE
efuse = 0x05
lock_bits = 0x2F
unlock_bits = 0x3F

upload_port = /dev/ttyUSB0
upload_speed = 19200
upload_flags = 
    -C
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -v
    -p
    $BOARD_MCU
    -c
    stk500v1
    -P
    $UPLOAD_PORT
    -b
    $UPLOAD_SPEED
    -e
    -Ulock:w:$unlock_bits:m
    -Uefuse:w:$efuse:m
    -Uhfuse:w:$hfuse:m
    -Ulfuse:w:$lfuse:m

upload_flags2 = 
    -C
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -v 
    -p
    $BOARD_MCU
    -c
    stk500v1 
    -P
    $UPLOAD_PORT
    -b
    $UPLOAD_SPEED
    -Uflash:w:$file:i
    -Ulock:w:$lock_bits:m
;upload_command = avrdude "-C/home/jirka/.arduino15/packages/arduino/tools/avrdude/6.0.1-arduino5/etc/avrdude.conf" -v -patmega328p -cstk500v1 -P/dev/ttyUSB0 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xF7:m && avrdude "-C/home/jirka/.arduino15/packages/arduino/tools/avrdude/6.0.1-arduino5/etc/avrdude.conf" -v -patmega328p -cstk500v1 -P/dev/ttyUSB0 -b19200 "-Uflash:w:/home/jirka/.arduino15/packages/Optiboot/hardware/avr/0.8.0/bootloaders/optiboot/optiboot_atmega328.hex:i" -Ulock:w:0x2F:m
upload_command = avrdude $UPLOAD_FLAGS && avrdude $upload_flags2

See documentation. You should be able to refactor it to e.g.

[fuse_data]
lfuse = 0xF7
hfuse = 0xDE
efuse = 0x05
lock_bits = 0x2F
unlock_bits = 0x3F

[env:optiboot_uno]
;...
upload_flags = 
    -C
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -v
    -p
    $BOARD_MCU
    -c
    stk500v1
    -P
    $UPLOAD_PORT
    -b
    $UPLOAD_SPEED
    -e
    -Ulock:w:${fuse_data.unlock_bits}:m
    -Uefuse:w:${fuse_data.efuse}:m
    -Uhfuse:w:${fuse_data.hfuse}:m
    -Ulfuse:w:${fuse_data.lfuse}:m

etc.

1 Like

Thanks, that is exactly what I’m looking for and couldn’t find!
It works now, here’s my working config:

[optiboot_data]
file = /home/jirka/.arduino15/packages/Optiboot/hardware/avr/0.8.0/bootloaders/optiboot/optiboot_atmega328.hex

lfuse = 0xF7
hfuse = 0xDE
efuse = 0x05
lock_bits = 0x2F
unlock_bits = 0x3F

[env:optiboot_uno]
build_type = debug

platform = atmelavr
framework = arduino

upload_port = /dev/ttyUSB0
upload_speed = 19200

board_build.mcu = atmega328p
board_build.f_cpu = 16000000L
board_hardware.uart = uart0
board_hardware.oscillator = external

upload_command = avrdude -C $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf -v -p $BOARD_MCU -c stk500v1 -P $UPLOAD_PORT -b $UPLOAD_SPEED -e -Ulock:w:${optiboot_data.unlock_bits}:m -Uefuse:w:${optiboot_data.efuse}:m -Uhfuse:w:${optiboot_data.hfuse}:m -Ulfuse:w:${optiboot_data.lfuse}:m && avrdude -C $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf -v -p $BOARD_MCU -c stk500v1 -P $UPLOAD_PORT -b $UPLOAD_SPEED -Uflash:w:${optiboot_data.file}:i -Ulock:w:${optiboot_data.lock_bits}:m