Skip to content

cpu/stm32f1: CPU hangs after wake-up from STOP power mode #13918

@jue89

Description

@jue89

Description

I am experiencing odd behavior with the STM32F103C8 CPU on current master. I am running the application tests/periph_pm on the board bluepill. After the RTC woke up the board from STM32_PM_STOP, it hangs.

After digging around I found out that the problem is solved by introducing two NOPs before re-initializing the clocks:

diff --git a/cpu/stm32_common/periph/pm.c b/cpu/stm32_common/periph/pm.c
index 4b4875ebf..b51b9d817 100644
--- a/cpu/stm32_common/periph/pm.c
+++ b/cpu/stm32_common/periph/pm.c
@@ -135,6 +136,8 @@ void pm_set(unsigned mode)
 
     if (deep) {
         /* Re-init clock after STOP */
+        __asm__("nop\n\t");
+        __asm__("nop\n\t");
         stmclk_init_sysclk();
     }
 }

Steps to reproduce the issue

Flash tests/periph_pm on the board bluepill:

Expected results

(The first unblock is required to release the block issued by the UART behind stdio_uart.)

cd tests/periph_pm
make BOARD=bluepill flash term
unblock 1
2020-04-21 18:44:05,125 #  unblock 1
2020-04-21 18:44:05,126 # Unblocking power mode 1.
unblock_rtc 1 2
2020-04-21 18:44:07,139 #  unblock_rtc 1 2
2020-04-21 18:44:07,140 # Unblocking power mode 1 for 2 seconds.
(... wait at least 2 secs)
help
2020-04-21 18:44:10,816 #  help
2020-04-21 18:44:10,817 # Command              Description
2020-04-21 18:44:10,817 # ---------------------------------------
2020-04-21 18:44:10,818 # off                  turn off
2020-04-21 18:44:10,818 # reboot               reboot
2020-04-21 18:44:10,819 # block                block power mode
2020-04-21 18:44:10,820 # set                  set power mode
2020-04-21 18:44:10,821 # unblock              unblock power mode
2020-04-21 18:44:10,822 # unblock_rtc          temporary unblock power mode

Actual results

cd tests/periph_pm
make BOARD=bluepill flash term
unblock 1
2020-04-21 18:44:05,125 #  unblock 1
2020-04-21 18:44:05,126 # Unblocking power mode 1.
unblock_rtc 1 2
2020-04-21 18:44:07,139 #  unblock_rtc 1 2
2020-04-21 18:44:07,140 # Unblocking power mode 1 for 2 seconds.
(... wait at least 2 secs)
help
(... the system is dead)

Versions

Operating System Environment
----------------------------
         Operating System: "Manjaro Linux" 
                   Kernel: Linux 5.4.33-3-MANJARO x86_64 unknown
             System shell: GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
             make's shell: GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)

Installed compiler toolchains
-----------------------------
               native gcc: gcc (Arch Linux 9.3.0-1) 9.3.0
        arm-none-eabi-gcc: arm-none-eabi-gcc (Arch Repository) 9.3.0
                  avr-gcc: missing
         mips-mti-elf-gcc: missing
               msp430-gcc: missing
     riscv-none-embed-gcc: missing
     xtensa-esp32-elf-gcc: missing
   xtensa-esp8266-elf-gcc: missing
                    clang: clang version 9.0.1 

Installed compiler libs
-----------------------
     arm-none-eabi-newlib: "3.3.0"
      mips-mti-elf-newlib: missing
  riscv-none-embed-newlib: missing
  xtensa-esp32-elf-newlib: missing
xtensa-esp8266-elf-newlib: missing
                 avr-libc: missing (missing)

Installed development tools
---------------------------
                   ccache: missing
                    cmake: cmake version 3.17.1
                 cppcheck: missing
                  doxygen: 1.8.17
                      git: git version 2.26.1
                     make: GNU Make 4.3
                  openocd: Open On-Chip Debugger 0.10.0
                   python: Python 3.8.2
                  python2: Python 2.7.17
                  python3: Python 3.8.2
                   flake8: error: /usr/bin/python3: No module named flake8
               coccinelle: missing

Metadata

Metadata

Labels

Area: cpuArea: CPU/MCU portsPlatform: ARMPlatform: This PR/issue effects ARM-based platformsType: bugThe issue reports a bug / The PR fixes a bug (including spelling errors)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions