【iCore1S 雙核心板_ARM】例程二十:UART_IAP_ARM實驗——更新升級STM32

XiaomaGee發表於2017-11-01

實驗現象及操作說明:

1、本例程共有兩個程式碼包,APP和IAP,IAP程式功能實現將APP程式升級至STM32中。

2、直接上電或燒寫程式將執行升級的APP應用程式。

BIN升級檔案產生方法:

1、編譯APP工程,產生.hex檔案。

2、將.hex檔案拖至HEX2BIN.EXE即可產生.bin檔案。

核心程式碼:

 

int main(void)
{

  /* USER CODE BEGIN 1 */
    int i;
  /* 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_CRC_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */
    usart1.initialize(115200);
    usart1.printf("\x0c");                                                      //ÇåÆÁ
    usart1.printf("\033[1;32;40m");                   //ÉèÖÃÖÕ¶Ë×ÖÌåΪÂÌÉ«    
    
  for(i=0;i<100000;i++);
    
    //°´¼üËÉ¿ª£¬ÌøÖÁstart
    if(ARM_KEY_STATE == KEY_UP){
        goto start;    
    }
    
    while(1){
        if(i ++ == 5000000){
            
            //´®¿Ú·¢ËÍ×Ö·ûC
            usart1.send_byte('C');
            i = 0;
        }
        
        if(usart1.receive_buffer[0] == SOH){
            
            break;
        }
    }
    
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
        if(usart1.receive_ok_flag == 1){
            usart1.receive_ok_flag = 0;
            xmodem.process();
                            
            if(usart1.receive_buffer[0] == EOT){
                usart1.send_byte(ACK);    
                
                //¶Á±£»¤
                for(i = 0; i < 100000; i ++);    
                HAL_FLASH_Lock();
                
                //·¢ËÍÎļþ³É¹¦£¬Â̵ÆÁÁ
                LED_BLUE_OFF;
                LED_RED_OFF;
                LED_GREEN_ON;
                
                while(1);
            }
        }

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }
    start:
        
    //²âÊÔÓû§´úÂëÊÇ·ñ´ÓAPPLICATION_ADDRESS±»±à³Ì
        if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000){ 
            
            //ÌøתÖÁÓû§³ÌÐò
            JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
            Jump_To_Application = (pFunction) JumpAddress;
            
            //³õʼ»¯Óû§³ÌÐòµÄ¶ÑÕ»Ö¸Õë
            __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
            
            //ÌøתÖÁÓ¦ÓóÌÐò
            Jump_To_Application();
        }else{                
            led_trade();

        }

  /* USER CODE END 3 */

}

實驗方法及指導書:

連結:http://pan.baidu.com/s/1jIaM6lo 密碼:7oiv

相關文章