烧写
由于芯片的内部SPI FLASH的0级BOOT 程序起到到开启JTAG SW 仿真功能,一旦内部SPI FLASH存储的BL0启动代码被损坏,芯片的JTAG 将不能被连接。所以对BL0的烧写需要谨慎,烧写BL0过程保证芯片不断电。
如果烧写了多备份的启动代码(该代码不能进行内部SPI FLASH的烧写功能),更新FLASH内容需要使用非多份的启动代码进行FLASH烧写。
打开工程 点击,download and debug 按钮,然后立即上电或复位设备。
下载完成后状态
保证USB 升级接口正常连接电脑,让后点击Go 按钮
库文件生成
屏蔽不用生成库的文件
删除不用生成库的文件
把要生成的.C保留,调用的.C 去除。比如main.C 去掉
生成库
在 Debug /Exe下
恢复到正常模式在设置中选择
使用LIB修改linker 设置
建议使用相对路径
P
R
O
J
D
I
R
PROJ_DIR
PROJDIR
设定程序运行地址
关于启动的起始位置(否则编译后BIN可能为空)使用报错
使用出现问题
正确处理
设置程序启动在指定位置。
错误处理取消沟通选(指标不治本,会发现main 不能打断点):
IAR官方有这样的介绍
Introduction
The application consists of two IAR Embedded Workbench projects, where the 1st project is linking the 2nd application as a binary image.
Issue
The startup code of the 2nd application is also included in the binary image. The issue is to reduce the size of the linked output. Only the startup code of the main project is needed, as it is in the 1st application execution starts.
我认为大概意思是对应第二部分程序,不需要启动代码可以不选择 entry symbol
部分程序可能需要启动初始化过程可能设置为No entry symbol ,正常jtag 调试需要设置entry symbol 。
不同情况可能需要修改,调试可能报错
宏定义
编译后处理
root 关键字
原文连接
定义:#define PAGE_ADDRESS 0x6000
__root __code const unsigned char IEEE_ADDRESS[8] @ PAGE_ADDRESS = { 'i','e','e','e','b','u','f',0};
__root 是IAR的扩展关键字,强制编译,保证没有使用的函数或者变量也能够包含在目标代码中
__code数据存储在code(程序区),对应的date为数据区
@的强制定义了数据的存储地址
上面的定义实际就是把IEEE_ADDRESS的数据强制写入到0x6000中。
自定义烧写
ST官方介绍
IAR 通过C-SPY将flash loader 加载到目标系统(MUCLEO-L476开发板)RAM中运行,完成目标falsh 的更新任务。
1.通过 C-SPY 将 flash loader 程序加载到目标系统预留的RAM区域。
2.通过 C-SPY 将需要下载测程序加载到目标系统预留的RAM区域,如果可执行程序比较大预留的RAM空间可能不能一次完全放下可以分割成多次传输。
3.将 IMAGE 镜像通过 flash loader 将 IMAGE 镜像下载至flash.
4.镜像下载完成后可以释放预留的RAM空间,至此已经完成下载。
IAR 与 KEIL 类似的地方是有提供烧写编程的例子。
{IAR安装目录}:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\src\flashloader
其中 ****.mac 是IAR的调用命令
.mac 文件定义了 C-SPY 调用的宏函数,如下宏函数会在 flash loader 的不同阶段调用宏函数。
execUserFlashInit() is called immediately before loading the flash loader
execUserPreload() is called immediately after the reset that follows the loading of the flash loader.
execUserFlashExit() is called immediately after flash loading has finished, but before the flash loader is unloaded.
中间可以做寄存器访问或者等操作,可以输出信息。
IAR 设置 ***F031X.board
设置Debugger的调用,使用对应的下载设置
.board 文件格式说明
此.board 配置文件的总入口,*.board 文件是什么文件,从IAR的帮助文档摘出如下说明,.board 文件是flash loader 下载镜像的配置文件被IAR 的C-SPY debug 对象引用
代码内容,指定使用的下载 **.flash 代码
<?xml version="1.0" encoding="iso-8859-1"?>
<flash_board>
<pass>
<loader>$PROJ_DIR$\..\..\..\..\XT32AF0X\flashloader\FlashXchip_**32F031X.flash</loader>
<range>CODE 0x0 0x177ff</range>
</pass>
</flash_board>
IAR FLASH设置
*.flash 文件格式说明
从配置选项可以看出,此.board主要的配置信息是告诉flash loader 要根据Flash STM32L4xxxG.flash 文件的配置下载镜像,此.flash 的文件是什么文件呢,从iar 的文件说明可知,.flash 文件也是C-SPY加载的文件,主要定义了flash 的相关属性配置。
LINK 相关
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x000177FF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x20005FFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x1000;
define symbol __ICFEDIT_size_heap__ = 0x0;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy { readwrite };
do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite,
block CSTACK, block HEAP };
define symbol op_rom_start = 0x1FF007E0;
define symbol op_rom_end = 0x1FF007FF;
define region OP_region = mem:[from op_rom_start to op_rom_end];
place in OP_region { readonly section .options };