2018-10 version bumps and compatibility updates

This commit is contained in:
Michael Droogleever
2018-10-13 21:52:24 +02:00
parent cac16f3494
commit da3e868599
21 changed files with 106 additions and 335 deletions

View File

@@ -1,9 +1,14 @@
# Configure builds for our target, the micro:bit's architecture
[target.thumbv6m-none-eabi] [target.thumbv6m-none-eabi]
# Execute binary using gdb when calling cargo run
runner = "arm-none-eabi-gdb" runner = "arm-none-eabi-gdb"
# Tweak to the linking process required by the cortex-m-rt crate
rustflags = [ rustflags = [
"-C", "link-arg=-Wl,-Tlink.x", "-C", "link-arg=-Tlink.x",
"-C", "link-arg=-nostartfiles", # The LLD linker is selected by default
#"-C", "linker=arm-none-eabi-ld",
] ]
# Automatically select this target when cargo building this project
[build] [build]
target = "thumbv6m-none-eabi" target = "thumbv6m-none-eabi"

View File

@@ -56,9 +56,11 @@
- [Multiplexing](display/03.02.MULT.md) - [Multiplexing](display/03.02.MULT.md)
- [Full Solution](display/03.03.FULL.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 - 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) - [WIP - Real time](rtfm/00.00.README.md)

View File

@@ -147,3 +147,14 @@ The `eh_personality` language item is used to implement stack unwinding in case
You need to use the correct target You need to use the correct target
by using `--target thumbv6m-none-eabi` by using `--target thumbv6m-none-eabi`
or modifying `.cargo/config` 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.

View File

@@ -3,7 +3,7 @@ name = "display"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
cortex-m-rt="~0.5" cortex-m-rt="~0.6"
cortex-m-semihosting="~0.3" cortex-m-semihosting="~0.3"
panic-semihosting = "~0.3" panic-semihosting = "~0.5"
microbit="~0.5" microbit="~0.6"

View File

