U盘升级函数:
/*
*********************************************************************************************************
* Function Name : Programing_From_Flie
* Function Detail : Programing The Chip From a Flie
* Paramater : None
* Return Value : None
*********************************************************************************************************
*/
void Programing_From_Flie(void)
{
static uint8_t page_buffer[4096];
#if defined BK180H
const char object_path[]="0:BK180H.bin";
#elif defined BK300H
const char object_path[]="0:BK300H.bin";
#elif defined U180
const char object_path[]="0:U180.bin";
#endif
PrintMessage("Udisk Connected!");
SysTick_Init();
do
{
USBH_Process(&USB_OTG_Core, &USB_Host);
}
while (count_ms<8000 && (USB_Host.gState!=HOST_CLASS || USBH_MSC_BOTXferParam.MSCState!=0x05));
SysTick->CTRL=0x00; //Stop Counter
char string_buf[24]="Scanning for ";
for (u8 i=13;i<24;i++)string_buf=object_path[i-11];
PrintMessage(string_buf);
result = f_mount(&fs,"0:",1); /* Mount a logical drive */
if (result != FR_OK)
{
PrintMessage("Mounting Failed!");
return;
}
result = f_open(&file, object_path, FA_OPEN_EXISTING | FA_READ);
if(result == FR_OK)
{
if (file.fsize==0 || file.fsize>0x1F8000)
{
PrintMessage("File Size Error!");
goto close_file_exit;
}
if (FLASH_If_GetWriteProtectionStatus() == 0)
{
/* Disable the write protection */
if (FLASH_If_DisableWriteProtection()==1)
{
PrintMessage("Write Protection disabled!");
}
else
{
PrintMessage("Error: Flash write unprotection failed!");
goto close_file_exit;
}
}