【iCore4 雙核心板_ARM】例程二十九:SD_IAP_FPGA實驗——更新升級FPGA

XiaomaGee發表於2017-09-30

實驗現象及操作說明:

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連結:

相關文章