/** * @brief IAP Write Flash memory. * @param None * @retval None */ void COMMAND_Download(void) { /* Open the binary file to be downloaded */ if(f_open(&MyFileR, DOWNLOAD_FILENAME, FA_READ) == FR_OK) { if(MyFileR.fsize > USER_FLASH_SIZE) { /* No available Flash memory size for the binary file: Turn LED4 On and Toggle LED3 in infinite loop */ BSP_LED_On(LED4); Fail_Handler(); } else { /* Download On Going: Turn LED4 On */ BSP_LED_On(LED4); /* Erase FLASH sectors to download image */ if(FLASH_If_EraseSectors(APPLICATION_ADDRESS) != 0x00) { /* Flash erase error: Turn LED4 On and Toggle LED2 and LED3 in infinite loop */ BSP_LED_Off(LED4); Erase_Fail_Handler(); } /* Program flash memory */ COMMAND_ProgramFlashMemory(); /* Download Done: Turn LED4 Off and LED2 On */ BSP_LED_Off(LED4); BSP_LED_On(LED2); /* Close file */ f_close(&MyFileR); } } else { /* The binary file is not available: Turn LED1, LED2 and LED4 On and Toggle LED3 in infinite loop */ BSP_LED_On(LED1); BSP_LED_On(LED2); BSP_LED_On(LED4); Fail_Handler(); } }
/** * @brief IAP write memory. * @param None * @retval None */ void COMMAND_DOWNLOAD(void) { /* Open the binary file to be downloaded */ if (f_open(&fileR, DOWNLOAD_FILENAME, FA_READ) == FR_OK) { if (fileR.fsize > USER_FLASH_SIZE) { /* Toggle Red LED in infinite loop: No available Flash memory size for the binary file */ Fail_Handler(); } else { /* Erase FLASH sectors to download image */ if (FLASH_If_EraseSectors(APPLICATION_ADDRESS) != 0x00) { /* Toggle Red LED in infinite loop: Flash erase error */ Fail_Handler(); } STM_EVAL_LEDOff(LED3); /* Program flash memory */ COMMAND_ProgramFlashMemory(); /* Set Green LED ON: Download Done */ STM_EVAL_LEDOn(LED3); /* Close file and filesystem */ f_close (&fileR); } } else { /* Toggle Red LED in infinite loop: the binary file is not available */ Fail_Handler(); } }