31 Commits

Author SHA1 Message Date
Michael Droogleever Fortuyn
cb48e8fbdd Merge branch 'rofrol-patch-1' 2020-04-27 18:54:57 +02:00
droogmic
492ef04d3d Merge pull request #24 from NOP0/master
Bumped micro-rust dependency to 0.8
2020-04-27 18:47:29 +02:00
droogmic
d8ee697999 Merge pull request #23 from rofrol/patch-6
we -> We
2020-04-27 18:47:20 +02:00
droogmic
3da68b5f1d Merge pull request #21 from rofrol/patch-5
Uninitialized _y has value -1
2020-04-27 18:47:09 +02:00
droogmic
69c27cf5f2 Merge pull request #20 from rofrol/patch-4
use #[entry] instead of entry!
2020-04-27 18:46:57 +02:00
droogmic
fe7a225b00 Merge pull request #19 from rofrol/patch-3
break main instead of break rustled::main
2020-04-27 18:46:46 +02:00
droogmic
e4e030c109 Merge pull request #17 from rofrol/patch-2
Missing extern crate panic_halt
2020-04-27 18:46:32 +02:00
droogmic
f278ec36b1 Use stable rust (#16)
* Stable rust in setup

* Version WIP

* Update panics

* fix1

* manual fixes

* autofix

* bump

* finish

* More stable fixes

* Stable nb block and editions
2020-04-27 18:45:47 +02:00
droogmic
6cc89a0423 Typos (#15)
* Typo: verify

* Typo: build

* Bump microbit

* Fix gdb command

* Fix gdbinit name

* Fix debugging binary name

* Add space

* Finish removing rustled
2020-04-27 18:45:12 +02:00
NOP0
b08613a7fd Bumped micro-rust dependency to 0.8 2020-01-05 21:29:32 +01:00
Roman Frołow
44c312271e we -> We 2019-12-30 15:14:19 +01:00
Roman Frołow
84783bca5e gdb-multiarch 2019-12-30 12:23:20 +01:00
Roman Frołow
7e1dd57395 Uninitialized _y has value -1 2019-12-30 12:19:08 +01:00
Roman Frołow
5810565cf6 use #[entry] instead of entry!
>[breaking-change] the entry!, pre_init! and exception! macros have been replaced with attributes: #[entry], #[pre_init] and #[exception], respectively.

9a4a260398/CHANGELOG.md (v060---2018-09-06)
2019-12-30 12:13:33 +01:00
Roman Frołow
bd34b10823 break main instead of break rustled::main
It didn't work for me with `rustled::`
2019-12-30 12:11:59 +01:00
Roman Frołow
f2dcd25d4e Missing extern crate panic_halt 2019-12-29 18:25:49 +01:00
Roman Frołow
a46be27bce Use gdb-multiarch instead of gdb-arm-none-eabi
https://askubuntu.com/questions/1031103/how-to-install-gdb-arm-none-eabi-on-ubuntu-18-04#comment1682182_1032469
2019-12-29 18:24:23 +01:00
droogmic
d16c5af8f7 Merge pull request #14 from beagleknight/fix/microbit-display-example
fix: microbit display example
2019-11-22 08:16:44 +01:00
droogmic
d2351e6049 Merge pull request #8 from rossjones/patch-1
Update macOS setup text
2019-11-22 08:16:27 +01:00
David Morcillo
d6e4a70e25 fix: microbit display example 2019-11-05 16:40:48 +01:00
Ross Jones
eeabf6b056 Update macOS setup text
The gcc-arm-embedded cask has been removed in favour of a not-yet-implemented normal homebrew formula.
I've tried the above however (as documented in the linked casks PR) and it works as advertised for now.
2019-10-26 14:57:02 +01:00
droogmic
0fdc235a3c Merge pull request #6 from mogenson/master
fixup serial output example so that it builds correctly
2019-10-16 21:08:14 +02:00
droogmic
aa3cc8bcb3 Merge pull request #7 from dstutman/patch-1
Fixes rust-lld errors when building example
2019-10-16 21:07:47 +02:00
Daniel Stutman
8545dda435 Fixes rust-lld errors when building example
Building the previous main.rs failed with: ERROR(cortex-m-rt): The interrupt vectors are missing.
Including the microbit crate in the example fixes this.
2019-04-20 22:16:56 +02:00
Michael Mogenson
7641877efe Remove unused mut
`gpio` does not need to be mutable. Remove `mut` to silence build
warning.
2019-03-27 11:39:35 -04:00
Michael Mogenson
d37d5726ce write_fmt() method needed for write!() macro
Include `use core::fmt::Write;` in serial example.
2019-03-27 11:37:44 -04:00
droogmic
2e48356a55 Merge pull request #4 from mogenson/master
Fixup Getting Started -> Building page
2019-03-17 10:28:26 +01:00
Michael Mogenson
feec6bfb2a Bump microbit crate version to the latest: ~0.7 2019-03-14 10:49:41 -04:00
Michael Mogenson
78bf6ff538 Remove semicolon after #[entry]
Otherwise you get the following build error:

```
error: expected item after attributes
 --> src/main.rs:8:8
  |
8 | #[entry];
  |        ^
```

This one confused me for awhile.
2019-03-14 10:47:26 -04:00
Michael Mogenson
9c6bcd2ee8 Use panic-halt crate, panic-abort requires nightly toolchain features
When trying to follow the Getting Started->Building instructions, the
`panic-abort` crate throws the following build error on rust stable
version 1.33:

```
   Compiling panic-abort v0.3.1
error[E0554]: #![feature] may not be used on the stable release channel
  --> /home/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-abort-0.3.1/src/lib.rs:22:1
   |
22 | #![feature(core_intrinsics)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: #![feature] may not be used on the stable release channel
  --> /home/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-abort-0.3.1/src/lib.rs:23:1
   |
23 | #![feature(panic_handler)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0554`.
error: Could not compile `panic-abort`.

To learn more, run the command again with --verbose.
```

Switch to the `panic-halt` crate that builds on stable and provides the
`#[panic_handler]` function necesary to get a minimal successful build.
2019-03-14 10:37:41 -04:00
bors[bot]
c2d5c26e49 Merge #3
3: 201810 updates r=droogmic a=droogmic



Co-authored-by: Michael Droogleever <droogmic@gmail.com>
2018-10-13 21:28:55 +00:00
23 changed files with 95 additions and 91 deletions

View File

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

View File

@@ -3,7 +3,7 @@
> Create a time delay.
Another piece of information you will need is how to create a time delay before moving to the next row.
we want the time spent switching LED lines on and off to be much shorter than the time spent waiting with LEDs on.
We want the time spent switching LED lines on and off to be much shorter than the time spent waiting with LEDs on.
### For loop

View File

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

View File

@@ -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);

View File

@@ -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() {
}
@@ -136,19 +136,21 @@ 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,
which in turn invokes the main function.
Having enabled `no_std`, as we are targeting on a microcontroller,
Having enabled `no_std`, as we are targeting a microcontroller,
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
#![no_std]
#![no_main]
extern crate panic_halt;
#[no_mangle]
pub extern "C" fn _start() -> ! {
loop {}
@@ -232,15 +234,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 +274,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;

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.
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.
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.
<dl>
<dt>OS</dt>
@@ -71,8 +71,9 @@ available.
I mentioned that OpenOCD provides a GDB server so let's connect to that right now:
``` console
$ arm-none-eabi-gdb -q target/thumbv6m-none-eabi/debug/rustled
Reading symbols from target/thumbv6m-none-eabi/debug/rustled...done.
# On Ubuntu use `gdb-mutliarch -q target/thumbv6m-none-eabi/debug//microrust-start`
$ arm-none-eabi-gdb -q target/thumbv6m-none-eabi/debug/microrust-start
Reading symbols from target/thumbv6m-none-eabi/debug/microrust-start...done.
(gdb)
```
@@ -157,9 +158,9 @@ set print asm-demangle on
# Load your program, breaks at entry
load
# (optional) Add breakpoint at function
break rustled::main
break main
# Continue with execution
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

@@ -6,7 +6,7 @@ Before we start, let's add some code to debug:
``` rust
// -- snip --
entry!(main);
#[entry]
fn main() -> ! {
let _y;
let x = 42;
@@ -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:
```
(gdb) break rustled::main
(gdb) break main
Breakpoint 1 at 0x8000218: file src/main.rs, line 8.
(gdb) continue
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.
Breakpoint 1, rustled::main () at src/rustled/src/main.rs:13
Breakpoint 1, main () at src/microrust-start/src/main.rs:13
13 let x = 42;
```
@@ -87,15 +87,15 @@ $1 = 42
$2 = (i32 *) 0x10001fdc
(gdb) print _y
$3 = 134219052
$3 = -1
(gdb) print &_y
$4 = (i32 *) 0x10001fd8
```
As expected, `x` contains the value `42`.
`_y` however, contains the value `134219052` (?).
Because `_y` has not been initialized yet, it contains some garbage value.
`_y` however, contains the value `-1` (?).
Because `_y` has not been initialized yet, it contains `-1`.
The command `print &x` prints the address of the variable `x`.
The interesting bit here is that GDB output shows the type of the reference:
@@ -108,7 +108,7 @@ Instead of printing the local variables one by one, you can also use the `info l
```
(gdb) info locals
x = 42
_y = 134219052
_y = -1
```
OK. With another `step`, we'll be on top of the `loop {}` statement:

View File

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

View File

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

View File

@@ -2,5 +2,5 @@
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.

View File

@@ -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();

View File

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

View File

@@ -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");
}

View File

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

View File

@@ -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();

View File

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

View File

@@ -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");
}
}

View File

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

View File

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

View File

@@ -9,7 +9,7 @@ Here are the installation commands for a few Linux distributions.
``` shell
$ sudo apt-get install \
gcc-arm-none-eabi \
gdb-arm-none-eabi \
gdb-multiarch \
minicom \
openocd
```

View File

@@ -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].

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).
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

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.
This means the file `/dev/bus/usb/002/033` *is* the Fmicro:bit3.
This means the file `/dev/bus/usb/002/033` is the micro:bit.
Let's check its permissions:
``` shell