10 Commits

Author SHA1 Message Date
Michael Droogleever Fortuyn
7ba80d5e0b Stable nb block and editions 2019-11-30 21:46:06 +01:00
Michael Droogleever Fortuyn
d6b866a4dd More stable fixes 2019-11-30 21:24:05 +01:00
Michael Droogleever Fortuyn
e957a7ccc1 finish 2019-11-30 20:47:27 +01:00
Michael Droogleever Fortuyn
c7c004bc20 bump 2019-11-30 20:39:29 +01:00
Michael Droogleever Fortuyn
ea52aa2ea6 autofix 2019-11-30 20:38:09 +01:00
Michael Droogleever Fortuyn
ded6d7f3d8 manual fixes 2019-11-30 20:37:55 +01:00
Michael Droogleever Fortuyn
037bcc3c64 fix1 2019-11-30 20:29:44 +01:00
Michael Droogleever Fortuyn
707ad39a62 Update panics 2019-11-23 15:51:34 +01:00
Michael Droogleever Fortuyn
ec972af59a Version WIP 2019-11-23 15:36:44 +01:00
Michael Droogleever Fortuyn
389e30a0cd Stable rust in setup 2019-11-23 12:07:31 +01:00
18 changed files with 53 additions and 54 deletions

View File

@@ -2,5 +2,5 @@ target remote :3333
monitor arm semihosting enable monitor arm semihosting enable
set print asm-demangle on set print asm-demangle on
load load
#break main break main
continue continue

View File

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

View File

