3.1 Python Script Operation
The example Python script uploads an application hex file to a device running the
bootloader example. This is achieved using the Xplained Pro Embedded Debugger as a
bridge between the device and the PC. For each byte sent, the same value is expected in
return to confirm that the data transfer was successful. The bootloader expects enough
data to fill APPCODE. If the hex file does not contain enough data to do so,
0xff
will be sent until APPCODE is filled. Figure 3-1 shows how this works.
To run the script, the following arguments are required:
- Hex file to upload. Include path if file is not in the same folder.
- Total Flash size. This is needed
to calculate byte array size and add
0xff
padding to unused codespace. - Virtual COM port used for UART
communication.
- This is listed in the
Device Manager on a Windows® PC. For an ATtiny817 Xplained Pro, it is listed as
EDBG Virtual COM Port (COMxxx).Note: The Virtual COM port is connected to USART pins (PB2-TxD and PB3- RxD) on the ATtiny817 device on the board.
- This is listed in the
Device Manager on a Windows® PC. For an ATtiny817 Xplained Pro, it is listed as
EDBG Virtual COM Port (COMxxx).
- Baud rate used. The default baud rate used by the example bootloader is 115200.
COM130
,
with a total Flash size of 8 KB, running the script looks like this when uploading the
release version of the example application:
python tiny_uploader.py ./App/Release/App.hex 8192 COM130 115200
c:\[your_path]>python tiny_uploader.py ./App/Release/App.hex 0x2000 COM130 115200
Uploading 7936 bytes...
100.00%
OK
The
following type of message appears if the upload fails. In this example, it is due to the
Virtual COM port returning 0x00
after a communication
timeout:Uploading 7936 bytes...
Failed at address 0x0100
Value 0x00 echoed, expected 0x19
Python Requirements
The script is written to support Python 2.7.13 and 3.5.2, and it will most likely run without error on later versions as well. Download Python from www.python.org/downloads/ or use your favorite Python distribution.
intelhex
, for parsing hex files.pyserial
, for serial communication.future
, for compatibility with both Python 2 and 3
python -m pip install -U future pyserial intelhex
This
command can also be used to upgrade the modules to the latest version.