Yes sure I’ll try that. Thanks so far for helping debug this
Wow I did the mass erase and re-programmed same code that got stuck before and now it is able to execute things normally
I will still perform some more testing but this looks promising already!
I have some suspicions for this. When you look at the size of the debug-optimized (-Og) firmware
Checking size .pio\build\savi\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [== ] 15.7% (used 3208 bytes from 20480 bytes)
Flash: [===== ] 52.3% (used 68608 bytes from 131072 bytes)
Building .pio\build\savi\firmware.bin
it’s sligthly over 64K, with it’s 68K. The STM32L072RBT6, as a 128 kByte flash device, internally actually has 2 banks of flash, 64K each.
(from RM0376 reference manual for STM32L0x2)
So it has an exact split in the middle. I think it just has problems when the firmware happens to be over 64K (which happened as you combined the two sketches into one more complex one), and if it doesn’t activate the second flash bank correctly it will just read garbage from it.
Maybe the one-time mass erase fixed it for once.
I tried with few debug session on the current code, all looking good. Then I added back all the BME280 stuff and it went to same reset loop. However after that I did mass flash erase again and re-programmed… now working again even after multiple debug sessions.
You might be right about the flash split theory. At least it sounds legit case
So for now I think I’m able to continue development again thanks to you. I would never have been able to solve this by myself. Huge thanks for the effort
Yikes.
OpenOCD has two config files: stm32l0.cfg
and stm32l0_dual_bank.cfg
.
Your STM32L072RB is a dual-bank device (2x64Kbyte). So it needs stm32l0_dual_bank
. But the board definition has the wrong file selected, stm32l0
.
Maybe it’s been a problem with how OpenOCD flashes the firmware on it all the time, and not the code itself. Can you correct the board definition to use stm32l0_dual_bank
as its openocd_target
? Mass erase the flash again if needed.
Sure I will test this and get back soon
I think it was this all along. Now I first uploaded code without BME280 stuff to have the size be under 64kb… works. Then I added back BME280 stuff with LoRa and size being over 64kb… still works without manual flash erase. I did not even know before that our MCU had dual bank flash and there is different OpenOCD target for that