mraardvark / pyupdi

Python UPDI driver for programming "new" tinyAVR and megaAVR devices
MIT License
210 stars 73 forks source link

Key not accepted programming ATtiny1614 with FTDI serial adapter #59

Closed vermeer closed 4 years ago

vermeer commented 4 years ago

I've got some functionality from the library; I can read info and fuses:

$ python3 pyupdi.py -d tiny1614 -c /dev/ttyUSB0 -fr
Device info: {'family': 'tinyAVR', 'nvm': 'P:0', 'ocd': 'D:0', 'osc': '3', 'device_id': '1E9422', 'device_rev': '0.0'}
Fuse:Value
0:0x00
1:0x00
2:0x02
3:0xFF
4:0x00
5:0xF6
6:0x07
7:0x00
8:0x00
9:0xFF
10:0xC5

But when I go to actually flash my device, it either errors out with Can't decode 0xB6 in position 33: invalid start byte:

$ python3 pyupdi.py -d tiny1614 -c /dev/ttyUSB0 -e -b 9600 -f ./image.elf 
Device info: {'family': 'tinyAVR', 'nvm': 'P:0', 'ocd': 'D:0', 'osc': '3', 'device_id': '1E9422', 'device_rev': '0.0'}
Traceback (most recent call last):
  File "pyupdi.py", line 182, in <module>
    _main()
  File "pyupdi.py", line 109, in _main
    if not _process(nvm, args):
  File "pyupdi.py", line 134, in _process
    return _flash_file(nvm, args.flash)
  File "pyupdi.py", line 142, in _flash_file
    data, start_address = nvm.load_ihex(filename)
  File "/home/kevinv/Documents/Boeing 6652 IPSS/pyupdi/pyupdi/updi/nvm.py", line 168, in load_ihex
    ih.loadhex(filename)
  File "/home/kevinv/.local/lib/python3.7/site-packages/intelhex/__init__.py", line 210, in loadhex
    for s in fobj:
  File "/usr/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 33: invalid start byte

or if I enable verbose output, it sits in a loop doing

$ python3 pyupdi.py -d tiny1614 -c /dev/ttyUSB0 -e -b 9600 -f ./image.elf -v
....
INFO:phy send 2 bytes
INFO:phy data:  : [0x55, 0x8b]
INFO:phy receive : [0x82]
INFO:app Wait for NVMPROG
INFO:link LDCS from 0x0B

indefinitely. When I hit ctrl-C to break out of this, it shows me Exception: Key not accepted.

What am I doing wrong? Do I have the wrong microcontroller configured in my compiler when I build the ELF file?

vermeer commented 4 years ago

Figured it out: pyupdi needs a hex file, not an ELF file. Would be nice if there was a warning when you pass in a filename that doesn't end in .hex, but it's working great when I use it right!