@@ -4,12 +4,10 @@
extern crate panic_semihosting; extern crate panic_semihosting;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh; extern crate cortex_m_semihosting as sh;
#[macro_use(entry, exception)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
use rt::ExceptionFrame; use rt::entry;
use sh::hio; use sh::hio;
use microbit::hal::delay::Delay; use microbit::hal::delay::Delay;
@@ -20,18 +18,6 @@ use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
use microbit::hal::prelude::*; 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<Output<PushPull>>; type LED = PIN<Output<PushPull>>;
const DEFAULT_DELAY_MS: u32 = 2; const DEFAULT_DELAY_MS: u32 = 2;
@@ -128,7 +114,7 @@ impl Display {
} }
} }
entry!(main); #[entry]
fn main() -> ! { fn main() -> ! {
let mut stdout = hio::hstdout().unwrap(); let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();

View File

@@ -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"

View File

@@ -1,9 +1,9 @@
# New Project # New Project
``` shell ``` shell
$ cargo new rustled $ cargo new microrust-start
Created binary (application) `rustled` project Created binary (application) `microrust-start` project
$ cd rustled $ cd microrust-start
Cargo.toml src Cargo.toml src
``` ```
@@ -47,7 +47,7 @@ error[E0463]: can't find crate for `std`
error: aborting due to previous error error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`. 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. To learn more, run the command again with --verbose.
``` ```
@@ -75,9 +75,6 @@ fn main() {
``` shell ``` shell
$ cargo build --target thumbv6m-none-eabi $ cargo build --target thumbv6m-none-eabi
```
``` shell
error: cannot find macro `println!` in this scope error: cannot find macro `println!` in this scope
--> src/main.rs:4:5 --> 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 ## Build 3
``` shell ``` 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, This error, is because rustc required a panic handler to be implemented.
when rustc needs it to have an implementation.
### `panic_impl` ### `panic_impl`
@@ -112,8 +109,7 @@ If you have forgotten how to do this, try looking at [the cargo book][cargo].
`Cargo.toml` `Cargo.toml`
``` toml ``` toml
[dependencies] {{#include Cargo.toml:5:6}}
panic-abort = "~0.2"
``` ```
`src/main.rs` `src/main.rs`
@@ -130,9 +126,6 @@ fn main() {
``` shell ``` shell
$ cargo build --target thumbv6m-none-eabi $ cargo build --target thumbv6m-none-eabi
```
``` shell
error: requires `start` lang_item 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. Let us add a dependency on the board crate for the micro:bit.
``` toml ``` toml
[dependencies] {{#include Cargo.toml:5:7}}
panic-abort = "~0.2"
microbit="~0.5"
``` ```
The microbit crate has 2 notable dependencies: 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. This crate implements the minimal startup / runtime for Cortex-M microcontrollers.
Among other things this crate provides: Among other things this crate provides:
- the `entry!` macro, to define the entry point of the program. - the `#[entry]` attribute, to define the entry point of the program.
- the `exception!` macro, to set or override a processor core exception handler. - a definition of the hard fault handler
- a definition of the default exception handler
This crate requires: This crate requires:
- a definition of the specific microcontroller's memory layout as a memory.x file. - a definition of the specific microcontroller's memory layout as a memory.x file.
- a definition of the hard fault handler fortunately this is usually provided by the board support crates
- a definition of the default exception handler
To use the `#[entry]` attribute, we will need to add this as a dependency.
For more detailed information, For more detailed information,
you can use the helpful [cortex-m-quickstart crate][qs] and [its documentation][doc]. 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 ## cargo config
Before we go any further, 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]. For more information, you can read [the documentation here][cargoconfig].
[cargoconfig]: https://doc.rust-lang.org/cargo/reference/config.html [cargoconfig]: https://doc.rust-lang.org/cargo/reference/config.html
### `.cargo/config` ### `.cargo/config`
``` toml <!-- ``` toml
# Configure builds for our target # Configure builds for our target
[target.thumbv6m-none-eabi] [target.thumbv6m-none-eabi]
# Execute binary using gdb # Execute binary using gdb
@@ -230,6 +223,10 @@ rustflags = [
# Automatically select this target when running cargo for this project # Automatically select this target when running cargo for this project
[build] [build]
target = "thumbv6m-none-eabi" target = "thumbv6m-none-eabi"
``` -->
``` toml
{{#include ../../.cargo/config}}
``` ```
### arm-none-eabi-gdb ### arm-none-eabi-gdb
@@ -246,9 +243,7 @@ and cargo will automatically add `--target thumbv6m-none-eabi`.
### `Cargo.toml` ### `Cargo.toml`
``` toml ``` toml
[dependencies] {{#include Cargo.toml:5:8}}
panic-abort = "~0.2"
microbit="~0.5"
``` ```
### `src/main.rs` ### `src/main.rs`
@@ -259,7 +254,9 @@ microbit="~0.5"
extern crate panic_abort; extern crate panic_abort;
entry!(main); use cortex_m_rt::entry;
#[entry];
fn main() { fn main() {
} }
``` ```
@@ -269,22 +266,20 @@ $ cargo build
``` ```
``` shell ``` shell
error[E0308]: mismatched types error: custom attribute panicked
--> src/main.rs:9:1 --> src/main.rs:7:1
| |
8 | entry!(main); 7 | #[entry]
| ^^^^^^^^^^^^^ expected !, found () | ^^^^^^^^
| |
= note: expected type `fn() -> !` = help: message: `#[entry]` function must have signature `[unsafe] 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)
``` ```
## `!` return type ## `!` return type
A little known rust feature, so I will forgive you if you do not know what this means. 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 A return type of `!` means that the function cannot return.
An easy way to implement this, is by using an infinite loop. An easy way to implement this is to use an infinite loop.
### `src/main.rs` ### `src/main.rs`
@@ -294,10 +289,9 @@ An easy way to implement this, is by using an infinite loop.
extern crate panic_abort; extern crate panic_abort;
#[macro_use(entry)] use cortex_m_rt::entry;
extern crate microbit;
entry!(main); #[entry]
fn main() -> ! { fn main() -> ! {
loop {} loop {}
} }
@@ -305,98 +299,19 @@ fn main() -> ! {
## Build 6 ## 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`! If you try building now, you should finally be greeted with `Finished`!
``` shell ``` shell
$ cargo build $ cargo build
Finished dev [unoptimized + debuginfo] target(s) in 20.51s Finished dev [unoptimized + debuginfo] target(s) in 0.04s
``` ```
## Build Complete ## Build Complete
As a sanity check, let's verify that the produced executable is actually an ARM binary: As a sanity check, let's verify that the produced executable is actually an ARM binary:
``` console ``` shell
$ file target/thumbv6m-none-eabi/debug/rustled $ file target/thumbv6m-none-eabi/debug/microrust-start
target/thumbv6m-none-eabi/debug/rustled: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped target/thumbv6m-none-eabi/debug/microrust-start: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
^^^ ^^^^ ^^^ ^^^^^
``` ```

View File

@@ -1,8 +1,8 @@
[package] [package]
name = "start" name = "start"
version = "0.1.0" version = "0.2.0"
[dependencies] [dependencies]
panic-abort = "~0.2" panic-abort = "~0.3"
cortex-m-rt="~0.5" microbit="~0.6"
microbit="~0.5" cortex-m-rt="~0.6"

View File

@@ -1,30 +1,16 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
extern crate panic_abort; extern crate cortex_m_rt;
extern crate cortex_m_rt as rt;
#[macro_use(entry, exception)]
extern crate microbit; extern crate microbit;
extern crate panic_abort;
use rt::ExceptionFrame; use cortex_m_rt::entry;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
let _y; let _y;
let x = 42; let x = 42;
_y = x; _y = x;
loop {} loop {}
} }

View File

@@ -1,9 +1,9 @@
[package] [package]
name = "hello" name = "hello"
version = "0.1.0" version = "0.2.0"
[dependencies] [dependencies]
cortex-m-rt="~0.5" microbit="~0.6"
cortex-m-semihosting="" cortex-m-rt="~0.6"
panic-semihosting = "~0.3" cortex-m-semihosting="~0.3"
microbit="~0.5" panic-semihosting = "~0.5"

View File

@@ -4,31 +4,17 @@
extern crate panic_semihosting; extern crate panic_semihosting;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh; extern crate cortex_m_semihosting as sh;
#[macro_use(entry, exception)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
use rt::ExceptionFrame; use rt::entry;
use sh::hio; use sh::hio;
use microbit::hal::prelude::*; use microbit::hal::prelude::*;
use microbit::hal::serial; use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
let mut stdout = hio::hstdout().unwrap(); let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();

View File

@@ -3,8 +3,8 @@ name = "microbit"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
cortex-m-rt="~0.5" cortex-m-rt="~0.6"
cortex-m-semihosting="" cortex-m-semihosting="~0.3"
panic-abort = "~0.2" panic-abort = "~0.3"
panic-semihosting = "~0.3" panic-semihosting = "~0.5"
microbit="~0.5" microbit="~0.6"

View File

@@ -3,30 +3,16 @@
extern crate panic_abort; extern crate panic_abort;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
#[macro_use(entry, exception)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
use rt::ExceptionFrame; use rt::entry;
use microbit::hal::prelude::*; use microbit::hal::prelude::*;
use microbit::hal::serial; use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
if let Some(p) = microbit::Peripherals::take() { if let Some(p) = microbit::Peripherals::take() {
// Split GPIO // Split GPIO

View File

@@ -3,8 +3,6 @@
extern crate panic_abort; extern crate panic_abort;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
#[macro_use(entry, exception)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
@@ -15,19 +13,7 @@ use microbit::hal::delay::Delay;
use microbit::hal::serial; use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
if let Some(p) = microbit::Peripherals::take() { if let Some(p) = microbit::Peripherals::take() {
// Split GPIO // Split GPIO

View File

@@ -8,29 +8,15 @@ extern crate cortex_m_semihosting as sh;
extern crate panic_abort; extern crate panic_abort;
use core::fmt::Write; use core::fmt::Write;
use rt::entry;
use rt::ExceptionFrame;
use microbit::hal::delay::Delay; use microbit::hal::delay::Delay;
use microbit::hal::prelude::*; use microbit::hal::prelude::*;
use microbit::hal::serial; use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
use microbit::led; use microbit::led;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
if let Some(p) = microbit::Peripherals::take() { if let Some(p) = microbit::Peripherals::take() {
let mut gpio = p.GPIO.split(); let mut gpio = p.GPIO.split();

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
[dependencies] [dependencies]
heapless="~0.3" heapless="~0.3"
cortex-m-rt="~0.5" cortex-m-rt="~0.6"
cortex-m-semihosting="" cortex-m-semihosting="~0.3"
panic-semihosting = "~0.3" panic-semihosting = "~0.5"
microbit="~0.5" microbit="~0.6"

View File

@@ -5,12 +5,10 @@ extern crate panic_semihosting;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh; extern crate cortex_m_semihosting as sh;
extern crate heapless; extern crate heapless;
#[macro_use(entry, exception, block)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
use rt::ExceptionFrame; use rt::entry;
use sh::hio; use sh::hio;
use heapless::{consts, Vec, String}; use heapless::{consts, Vec, String};
@@ -19,19 +17,7 @@ use microbit::hal::delay::Delay;
use microbit::hal::serial; use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
let mut stdout = hio::hstdout().unwrap(); let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();

View File

@@ -5,12 +5,10 @@ extern crate panic_semihosting;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh; extern crate cortex_m_semihosting as sh;
extern crate heapless; extern crate heapless;
#[macro_use(entry, exception, block)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
use rt::ExceptionFrame; use rt::entry;
use sh::hio; use sh::hio;
use heapless::{consts, Vec, String}; use heapless::{consts, Vec, String};
@@ -19,19 +17,7 @@ use microbit::hal::delay::Delay;
use microbit::hal::serial; use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
let mut stdout = hio::hstdout().unwrap(); let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();

View File

@@ -4,12 +4,10 @@
extern crate panic_semihosting; extern crate panic_semihosting;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh; extern crate cortex_m_semihosting as sh;
#[macro_use(entry, exception, block)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
use rt::ExceptionFrame; use rt::entry;
use sh::hio; use sh::hio;
use microbit::hal::delay::Delay; use microbit::hal::delay::Delay;
@@ -18,18 +16,6 @@ use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
use microbit::led; 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 WINNING_SCORE: u8 = 6;
const QUESTION_COUNT: u8 = 2*WINNING_SCORE - 1; const QUESTION_COUNT: u8 = 2*WINNING_SCORE - 1;
@@ -49,7 +35,7 @@ const LETTER_B: [[u8; 5]; 5] = [
[0, 1, 1, 0, 0], [0, 1, 1, 0, 0],
]; ];
entry!(main); #[entry]
fn main() -> ! { fn main() -> ! {
let mut stdout = hio::hstdout().unwrap(); let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();

View File

@@ -5,12 +5,10 @@ extern crate panic_semihosting;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh; extern crate cortex_m_semihosting as sh;
extern crate heapless; extern crate heapless;
#[macro_use(entry, exception, block)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
use rt::ExceptionFrame; use rt::entry;
use sh::hio; use sh::hio;
use heapless::{consts, Vec}; use heapless::{consts, Vec};
@@ -19,19 +17,7 @@ use microbit::hal::delay::Delay;
use microbit::hal::serial; use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
let mut stdout = hio::hstdout().unwrap(); let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();

View File

@@ -4,31 +4,18 @@
extern crate panic_semihosting; extern crate panic_semihosting;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh; extern crate cortex_m_semihosting as sh;
#[macro_use(entry, exception, block)]
extern crate microbit; extern crate microbit;
use core::fmt::Write; use core::fmt::Write;
use rt::ExceptionFrame; use rt::entry;
use sh::hio; use sh::hio;
use microbit::hal::prelude::*; use microbit::hal::prelude::*;
use microbit::hal::serial; use microbit::hal::serial;
use microbit::hal::serial::BAUD115200; use microbit::hal::serial::BAUD115200;
use microbit::nb::block;
exception!(HardFault, hard_fault); #[entry]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
entry!(main);
fn main() -> ! { fn main() -> ! {
let mut stdout = hio::hstdout().unwrap(); let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();