FTDI Community

General Category => Discussion - Software => Topic started by: TylerTiede on May 03, 2018, 07:25:18 PM

Title: VNC2 Firmware Update over USB
Post by: TylerTiede on May 03, 2018, 07:25:18 PM
Hello Everyone,

I am using the VNC2 chip on a custom board. I have successfully implemented the firmware update and reflasher rom onto the board (the firmware update app code is given below). I have a customer I send updates to regularly, but we have run into a problem where the firmware update will not work occasionally. We have narrowed it down to the call:
       file = fopen("FWUPDATE.ROM", "r");

This command won't open the file because there is not enough heap space left. We believe this to be the case due to it working after reducing a couple stack sizes on our threads. Is there a way to allocate the heap space on startup for the fopen command? Is there a way to separate the firmware update over USB completely from the application code (ie on bootup it selects between update or app code)?

My understanding is when using firmware updates, the ROM size is cut in half. One half is for the current loaded ROM, and the other half is to upload the new firmware. This observation is based on the offset used when flashing the reflasher ROM following AN_159. Is there a way to limit the size of my app ROM file, and if so what is the max ROM file size before the reflasher code gets overwritten? I have also had the problem of my ROM being too large and overwriting the reflasher code. 

void Firmware_Update(void){
   unsigned char status;
   usbhost_device_handle_ex ifDev;
   usbhost_ioctl_cb_t hc_iocb;
   usbhost_ioctl_cb_class_t hc_iocb_class;
   // BOMS device variables
   msi_ioctl_cb_t boms_iocb;
   boms_ioctl_cb_attach_t boms_att;
   // FAT file system variables
   fat_ioctl_cb_t fat_ioctl;
   fatdrv_ioctl_cb_attach_t fat_att;
   FILE *file;
   hBOMS = boms_attach(hUSBHOST_1, VOS_DEV_BOMS);

         if (hBOMS == NULL)
         {
            
         }
         else
         {
            hFAT_FILE_SYSTEM = fat_attach(hBOMS, VOS_DEV_FAT_FILE_SYSTEM);

            if (hFAT_FILE_SYSTEM == NULL)
            {
         
            }
            else
            {
               // lastly attach the stdio file system to the FAT file system
               fsAttach(hFAT_FILE_SYSTEM);

               // now call the stdio runtime functions
            problem---->   file = fopen("FWUPDATE.ROM", "r");

               if (file == NULL)
               {
         
               }
               else
               {
            
                  //printf("Calling firmware update\n");
         
                  status = FirmwareUpdateFATFile(file, REFLASHER_OFFSET);

                  //printf("Returned %d\n", status);

                  fclose(file);
               }

               fat_ioctl.ioctl_code = FAT_IOCTL_FS_DETACH;

               vos_dev_ioctl(hFAT_FILE_SYSTEM, &fat_ioctl);
               vos_dev_close(hFAT_FILE_SYSTEM);
            }

            boms_iocb.ioctl_code = MSI_IOCTL_BOMS_DETACH;

            vos_dev_ioctl(hBOMS, &boms_iocb);
            vos_dev_close(hBOMS);
         }
}
Title: Re: VNC2 Firmware Update over USB
Post by: FTDI Community on May 04, 2018, 01:46:08 PM
Hello,

Please see AN_151 Vinculum II User Guide (http://www.ftdichip.com/Support/Documents/AppNotes/AN_151_Vinculum-II_User_Guide.pdf) for all available functionality.

You can also use the IDE's help menu to easily search. This function might be useful to you:

(https://s9.postimg.cc/uplj5wkhb/VNC2_IDE_Help1.jpg)

If you have any further detailed questions which might need involvement from R&D, please contust us (http://www.ftdichip.com/FTContact.htm) directly.

Best Regards,
FTDI Community