Burn Bootloader to ATTiny85 via ArduinoAsISP

Hello, PlatformIO Pipz! nice to meet your community!
I use PlatformIO CLI and i have a question: how can i burn a bootloader to my ATTiny85? The clock on Tiny runs very slow, i need to flash it first, that Tiny runs properly.
Thanks, guys!

Hey :slight_smile:
I don’t remember where, but I already explained it. Can’t find :frowning: Let’s start from the beginning.

Could you burn bootloader with Arduino IDE?

Yes, but i want to use only the PlatformIO for all my projects without to installing Arduino IDE. Therefore i am here :slight_smile:

I understand. We need Arduino IDE to understand which commands need to run and with wich flags/options. Please go to Arduino IDE settings and enable verbose mode for build/upload operation. Then, you will see the full log. Please paste it on http://pastebin.com and share URL here.

Thanks.

here is the verbose output during upload via Arduino nano (as ISP Programmer) to ATTiny85
p62Z3sKc

Thanks. Are you familiar with Python?

yes, i hope i have enough knowledge about low level stuff as a designer :stuck_out_tongue:

Can your help me with this problem, please?

  1. Check advanced extra scripting and custom upload tool: Redirecting...

You need to create extra script that defines new target. Let’s name it as uploadboot:

extra_script.py

Import("env")

env.Replace(
    SETFUSECMD='$UPLOADER $UPLOADERFLAGS -P $UPLOAD_PORT -b $UPLOAD_SPEED -Ulock:w:0xFF:m -Uefuse:w:0xFF:m -Uhfuse:w:0xD7:m -Ulfuse:w:0xE2:m',
    UPLOADBOOTCMD='$UPLOADER $UPLOADERFLAGS -P $UPLOAD_PORT -b $UPLOAD_SPEED -Uflash:w:$SOURCES:i -Ulock:w:0xFF:m'
)

bootloader_path = "/Users/antonkluev/Library/Arduino15/packages/ATTinyCore/hardware/avr/1.1.1/bootloaders/empty/empty_all.hex"
uploadboot = env.Alias(
    "uploadboot", bootloader_path,
    [env.VerboseAction(env.AutodetectUploadPort, "Looking for upload port..."),
     env.VerboseAction("$SETFUSECMD", "Setting fuses"),
     env.VerboseAction("$UPLOADBOOTCMD", "Uploading bootloader $SOURCE")])
AlwaysBuild(uploadboot)

platformio.ini

[env:burn_boot]
platform = atmelavr
framework = arduino
board = <BOARD_ID>
upload_speed = 19200
extra_scripts = extra_script.py

Burn bootloder

pio run -t uploadboot

omg, you are the greatest! i will test it on weekend, and then i will tell you if it works…
And once again, thanks for such great work, i very appreciate it!

1 Like

i did exactly as you said, but i get everytime a problem with atmelavr platform, that is currently not available:

Please wait while upgrading PlatformIO ...
PlatformManager: Installing atmelavr
Warning! Package Mirror: Got an unrecognized status code '404' when downloaded https://github.com/platformio/platform-atmelavr/archive/archive/v1.0.1.tar.gz
Looking for the another mirror...
Error: Can not install 'atmelavr' with version requirements '*' for your system 'darwin_x86_64'

Thanks! I’ve just fixed it. Try again.

It uploads but makes no effect :cry:

[env:85.boot]
board           = attiny85
extra_script    = ./bootloader/extra_script.py
upload_port     = /dev/cu.wchusbserial1410
upload_speed    = 19200
board_f_cpu     = 8000000L
platform        = atmelavr
upload_protocol = stk500v1
framework       = arduino
upload_flags    = -P$UPLOAD_PORT -b$UPLOAD_SPEED
targets         = program



❱ pio run -e 85.boot -v
[Sun Sep  4 01:01:54 2016] Processing 85.boot (upload_protocol: stk500v1, framework: arduino, upload_flags: -P$UPLOAD_PORT -b$UPLOAD_SPEED, board_f_cpu: 8000000L, platform: atmelavr, upload_speed: 19200, board: attiny85, extra_script: ./bootloader/extra_script.py, upload_port: /dev/cu.wchusbserial1410, targets: program)
-----------------------------------------------------------------------------------------------------
Collected 25 compatible libraries
Looking for dependencies...
Project does not have dependencies
BeforeUpload(["program"], [".pioenvs/85.boot/firmware.hex"])
avrdude -v -p attiny85 -C "/Users/antonkluev/.platformio/packages/tool-avrdude/avrdude.conf" -c stk500v1 -P/dev/cu.wchusbserial1410 -b19200 -U flash:w:.pioenvs/85.boot/firmware.hex:i

