You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/10/22 09:15:13 UTC

[mynewt-core] branch master updated: mcu/stm32: STM32F4x5/4x7 Errata fix

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 0f0b998  mcu/stm32: STM32F4x5/4x7 Errata fix
0f0b998 is described below

commit 0f0b998807fc70f544ece236d245fa9d05d75120
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Oct 21 11:25:00 2019 +0200

    mcu/stm32: STM32F4x5/4x7 Errata fix
    
    Having 3 NOPs after WFI seems not always help for instruction
    placed at 0x080xxxx4 addresses.
    So now code makes sure that WFI is never placed at dangerous
    address by placing it in function with know alignment.
---
 hw/mcu/stm/stm32_common/src/hal_os_tick.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/hw/mcu/stm/stm32_common/src/hal_os_tick.c b/hw/mcu/stm/stm32_common/src/hal_os_tick.c
index 7496667..05ceff4 100644
--- a/hw/mcu/stm/stm32_common/src/hal_os_tick.c
+++ b/hw/mcu/stm/stm32_common/src/hal_os_tick.c
@@ -24,25 +24,32 @@
 /*
  * XXX implement tickless mode.
  */
-void
-os_tick_idle(os_time_t ticks)
-{
-    OS_ASSERT_CRITICAL();
-    __DSB();
-    __WFI();
+
 /*
  * Errata for STM32F405, STM32F407, STM32F415, STM32F417.
- * When WFI instruction is placed at address ending with xxx4
+ * When WFI instruction is placed at address like 0x080xxxx4
  * (also seen for addresses ending with xxx2). System may
  * crash.
- * Simplest workaround is to add 3 NOP instructions after WFI.
+ * __WFI function places WFI instruction at address ending with x0 or x8
+ * for affected MCUs.
  */
 #if defined(STM32F405xx) || defined(STM32F407xx) || \
     defined(STM32F415xx) || defined(STM32F417xx)
-    __NOP();
-    __NOP();
-    __NOP();
+#undef __WFI
+__attribute__((aligned(8), naked)) void static
+__WFI(void)
+{
+     __ASM volatile("wfi\n"
+                    "bx lr");
+}
 #endif
+
+void
+os_tick_idle(os_time_t ticks)
+{
+    OS_ASSERT_CRITICAL();
+    __DSB();
+    __WFI();
 }
 
 void