Compare commits
24 Commits
201810-upd
...
stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ba80d5e0b | ||
|
|
d6b866a4dd | ||
|
|
e957a7ccc1 | ||
|
|
c7c004bc20 | ||
|
|
ea52aa2ea6 | ||
|
|
ded6d7f3d8 | ||
|
|
037bcc3c64 | ||
|
|
707ad39a62 | ||
|
|
ec972af59a | ||
|
|
389e30a0cd | ||
|
|
d16c5af8f7 | ||
|
|
d2351e6049 | ||
|
|
d6e4a70e25 | ||
|
|
eeabf6b056 | ||
|
|
0fdc235a3c | ||
|
|
aa3cc8bcb3 | ||
|
|
8545dda435 | ||
|
|
7641877efe | ||
|
|
d37d5726ce | ||
|
|
2e48356a55 | ||
|
|
feec6bfb2a | ||
|
|
78bf6ff538 | ||
|
|
9c6bcd2ee8 | ||
|
|
c2d5c26e49 |
2
.gdbinit
2
.gdbinit
@@ -2,5 +2,5 @@ target remote :3333
|
||||
monitor arm semihosting enable
|
||||
set print asm-demangle on
|
||||
load
|
||||
#break main
|
||||
break main
|
||||
continue
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
[package]
|
||||
name = "display"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
cortex-m-rt="~0.6"
|
||||
cortex-m-semihosting="~0.3"
|
||||
panic-semihosting = "~0.5"
|
||||
microbit="~0.6"
|
||||
microbit="~0.8"
|
||||
|
||||
@@ -69,10 +69,10 @@ impl Display {
|
||||
/// Clear display
|
||||
pub fn clear(&mut self) {
|
||||
for row in &mut self.rows {
|
||||
row.set_low();
|
||||
row.set_low().unwrap();
|
||||
}
|
||||
for col in &mut self.cols {
|
||||
col.set_high();
|
||||
col.set_high().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,18 +97,18 @@ impl Display {
|
||||
let loops = duration_ms / (self.rows.len() as u32 * self.delay_ms);
|
||||
for _ in 0..loops {
|
||||
for (row_line, led_matrix_row) in self.rows.iter_mut().zip(led_matrix.iter()) {
|
||||
row_line.set_high();
|
||||
row_line.set_high().unwrap();
|
||||
for (col_line, led_matrix_val) in self.cols.iter_mut().zip(led_matrix_row.iter()) {
|
||||
// We are keeping it simple, and not adding brightness
|
||||
if *led_matrix_val > 0 {
|
||||
col_line.set_low();
|
||||
col_line.set_low().unwrap();
|
||||
}
|
||||
}
|
||||
delay.delay_ms(self.delay_ms);
|
||||
for col_line in &mut self.cols {
|
||||
col_line.set_high();
|
||||
col_line.set_high().unwrap();
|
||||
}
|
||||
row_line.set_low();
|
||||
row_line.set_low().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,15 +120,15 @@ fn main() -> ! {
|
||||
writeln!(stdout, "Start").unwrap();
|
||||
if let Some(p) = microbit::Peripherals::take() {
|
||||
// Split GPIO
|
||||
let mut gpio = p.GPIO.split();
|
||||
let gpio = p.GPIO.split();
|
||||
|
||||
// Configure RX and TX pins accordingly
|
||||
let tx = gpio.pin24.into_push_pull_output().downgrade();
|
||||
let rx = gpio.pin25.into_floating_input().downgrade();
|
||||
// Configure serial communication
|
||||
let (mut tx, _) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split();
|
||||
writeln!(tx, "");
|
||||
writeln!(tx, "Init");
|
||||
writeln!(tx, "").unwrap();
|
||||
writeln!(tx, "Init").unwrap();
|
||||
|
||||
// Create delay provider
|
||||
let mut delay = Delay::new(p.TIMER0);
|
||||
@@ -179,10 +179,10 @@ fn main() -> ! {
|
||||
[0, 1, 1, 1, 0],
|
||||
];
|
||||
|
||||
writeln!(tx, "Starting!");
|
||||
writeln!(tx, "Starting!").unwrap();
|
||||
|
||||
loop {
|
||||
writeln!(tx, "I <3 Rust on the micro:bit!");
|
||||
writeln!(tx, "I <3 Rust on the micro:bit!").unwrap();
|
||||
leds.display(&mut delay, letter_I, 1000);
|
||||
leds.display(&mut delay, heart, 1000);
|
||||
leds.display(&mut delay, letter_U, 1000);
|
||||
|
||||
@@ -116,7 +116,7 @@ If you have forgotten how to do this, try looking at [the cargo book][cargo].
|
||||
``` rust
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_abort;
|
||||
extern crate panic_halt;
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -141,8 +141,8 @@ neither the crt0 nor the rust runtime are available,
|
||||
so even implementing `start` would not help us.
|
||||
We need to replace the operating system entry point.
|
||||
|
||||
You could for example name a function after the default entry point,
|
||||
which for linux is `_start`, and start that way.
|
||||
You could for example name a function after the default entry point,
|
||||
which for linux is `_start`, and start that way.
|
||||
Note, you would also need to disable [name mangling][nm]:
|
||||
|
||||
``` rust
|
||||
@@ -232,15 +232,16 @@ and cargo will automatically add `--target thumbv6m-none-eabi`.
|
||||
|
||||
### `src/main.rs`
|
||||
|
||||
``` rust
|
||||
``` rust
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate panic_abort;
|
||||
extern crate panic_halt;
|
||||
extern crate microbit;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
|
||||
#[entry];
|
||||
#[entry]
|
||||
fn main() {
|
||||
}
|
||||
```
|
||||
@@ -271,7 +272,8 @@ An easy way to implement this is to use an infinite loop.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate panic_abort;
|
||||
extern crate panic_halt;
|
||||
extern crate microbit;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
[package]
|
||||
name = "start"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
panic-abort = "~0.3"
|
||||
microbit="~0.6"
|
||||
panic-halt = "~0.2"
|
||||
microbit="~0.8"
|
||||
cortex-m-rt="~0.6"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
extern crate cortex_m_rt;
|
||||
extern crate microbit;
|
||||
extern crate panic_abort;
|
||||
extern crate panic_halt;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
|
||||
|
||||
@@ -24,12 +24,13 @@ To read and write to the serial bus from your computer, you will need to configu
|
||||
## Code
|
||||
|
||||
``` rust
|
||||
use core::fmt::Write;
|
||||
use microbit::hal::prelude::*;
|
||||
use microbit::hal::serial;
|
||||
use microbit::hal::serial::BAUD115200;
|
||||
// -- snip --
|
||||
if let Some(p) = microbit::Peripherals::take() {
|
||||
let mut gpio = p.GPIO.split();
|
||||
let gpio = p.GPIO.split();
|
||||
// Configure RX and TX pins accordingly
|
||||
let tx = gpio.pin24.into_push_pull_output().downgrade();
|
||||
let rx = gpio.pin25.into_floating_input().downgrade();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
[package]
|
||||
name = "hello"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
microbit="~0.6"
|
||||
microbit="~0.8"
|
||||
cortex-m-rt="~0.6"
|
||||
cortex-m-semihosting="~0.3"
|
||||
panic-semihosting = "~0.5"
|
||||
|
||||
@@ -20,20 +20,20 @@ fn main() -> ! {
|
||||
writeln!(stdout, "Start").unwrap();
|
||||
if let Some(p) = microbit::Peripherals::take() {
|
||||
// Split GPIO
|
||||
let mut gpio = p.GPIO.split();
|
||||
let gpio = p.GPIO.split();
|
||||
// Configure RX and TX pins accordingly
|
||||
let tx = gpio.pin24.into_push_pull_output().downgrade();
|
||||
let rx = gpio.pin25.into_floating_input().downgrade();
|
||||
// Configure serial communication
|
||||
let (mut tx, _) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split();
|
||||
write!(tx, "serial - start\r\n");
|
||||
write!(tx, "serial - start\r\n").unwrap();
|
||||
// Get row and column for display
|
||||
let mut led = gpio.pin13.into_push_pull_output();
|
||||
let _ = gpio.pin4.into_push_pull_output();
|
||||
// Set row high (column starts low)
|
||||
led.set_high();
|
||||
led.set_high().unwrap();
|
||||
// Write string with newline and carriage return
|
||||
write!(tx, "serial - LED on\r\n");
|
||||
write!(tx, "serial - LED on\r\n").unwrap();
|
||||
}
|
||||
panic!("End");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
[package]
|
||||
name = "microbit"
|
||||
version = "0.1.0"
|
||||
name = "micro"
|
||||
version = "0.2.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
cortex-m-rt="~0.6"
|
||||
cortex-m-semihosting="~0.3"
|
||||
panic-abort = "~0.3"
|
||||
panic-halt = "~0.2"
|
||||
panic-semihosting = "~0.5"
|
||||
microbit="~0.6"
|
||||
microbit="~0.8"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate panic_abort;
|
||||
extern crate panic_halt;
|
||||
extern crate cortex_m_rt as rt;
|
||||
extern crate microbit;
|
||||
|
||||
@@ -16,7 +16,7 @@ use microbit::hal::serial::BAUD115200;
|
||||
fn main() -> ! {
|
||||
if let Some(p) = microbit::Peripherals::take() {
|
||||
// Split GPIO
|
||||
let mut gpio = p.GPIO.split();
|
||||
let gpio = p.GPIO.split();
|
||||
// Configure RX and TX pins accordingly
|
||||
let tx = gpio.pin24.into_push_pull_output().downgrade();
|
||||
let rx = gpio.pin25.into_floating_input().downgrade();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate panic_abort;
|
||||
extern crate panic_halt;
|
||||
extern crate cortex_m_rt as rt;
|
||||
extern crate microbit;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
extern crate microbit;
|
||||
extern crate cortex_m_rt as rt;
|
||||
extern crate cortex_m_semihosting as sh;
|
||||
extern crate panic_abort;
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::fmt::Write;
|
||||
use rt::entry;
|
||||
@@ -23,25 +23,25 @@ fn main() -> ! {
|
||||
let mut delay = Delay::new(p.TIMER0);
|
||||
|
||||
// Configure display pins
|
||||
let row1 = gpio.pin13.into_push_pull_output().downgrade();
|
||||
let row2 = gpio.pin14.into_push_pull_output().downgrade();
|
||||
let row3 = gpio.pin15.into_push_pull_output().downgrade();
|
||||
let col1 = gpio.pin4.into_push_pull_output().downgrade();
|
||||
let col2 = gpio.pin5.into_push_pull_output().downgrade();
|
||||
let col3 = gpio.pin6.into_push_pull_output().downgrade();
|
||||
let col4 = gpio.pin7.into_push_pull_output().downgrade();
|
||||
let col5 = gpio.pin8.into_push_pull_output().downgrade();
|
||||
let col6 = gpio.pin9.into_push_pull_output().downgrade();
|
||||
let col7 = gpio.pin10.into_push_pull_output().downgrade();
|
||||
let col8 = gpio.pin11.into_push_pull_output().downgrade();
|
||||
let col9 = gpio.pin12.into_push_pull_output().downgrade();
|
||||
let row1 = gpio.pin13.into_push_pull_output();
|
||||
let row2 = gpio.pin14.into_push_pull_output();
|
||||
let row3 = gpio.pin15.into_push_pull_output();
|
||||
let col1 = gpio.pin4.into_push_pull_output();
|
||||
let col2 = gpio.pin5.into_push_pull_output();
|
||||
let col3 = gpio.pin6.into_push_pull_output();
|
||||
let col4 = gpio.pin7.into_push_pull_output();
|
||||
let col5 = gpio.pin8.into_push_pull_output();
|
||||
let col6 = gpio.pin9.into_push_pull_output();
|
||||
let col7 = gpio.pin10.into_push_pull_output();
|
||||
let col8 = gpio.pin11.into_push_pull_output();
|
||||
let col9 = gpio.pin12.into_push_pull_output();
|
||||
|
||||
// Configure RX and TX pins accordingly
|
||||
let tx = gpio.pin24.into_push_pull_output().downgrade();
|
||||
let rx = gpio.pin25.into_floating_input().downgrade();
|
||||
|
||||
let mut leds = led::Display::new(
|
||||
row1, row2, row3, col1, col2, col3, col4, col5, col6, col7, col8, col9,
|
||||
col1, col2, col3, col4, col5, col6, col7, col8, col9, row1, row2, row3,
|
||||
);
|
||||
|
||||
let (mut tx, _) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split();
|
||||
@@ -84,4 +84,4 @@ fn main() -> ! {
|
||||
}
|
||||
}
|
||||
panic!("End");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
[package]
|
||||
name = "serial"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
heapless="~0.3"
|
||||
heapless="~0.5"
|
||||
cortex-m-rt="~0.6"
|
||||
cortex-m-semihosting="~0.3"
|
||||
panic-semihosting = "~0.5"
|
||||
microbit="~0.6"
|
||||
microbit="~0.8"
|
||||
|
||||
@@ -13,7 +13,7 @@ use sh::hio;
|
||||
use microbit::hal::prelude::*;
|
||||
use microbit::hal::serial;
|
||||
use microbit::hal::serial::BAUD115200;
|
||||
use microbit::nb::block;
|
||||
use microbit::block;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@@ -21,16 +21,16 @@ fn main() -> ! {
|
||||
writeln!(stdout, "Start").unwrap();
|
||||
if let Some(p) = microbit::Peripherals::take() {
|
||||
// Split GPIO
|
||||
let mut gpio = p.GPIO.split();
|
||||
let gpio = p.GPIO.split();
|
||||
// Configure RX and TX pins accordingly
|
||||
let tx = gpio.pin24.into_push_pull_output().downgrade();
|
||||
let rx = gpio.pin25.into_floating_input().downgrade();
|
||||
// Configure serial communication
|
||||
let (mut tx, mut rx) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split();
|
||||
writeln!(tx, "Start");
|
||||
writeln!(tx, "Start").unwrap();
|
||||
loop {
|
||||
let val = block!(rx.read()).unwrap();
|
||||
block!(tx.write(val));
|
||||
block!(tx.write(val)).unwrap();
|
||||
}
|
||||
}
|
||||
panic!("End");
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
# macOS
|
||||
|
||||
> UNTESTED: please submit an issue if you can confirm this works.
|
||||
|
||||
All the tools can be install using [Homebrew]:
|
||||
|
||||
[Homebrew]: http://brew.sh/
|
||||
|
||||
``` shell
|
||||
$ brew cask install gcc-arm-embedded
|
||||
$ brew cask install https://raw.githubusercontent.com/Homebrew/homebrew-cask/b88346667547cc85f8f2cacb3dfe7b754c8afc8a/Casks/gcc-arm-embedded.rb
|
||||
$ brew install minicom openocd
|
||||
```
|
||||
|
||||
If the `brew cask` command doesn't work (`Error: Unknown command: cask`), then run `brew tap
|
||||
Caskroom/tap` first and try again.
|
||||
Unfortunately gcc-arm-embedded has been [removed from Homebrew casks] in an attempt to force somebody to move it to Homebrew, and so it has to be installed using the cask in an earlier commit.
|
||||
|
||||
[removed from Homebrew casks]: https://github.com/Homebrew/homebrew-cask/pull/56802
|
||||
|
||||
That's all! Go to the [next section].
|
||||
|
||||
|
||||
@@ -38,18 +38,12 @@ Next, follow OS-agnostic installation instructions for a few of the tools:
|
||||
|
||||
Install rustup by following the instructions at [https://rustup.rs](https://rustup.rs).
|
||||
|
||||
Then, install or switch to the nightly channel.
|
||||
|
||||
``` shell
|
||||
$ rustup default nightly
|
||||
```
|
||||
|
||||
**NOTE** Make sure you have a nightly newer than `nightly-2018-10-12`.
|
||||
**NOTE** Make sure you have a recent version, but only `1.39.0` is validated.
|
||||
`rustc -V` should return a date newer than the one shown below:
|
||||
|
||||
``` shell
|
||||
$ rustc -V
|
||||
rustc 1.31.0-nightly (2c2e2c57d 2018-10-12)
|
||||
rustc 1.39.0 (4560ea788 2019-11-04)
|
||||
```
|
||||
|
||||
### OS specific instructions
|
||||
|
||||
Reference in New Issue
Block a user