avrdude: Version 6.0.1, compiled on Jan 15 2015 at 12:42:51
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

System wide configuration file is "/Users/antonkluev/.platformio/packages/tool-avrdude/avrdude.conf"
User configuration file is "/Users/antonkluev/.avrduderc"
User configuration file does not exist or is not a regular file, skipping

Using Port                    : /dev/cu.wchusbserial1410
Using Programmer              : stk500v1
Overriding Baud Rate          : 19200
AVR Part                      : ATtiny85
Chip Erase delay              : 400000 us
PAGEL                         : P00
BS2                           : P00
RESET disposition             : possible i/o
RETRY pulse                   : SCK
serial program mode           : yes
parallel program mode         : yes
Timeout                       : 200
StabDelay                     : 100
CmdexeDelay                   : 25
SyncLoops                     : 32
ByteDelay                     : 0
PollIndex                     : 3
PollValue                     : 0x53
Memory Detail                 :

Block Poll               Page                       Polled
Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom        65    12     4    0 no        512    4      0  4000  4500 0xff 0xff
flash         65     6    32    0 yes      8192   64    128 30000 30000 0xff 0xff
signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00

Programmer Type : STK500
Description     : Atmel STK500 Version 1.x firmware
Hardware Version: 2
Firmware Version: 1.18
Topcard         : Unknown
Vtarget         : 0.0 V
Varef           : 0.0 V
Oscillator      : Off
SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.09s

avrdude: Device signature = 0x1e930b
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF
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 ".pioenvs/85.boot/firmware.hex"
avrdude: writing flash (864 bytes):

Writing | ################################################## | 100% 1.88s

avrdude: 864 bytes of flash written
avrdude: verifying flash memory against .pioenvs/85.boot/firmware.hex:
avrdude: load data flash data from input file .pioenvs/85.boot/firmware.hex:
avrdude: input file .pioenvs/85.boot/firmware.hex contains 864 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.23s

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

avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (H:FF, E:DF, L:62)

avrdude done.  Thank you.

==================================== [SUCCESS] Took 6.45 seconds ====================================

Ems… You’ve changed significantly logic. Ok, now you need modified extra_script.py

1

Import("env")

env.Replace(
    SETFUSECMD='$UPLOADER $UPLOADERFLAGS -Ulock:w:0xFF:m -Uefuse:w:0xFF:m -Uhfuse:w:0xD7:m -Ulfuse:w:0xE2:m',
    UPLOADBOOTCMD='$UPLOADER $UPLOADERFLAGS -Uflash:w:$SOURCES:i -Ulock:w:0xFF:m'
)

bootloader_path = "/Users/antonkluev/Library/Arduino15/packages/ATTinyCore/hardware/avr/1.1.1/bootloaders/empty/empty_all.hex"
uploadboot = env.Alias(
    "uploadboot", bootloader_path,
    [env.VerboseAction(env.AutodetectUploadPort, "Looking for upload port..."),
     env.VerboseAction("$SETFUSECMD", "Setting fuses"),
     env.VerboseAction("$UPLOADBOOTCMD", "Uploading bootloader $SOURCE")])
AlwaysBuild(uploadboot)

2

Please remove targets = program line from platformio.ini. Use pio run -t program to upload firmware and pio run -t uploadboot to burn bootloader.

somehow i receiving this error:

❱ pio run -e 85.boot -t uploadboot -v
[Sun Sep  4 21:32:01 2016] Processing 85.boot (upload_protocol: stk500v1, framework: arduino, upload_flags: -P$UPLOAD_PORT -b$UPLOAD_SPEED, board_f_cpu: 8000000L, platform: atmelavr, upload_speed: 19200, board: attiny85, extra_script: ./bootloader/extra_script.py, upload_port: /dev/cu.wchusbserial1410)
------------------------------------------------------------------------------------------
Collected 25 compatible libraries
Looking for dependencies...
Project does not have dependencies
MethodWrapper(["uploadboot"], ["bootloader/empty_all.hex"])
Use manually specified: /dev/cu.wchusbserial1410
avrdude -v -p attiny85 -C "/Users/antonkluev/.platformio/packages/tool-avrdude/avrdude.conf" -c stk500v1 -P/dev/cu.wchusbserial1410 -b19200 -Ulock:w:0xFF:m -Uefuse:w:0xFF:m -Uhfuse:w:0xD7:m -Ulfuse:w:0xE2:m

