實驗現象及操做說明:oop
一、燒寫程序成功,綠色ARM·LED燈點亮,三色FPGA·LED燈循環點亮,燒寫失敗,若是掛載SD卡失敗,紅燈快閃,若是打開文件失敗,藍燈快閃,讀取文件指針移動失敗,白燈點亮,升級失敗,紅燈慢閃。spa
二、上電時按着ARM·KEY,進入虛擬U盤模式,計算機將出現一個磁盤,可將升級文件拷入SD卡。指針
核心代碼:code
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(); MX_SDIO_SD_Init(); // MX_USB_DEVICE_Init(); MX_FATFS_Init(); /* USER CODE BEGIN 2 */ if(!KEY_INPUT){ MX_USB_DEVICE_Init(); while(1){ LED_RED_ON; HAL_Delay(300); LED_RED_OFF; HAL_Delay(300); } } if(BSP_SD_Init() != USBD_OK){ while(1){ LED_RED_ON; for(i = 0;i < 3000000;i++); LED_RED_OFF; for(i = 0;i < 3000000;i++); } } HAL_Delay(500); //¹ÒÔØSD¿¨ res = f_mount(&fatfs,"0:",1); if(res != RES_OK){ //¹ÒÔØʧ°Ü£¬Â̵ƿìÉÁ while(1){ LED_GREEN_ON; for(i = 0;i < 3000000;i++); LED_GREEN_OFF; for(i = 0;i < 3000000;i++); } } res = f_open(&fil,"0:/system/sdram.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 */ }
實驗方法及指導書:htm
連接:http://pan.baidu.com/s/1dFjJs5N 密碼:kylwblog