【iCore4 双核心板_ARM】例程二十九:SD_IAP_FPGA实验——更新升级FPGA
实验现象及操作说明:
1、烧写程序成功,绿色ARM·LED灯点亮,三色FPGA·LED灯循环点亮,烧写失败,如果挂载SD卡失败,红灯快闪,如果打开文件失败,蓝灯快闪,读取文件指针移动失败,白灯点亮,升级失败,红灯慢闪。
2、上电时按着ARM·KEY,进入虚拟U盘模式,计算机将出现一个磁盘,可将升级文件拷入SD卡。
核心代码:
int main(void) { /* USER CODE BEGIN 1 */ int i; int k; unsigned int counter; unsigned long int ncounter = 0; unsigned char buffer[1024]; FIL fil; FATFS fatfs; static FRESULT res; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ if(ARM_KEY_STATE == KEY_DOWN){ MX_USB_DEVICE_Init(); while(1){ LED_RED_ON; HAL_Delay(300); LED_RED_OFF; HAL_Delay(300); } } if(BSP_SD_Init() != MSD_OK){ while(1){ LED_RED_ON; for(i = 0;i < 3000000;i ++); LED_RED_OFF; for(i = 0;i < 3000000;i ++); } } HAL_Delay(500); res = f_mount(&fatfs,"0",1); if(res != RES_OK){ while(1){ LED_RED_ON; for(i = 0;i < 3000000;i ++); LED_RED_OFF; for(i = 0;i < 3000000;i ++); } } res = f_open(&fil,"0:/system/sram.rbf",FA_READ); if(res != RES_OK){ while(1){ LED_BLUE_ON; for(i = 0;i < 3000000;i++); LED_BLUE_OFF; for(i = 0;i < 3000000;i++); } } res = f_lseek(&fil,0); if(res != RES_OK){ //°×É« LED_RED_ON; LED_BLUE_ON; LED_GREEN_ON; while(1){ } } //开始升级FPGA NCONFIG_OFF; DCLK_OFF; for(i = 0; i < 5000; i++); if(NSTATUS == 1) { LED_RED_ON; return 0; } for(i = 0;i < 40;i++); NCONFIG_ON; for(i = 0; i < 40; i++); while(ncounter < fil.fsize) { res = f_read(&fil,buffer,1024,&counter); if(res != RES_OK){ while(1){ LED_RED_ON; for(i = 0;i < 10000000;i++); LED_RED_OFF; for(i = 0;i < 10000000;i++); } } for(k = 0; k < counter; k++) { for(i = 0; i < 8; i++) { if(buffer[k]&0x01)DATA0_ON; else DATA0_OFF; DCLK_ON; buffer[k] >>= 1; DCLK_OFF; } ncounter++; } } if(CONFIG_DONE == 1){ LED_GREEN_ON; }else { LED_BLUE_ON; } for(i = 0; i < 40; i++) { DCLK_ON; for(i = 0; i < 800; i++); DCLK_OFF; for(i = 0; i < 800; i++); } /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
源代码下载链接:
链接:http://pan.baidu.com/s/1skMtdDV 密码:5bbq
iCore4链接: