From: Leonardo S. d. S. <leo...@gm...> - 2017-04-15 22:35:17
|
Hello everyone, I found a Flash programming issue on some parts and a workaround below. OpenOCD loads this code in RAM to program any STM32Lx (loaded in stm32lx_write_half_pages() ): 0x20000000 0x2300 MOVS r3, #00 0x20000002 0xe004 B 0x2000000e 0x20000004 0xf851cb04 LDR r12, [r1], #4 ; 0x04 0x20000008 0xf840cb04 STR r12, [r0], #4 ; 0x04 0x2000000c 0x3301 ADDS r3, #0x01 0x2000000e 0x4293 CMP r3, r2 0x20000010 0xd3f8 BCC 0x20000004 0x20000012 0xbe00 BKPT 00 This code will always cause a Hard Fault on STM32L0 parts (undefined instruction - this form of the LDR and STR instructions doesn't exist in ARMv6-M). Usually, OpenOCD detects the Hard Fault and falls back to another method. The issue appears on STM32L011 and L021 that have the "empty check" and the 14-pin package. The factory bootloader (selected by default) takes over from the Hard Fault handler. I think it reconfigures the SWD lines to another function and the debug connection is lost. *Workaround:* I managed to program an STM32L021 after adding this to the config file: $_TARGETNAME configure -event reset-end { echo "Remapping Flash to address 0x00000000" # RCC_APB2ENR <= 0x1 mww 0x40021034 0x1 # SYSCFG_CFGR1 <= 0x0 mww 0x40010000 0x0 } It simply remaps the Flash to address 0 instead of bootloader ROM, changing the Vector Table, so the Hard Fault handler from the bootloader never runs and the connection is not dropped. One more correction: config script target/stm32l0.cfg sets _WORKAREASIZE to 8 kB by default, but these new parts have only 2 kB RAM. Regards, Leonardo |