Updating Firmware via USB DFU Based on RT1170
Updating Firmware via USB DFU Based on RT1170 Development Environment Preparing dfu-util Steps to Prepare dfu-util Running the Demo Using Prebuilt Firmware from SDK Using Custom Firmware
Performing microcontroller (MCU) firmware upgrades in the field without the aid of external programming tools is a necessary feature. For MCUs that support USB device controllers, the USB Device Firmware Update (DFU) class offers a solution. the USB_DFU bootloader requires only a PC and a USB cable.
The RT series also provides this feature. In the case of the RT1170, for example, a DFU project is provided in the SDK under the USB class. The project is based on the MCUXpresso IDE. by running the dev_dfu_freertos_cm7 project in the SDK, the RT1170 will be enumerated as a dfu device, and after connecting it to the Host PC via another USB cable, the user can use the “dfu-util” utility to download a firmware to this device.
Development Environment
Software Environment:
SDK Version: 2.15.000
IDE: MCUXpresso IDE
Demo Project: dev_dfu_freertos_cm7
Host Software: dfu-util
Download link: dfu-util
For Windows 64-bit: Download dfu-util-0.9-win64.zip
Hardware Environment:
Board: RT1170-EVKB
Preparing dfu-util
dfu-util is used to download Firmware to a DFU device, but it does not add CRC32 to the Firmware. Since the DFU demo in the SDK verifies the CRC32 to ensure the Firmware written to Flash is free from bit errors, modifications to the dfu-util source code are necessary.
Steps to Prepare dfu-util
Install Dependencies
sudo apt-get build-dep libusb-1.0-0 dfu-util sudo apt-get install gcc-mingw-w64-x86-64
Download dfu-util and libusb Source Code
git clone https://git.code.sf.net/p/dfu-util/dfu-util git clone https://github.com/libusb/libusb.git
Modify CRC Code in Source Modify the dfu_store_file function in dfu_file.c to add CRC32 to the Firmware suffix.
/* write suffix, if any */ if (write_suffix) { uint8_t dfusuffix[DFU_SUFFIX_LENGTH]; dfusuffix[0] = file->bcdDevice & 0xff; dfusuffix[1] = file->bcdDevice >> 8; dfusuffix[2] = file->idProduct & 0xff; dfusuffix[3] = file->idProduct >> 8; dfusuffix[4] = file->idVendor & 0xff; dfusuffix[5] = file->idVendor >> 8; dfusuffix[6] = file->bcdDFU & 0xff; dfusuffix[7] = file->bcdDFU >> 8; dfusuffix[8] = 'U'; dfusuffix[9] = 'F'; dfusuffix[10] = 'D'; dfusuffix[11] = DFU_SUFFIX_LENGTH; /*crc = dfu_file_write_crc(f, crc, dfusuffix, DFU_SUFFIX_LENGTH - 4);*/ dfusuffix[12] = crc; dfusuffix[13] = crc >> 8; dfusuffix[14] = crc >> 16; dfusuffix[15] = crc >> 24; crc = dfu_file_write_crc(f, crc, dfusuffix + 12, 4); }
Build libusb
mkdir -p build cd libusb-1.0.24 ./autogen.sh PKG_CONFIG_PATH=$PWD/../build/lib/pkgconfig ./configure --host=x86_64-w64-mingw32 --prefix=$PWD/../build make make install cd ..
Build dfu-util
cd dfu-util-0.11 ./autogen.sh PKG_CONFIG_PATH=$PWD/../build/lib/pkgconfig ./configure --host=x86_64-w64-mingw32 --prefix=$PWD/../build make make install cd ..
After these steps, the newly built tool will be located in the /build/bin folder.
Open cmd for Windows. Run the following command with the new dfu-suffix.exe and CRC32 will be added to the Firmware.
dfu-suffix.1 exe -a your_Firmware
Running the Demo
Using Prebuilt Firmware from SDK
The SDK provides a prebuilt Firmware binary (dev_hid_mouse_bm.bin) that already includes CRC32. Follow these steps:
Use MCUXpresso IDE to flash the dev_dfu_freertos_cm7 demo to the EVKB board.
Connect the board to the Host PC via USB.
In the USB Device Descriptor, we find the Vendor ID and Product ID:
Run the following command to download the Firmware:
dfu-util.exe -d <your_vid:pid> -D <your_Firmware>
After downloading, the DFU demo will verify the CRC32 and execute the new Firmware in RAM. The device will be enumerated as a USB mouse, moving in a rectangular pattern on the screen.
Using Custom Firmware
When using custom Firmware, ensure that the image is loaded at the correct address (e.g., 0x10000). If the offset is incorrect, the DFU demo will fail to load the Firmware, even if the CRC check passes.
To build and load custom Firmware:
Import the hello_world_cm7 project into MCUXpresso IDE.
In the Managed Linker Script settings, enable "Link application to RAM".
Adjust memory settings to match the DFU project requirements, ensuring ITCM is the first RAM region.
Build the project and generate a binary file.
Use the modified dfu-util tool to append CRC32 to the binary and download it to the board. Verify that the custom Firmware executes correctly.
CRC Added:
New Firmware loaded successfully:
For Chinese version and demo, please check this link: https://www.nxpic.org.cn/module/forum/forum.php?mod=viewthread&tid=803149&fromuid=3253523
View full article