avrdude: Version 6.0.1, compiled on Jan 15 2015 at 12:42:51
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

System wide configuration file is "/Users/antonkluev/.platformio/packages/tool-avrdude/avrdude.conf"
User configuration file is "/Users/antonkluev/.avrduderc"
User configuration file does not exist or is not a regular file, skipping

Using Port                    : /dev/cu.wchusbserial1410
Using Programmer              : stk500v1
Overriding Baud Rate          : 19200
AVR Part                      : ATtiny85
Chip Erase delay              : 400000 us
PAGEL                         : P00
BS2                           : P00
RESET disposition             : possible i/o
RETRY pulse                   : SCK
serial program mode           : yes
parallel program mode         : yes
Timeout                       : 200
StabDelay                     : 100
CmdexeDelay                   : 25
SyncLoops                     : 32
ByteDelay                     : 0
PollIndex                     : 3
PollValue                     : 0x53
Memory Detail                 :

Block Poll               Page                       Polled
Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom        65    12     4    0 no        512    4      0  4000  4500 0xff 0xff
flash         65     6    32    0 yes      8192   64    128 30000 30000 0xff 0xff
signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00

Programmer Type : STK500
Description     : Atmel STK500 Version 1.x firmware
Hardware Version: 2
Firmware Version: 1.18
Topcard         : Unknown
Vtarget         : 0.0 V
Varef           : 0.0 V
Oscillator      : Off
SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.09s

avrdude: Device signature = 0x1e930b
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF
avrdude: reading input file "0xFF"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.04s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0xFF:
avrdude: load data lock data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lock data:

Reading | avr_read(): error reading address 0x0000
read operation not supported for memory "lock"
avrdude: failed to read all of lock memory, rc=-2

avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (H:FF, E:DF, L:62)

avrdude done.  Thank you.

*** [uploadboot] Error 1
=============================== [ERROR] Took 2.65 seconds ===============================

this is my .ini now

[env:85.boot]
board           = attiny85
extra_script    = ./bootloader/extra_script.py
upload_port     = /dev/cu.wchusbserial1410
upload_speed    = 19200
board_f_cpu     = 8000000L
platform        = atmelavr
upload_protocol = stk500v1
framework       = arduino
upload_flags    = -P$UPLOAD_PORT -b$UPLOAD_SPEED

I copied the “empty_all.hex” to my project folder, to be completly independent from arduino ide and updated the link in “extra_script.py” to “./empty_all.hex”

You personally create the problems for self. I wrote for you valid platformio.ini and extra_script.py. Why did you specify upload_protocol = stk500v1? In any case, you can compare 2 versions. See your Arduino output http://pastebin.com/p62Z3sKc. Where is difference?

PlatformIO

avrdude -v -p attiny85 -C "/Users/antonkluev/.platformio/packages/tool-avrdude/avrdude.conf" -c stk500v1 -P/dev/cu.wchusbserial1410 -b19200 -Ulock:w:0xFF:m -Uefuse:w:0xFF:m -Uhfuse:w:0xD7:m -Ulfuse:w:0xE2:m

Arduino IDE

/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/Users/antonkluev/Library/Arduino15/packages/ATTinyCore/hardware/avr/1.1.1/avrdude.conf -v -pattiny85 -carduino -P/dev/cu.wchusbserial14110 -b19200 -e -Ulock:w:0xFF:m -Uefuse:w:0xFF:m -Uhfuse:w:0xD7:m -Ulfuse:w:0xE2:m

This is puzzle for you. Try to resolve it :blush:

Because im not familiar with the whole logic that happens behind platformio. This is why Platformio exist and should do all this stuff automaticaly, to make the life easer without to learn lowlevel theory, right? I using upload protocol because i use arduino nano for uploading anything to my attiny, i found this in tutorials on your website. If i do not need this part, just say it to me, im not a computer specialist, i am just a dump designer ) I dont know, what actualy happens if i upload something to the chip, therefore i need your help. Sorry if i do something wrong.

what ive done:

  1. include in “platformio.ini” the “extra_script” with the right path? yes
  2. make an “extra_script” with the right path to the “empty_all.hex”? yes
  3. i used -t uploadboot? yes
    everything exact so like you said, excluding the movement of “empty_all.hex” to the root folder of my project
    but all the pathes are correct, and there no errors about wrong pathes.

See Atmel AVR — PlatformIO latest documentation

1 Like