STMCU小助手
发布时间:2022-2-28 20:18
|
前言 客户发现使用 ST Link Utility 对已檫除的 STM32L011 烧录程序后,用户的应用程序 UART 功能运行不正确,下面就对此问题展开分析。$ y( w# ]& G* X" c 一、问题的复现 测试环境搭建: PC 端软件: STM32 ST_LINK Utility+ R* u, e O5 `0 B' \5 V2 R 下载工具: ST-Link; R3 d. r, t" V2 X: Z2 T" f( ?; D, m 软件代码: STM32Cube_FW_L0_V1.9.0\Projects\STM32L073RZnucleo\Examples_LL\USART\USART_Communication_Rx_IT 问题复现步骤: Step1 获得空片:先对 flash 进行整体檫除 – >掉电操作 -> 等待 10~20ms -> 上电. e% L: W& W- ?1 q$ i 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”7 Q" W. y* a* h) r6 A STM32 ST_LINK Utility 具体配置如下: * C; Q5 Z# F! b) E) c/ A
) V; T$ S8 m# ^* {0 U2 p
' C8 W. w+ V1 c( U! ^( Z5 O; S
- r; P( t+ ^8 O# c! @% O) p; N; ~ Step3 运行代码并复现问题: 下载完成后不要断电或是执行硬件复位操作,然后观察 UART 代码的执行,发现运行不正常。0 M! ]) f7 Q' ^6 |* T! w$ k Step4 对 STM32F011 进行重新上电过程: 断电 -> 上电 -> 程序运行后 UART 功能正常。1 W5 ]" k7 w9 b3 n2 e Step5:然后在 Step4 程序运行正常的情况下执行 Step2 的烧录代码动作,再到 step3 (不断电或是执行硬件复位操作)下UART 代码执行正常。3 z/ u) M: P, a 然后我们又进行了如下测试:! W' M7 e( Y9 p5 f6 l 在 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 没问题1 C2 G3 P+ }' g 4. ST-Link + keil + ST LL code + L051 --- UART 没问题 5. ST-Link + ST-LINK Utility + ST LL code + L071 --- UART 没问题 s N5 {3 v" a) q3 E( `$ ~* [9 y 6. ST-Link + keil + ST LL code + L071 --- UART 没问题 " \ x l: x& u& ]' q K 二、原因分析 以上问题产生的原因是由于 STM32L011 (L0 家族)的 "Empty check" 机制引起的,在对空片编程时,empty check 标志位会被置位,程序会从 bootloader 代码开始执行。这个在 STM32L011 参考手册中有提及 RM0377 (page 55): ; f: w9 p9 f) q1 ? ---, ]4 R( n s* d+ a 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 is2 b9 e4 \, N) }* a/ t 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- x2 X7 C! K1 D* t 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: o5 D7 u% q0 _0 f! M1 d( ]7 a 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.9 v" @, o P* e2 g' E9 h& A -------------------------------------------------------------------------- p- L1 f2 ] v3 S9 O: q/ ` % u+ ^% N6 v9 J) C 当 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 复位命令,因此客户的应用程序不会被执行。; L) P/ y. f- U- [7 y: A" G 解决的办法是:" o$ T$ ~. {) @# H6 q 可以使用 PC debug 工具 IAR 或是 Kei 进行代码的下载,这些工具通常会对 IC 的 flash 进行编程后执行 OBL_LAUNCH 复位命令。/ R- n0 b5 y1 F5 B) i: q: ~ 可以使用"STM32CubeProgrammer"进行代码的下载,此工具也会对 MCU 的 flash 进行编程后会执行 OBL_LAUNCH 复位命令。 3 O9 u9 ~. p6 ^ 4 q+ b" W, h& B, Q6 A9 u) } 三、结论9 S0 a& Z2 x8 S7 s1 Q 在产品的量产烧录过程中,在对烧录工具不了解的情况下最好增加产品的断电环节。 0 h+ W# T0 Z8 }- u & e* a' t6 V- P) c$ {9 g' y7 U1 j |
微信公众号
手机版