Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1587daf5d1 | ||
|
|
4d631b12aa | ||
|
|
72532bcee1 | ||
|
|
6ed3b08955 | ||
|
|
254312a988 | ||
|
|
4b6be8fb61 | ||
|
|
74c52e42b6 | ||
|
|
74950c7a78 | ||
|
|
d16c5af8f7 | ||
|
|
d2351e6049 | ||
|
|
d6e4a70e25 | ||
|
|
eeabf6b056 | ||
|
|
0fdc235a3c | ||
|
|
aa3cc8bcb3 | ||
|
|
8545dda435 | ||
|
|
7641877efe | ||
|
|
d37d5726ce | ||
|
|
2e48356a55 | ||
|
|
feec6bfb2a | ||
|
|
78bf6ff538 | ||
|
|
9c6bcd2ee8 |
@@ -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,13 +136,13 @@ 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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,8 @@ 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.
|
||||
$ 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 +157,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.
|
||||
|
||||
@@ -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;
|
||||
```
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@ name = "start"
|
||||
version = "0.2.0"
|
||||
|
||||
[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;
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,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].
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user