STMCU小助手
发布时间:2022-2-28 20:18
|
前言 客户发现使用 ST Link Utility 对已檫除的 STM32L011 烧录程序后,用户的应用程序 UART 功能运行不正确,下面就对此问题展开分析。 一、问题的复现 测试环境搭建: PC 端软件: STM32 ST_LINK Utility 下载工具: ST-Link 软件代码: STM32Cube_FW_L0_V1.9.0\Projects\STM32L073RZnucleo\Examples_LL\USART\USART_Communication_Rx_IT 问题复现步骤: Step1 获得空片:先对 flash 进行整体檫除 – >掉电操作 -> 等待 10~20ms -> 上电 Step2 配置 ST-Link Utility 并进行烧录: 使用 STM32 ST_LINK Utility PC 端软件下载 L011 的代码(bin/hex), 具体代码可以使用” STM32Cube_FW_L0_V1.9.0\Projects\STM32L073RZ-Nucleo\Examples_LL\USART\USART_Communication_Rx_IT” STM32 ST_LINK Utility 具体配置如下:
Step3 运行代码并复现问题: 下载完成后不要断电或是执行硬件复位操作,然后观察 UART 代码的执行,发现运行不正常。 Step4 对 STM32F011 进行重新上电过程: 断电 -> 上电 -> 程序运行后 UART 功能正常。 Step5:然后在 Step4 程序运行正常的情况下执行 Step2 的烧录代码动作,再到 step3 (不断电或是执行硬件复位操作)下UART 代码执行正常。 然后我们又进行了如下测试: 在 STM32L051C8Tx / STM32L071C8Tx 上执行 step1 到 step3 的动作: 1. ST-Link + ST-LINK Utility + ST LL code+ L011 --- UART 存在问题 2. ST-Link + Keil + ST LL code + L011 --- UART 存在问题 3. ST-Link + ST-LINK Utility + ST LL code +L051 --- UART 没问题 4. ST-Link + keil + ST LL code + L051 --- UART 没问题 5. ST-Link + ST-LINK Utility + ST LL code + L071 --- UART 没问题 6. ST-Link + keil + ST LL code + L071 --- UART 没问题 二、原因分析 以上问题产生的原因是由于 STM32L011 (L0 家族)的 "Empty check" 机制引起的,在对空片编程时,empty check 标志位会被置位,程序会从 bootloader 代码开始执行。这个在 STM32L011 参考手册中有提及 RM0377 (page 55): --- Empty check (category 1 devices only) On category 1 devices, an internal empty check flag is implemented to allow easy programming of virgin devices by the bootloader. This flag is used when BOOT0 pin is configured to select Flash program memory as target boot area. When this flag is set, the device is considered as unprogrammed and the system memory (bootloader) is selected as boot area instead of the Flash program memory to allow the application to program the Flash memory. The empty check flag is updated only when the option bytes are loaded: it is set when the content of address 0x8000 0000 is read as 0x0000 0000 and cleared otherwise. As a result, only a power-on reset or setting OBL_LAUNCH bit in FLASH_CR register can clear this flag after programming a virgin device to execute user code after system reset. -------------------------------------------------------------------------- 当 MCU flash 被檫除,之后又执行了断电上电过程,“empty check”标志会被置位(IC 为空),这种情况下内部 bootloader 代码将被执行。“empty check”标志是在装载 option bytes 时置位的,option bytes 在 power-on 和 OBL_LAUNCH 复位时会进行装载。在客户的应用中 ST-Link Utility 对 IC 进行编程结束时复位了 IC,但“empty check”标志仍然是置位的。因此在“emptycheck”置位的情况下即使客户应用代码存在,但仍会运行 bootloader 代码。如果要刷新“empty check”标志只能通过断电上电过程或是执行 OBL_LAUNCH 复位命令。ST-Link Utility 在编程后没有执行 OBL_LAUNCH 复位命令,因此客户的应用程序不会被执行。 解决的办法是: 可以使用 PC debug 工具 IAR 或是 Kei 进行代码的下载,这些工具通常会对 IC 的 flash 进行编程后执行 OBL_LAUNCH 复位命令。 可以使用"STM32CubeProgrammer"进行代码的下载,此工具也会对 MCU 的 flash 进行编程后会执行 OBL_LAUNCH 复位命令。 三、结论 在产品的量产烧录过程中,在对烧录工具不了解的情况下最好增加产品的断电环节。 |
微信公众号
手机版