1 Reply Latest reply on Nov 2, 2020 9:05 PM by JayakrishnaT_76
      • 1. Re: CX3: Update firmware in SPI flash over HID interface
        JayakrishnaT_76

        Hello,

         

        We have an example project (firmware and host application) developed for this purpose.

         

        This project was implemented by modifying the SDK example CX3_UVC_OV5640. This project can be used to update a firmware that is present in the SPI Flash by using the custom host application that is attached along with this thread. This firmware makes the device enumerate as a composite device with UVC and HID interfaces. The host application communicates with the HID interface and send HID class requests that are handled by the firmware to update the SPI flash contents. The firmware was tested in Denebola kit on a Windows 10 PC using the release build of the host application.

         

        The following changes were made on the SDK example CX3_UVC_OV5640 for adding the firmware update capability:

        1. Modified the cycx3_uvcdscr.c file for adding the descriptors for HID interface. The configuration descriptors were changed, and a new interface descriptor, HID descriptor and Endpoint descriptor were added for enumerating the device with the HID interface.

         

        2. A vendor defined HID interface was used in this project for performing the firmware update. So, a custom report descriptor was written for the custom HID interface. This is shown below:

         

        uint8_t glReportDesc[REPORT_DESCRIPTION_SIZE] = {

        0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined Page 1)

        0x09, 0x01, // USAGE (Vendor Usage 1)

        0xa1, 0x01, // COLLECTION (Application)

        0x09, 0x01, // USAGE (Vendor Usage 1)

        0x15, 0x00, // LOGICAL_MINIMUM (0)

        0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)

        0x85, 0x01, // REPORT_ID (1) - CFG_MODE_FEATURE_ID

        0x09, 0x01, // USAGE (Vendor Usage 1)

        0x75, 0x08, // REPORT_SIZE (8)

        0x95, 0x01, // REPORT_COUNT (1)

        0xB1, 0x00, // FEATURE (Data,Ary,Abs)

        0x85, 0x02, // REPORT_ID (2) - FLASH_READ_SET_ID

        0x09, 0x01, // USAGE (Vendor Usage 1)

        0x75, 0x08, // REPORT_SIZE (8)

        0x95, 0x04, // REPORT_COUNT (4)

        0x91, 0x00, // OUTPUT (Data,Ary,Abs)

        0x85, 0x03, // REPORT_ID (3) - FLASH_READ_GET_ID

        0x09, 0x01, // USAGE (Vendor Usage 1)

        0x75, 0x08, // REPORT_SIZE (8)

        0x96, 0x02, 0x01, // REPORT_COUNT (258)

        0x81, 0x00, // INPUT (Data,Ary,Abs)

        0x85, 0x04, // REPORT_ID (4) - FLASH_WRITE_ID

        0x09, 0x01, // USAGE (Vendor Usage 1)

        0x75, 0x08, // REPORT_SIZE (8)

        0x96, 0x04, 0x01, // REPORT_COUNT (260)

        0x91, 0x00, // OUTPUT (Data,Ary,Abs)

        0x85, 0x05, // REPORT_ID (5) - FLASH_ERASE_ID

        0x09, 0x01, // USAGE (Vendor Usage 1)

        0x75, 0x08, // REPORT_SIZE (8)

        0x95, 0x01, // REPORT_COUNT (1)

        0x91, 0x00, // OUTPUT (Data,Ary,Abs)

        0x85, 0x06, // REPORT_ID (6) - FLASH_ERASE_POLL_ID

        0x09, 0x01, // USAGE (Vendor Usage 1)

        0x75, 0x08, // REPORT_SIZE (8)

        0x95, 0x01, // REPORT_COUNT (1)

        0x81, 0x00, // INPUT (Data,Ary,Abs)

        0xc0 // END_COLLECTION

        };

         

        The same report IDs are used by the custom host application for performing different steps in firmware update process. The host application will send a GET_REPORT or SET_REPORT request by specifying the appropriate report ID. These requests are handled in the firmware for performing the firmware update.

         

        3. The report descriptor should be sent to the host when the host request for it. The snippet of this section of code is shown below:

         

        Make sure that the size of the report descriptor sent above and the size reported in the descriptors are the same to avoid enumeration issues.

         

        4. Handle the HID class requests. For this, the function HandleHIDRequests() will be used. Inside this the report ID will be checked and the corresponding step in the firmware update process is done.

         

        5. The different report IDs and their impact in firmware update process is described below in the order at which they are received by the device:

        a. FLASH_ERASE_ID (Report ID : 5): Upon reception of this, erasing of the flash sectors will be done.

        b. FLASH_ERASE_POLL_ID (Report ID: 6): Upon reception of this, the status of erase command would be checked.

        c. FLASH_WRITE_ID (Report ID: 4). Upon reception of this, an amount of data equal to the Page size of the flash (received from the host application) will be written into the SPI flash. The flash address were the data is to be written also comes from the host application.

        d. FLASH_READ_SET_ID (Report ID: 2). Upon reception of this, the data that was written at a particular flash address will be read and stored in a buffer.

        e. FLASH_READ_GET_ID (Report ID: 3). Upon reception of this, the buffer that holds the flash contents that was obtained by using FLASH_READ_SET_ID will be sent to the host.

        The steps c, d and e will be repeated until the firmware update is complete.

         

        The project along with the host application (including the source code) is added as an attachment to this thread. For updating the firmware in the flash, use the following command after going to the location where the executable for the host application is present.

         

        <Application_Name.exe> <Firmware_Image.img>

         

        The complete implementation of firmware and host application is added as attachments to this thread.

        Passwords for the attachments: cypress

         

        Best Regards,

        Jayakrishna