embedded-trainings-2020/embedded-workshop-book/src/bsc-exercise.md

68 lines
3 KiB
Markdown
Raw Normal View History

2023-02-14 17:46:54 +00:00
# BSC Exercise
In this exercise you will learn how to write a *Board Support Crate* (or BSC, also known as a *Board Support Package*) by implementing support for handling button presses, and support for using the UARTE peripheral.
2023-02-21 15:24:41 +00:00
2023-03-17 18:31:07 +00:00
The template `down-the-stack/dk_bsc/src/lib.rs` already contains the LED and Timer implementations. Add your code to the designated lines. You'll find a `//todo!` there.
2023-03-07 15:58:17 +00:00
You can test after each step by running the following command out of `down-the-stack/apps`
```
cargo run --bin hello
```
2023-03-07 16:08:38 +00:00
This program will not call any of the functions you are implementing, so it does not matter if they are incomplete. It will refuse to build if there are errors present in the `lib.rs`!
2023-03-07 15:58:17 +00:00
2023-03-10 16:13:28 +00:00
`down-the-stack/dk_bsc/src/lib_solution.rs` contains the full solution code.
2023-03-07 15:58:17 +00:00
2023-02-22 18:11:13 +00:00
## You will learn how to
* modify the `init()` function that brings up the board's peripherals
* how to configure pins
* how to write a function that checks the state of a pin
* implement functionality on a type
2023-02-22 18:11:13 +00:00
* implement a Trait
* to document and generate docs for your own library!
2023-02-14 17:46:54 +00:00
2023-03-21 16:36:25 +00:00
## Prerequisites
* installation of `pyserial` or other serial terminal that you are familiar with.
* `impl` keyword
* methods and associated functions
* `pub` keyword
* usage of structs to represent registers
* Trait
2023-02-21 15:24:41 +00:00
## Tasks
### Write a button implementation. This entails the following steps:
* Add `struct Buttons` with 4 fields, that represents each of the four buttons.
* Add `struct Button` that is a wrapper for the pin that a single button is connected to.
* Write a method `is_pushed` that checks if a single button is pushed.
* Initialize the pins in `fn init()`.
* Add the `struct Button` to the definition and instantiation of `struct Board`.
* Run `apps/buttons.rs` to test.
* Run `cargo doc` out of the apps folder to find all your doc comments!
### Write a UARTE implementation. This entails the following steps:
* Check the `uarte` module of the `nrf-hal` for requirements of the instantiating method.
* Add `struct Uarte` that serves as wrapper for the `UARTE1` instance.
* Initialize the UARTE1 peripheral in `fn init()` using the following settings:
2023-03-07 17:08:33 +00:00
* parity: included
* baudrate: 115200 baud
* Add `struct Uarte` to the definition and instantiation of `struct Board`.
* Implement the `fmt::Write` trait for `struct Uarte`.
* Connect your computer to the virtual UART port with `screen`.
* Run `apps/uarte_print.rs` to test.
2023-02-21 15:24:41 +00:00
## Knowledge
### Comments
2023-03-17 18:31:07 +00:00
The `lib.rs` has an attribute `#![deny(missing_docs)]`. This means, that missing doc comments for structs are returned as compiler errors, to remind you to document your work properly.
2023-03-07 16:08:38 +00:00
```rust
/// This is a doc comment
// This is a normal comment
```
### Structs represent Registers
2023-02-21 15:24:41 +00:00
[todo!] insert refresher from rust fundamentals
2023-02-21 15:24:41 +00:00
## Hardware documentation for pin configuration
2023-02-14 17:46:54 +00:00
2023-03-07 15:46:03 +00:00
Go to [Nordic Infocenter](https://infocenter.nordicsemi.com/topic/ug_nrf52840_dk/UG/dk/intro.html) to download the User Guide. You can find all the information that is relevant to this exercise in there.
2023-02-14 17:46:54 +00:00