@@ -69,10 +69,10 @@ impl Display {
/// Clear display /// Clear display
pub fn clear(&mut self) { pub fn clear(&mut self) {
for row in &mut self.rows { for row in &mut self.rows {
row.set_low(); row.set_low().unwrap();
} }
for col in &mut self.cols { 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); let loops = duration_ms / (self.rows.len() as u32 * self.delay_ms);
for _ in 0..loops { for _ in 0..loops {
for (row_line, led_matrix_row) in self.rows.iter_mut().zip(led_matrix.iter()) { 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()) { 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 // We are keeping it simple, and not adding brightness
if *led_matrix_val > 0 { if *led_matrix_val > 0 {
col_line.set_low(); col_line.set_low().unwrap();
} }
} }
delay.delay_ms(self.delay_ms); delay.delay_ms(self.delay_ms);
for col_line in &mut self.cols { 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(); writeln!(stdout, "Start").unwrap();
if let Some(p) = microbit::Peripherals::take() { if let Some(p) = microbit::Peripherals::take() {
// Split GPIO // Split GPIO
let mut gpio = p.GPIO.split(); let gpio = p.GPIO.split();
// Configure RX and TX pins accordingly // Configure RX and TX pins accordingly
let tx = gpio.pin24.into_push_pull_output().downgrade(); let tx = gpio.pin24.into_push_pull_output().downgrade();
let rx = gpio.pin25.into_floating_input().downgrade(); let rx = gpio.pin25.into_floating_input().downgrade();
// Configure serial communication // Configure serial communication
let (mut tx, _) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split(); let (mut tx, _) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split();
writeln!(tx, ""); writeln!(tx, "").unwrap();
writeln!(tx, "Init"); writeln!(tx, "Init").unwrap();
// Create delay provider // Create delay provider
let mut delay = Delay::new(p.TIMER0); let mut delay = Delay::new(p.TIMER0);
@@ -179,10 +179,10 @@ fn main() -> ! {
[0, 1, 1, 1, 0], [0, 1, 1, 1, 0],
]; ];
writeln!(tx, "Starting!"); writeln!(tx, "Starting!").unwrap();
loop { 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, letter_I, 1000);
leds.display(&mut delay, heart, 1000); leds.display(&mut delay, heart, 1000);
leds.display(&mut delay, letter_U, 1000); leds.display(&mut delay, letter_U, 1000);

View File

@@ -136,7 +136,7 @@ executing the binary usually has the operating system start by executing the C r
This in turn invokes the Rust runtime, as marked by the `start` language item, This in turn invokes the Rust runtime, as marked by the `start` language item,
which in turn invokes the main function. which in turn invokes the main function.
Having enabled `no_std`, as we are targeting a microcontroller, Having enabled `no_std`, as we are targeting on a microcontroller,
neither the crt0 nor the rust runtime are available, neither the crt0 nor the rust runtime are available,
so even implementing `start` would not help us. so even implementing `start` would not help us.
We need to replace the operating system entry point. We need to replace the operating system entry point.

View File

@@ -2,7 +2,7 @@
Flashing is the process of moving our program into the microcontroller's (persistent) memory. Once flashed, the microcontroller will execute the flashed program every time it is powered on. Flashing is the process of moving our program into the microcontroller's (persistent) memory. Once flashed, the microcontroller will execute the flashed program every time it is powered on.
In this case, our `microrust-start` program will be the only program in the microcontroller memory. By this I mean that there's nothing else running on the microcontroller: no OS, no daemon, nothing. `microrust-start` has full control over the device. This is what is meant by *bare-metal* programming. In this case, our `rustled` program will be the only program in the microcontroller memory. By this I mean that there's nothing else running on the microcontroller: no OS, no daemon, nothing. `rustled` has full control over the device. This is what is meant by *bare-metal* programming.
<dl> <dl>
<dt>OS</dt> <dt>OS</dt>
@@ -71,8 +71,8 @@ available.
I mentioned that OpenOCD provides a GDB server so let's connect to that right now: I mentioned that OpenOCD provides a GDB server so let's connect to that right now:
``` console ``` console
$ arm-none-eabi-gdb -q target/thumbv6m-none-eabi/debug/microrust-start $ arm-none-eabi-gdb -q target/thumbv6m-none-eabi/debug/rustled
Reading symbols from target/thumbv6m-none-eabi/debug/microrust-start...done. Reading symbols from target/thumbv6m-none-eabi/debug/rustled...done.
(gdb) (gdb)
``` ```
@@ -157,9 +157,9 @@ set print asm-demangle on
# Load your program, breaks at entry # Load your program, breaks at entry
load load
# (optional) Add breakpoint at function # (optional) Add breakpoint at function
break main break rustled::main
# Continue with execution # Continue with execution
continue continue
``` ```
Now we can learn how to debug code on the micro:bit. Now we can learn how to debug code on the micro:bit.

View File

@@ -28,14 +28,14 @@ At this time, we are not interested in that "pre-main" part so let's skip right
the `main` function. We'll do that using a breakpoint: the `main` function. We'll do that using a breakpoint:
``` ```
(gdb) break main (gdb) break rustled::main
Breakpoint 1 at 0x8000218: file src/main.rs, line 8. Breakpoint 1 at 0x8000218: file src/main.rs, line 8.
(gdb) continue (gdb) continue
Continuing. Continuing.
Note: automatically using hardware breakpoints for read-only addresses. Note: automatically using hardware breakpoints for read-only addresses.
Breakpoint 1, main () at src/microrust-start/src/main.rs:13 Breakpoint 1, rustled::main () at src/rustled/src/main.rs:13
13 let x = 42; 13 let x = 42;
``` ```

View File

@@ -1,6 +1,7 @@
[package] [package]
name = "start" name = "start"
version = "0.2.0" version = "0.3.0"
edition = "2018"
[dependencies] [dependencies]
panic-halt = "~0.2" panic-halt = "~0.2"

View File

@@ -2,5 +2,5 @@
In this chapter, we will discuss the basic I/O of embedded development in rust. In this chapter, we will discuss the basic I/O of embedded development in rust.
After this chapter, you should have all the neccesary basic knowledge to do embedded development in Rust, After this chapter,you should have all the neccesary basic knowledge to do embedded development in Rust,
with anything remaining being solution specific. with anything remaining being solution specific.

View File

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

View File

@@ -20,20 +20,20 @@ fn main() -> ! {
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();
if let Some(p) = microbit::Peripherals::take() { if let Some(p) = microbit::Peripherals::take() {
// Split GPIO // Split GPIO
let mut gpio = p.GPIO.split(); let gpio = p.GPIO.split();
// Configure RX and TX pins accordingly // Configure RX and TX pins accordingly
let tx = gpio.pin24.into_push_pull_output().downgrade(); let tx = gpio.pin24.into_push_pull_output().downgrade();
let rx = gpio.pin25.into_floating_input().downgrade(); let rx = gpio.pin25.into_floating_input().downgrade();
// Configure serial communication // Configure serial communication
let (mut tx, _) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split(); 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 // Get row and column for display
let mut led = gpio.pin13.into_push_pull_output(); let mut led = gpio.pin13.into_push_pull_output();
let _ = gpio.pin4.into_push_pull_output(); let _ = gpio.pin4.into_push_pull_output();
// Set row high (column starts low) // Set row high (column starts low)
led.set_high(); led.set_high().unwrap();
// Write string with newline and carriage return // Write string with newline and carriage return
write!(tx, "serial - LED on\r\n"); write!(tx, "serial - LED on\r\n").unwrap();
} }
panic!("End"); panic!("End");
} }

View File

@@ -1,10 +1,11 @@
[package] [package]
name = "microbit" name = "micro"
version = "0.1.0" version = "0.2.0"
edition = "2018"
[dependencies] [dependencies]
cortex-m-rt="~0.6" cortex-m-rt="~0.6"
cortex-m-semihosting="~0.3" cortex-m-semihosting="~0.3"
panic-abort = "~0.3" panic-halt = "~0.2"
panic-semihosting = "~0.5" panic-semihosting = "~0.5"
microbit="~0.6" microbit="~0.8"

View File

@@ -1,7 +1,7 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
extern crate panic_abort; extern crate panic_halt;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate microbit; extern crate microbit;
@@ -16,7 +16,7 @@ use microbit::hal::serial::BAUD115200;
fn main() -> ! { fn main() -> ! {
if let Some(p) = microbit::Peripherals::take() { if let Some(p) = microbit::Peripherals::take() {
// Split GPIO // Split GPIO
let mut gpio = p.GPIO.split(); let gpio = p.GPIO.split();
// Configure RX and TX pins accordingly // Configure RX and TX pins accordingly
let tx = gpio.pin24.into_push_pull_output().downgrade(); let tx = gpio.pin24.into_push_pull_output().downgrade();
let rx = gpio.pin25.into_floating_input().downgrade(); let rx = gpio.pin25.into_floating_input().downgrade();

View File

@@ -1,7 +1,7 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
extern crate panic_abort; extern crate panic_halt;
extern crate cortex_m_rt as rt; extern crate cortex_m_rt as rt;
extern crate microbit; extern crate microbit;

View File

@@ -5,7 +5,7 @@
extern crate microbit; extern crate microbit;
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 panic_abort; extern crate panic_halt;
use core::fmt::Write; use core::fmt::Write;
use rt::entry; use rt::entry;

View File

@@ -1,10 +1,11 @@
[package] [package]
name = "serial" name = "serial"
version = "0.1.0" version = "0.2.0"
edition = "2018"
[dependencies] [dependencies]
heapless="~0.3" heapless="~0.5"
cortex-m-rt="~0.6" cortex-m-rt="~0.6"
cortex-m-semihosting="~0.3" cortex-m-semihosting="~0.3"
panic-semihosting = "~0.5" panic-semihosting = "~0.5"
microbit="~0.6" microbit="~0.8"

View File

@@ -13,7 +13,7 @@ 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; use microbit::block;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
@@ -21,16 +21,16 @@ fn main() -> ! {
writeln!(stdout, "Start").unwrap(); writeln!(stdout, "Start").unwrap();
if let Some(p) = microbit::Peripherals::take() { if let Some(p) = microbit::Peripherals::take() {
// Split GPIO // Split GPIO
let mut gpio = p.GPIO.split(); let gpio = p.GPIO.split();
// Configure RX and TX pins accordingly // Configure RX and TX pins accordingly
let tx = gpio.pin24.into_push_pull_output().downgrade(); let tx = gpio.pin24.into_push_pull_output().downgrade();
let rx = gpio.pin25.into_floating_input().downgrade(); let rx = gpio.pin25.into_floating_input().downgrade();
// Configure serial communication // Configure serial communication
let (mut tx, mut rx) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split(); let (mut tx, mut rx) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split();
writeln!(tx, "Start"); writeln!(tx, "Start").unwrap();
loop { loop {
let val = block!(rx.read()).unwrap(); let val = block!(rx.read()).unwrap();
block!(tx.write(val)); block!(tx.write(val)).unwrap();
} }
} }
panic!("End"); panic!("End");

View File

@@ -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). Install rustup by following the instructions at [https://rustup.rs](https://rustup.rs).
Then, install or switch to the nightly channel. **NOTE** Make sure you have a recent version, but only `1.39.0` is validated.
``` shell
$ rustup default nightly
```
**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: `rustc -V` should return a date newer than the one shown below:
``` shell ``` shell
$ rustc -V $ rustc -V
rustc 1.31.0-nightly (2c2e2c57d 2018-10-12) rustc 1.39.0 (4560ea788 2019-11-04)
``` ```
### OS specific instructions ### OS specific instructions

View File

@@ -18,7 +18,7 @@ Bus 002 Device 033: ID 0d28:0204 NXP ARM mbed
``` ```
In my case, the micro:bit got connected to the bus #2 and got enumerated as the device #33. In my case, the micro:bit got connected to the bus #2 and got enumerated as the device #33.
This means the file `/dev/bus/usb/002/033` is the micro:bit. This means the file `/dev/bus/usb/002/033` *is* the Fmicro:bit3.
Let's check its permissions: Let's check its permissions:
``` shell ``` shell