项目作者: zabereer

项目描述 :
SPI loader running on Arduino Uno using SPI to load code onto other AVR chips (ATtiny85)
高级语言: C++
项目地址: git://github.com/zabereer/SPI_AVR_loader.git
创建时间: 2016-05-02T17:45:22Z
项目社区:https://github.com/zabereer/SPI_AVR_loader

开源协议:MIT License

下载


SPI_AVR_loader

SPI loader running on Arduino Uno using SPI to load code onto other AVR chips (like ATtiny85)

This code runs on an Arduino Uno and can be used to use SPI to program another AVR device.
I wrote this to program Adafruit Trinket (ATtiny85) devices from Linux.

It depends on Arduino-Makefile (https://github.com/sudar/Arduino-Makefile) to be present in an adjacent directory as this project.
The Uno should be connected to a target AVR device as described by https://www.arduino.cc/en/reference/SPI
It uses the serial interface to present a menu which can be used to read and modify the target device fuse bytes
and backup or load a new program image in I8HEX format (https://en.wikipedia.org/wiki/Intel_HEX) onto the device.

Any Arduino project build with the Arduino-Makefile will have an I8HEX file in its output build directory.
This file can be loaded onto a target device via the serial output menus from the Uno using miniterm.py:

Wiring

ISP

  1. Connections when using Arduino UNO as ISP for Adafruit Trinket
  2. +===============+===============+===============+
  3. | Trinket | Arduino Uno | SPI (target) |
  4. +===============+===============+===============+
  5. | VBAT | 3V / 5V | Vcc |
  6. +---------------|---------------|---------------+
  7. | GND | GND | GND |
  8. +---------------|---------------|---------------+
  9. | RST | #10 | SS |
  10. +---------------|---------------|---------------+
  11. | #0 | #11 | MOSI |
  12. +---------------|---------------|---------------+
  13. | #1 | #12 | MISO |
  14. +---------------|---------------|---------------+
  15. | #2 | #13 | SCK |
  16. +---------------|---------------|---------------+

Also see the AVR ATtiny85 datasheet section 20.5 for more details.

High voltage serial programming

Use this only to reset fuses of a bricked chip or chip erase. The pins were chosen to match the SPI pins as closely as possible to avoid having to completely rewire.

  1. Connections for high voltage programming
  2. +===============+===============+===============+
  3. | Trinket | Arduino Uno | HVSP (target) |
  4. +===============+===============+===============+
  5. | VBAT | #9 | Vcc |
  6. +---------------|---------------|---------------+
  7. | GND | GND | GND |
  8. +---------------|---------------|---------------+
  9. | RST |#8 (transistor)| 12V* |
  10. +---------------|---------------|---------------+
  11. | #0 | #11 | SDI |
  12. +---------------|---------------|---------------+
  13. | #1 | #12 | SII |
  14. +---------------|---------------|---------------+
  15. | #2 | #13 | SDO |
  16. +---------------|---------------|---------------+
  17. | #3 | #10 | SCI |
  18. +---------------|---------------|---------------+

External 12V supply on RESET pin is required, ensure an NPN transistor’s base is connected to the Uno pin #8 to control the switching of the 12V to the Trinket’s RESET pin.
The miniterm menu will prompt whether you used an inverted level shifter or not. If inverted then pin #8 will be HIGH to shut off the 12V supply on Trinket’s RESET pin.
Remember resistors on all connections (SDI, SII, SDO, SCI, #8) (1K) and on 12V input source, but not on Vcc. (Depending on 12V source adjust resistor - 10K worked for me using 9V 6LR61 and 3V CR2032).
Also see the AVR ATtiny85 datasheet section 20.6 and 20.7 for more details.

Example use

After uno is wired to Trinket and plugged in.

  1. $ pyserial-miniterm
  2. --- Available ports:
  3. --- 1: /dev/ttyACM0 'ttyACM0'
  4. --- Enter port index or full name: 1
  5. --- Miniterm on /dev/ttyACM0 9600,8,N,1 ---
  6. --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
  7. AVR SPI programmer
  8. === Main menu ===
  9. v - toggle verbose (current N)
  10. s - display device signature
  11. f - read/write fuses
  12. b - read flash (backup) to serial
  13. e - chip erase (sometimes required before load)
  14. l - write flash from serial (load target)
  15. z - zap fuses with high voltage serial programming
  16. f
  17. Failed to enable programming at clock 8000000 - reducing to 4000000
  18. === Fuses ===
  19. r - read fuses
  20. w - write fuses
  21. q - quite fuses menu
  22. r
  23. lock = 0xFF low = 0xF1 high = 0xD5 ext = 0xFE

A device’s image can be backed up using b, and then need to be copied from the output into a file.
To load a file select l and then press Ctrl+T Ctrl+U and enter the filename to load.
Sometimes this only works after a chip erase has been performed with e.

  1. === Main menu ===
  2. v - toggle verbose (current N)
  3. s - display device signature
  4. f - read/write fuses
  5. b - read flash (backup) to serial
  6. e - chip erase (sometimes required before load)
  7. l - write flash from serial (load target)
  8. z - zap fuses using high voltage serial programming
  9. l
  10. Failed to enable programming at clock 8000000 - reducing to 4000000
  11. CPU ATtiny85
  12. Paste image below or upload hex file
  13. --- File to upload: blinker_trinket/build-trinket3/blinker_trinket_.hex

Example of high voltage serial programming menu - it is quite fiddly to use, but in the end I did manage to unbrick an Adafruit trinket by resetting its fuses.

  1. High Voltage fuses reset - don't brick it further
  2. Set to using inverted level shifter on pin 8
  3. i - change to using non-inverted level shifter on pin 8
  4. k - modify lock fuse for next write
  5. l - modify low fuse for next write
  6. h - modify high fuse for next write
  7. x - modify ext fuse for next write
  8. d - crude delay loop iterations - set to 0x10
  9. r - read fuses (will prompt to connect 12V)
  10. w - write fuses (will prompt to connect 12V)
  11. e - chip erase (will prompt to connect 12V)
  12. q - quite high voltage fuses reset menu
  13. ! DO NOT connect 12V source yet !
  14. About to read fuses using high voltage
  15. Pin #8 set to HIGH to disable external 12V source
  16. Connect external 12V power source now
  17. Press y to continue, n to abandon