网站做外链平台有哪些电商网络推广
头文件重复引用解决办法。
参考:STM32CubeIDE IAP原理讲解,及UART双APP交替升级IAP实现-CSDN博客
移植到Air32时,RAM的大小(无论boot程序还是app 程序) 尽量不动,如果动了会影响最终的 APP 跳转
flash 大小可以随意修改,根据 实际大小修改就好
bootloader 和App程序 都需要手动修改下面的Flash 大小
boot从0x0800 0000 开始,后面legth 为分给boot的 flash大小
App从0x0800 4000 开始,后面legth 为分给app的 flash大小
编译完成后,可以通过build ana 查看RAM 和flash内存大小
另外APP 需要在 system_stm32f1xx.c 修改偏移向量 表(实际试下来,改上面.ld 文件 就不用改这里的)
手动添加
#define USER_VECT_TAB_ADDRESS另外修改APP的起始地址为
#define VECT_TAB_OFFSET 0x00004000U
Bootloader.c
#include "Bootloader.h"
#include "stdint.h"
#include "usart.h"
//#include "stm32f1xx_hal_uart.h"
#include "string.h"
#include "stdio.h"extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;//#define APP_ADDR_20K 0x08005000 //应用程序首地址定义 bootload 占20KB
// MSP:主堆栈
// PSP:线程堆栈//__asm void MSR_MSP(uint32_t addr)
//{
// MSR MSP, r0
// BX r14;
//}void iap_load_app(void)
{APP_FUNC jump2app;//定义一个函数指针printf("MSP=%x,%x\r\n",(uint32_t *)BOOT_SECTOR_ADDR,*(uint32_t *)BOOT_SECTOR_ADDR);printf("RSH=%x,%x\r\n",(uint32_t *)(BOOT_SECTOR_ADDR+4),*(uint32_t *)(BOOT_SECTOR_ADDR+4));printf("APP=%x,%x\r\n",(uint32_t *)APP_ADDR,*(uint32_t *)APP_ADDR);/* 栈顶地址是否合法(这里sram大小为8k) */if( ( (*(uint32_t *)APP_ADDR) & 0x2FFE0000) == 0x20000000){/* 设置栈指针 */
// MSR_MSP(APP_ADDR);/* 获取复位地址 */jump2app=(APP_FUNC)*(volatile uint32_t *)(APP_ADDR+4); printf("AppJump=%x,%x\r\n",(uint32_t *)jump2app,*(uint32_t *)jump2app);/* 设置栈指针 */__set_MSP(*(volatile uint32_t *)APP_ADDR);#ifdef BOOTLOADER_LOG HAL_UART_Transmit(&huart1,(uint8_t*)"Bootloader end load app\r\n",(uint16_t)strlen("Bootloader end load app\r\n"),0xf);HAL_UART_Transmit(&huart2,(uint8_t*)"Bootloader end load app\r\n",(uint16_t)strlen("Bootloader end load app\r\n"),0xf);HAL_Delay(100);#endif/* 跳转之前关闭相应的中断 */
// CLOSE_ALL_INT();/* 跳转至APP */jump2app();}#ifdef BOOTLOADER_LOGelse{HAL_UART_Transmit(&huart1,(uint8_t*)"APP Not Found!\n",(uint16_t)strlen("APP Not Found!\n"),0xf);HAL_UART_Transmit(&huart2,(uint8_t*)"APP Not Found!\n",(uint16_t)strlen("APP Not Found!\n"),0xf);HAL_Delay(100);}
#endif}
Bootloader.h
#ifndef _BOOTLOADER_H_
#define _BOOTLOADER_H_#include "main.h"/********************************************************
| 0x08000000 | 0x08003000 | 0x08004000 | 0x08012000 |
---------------------------------------------------------
| BOOT | SETTING | APP | DOWNLOAD |
---------------------------------------------------------
| 12k | 4K | 56K | 56K |
*********************************************************/#define FLASH_SECTOR_SIZE 1024
#define FLASH_SECTOR_NUM 128 // 128K
#define FLASH_START_ADDR ((uint32_t)0x8000000)
#define FLASH_END_ADDR ((uint32_t)(0x8000000 + FLASH_SECTOR_NUM * FLASH_SECTOR_SIZE))#define BOOT_SECTOR_ADDR 0x08000000
#define BOOT_SECTOR_SIZE 0x3000#define SETTING_SECTOR_ADDR 0x08003000
#define SETTING_SECTOR_SIZE 0x1000#define APP_SECTOR_ADDR 0x08004000 // APP sector start address
#define APP_SECTOR_SIZE 0xE000 // APP sector size 56KB#define DOWNLOAD_SECTOR_ADDR 0x08012000 // Download sector start address
#define DOWNLOAD_SECTOR_SIZE 0xE000 // Download sector size 56KB #define APP_ADDR_8K 0x08002000 //应用程序首地址定义 bootload 占8KB
#define APP_ADDR_16K 0x08004000 //应用程序首地址定义 bootload 占16KB
#define APP_ADDR_20K 0x08005000 //应用程序首地址定义 bootload 占20KB
#define APP_ADDR_32K 0x08008000 //应用程序首地址定义 bootload 占32KB#define APP_ADDR APP_ADDR_16K //应用程序首地址定义/*选择性开启相应的LOG信息*/
#define BOOTLOADER_LOG 1#define CLOSE_ALL_INT() __set_PRIMASK(1) //关闭所有中断
typedef void (*APP_FUNC)(); //函数指针类型定义void iap_load_app(void); //跳转函数#endif
不同RAM 的 bootloader 和APP 组合,主要修改下面的值
APP\BOOT | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 96 |
10 | OK | OK | OK | NO | NO | NO | NO | NO | NO |
20 | OK | OK | OK | NO | NO | NO | NO | NO | NO |
30 | OK | OK | OK | NO | NO | NO | NO | NO | NO |
40 | NO | NO | NO | NO | NO | NO | NO | NO | NO |
50 | NO | NO | NO | NO | NO | NO | NO | NO | NO |
60 | NO | NO | NO | NO | NO | NO | NO | NO | NO |
70 | NO | NO | NO | NO | NO | NO | NO | NO | NO |
80 | NO | NO | NO | NO | NO | NO | NO | NO | NO |
96 | NO | NO | NO | NO | NO | NO | NO | NO | NO |
经过上面的组合 RAM 10K和20K ,30K,boot和APP 可以任意组合。
超过40K的RAM 无法进入boot 可能和STM32F103 的底层有关系,暂时没有去研究