platformio / platform-ststm32

ST STM32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/ststm32
Apache License 2.0
385 stars 303 forks source link

Flashing STM32 in Low Power Mode #255

Open pfeerick opened 5 years ago

pfeerick commented 5 years ago

Reported by solenoid on the PIO forum.

With a Nucleo L031K6 w/ on-board ST-Link (but possibly applies to other STM32 setups), with default configuration, flashing the board fails if the STM32 is in a low power mode (both sleep and stop modes). Changing the following line in stm32l0.cfg fixes the problem:

# default configuration - flashing fails when stm32 is in low power mode
reset_config srst_nogate
# updated configuration - flashing works when stm32 is in low power mode
reset_config trst_and_srst srst_nogate connect_assert_srst

I would have posted a PR against the openocd settings file but AFAIK it's only on bintray?

Forum ref: https://community.platformio.org/t/flashing-stm32-in-low-power-mode/8423

jakematlick commented 5 years ago

The change to reset_config works for uploading, but unfortunately breaks debugging (even when not in low power mode). It would be great if there were a way to support both uploading and debugging in low power mode (and run mode).

Here's the error I get when trying to debug:

Info : clock speed 300 kHz
Info : STLINK V2J29M18 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.282540
Info : stm32l0.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : accepting 'gdb' connection from pipe
Info : Halt timed out, wake up GDB.
Error: timed out while waiting for target halted

Warn : Cannot identify target as a STM32L family.
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.
Error: attempted 'gdb' connection rejected
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response