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 1 shows how this works.

Figure 1. Python Script Flowchart

To run the script, the following arguments are required:

  1. Hex file to upload. Include path if file is not in the same folder.
  2. Total Flash size. This is needed to calculate byte array size and add 0xff padding to unused codespace.
  3. 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).
      Figure 2. mEDBG Virtual COM Port
      Note: The Virtual COM port is connected to USART pins (PB2-TxD and PB3- RxD) on the ATtiny817 device on the board.
  4. Baud rate used. The default baud rate used by the example bootloader is 115200.
For an ATtiny817 Xplained Pro connected to port 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
Note: Make sure to put the device in Bootloader mode before starting the script. This is done by pressing SW1 while powering or resetting the ATtiny817 Xplained Pro.
After a successful application upload, the command window may look like this:
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 https://www.python.org/downloads/ or use your favorite Python distribution.

In addition to Python, these modules need to be installed:
  • intelhex, for parsing hex files.
  • pyserial, for serial communication.
  • future, for compatibility with both Python 2 and 3
The following command will install the latest version of the modules, with dependencies, from the Python Packaging Index.
python -m pip install -U future pyserial intelhex
This command can also be used to upgrade the modules to the latest version.