From da3e868599123513530586b1df193f46e83cddfb Mon Sep 17 00:00:00 2001 From: Michael Droogleever Date: Sat, 13 Oct 2018 21:52:24 +0200 Subject: [PATCH 1/6] 2018-10 version bumps and compatibility updates --- .cargo/config | 9 +- src/SUMMARY.md | 4 +- src/appendix/troubleshooting.md | 11 ++ src/display/Cargo.toml | 6 +- src/display/src/main.rs | 18 +- src/getting-started/.cargo/config | 9 - src/getting-started/01.00.BUILD.md | 163 +++++-------------- src/getting-started/Cargo.toml | 8 +- src/getting-started/src/main.rs | 24 +-- src/hello-world/Cargo.toml | 10 +- src/hello-world/src/main.rs | 18 +- src/microbit/Cargo.toml | 10 +- src/microbit/examples/buttons.rs | 18 +- src/microbit/examples/buttons_poll.rs | 16 +- src/microbit/examples/display_blocking.rs | 18 +- src/serial/Cargo.toml | 8 +- src/serial/examples/countdown.rs | 18 +- src/serial/examples/display_echo.rs.disabled | 18 +- src/serial/examples/quiz.rs | 18 +- src/serial/examples/reverse.rs | 18 +- src/serial/src/main.rs | 19 +-- 21 files changed, 106 insertions(+), 335 deletions(-) delete mode 100644 src/getting-started/.cargo/config diff --git a/.cargo/config b/.cargo/config index 532c2e6..1db93ac 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,9 +1,14 @@ +# Configure builds for our target, the micro:bit's architecture [target.thumbv6m-none-eabi] +# Execute binary using gdb when calling cargo run runner = "arm-none-eabi-gdb" +# Tweak to the linking process required by the cortex-m-rt crate rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x", - "-C", "link-arg=-nostartfiles", + "-C", "link-arg=-Tlink.x", + # The LLD linker is selected by default + #"-C", "linker=arm-none-eabi-ld", ] +# Automatically select this target when cargo building this project [build] target = "thumbv6m-none-eabi" diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 0556fc1..b579f44 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -56,9 +56,11 @@ - [Multiplexing](display/03.02.MULT.md) - [Full Solution](display/03.03.FULL.md) +- [WIP - Sensors and I²C](sensors/00.00.README.md) + - [WIP - Non-blocking](nb/00.00.README.md) -- [WIP - Sensors and I²C](sensors/00.00.README.md) +- [WIP - Interrupts](nb/00.00.README.md) - [WIP - Real time](rtfm/00.00.README.md) diff --git a/src/appendix/troubleshooting.md b/src/appendix/troubleshooting.md index b820635..d16ea45 100644 --- a/src/appendix/troubleshooting.md +++ b/src/appendix/troubleshooting.md @@ -147,3 +147,14 @@ The `eh_personality` language item is used to implement stack unwinding in case You need to use the correct target by using `--target thumbv6m-none-eabi` or modifying `.cargo/config` + +### `error: ld: cannot open linker script file memory.x: No such file or directory` + +#### Cause + +A memory.x file is needed, this specifies memory layout. + +#### Fix + +Either ask the board support crate maintainer to add memory.x to their crate, +or add a memory.x file to your project. diff --git a/src/display/Cargo.toml b/src/display/Cargo.toml index 07000cc..261d5c5 100644 --- a/src/display/Cargo.toml +++ b/src/display/Cargo.toml @@ -3,7 +3,7 @@ name = "display" version = "0.1.0" [dependencies] -cortex-m-rt="~0.5" +cortex-m-rt="~0.6" cortex-m-semihosting="~0.3" -panic-semihosting = "~0.3" -microbit="~0.5" +panic-semihosting = "~0.5" +microbit="~0.6" diff --git a/src/display/src/main.rs b/src/display/src/main.rs index 3c468d9..35a7eb5 100644 --- a/src/display/src/main.rs +++ b/src/display/src/main.rs @@ -4,12 +4,10 @@ extern crate panic_semihosting; extern crate cortex_m_rt as rt; extern crate cortex_m_semihosting as sh; - -#[macro_use(entry, exception)] extern crate microbit; use core::fmt::Write; -use rt::ExceptionFrame; +use rt::entry; use sh::hio; use microbit::hal::delay::Delay; @@ -20,18 +18,6 @@ use microbit::hal::serial; use microbit::hal::serial::BAUD115200; use microbit::hal::prelude::*; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - type LED = PIN>; const DEFAULT_DELAY_MS: u32 = 2; @@ -128,7 +114,7 @@ impl Display { } } -entry!(main); +#[entry] fn main() -> ! { let mut stdout = hio::hstdout().unwrap(); writeln!(stdout, "Start").unwrap(); diff --git a/src/getting-started/.cargo/config b/src/getting-started/.cargo/config deleted file mode 100644 index bbcd7f8..0000000 --- a/src/getting-started/.cargo/config +++ /dev/null @@ -1,9 +0,0 @@ -[target.thumbv6m-none-eabi] -runner = "arm-none-eabi-gdb" -rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x", - "-C", "link-arg=-nostartfiles", -] - -[build] -target = "thumbv6m-none-eabi" \ No newline at end of file diff --git a/src/getting-started/01.00.BUILD.md b/src/getting-started/01.00.BUILD.md index ff00849..eb57443 100644 --- a/src/getting-started/01.00.BUILD.md +++ b/src/getting-started/01.00.BUILD.md @@ -1,9 +1,9 @@ # New Project ``` shell -$ cargo new rustled - Created binary (application) `rustled` project -$ cd rustled +$ cargo new microrust-start + Created binary (application) `microrust-start` project +$ cd microrust-start Cargo.toml src ``` @@ -47,7 +47,7 @@ error[E0463]: can't find crate for `std` error: aborting due to previous error For more information about this error, try `rustc --explain E0463`. -error: Could not compile `rustled`. +error: Could not compile `microrust-start`. To learn more, run the command again with --verbose. ``` @@ -75,9 +75,6 @@ fn main() { ``` shell $ cargo build --target thumbv6m-none-eabi -``` - -``` shell error: cannot find macro `println!` in this scope --> src/main.rs:4:5 | @@ -91,11 +88,11 @@ We don't need it at the moment, so we can remove it and try to build again. ## Build 3 ``` shell -error: language item required, but not found: `panic_impl` +$ cargo build --target thumbv6m-none-eabi +error: `#[panic_handler]` function required, but not found ``` -This error, is because the panic macro is unimplemented, -when rustc needs it to have an implementation. +This error, is because rustc required a panic handler to be implemented. ### `panic_impl` @@ -112,8 +109,7 @@ If you have forgotten how to do this, try looking at [the cargo book][cargo]. `Cargo.toml` ``` toml -[dependencies] -panic-abort = "~0.2" +{{#include Cargo.toml:5:6}} ``` `src/main.rs` @@ -130,9 +126,6 @@ fn main() { ``` shell $ cargo build --target thumbv6m-none-eabi -``` - -``` shell error: requires `start` lang_item ``` @@ -172,9 +165,7 @@ At this point we need the help of a board-specific support crate and a few cargo Let us add a dependency on the board crate for the micro:bit. ``` toml -[dependencies] -panic-abort = "~0.2" -microbit="~0.5" +{{#include Cargo.toml:5:7}} ``` The microbit crate has 2 notable dependencies: @@ -192,13 +183,15 @@ be implemented by board specific crates. This crate implements the minimal startup / runtime for Cortex-M microcontrollers. Among other things this crate provides: - - the `entry!` macro, to define the entry point of the program. - - the `exception!` macro, to set or override a processor core exception handler. + - the `#[entry]` attribute, to define the entry point of the program. + - a definition of the hard fault handler + - a definition of the default exception handler This crate requires: - a definition of the specific microcontroller's memory layout as a memory.x file. - - a definition of the hard fault handler - - a definition of the default exception handler + fortunately this is usually provided by the board support crates + +To use the `#[entry]` attribute, we will need to add this as a dependency. For more detailed information, you can use the helpful [cortex-m-quickstart crate][qs] and [its documentation][doc]. @@ -209,14 +202,14 @@ you can use the helpful [cortex-m-quickstart crate][qs] and [its documentation][ ## cargo config Before we go any further, -we are going to tweak the cargo's configuration by editing `rustled/.cargo/config`. +we are going to tweak the cargo's configuration by editing `microrust-start/.cargo/config`. For more information, you can read [the documentation here][cargoconfig]. [cargoconfig]: https://doc.rust-lang.org/cargo/reference/config.html ### `.cargo/config` -``` toml + + +``` toml +{{#include ../../.cargo/config}} ``` ### arm-none-eabi-gdb @@ -246,9 +243,7 @@ and cargo will automatically add `--target thumbv6m-none-eabi`. ### `Cargo.toml` ``` toml -[dependencies] -panic-abort = "~0.2" -microbit="~0.5" +{{#include Cargo.toml:5:8}} ``` ### `src/main.rs` @@ -259,7 +254,9 @@ microbit="~0.5" extern crate panic_abort; -entry!(main); +use cortex_m_rt::entry; + +#[entry]; fn main() { } ``` @@ -269,22 +266,20 @@ $ cargo build ``` ``` shell -error[E0308]: mismatched types - --> src/main.rs:9:1 +error: custom attribute panicked + --> src/main.rs:7:1 | -8 | entry!(main); - | ^^^^^^^^^^^^^ expected !, found () +7 | #[entry] + | ^^^^^^^^ | - = note: expected type `fn() -> !` - found type `fn() {main}` - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + = help: message: `#[entry]` function must have signature `[unsafe] fn() -> !` ``` ## `!` return type A little known rust feature, so I will forgive you if you do not know what this means. -A return type of `!` means that the function cannot return -An easy way to implement this, is by using an infinite loop. +A return type of `!` means that the function cannot return. +An easy way to implement this is to use an infinite loop. ### `src/main.rs` @@ -294,10 +289,9 @@ An easy way to implement this, is by using an infinite loop. extern crate panic_abort; -#[macro_use(entry)] -extern crate microbit; +use cortex_m_rt::entry; -entry!(main); +#[entry] fn main() -> ! { loop {} } @@ -305,98 +299,19 @@ fn main() -> ! { ## Build 6 -``` shell -error: linking with `arm-none-eabi-gcc` failed: exit code: 1 - | - = note: "arm-none-eabi-gcc" "-L" "/home/xxx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv6m-none-eabi/lib" "/home/xxx/rust/rustled/target/thumbv6m-none-eabi/debug/deps/rustled-e6053d34b0422141.2yhvr0tmp69gb94x.rcgu.o" "-o" -# SNIP - "/home/xxx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv6m-none-eabi/lib/libcore-fb37a4ea1db1e473.rlib" "-Wl,--end-group" "/home/xxx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv6m-none-eabi/lib/libcompiler_builtins-f2357c0397dd7e0d.rlib" "-Wl,-Tlink.x" "-nostartfiles" "-Wl,-Bdynamic" - = note: /usr/lib/gcc/arm-none-eabi/8.1.0/../../../../arm-none-eabi/bin/ld: cannot open linker script file memory.x: No such file or directory - collect2: error: ld returned 1 exit status -``` - -A scary error, but if you look closely you will see `cannot open linker script file memory.x: No such file or directory`. -We mentioned something a little earlier about memory.x file. -To save you the hassle of scouring the internet for one or creating your own, you can copy it over into your project: - -``` shell -$ cp ../../memory.x ./ -``` - -> Often a board support crate will already include this, so this step will not be necessary. - -## Build 7 - -``` shell -error: linking with `arm-none-eabi-gcc` failed: exit code: 1 - | - = note: "arm-none-eabi-gcc" "-L" "/home/xxx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv6m-none-eabi/lib" "/home/xxx/rust/rustled/target/thumbv6m-none-eabi/debug/deps/rustled-e6053d34b0422141.2yhvr0tmp69gb94x.rcgu.o" "-o" -# SNIP - "/home/xxx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv6m-none-eabi/lib/libcompiler_builtins-f2357c0397dd7e0d.rlib" "-Wl,-Tlink.x" "-nostartfiles" "-Wl,-Bdynamic" - = note: device.x:1: undefined symbol `DefaultHandler' referenced in expression - collect2: error: ld returned 1 exit status - -``` - -Notice `undefined symbol 'DefaultHandler' referenced in expression`. -We said earlier, as with the memory, -that the hard fault handler and default exception handler both need defining. - -### `Cargo.toml` - -``` toml -[dependencies] -panic-abort = "~0.2" -cortex-m-rt="~0.5" -microbit="~0.5" -``` - -### `src/main.rs` - -``` rust -#![no_std] -#![no_main] - -extern crate panic_abort; -extern crate cortex_m_rt as rt; - -#[macro_use(entry, exception)] -extern crate microbit; - -use rt::ExceptionFrame; - -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); -fn main() -> ! { - loop {} -} -``` - -It is all a bit ugly, but fortunately it only needs to be done once. If you try building now, you should finally be greeted with `Finished`! ``` shell $ cargo build -Finished dev [unoptimized + debuginfo] target(s) in 20.51s + Finished dev [unoptimized + debuginfo] target(s) in 0.04s ``` ## Build Complete As a sanity check, let's verify that the produced executable is actually an ARM binary: -``` console -$ file target/thumbv6m-none-eabi/debug/rustled -target/thumbv6m-none-eabi/debug/rustled: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped - ^^^ ^^^^ +``` shell +$ file target/thumbv6m-none-eabi/debug/microrust-start +target/thumbv6m-none-eabi/debug/microrust-start: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped + ^^^ ^^^^^ ``` diff --git a/src/getting-started/Cargo.toml b/src/getting-started/Cargo.toml index fcdf173..186ff92 100644 --- a/src/getting-started/Cargo.toml +++ b/src/getting-started/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "start" -version = "0.1.0" +version = "0.2.0" [dependencies] -panic-abort = "~0.2" -cortex-m-rt="~0.5" -microbit="~0.5" \ No newline at end of file +panic-abort = "~0.3" +microbit="~0.6" +cortex-m-rt="~0.6" diff --git a/src/getting-started/src/main.rs b/src/getting-started/src/main.rs index 822e61c..db8c9ce 100644 --- a/src/getting-started/src/main.rs +++ b/src/getting-started/src/main.rs @@ -1,30 +1,16 @@ #![no_std] #![no_main] -extern crate panic_abort; -extern crate cortex_m_rt as rt; - -#[macro_use(entry, exception)] +extern crate cortex_m_rt; extern crate microbit; +extern crate panic_abort; -use rt::ExceptionFrame; +use cortex_m_rt::entry; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { let _y; let x = 42; _y = x; loop {} -} \ No newline at end of file +} diff --git a/src/hello-world/Cargo.toml b/src/hello-world/Cargo.toml index c8b2012..4a939ce 100644 --- a/src/hello-world/Cargo.toml +++ b/src/hello-world/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "hello" -version = "0.1.0" +version = "0.2.0" [dependencies] -cortex-m-rt="~0.5" -cortex-m-semihosting="" -panic-semihosting = "~0.3" -microbit="~0.5" +microbit="~0.6" +cortex-m-rt="~0.6" +cortex-m-semihosting="~0.3" +panic-semihosting = "~0.5" diff --git a/src/hello-world/src/main.rs b/src/hello-world/src/main.rs index 919ecc2..253bdcb 100644 --- a/src/hello-world/src/main.rs +++ b/src/hello-world/src/main.rs @@ -4,31 +4,17 @@ extern crate panic_semihosting; extern crate cortex_m_rt as rt; extern crate cortex_m_semihosting as sh; - -#[macro_use(entry, exception)] extern crate microbit; use core::fmt::Write; -use rt::ExceptionFrame; +use rt::entry; use sh::hio; use microbit::hal::prelude::*; use microbit::hal::serial; use microbit::hal::serial::BAUD115200; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { let mut stdout = hio::hstdout().unwrap(); writeln!(stdout, "Start").unwrap(); diff --git a/src/microbit/Cargo.toml b/src/microbit/Cargo.toml index 6c033ad..7a57323 100644 --- a/src/microbit/Cargo.toml +++ b/src/microbit/Cargo.toml @@ -3,8 +3,8 @@ name = "microbit" version = "0.1.0" [dependencies] -cortex-m-rt="~0.5" -cortex-m-semihosting="" -panic-abort = "~0.2" -panic-semihosting = "~0.3" -microbit="~0.5" +cortex-m-rt="~0.6" +cortex-m-semihosting="~0.3" +panic-abort = "~0.3" +panic-semihosting = "~0.5" +microbit="~0.6" diff --git a/src/microbit/examples/buttons.rs b/src/microbit/examples/buttons.rs index 6d2a358..1b75469 100644 --- a/src/microbit/examples/buttons.rs +++ b/src/microbit/examples/buttons.rs @@ -3,30 +3,16 @@ extern crate panic_abort; extern crate cortex_m_rt as rt; - -#[macro_use(entry, exception)] extern crate microbit; use core::fmt::Write; -use rt::ExceptionFrame; +use rt::entry; use microbit::hal::prelude::*; use microbit::hal::serial; use microbit::hal::serial::BAUD115200; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { if let Some(p) = microbit::Peripherals::take() { // Split GPIO diff --git a/src/microbit/examples/buttons_poll.rs b/src/microbit/examples/buttons_poll.rs index 53afa01..fbeb5b0 100644 --- a/src/microbit/examples/buttons_poll.rs +++ b/src/microbit/examples/buttons_poll.rs @@ -3,8 +3,6 @@ extern crate panic_abort; extern crate cortex_m_rt as rt; - -#[macro_use(entry, exception)] extern crate microbit; use core::fmt::Write; @@ -15,19 +13,7 @@ use microbit::hal::delay::Delay; use microbit::hal::serial; use microbit::hal::serial::BAUD115200; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { if let Some(p) = microbit::Peripherals::take() { // Split GPIO diff --git a/src/microbit/examples/display_blocking.rs b/src/microbit/examples/display_blocking.rs index a41a3df..5e57251 100644 --- a/src/microbit/examples/display_blocking.rs +++ b/src/microbit/examples/display_blocking.rs @@ -8,29 +8,15 @@ extern crate cortex_m_semihosting as sh; extern crate panic_abort; use core::fmt::Write; - -use rt::ExceptionFrame; +use rt::entry; use microbit::hal::delay::Delay; use microbit::hal::prelude::*; use microbit::hal::serial; use microbit::hal::serial::BAUD115200; - use microbit::led; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { if let Some(p) = microbit::Peripherals::take() { let mut gpio = p.GPIO.split(); diff --git a/src/serial/Cargo.toml b/src/serial/Cargo.toml index 6d80b8d..cb62ac3 100644 --- a/src/serial/Cargo.toml +++ b/src/serial/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" [dependencies] heapless="~0.3" -cortex-m-rt="~0.5" -cortex-m-semihosting="" -panic-semihosting = "~0.3" -microbit="~0.5" +cortex-m-rt="~0.6" +cortex-m-semihosting="~0.3" +panic-semihosting = "~0.5" +microbit="~0.6" diff --git a/src/serial/examples/countdown.rs b/src/serial/examples/countdown.rs index cd2aff2..5639429 100644 --- a/src/serial/examples/countdown.rs +++ b/src/serial/examples/countdown.rs @@ -5,12 +5,10 @@ extern crate panic_semihosting; extern crate cortex_m_rt as rt; extern crate cortex_m_semihosting as sh; extern crate heapless; - -#[macro_use(entry, exception, block)] extern crate microbit; use core::fmt::Write; -use rt::ExceptionFrame; +use rt::entry; use sh::hio; use heapless::{consts, Vec, String}; @@ -19,19 +17,7 @@ use microbit::hal::delay::Delay; use microbit::hal::serial; use microbit::hal::serial::BAUD115200; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { let mut stdout = hio::hstdout().unwrap(); writeln!(stdout, "Start").unwrap(); diff --git a/src/serial/examples/display_echo.rs.disabled b/src/serial/examples/display_echo.rs.disabled index e96f0fd..4171093 100644 --- a/src/serial/examples/display_echo.rs.disabled +++ b/src/serial/examples/display_echo.rs.disabled @@ -5,12 +5,10 @@ extern crate panic_semihosting; extern crate cortex_m_rt as rt; extern crate cortex_m_semihosting as sh; extern crate heapless; - -#[macro_use(entry, exception, block)] extern crate microbit; use core::fmt::Write; -use rt::ExceptionFrame; +use rt::entry; use sh::hio; use heapless::{consts, Vec, String}; @@ -19,19 +17,7 @@ use microbit::hal::delay::Delay; use microbit::hal::serial; use microbit::hal::serial::BAUD115200; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { let mut stdout = hio::hstdout().unwrap(); writeln!(stdout, "Start").unwrap(); diff --git a/src/serial/examples/quiz.rs b/src/serial/examples/quiz.rs index b4ddb32..612edd0 100644 --- a/src/serial/examples/quiz.rs +++ b/src/serial/examples/quiz.rs @@ -4,12 +4,10 @@ extern crate panic_semihosting; extern crate cortex_m_rt as rt; extern crate cortex_m_semihosting as sh; - -#[macro_use(entry, exception, block)] extern crate microbit; use core::fmt::Write; -use rt::ExceptionFrame; +use rt::entry; use sh::hio; use microbit::hal::delay::Delay; @@ -18,18 +16,6 @@ use microbit::hal::serial; use microbit::hal::serial::BAUD115200; use microbit::led; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - const WINNING_SCORE: u8 = 6; const QUESTION_COUNT: u8 = 2*WINNING_SCORE - 1; @@ -49,7 +35,7 @@ const LETTER_B: [[u8; 5]; 5] = [ [0, 1, 1, 0, 0], ]; -entry!(main); +#[entry] fn main() -> ! { let mut stdout = hio::hstdout().unwrap(); writeln!(stdout, "Start").unwrap(); diff --git a/src/serial/examples/reverse.rs b/src/serial/examples/reverse.rs index a835d3f..0b53bf1 100644 --- a/src/serial/examples/reverse.rs +++ b/src/serial/examples/reverse.rs @@ -5,12 +5,10 @@ extern crate panic_semihosting; extern crate cortex_m_rt as rt; extern crate cortex_m_semihosting as sh; extern crate heapless; - -#[macro_use(entry, exception, block)] extern crate microbit; use core::fmt::Write; -use rt::ExceptionFrame; +use rt::entry; use sh::hio; use heapless::{consts, Vec}; @@ -19,19 +17,7 @@ use microbit::hal::delay::Delay; use microbit::hal::serial; use microbit::hal::serial::BAUD115200; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { let mut stdout = hio::hstdout().unwrap(); writeln!(stdout, "Start").unwrap(); diff --git a/src/serial/src/main.rs b/src/serial/src/main.rs index c2c660b..4773c79 100644 --- a/src/serial/src/main.rs +++ b/src/serial/src/main.rs @@ -4,31 +4,18 @@ extern crate panic_semihosting; extern crate cortex_m_rt as rt; extern crate cortex_m_semihosting as sh; - -#[macro_use(entry, exception, block)] extern crate microbit; use core::fmt::Write; -use rt::ExceptionFrame; +use rt::entry; use sh::hio; use microbit::hal::prelude::*; use microbit::hal::serial; use microbit::hal::serial::BAUD115200; +use microbit::nb::block; -exception!(HardFault, hard_fault); - -fn hard_fault(ef: &ExceptionFrame) -> ! { - panic!("{:#?}", ef); -} - -exception!(*, default_handler); - -fn default_handler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} - -entry!(main); +#[entry] fn main() -> ! { let mut stdout = hio::hstdout().unwrap(); writeln!(stdout, "Start").unwrap(); From ec59c1c010d6167a322e7d2f2d7ab550f02b0ce8 Mon Sep 17 00:00:00 2001 From: Michael Droogleever Date: Sat, 13 Oct 2018 22:10:13 +0200 Subject: [PATCH 2/6] fix broken include --- ci/install.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ci/install.sh b/ci/install.sh index 11150c7..18dd46d 100644 --- a/ci/install.sh +++ b/ci/install.sh @@ -1,24 +1,26 @@ set -euxo pipefail +MDBOOK_VER=0.2.1 + main() { - if [ "$(mdbook -V)" != "mdbook v0.1.8" ]; then + if [ "$(mdbook -V)" != "mdbook v$MDBOOK_VER" ]; then curl -LSfs https://japaric.github.io/trust/install.sh | \ sh -s -- \ --force \ --git rust-lang-nursery/mdBook \ - --tag v0.1.8 \ + --tag v$MDBOOK_VER \ --target x86_64-unknown-linux-musl \ || true fi - if [ "$(mdbook -V)" != "mdbook v0.1.8" ]; then - cargo install --target x86_64-unknown-linux-gnu --version 0.1.8 mdbook \ + if [ "$(mdbook -V)" != "mdbook v$MDBOOK_VER" ]; then + cargo install --target x86_64-unknown-linux-gnu --version $MDBOOK_VER mdbook \ || true fi - if [ "$(mdbook -V)" != "mdbook v0.1.8" ]; then - cargo install --force --target x86_64-unknown-linux-gnu --version 0.1.8 mdbook + if [ "$(mdbook -V)" != "mdbook v$MDBOOK_VER" ]; then + cargo install --force --target x86_64-unknown-linux-gnu --version $MDBOOK_VER mdbook fi rustup target add thumbv6m-none-eabi From 28e7da3ad116fe5fe67ad98b3ae259e4aeb5942b Mon Sep 17 00:00:00 2001 From: Michael Droogleever Date: Sat, 13 Oct 2018 22:34:32 +0200 Subject: [PATCH 3/6] bump mdbook to v0.2.1, fix ci and links --- src/appendix/troubleshooting.md | 2 +- src/getting-started/04.00.SOLUTION.md | 2 +- src/hello-world/02.00.UART.md | 4 +- src/hello-world/03.01.SOLUTION.md | 2 +- src/microbit/03.00.DISPLAY.md | 2 +- src/setup/LINUX.md | 4 +- src/setup/MACOS.md | 2 +- src/setup/README.md | 6 +-- src/setup/VERIFY.md | 4 +- src/setup/WINDOWS.md | 2 +- src/theme/index.hbs | 73 ++++++++++++--------------- 11 files changed, 47 insertions(+), 56 deletions(-) diff --git a/src/appendix/troubleshooting.md b/src/appendix/troubleshooting.md index d16ea45..82d1727 100644 --- a/src/appendix/troubleshooting.md +++ b/src/appendix/troubleshooting.md @@ -26,7 +26,7 @@ in procedure 'ocd_bouncer' without root privilege. - Windows: You are probably missing the USB drivers. -[these instructions]: setup/LINUX.html#udev%20rules +[these instructions]: ../setup/LINUX.html#udev%20rules ### can't connect to OpenOCD - "Polling again in X00ms" diff --git a/src/getting-started/04.00.SOLUTION.md b/src/getting-started/04.00.SOLUTION.md index 6f9b9ef..b8dd458 100644 --- a/src/getting-started/04.00.SOLUTION.md +++ b/src/getting-started/04.00.SOLUTION.md @@ -17,7 +17,7 @@ This is a recap of what we have done so far. ## `.cargo/config` ``` toml -{{#include .cargo/config}} +{{#include ../../.cargo/config}} ``` ## `.gdbinit` diff --git a/src/hello-world/02.00.UART.md b/src/hello-world/02.00.UART.md index ae13bb8..af9a110 100644 --- a/src/hello-world/02.00.UART.md +++ b/src/hello-world/02.00.UART.md @@ -18,8 +18,8 @@ The micro:bit allows us to transmit and receive this serial communication over U To read and write to the serial bus from your computer, you will need to configure your tooling: -- [*nix](hello-world/02.01.NIX.html) -- [Windows](hello-world/02.02.WINDOWS.html) +- [*nix](02.01.NIX.html) +- [Windows](02.02.WINDOWS.html) ## Code diff --git a/src/hello-world/03.01.SOLUTION.md b/src/hello-world/03.01.SOLUTION.md index ccc153a..6ad5fab 100644 --- a/src/hello-world/03.01.SOLUTION.md +++ b/src/hello-world/03.01.SOLUTION.md @@ -12,4 +12,4 @@ You now know enough to start playing around with the micro:bit's LED display and as well as logging data back to the host. You should know that the microbit crate already includes an abstraction for the LED display for you to use. -How to implemented a simple blocking display driver is demonstrated in the [LED display chapter](display/00.00.README.html). +How to implemented a simple blocking display driver is demonstrated in the [LED display chapter](../display/00.00.README.html). diff --git a/src/microbit/03.00.DISPLAY.md b/src/microbit/03.00.DISPLAY.md index 9542286..517ea52 100644 --- a/src/microbit/03.00.DISPLAY.md +++ b/src/microbit/03.00.DISPLAY.md @@ -1,7 +1,7 @@ # Display The micro:bit display is not trivial to control, so a driver is needed; -see [the display chapter](display/00.00.README.html) for more details. +see [the display chapter](../display/00.00.README.html) for more details. Display calls for now are only blocking, and can either be for binary images (0 for off, 1 for on), or for monochrome images with differing brightness levels diff --git a/src/setup/LINUX.md b/src/setup/LINUX.md index ba83668..96769ca 100644 --- a/src/setup/LINUX.md +++ b/src/setup/LINUX.md @@ -85,8 +85,6 @@ $ # ^^^^ If `uucp` appears in the output. You are all set! Go to the [next section]. Otherwise, keep reading: -[next section]: setup/VERIFY.html - - Add yourself to the `uucp` group. ``` shell @@ -117,3 +115,5 @@ shells *won't* have access to `uucp` devices unless you manually re-log on them command. Now, go to the [next section]. + +[next section]: ../setup/VERIFY.html diff --git a/src/setup/MACOS.md b/src/setup/MACOS.md index 0278f28..eb58077 100644 --- a/src/setup/MACOS.md +++ b/src/setup/MACOS.md @@ -16,4 +16,4 @@ Caskroom/tap` first and try again. That's all! Go to the [next section]. -[next section]: setup/VERIFY.html +[next section]: ../setup/VERIFY.html diff --git a/src/setup/README.md b/src/setup/README.md index 43c1238..a0ff340 100644 --- a/src/setup/README.md +++ b/src/setup/README.md @@ -56,6 +56,6 @@ rustc 1.28.0-nightly (056f589fb 2018-06-22) Now follow the instructions specific to the OS you are using: -- [Linux](setup/LINUX.html) -- [Windows](setup/WINDOWS.html) -- [macOS](setup/MACOS.html) +- [Linux](../setup/LINUX.html) +- [Windows](../setup/WINDOWS.html) +- [macOS](../setup/MACOS.html) diff --git a/src/setup/VERIFY.md b/src/setup/VERIFY.md index b0577d6..b22cbf0 100644 --- a/src/setup/VERIFY.md +++ b/src/setup/VERIFY.md @@ -30,7 +30,7 @@ crw-rw---- 1 root uucp 189, 160 Jul 8 14:06 /dev/bus/usb/002/033 The group should be `uucp`. If it's not ... then check your [udev rules] and try re-loading them with: -[udev rules]: setup/LINUX.html#udev%20rules +[udev rules]: ../setup/LINUX.html#udev%20rules ``` shell $ sudo udevadm control --reload-rules @@ -79,7 +79,7 @@ Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints (If you don't ... then check the [general troubleshooting] instructions.) -[general troubleshooting]: appendix/troubleshooting.html +[general troubleshooting]: ../appendix/troubleshooting.html `openocd` will block the terminal. That's fine. diff --git a/src/setup/WINDOWS.md b/src/setup/WINDOWS.md index ee008aa..f7ac5d2 100644 --- a/src/setup/WINDOWS.md +++ b/src/setup/WINDOWS.md @@ -40,4 +40,4 @@ Download the latest `putty.exe` from [this site] and place it somewhere in your That's all! Go to the [next section]. -[next section]: setup/VERIFY.html +[next section]: ../setup/VERIFY.html diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 7f835e2..7923f75 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -9,42 +9,36 @@ - + + + + + - + + - - - - - - - - + + + + {{#each additional_css}} - + {{/each}} {{#if mathjax_support}} {{/if}} - - - - - + + + - - - - + + + + + {{/if}} - {{#if search_enabled}} - - {{/if}} {{#if search_js}} - - - + + + {{/if}} - - - + + + {{#each additional_js}} - + {{/each}} {{#if is_print}} From 1edb3b94e3bd6bfbd7906880bbcd30709b3659c4 Mon Sep 17 00:00:00 2001 From: Michael Droogleever Date: Sat, 13 Oct 2018 22:37:28 +0200 Subject: [PATCH 4/6] small fixes --- src/appendix/troubleshooting.md | 2 +- src/getting-started/01.00.BUILD.md | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/appendix/troubleshooting.md b/src/appendix/troubleshooting.md index 82d1727..b9156e6 100644 --- a/src/appendix/troubleshooting.md +++ b/src/appendix/troubleshooting.md @@ -136,7 +136,7 @@ $ rustup target add thumbv7em-none-eabihf ## Build problems -### `error: language item required, but not found: \`eh_personality\`` +### `error: language item required, but not found: 'eh_personality'` #### Cause diff --git a/src/getting-started/01.00.BUILD.md b/src/getting-started/01.00.BUILD.md index eb57443..83a6688 100644 --- a/src/getting-started/01.00.BUILD.md +++ b/src/getting-started/01.00.BUILD.md @@ -209,22 +209,6 @@ For more information, you can read [the documentation here][cargoconfig]. ### `.cargo/config` - - ``` toml {{#include ../../.cargo/config}} ``` From 498601c45199e4c54472768193cc367902e8f204 Mon Sep 17 00:00:00 2001 From: Michael Droogleever Date: Sat, 13 Oct 2018 22:42:03 +0200 Subject: [PATCH 5/6] bump rust nightly --- .travis.yml | 2 +- src/setup/README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 01d4132..f03abe8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: rust -rust: nightly-2018-08-01 +rust: nightly-2018-10-12 addons: apt: diff --git a/src/setup/README.md b/src/setup/README.md index a0ff340..c896bab 100644 --- a/src/setup/README.md +++ b/src/setup/README.md @@ -27,7 +27,7 @@ any recent version should work but we have listed the version we have tested. - `arm-none-eabi-gdb`. -- `minicom` on Linux and macOS. Tested version: 2.7. +- `minicom` on Linux and macOS. Tested version: 2.7. Readers report that `picocom` also works but we'll use `minicom` in this book. - `PuTTY` on Windows. @@ -44,12 +44,12 @@ Then, install or switch to the nightly channel. $ rustup default nightly ``` -**NOTE** Make sure you have a nightly newer than `nightly-2018-06-22`. +**NOTE** Make sure you have a nightly newer than `nightly-2018-10-12`. `rustc -V` should return a date newer than the one shown below: ``` shell $ rustc -V -rustc 1.28.0-nightly (056f589fb 2018-06-22) +rustc 1.31.0-nightly (2c2e2c57d 2018-10-12) ``` ### OS specific instructions From 590efd3cfd145ac5a2fe5dd9d6ceb89456e2a9ff Mon Sep 17 00:00:00 2001 From: Michael Droogleever Date: Sat, 13 Oct 2018 23:00:57 +0200 Subject: [PATCH 6/6] fix mdbook broken links --- src/hello-world/02.00.UART.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hello-world/02.00.UART.md b/src/hello-world/02.00.UART.md index af9a110..b661a02 100644 --- a/src/hello-world/02.00.UART.md +++ b/src/hello-world/02.00.UART.md @@ -18,8 +18,8 @@ The micro:bit allows us to transmit and receive this serial communication over U To read and write to the serial bus from your computer, you will need to configure your tooling: -- [*nix](02.01.NIX.html) -- [Windows](02.02.WINDOWS.html) +- [*nix](../hello-world/02.01.NIX.html) +- [Windows](../hello-world/02.02.WINDOWS.html) ## Code