【iCore4 双核心板_ARM】例程三十二:UART_IAP_ARM实验——更新升级STM32

时间:2021-04-04 16:12:43

实验现象及操作说明:

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_USART6_UART_Init(); /* USER CODE BEGIN 2 */
//³õʼ»¯´®¿Ú²¨ÌØÂÊ 115200
usart6.initialize();
usart6.printf("\x0c"); //ÇåÆÁ
usart6.printf("\033[1;32;40m"); //ÉèÖÃÖÕ¶Ë×ÖÌåΪÂÌÉ« LED_GREEN_ON;
if(ARM_KEY_STATE == KEY_UP){ //°´¼üËÉ¿ª×´Ì¬Ö±½ÓÌøÏòÓ¦ÓóÌÐò
goto start;
}
while(){ //°´¼ü°´Ï£¬½øÈëÉý¼¶×´Ì¬
if(i++ == ){
//´®¿Ú·¢ËÍ×Ö·ûC
usart6.send_byte('C');
i = ;
} if(usart6.receive_buffer[] == SOH){
break;
}
}
/* USER CODE END 2 */ /* Infinite loop */
/* USER CODE BEGIN WHILE */
while ()
{
/* USER CODE END WHILE */
if(usart6.receive_ok_flag == ){
usart6.receive_ok_flag = ;
LED_GREEN_OFF;
xmodem.process(); if(usart6.receive_buffer[] == EOT){
usart6.send_byte(ACK); //¶Á±£»¤
for(i = ; i < ; i ++);
HAL_FLASH_Lock(); //·¢ËÍÎļþ³É¹¦£¬Â̵ÆÁÁ
LED_BLUE_OFF;
LED_RED_OFF;
LED_GREEN_ON; while();
}
}
/* USER CODE BEGIN 3 */ }
start: //²âÊÔÓû§´úÂëÊÇ·ñ´ÓAPPLICATION_ADDRESS±»±à³Ì
if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000){ //ÌøתÖÁÓû§³ÌÐò
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + );
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/1kVLzFPP 密码:37zh

iCore4链接:

【iCore4 双核心板_ARM】例程三十二:UART_IAP_ARM实验——更新升级STM32