Python™ Scripts Operation

The provided Python scripts convert the .hex file into a .bin file that contains the application information about the application image (start address and size). Before writing the information area, the script rounds the file size to the multiple of page size (multiple of 512 bytes), by filling the additional area with 0xFF. After that, the information area is completed according to structure described in Application Code Format and inserted at the beginning of .bin file.

The Python script execution continues by uploading the generated .bin file using the communication interface. For this example, the embedded debugger on the Curiosity Nano board is used as a bridge between the microcontroller and the PC. For each byte sent, the same value is expected in return to confirm that the data transfer was successful.

The Python script has the following flowchart:

Figure 1. Python Script Flowchart
To run the script, the following arguments are required:
  1. 1.Hex file to be uploaded. Include the path if the file is not in the same folder.
  2. 2.Maximum Flash size of the microcontroller.
  3. 3.Virtual COM port used for UART communication.
    • This is listed in the Device Manager on a Windows® PC. For an AVR128DA48 Curiosity Nano it is listed as CuriosityVirtual COM Port (COMxxx). For the current example, COM10 port is used.
      Figure 2. Curiosity Virtual COM Port
    Note: The Virtual COM port is connected to the UART pins (PC0-TxD and PC1-RxD) on the AVR128DA48 device on the board.
  4. 4.Baud rate used. The default baud rate used by this example bootloader is 9600.

To run the script for an AVR128DA48 Curiosity Nano connected to port COM10 and of a 128 KB Flash size, the following format must be used:

python AVR-DA_uploader.py AVR_Dx_app_example.hex 0x20000 COM10 9600
Note: Make sure to put the device in Bootloader mode before starting the script. This is done by pressing SW0 while powering or resetting the AVR128DA48 Curiosity Nano board.