From b4dcc958aa9d8005de76d4c4774e67d63c8a49d5 Mon Sep 17 00:00:00 2001
From: Per <Per Lindgren>
Date: Mon, 23 Oct 2017 10:45:31 +0200
Subject: [PATCH] Embedded and Nucleo_64

---
 doc/Embedded.md | 51 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/doc/Embedded.md b/doc/Embedded.md
index 3a10ea2..8ec6b9c 100644
--- a/doc/Embedded.md
+++ b/doc/Embedded.md
@@ -73,7 +73,7 @@ Install the latest version of Visual Studio Code using your packet manager, unde
     "request": "attach",
     "name": "Debug",
     "gdbpath": "/usr/bin/arm-none-eabi-gdb",
-    "executable": "./target/thumbv7em-none-eabihf/debug/bluepill",
+    "executable": "./target/thumbv7m-none-eabi/debug/bluepill",
     "target": ":3333",
     "remote": true,
     "autorun": [
@@ -82,7 +82,7 @@ Install the latest version of Visual Studio Code using your packet manager, unde
         "set mem inaccessible-by-default off",
         "d breakpoints",
         "set remotetimeout 300",
-        "load ./target/thumbv7em-none-eabihf/debug/bluepill",
+        "load ./target/thumbv7m-none-eabi/debug/bluepill",
         "step",
         "monitor reset halt"
     ],
@@ -104,7 +104,7 @@ Similarly a launch confirguration for release (optimised) builds:
     "request": "attach",
     "name": "Debug",
     "gdbpath": "/usr/bin/arm-none-eabi-gdb",
-    "executable": "./target/thumbv7em-none-eabihf/release/bluepill",
+    "executable": "./target/thumbv7m-none-eabi/release/bluepill",
     "target": ":3333",
     "remote": true,
     "autorun": [
@@ -113,7 +113,7 @@ Similarly a launch confirguration for release (optimised) builds:
         "set mem inaccessible-by-default off",
         "d breakpoints",
         "set remotetimeout 300",
-        "load ./target/thumbv7em-none-eabihf/release/bluepill",
+        "load ./target/thumbv7m-none-eabi/release/bluepill",
         "step",
         "monitor reset halt"
     ],
@@ -126,3 +126,46 @@ An optimized build is generated by
 ``` 
 You may set specific settings in the `Cargo.toml` for each build type (`dev` for debug, `release` for release). Notice debugging of optimized code may be difficult as many symbols are *optimised out* and setting breakpoints may not give the desired results. To that end you may choose to use `asm::bkpt()` (defined in the [contex-m](https://github.com/japaric/cortex-m) crate) in the code instead of breakpoints in the debugger.  
 
+## Compilation and Linking
+The `xargo/cargo` build system will look into your `.cargo/config` for flags. The first example builds for the `m3` architecture while the second for the `m4` with *hard float* code. Notice, to use the *hard floats*, they need to be enabled in the ARM-core (not enabled at reset by default to save power...). You may have several configurations in the `.cargo/config`, and the `[build] = "..."` determintes the default configuration, it may be overridden e.g, by 
+
+```
+> xargo build ... --target thumbv7m-none-eabi
+```
+
+```
+[target.thumbv7m-none-eabi]
+runner = 'arm-none-eabi-gdb'
+rustflags = [
+  "-C", "link-arg=-Tlink.x",
+  "-C", "linker=arm-none-eabi-ld",
+  "-Z", "linker-flavor=ld",
+]
+
+[build]
+target = "thumbv7m-none-eabi"
+```
+
+```
+[target.thumbv7em-none-eabihf]
+runner = 'arm-none-eabi-gdb'
+rustflags = [
+  "-C", "link-arg=-Tlink.x",
+  "-C", "linker=arm-none-eabi-ld",
+  "-Z", "linker-flavor=ld",
+]
+
+[build]
+target = "thumbv7em-none-eabihf"
+```
+
+
+## A note on WFI
+If your code hits a `WFI` (Wait For Interrupt), the MCU is put into a low power mode, and by default not accepting new debug request. Thus if trying to connect a new `gdb` session, it will fail (or even worse partially work, while not behaving correctly). To remedy this you may try:
+* close `openocd` and restart it
+* unplug the the debugger (`stlink` probe), and re-plug it, you may need to hold the `reset` at startup to force the debugger and MCU into a correct state
+
+If we want to overcome this problem alltogether, there is a setting in the ARM-core debug unit that allows incoming connections on `WFI` (this feature is disabled by defauld to save power).
+
+
+
-- 
GitLab