6.2.1 DFU over Serial Using Python Script

This chapter provides the details about the prerequsites for performing DFU over serial using python scripts.
  • Hardware – PIC32WM-BW1 Curiosity Board

The following tables detail the prerequisites for the DFU over serial using Python scripts.

Table 6-1. OTA BLE Sensor Project and Precompiled BLE Sensor Image
Item DescriptionVersionFile Location/Name
OTA Bluetooth® LE sensor (ota_ble_sensor) project (current user application)1.0.0.0wireless_apps_pic32_bw1\apps\ble\peripheral\ota_ble_sensor\firmware\
Table 6-2. Precompiled Bootloader Hex Files Table
Bootloader Trigger ModePrecompiled Hex File Location
GPIO Trigger mode DFUwireless_apps_pic32_bw1\apps\bootloader\bootloader_GPIO\precompiled_hex\bootloader_gpio.X.production.hex
Timer Based Trigger mode DFUwireless_apps_pic32_bw1\apps\bootloader\bootloader_timer\precompiled_hex\bootloader_timer.X.production.hex
Note: Ensure to have Python version v3.12.7 only and libraries like pyserial, numpy must be pre-installed.
Table 6-3. Python Script Files for DFU Bootloader Modes
Bootloader Trigger ModeRequired Python ScriptsDefault Python Script Location
GPIO Trigger mode DFUflash_load_2ndSlot.py and progctrl.pywireless_apps_pic32_bw1\apps\utilities\pic32wm-bw1\dfuPythonScripts
Timer Based Trigger mode DFUflash_load_2ndSlot_timer.py and progctrlOptimized.pywireless_apps_pic32_bw1\apps\utilities\pic32wm-bw1\dfuPythonScripts

Running Python Script for DFU (Device Firmware Update)

  • For GPIO Trigger mode DFU, the user must execute the following command:
    python flash_load_2ndSlot.py -i image.bin
    
  • For Timer Based Trigger mode DFU, the user must execute the following command:
    python flash_load_2ndSlot_timer.py -i image.bin
  • The user application generates the binary file image.bin, which represents a new user image, using MPLAB® X IDE. Depending on the user’s application, the file name can vary, and it can include a path name before the file name.

Preparation: Creating and Programming the Unified Image

The following are the steps to operate DFU over serial and program a new user image using the Bootloader.
Note: Before the DFU operation, create and program the unified image containing the bootloader and current user application.
  1. Open the ota_ble_sensor project in MPLAB® X IDE.
  2. Click on “Loadables” to verify that the bootloader precompiled hex file is added into the project.
    Figure 6-27. Verify Loadable File in ota_ble_sensor Project
    Tip: For Timer Based Trigger mode DFU, remove the GPIO bootloader hex and add bootloader_timer.X.production.hex as the loadable file.
  3. Click Clean and Build Main Project to build the unified image:
    1. This action creates a unified image ota_ble_sensor.X.production.signed.unified.hex
    Tip: This action creates another binary file named ota_ble_sensor.X.production.signed.bin at the same time. The bootloader uses this binary file as the target image file for DFU. However, in this demonstration, the user uses another precompiled binary file as the target image, since that image contains a different firmware version to indicate that DFU is successful.
    Figure 6-28. Build Unified Image
  4. Once the code building is complete, click the Make and Program Device Main Project icon on the MPLAB X IDE tools bar to program the device. The unified image will be programmed into the PIC32WM-BW1 Curiosity Board.
    Figure 6-29. Program Unified Image
  5. Now that the board is ready, the user uses DFU over serial to upgrade it to a new image ota_ble_sensor.X.production.signed.bin.
    Note: User needs to generate ota_ble_sensor.X.production.signed.bin with updated firmware. To do this, change #define BLE_SENSOR_VERSION to “1.0.0.1” in app.c, compile and build the project. The file will be generated in ota_ble_sensor/firmware/ota_ble_sensor.X/dist/default/production/ota_ble_sensor.X.production.signed.bin. This .bin file is the updated firmware bin file.

For more details on creating unified image, refer to the Add Bootloader as Lodable File/Project to Create Unified Image section of the Configure User Application to Use Bootloader from Related Links.