Skip to content

Commit ca80587

Browse files
alexandruradoviciDanutAldeaJADarius
authored
Add the Tock Workshop initial track (#1)
* add the Tock Workshop inital track * added prerequisites * fixed introduction typo * architecture WIP * added build capsule task * Small fixes This commit adds the prerequisites for `probe-rs` and adds some clarifications regarding some of the necessary actions. * fix: added list output * added test application task * nit: fixed format on list * added periodic print task * added thermistor task * Add GitHub links for the repositories * Small fixes This commit adds small fixes based on the received feedback. * Add NixOS alternative for TockWorld. This commit adds a NixOS VM alternative for Windows users or user that don't want to follow the prerequisites. The text of the workshop has been modified to reflect this addition. --------- Co-authored-by: George-Dănuț Aldea <[email protected]> Co-authored-by: Darius-Andrei Jipa <[email protected]> Co-authored-by: Darius-Andrei Jipa <[email protected]> Co-authored-by: Darius-Andrei Jipa <[email protected]>
1 parent 91b18c7 commit ca80587

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

docs/tock_workshop/index.md

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
## Prerequisites
44

5+
:::note Windows Users or participants that are willing to use a VM
6+
This workshop will not work on Windows systems.
7+
You can try following the guide using a Linux VM/WSL2,
8+
or you can use the NixOS VM we provide [here](https://drive.google.com/file/d/1-jOsuWdSnOlmyupMWb3Vw4oG_t77BnwQ/view?usp=sharing) (only works on VirtualBox).
9+
The username and password are both `ipwembedded`.
10+
If you will be using the NixOS VM, you can skip the prerequisites.
11+
:::
512
### Rust Toolchain
613

714
You will need to install the Rust toolchain. To do so, you can follow the instructions on the [Getting started](https://www.rust-lang.org/learn/get-started) page of the Rust Language website.
815

9-
:::info Windows Install Tips
10-
If you are using Windows, you may be prompted to install [Visual Studio C++ Build tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/). If so, follow the instructions from the previous link.
11-
12-
Even if Visual Studio is already on your machine, rustup will not verify if the required components are present. If you experience issues with the `rustup` installation on Windows, please follow [these instructions](https://rust-lang.github.io/rustup/installation/windows-msvc.html) to manually add the missing components.
13-
:::
14-
1516
To verify that the installation, open a terminal and run `rustup --version`. If everything went well, you should see an output similar to this:
1617

1718
```shell
@@ -32,7 +33,7 @@ The simplest installation method involves using the `cargo` packet manager, but
3233
sudo apt install -y pkg-config libudev-dev cmake git
3334
```
3435

35-
* On Mac OS and Windows, no additional setup is needed.
36+
* On Mac OS, no additional setup is needed.
3637

3738
After that, use `cargo` to install `probe-rs`:
3839

@@ -125,10 +126,27 @@ git clone https://github.com/OxidosAutomotive/tock.git --branch=psoc6-workshop
125126
cd tock
126127
```
127128

129+
:::note NixOS VM users
130+
You don't have to clone the Tock OS repository, it is already cloned in the home directory.
131+
You will have to run `nix-shell` once you enter the `tock` directory.
132+
:::
133+
128134
The configuration for the various boards supported can be found in the `boards` directory. To compile the kernel, you can use the `cargo flash` utility.
129135

130136
```shell
131137
cd boards/cy8cproto_62_4343_w
138+
make flash
139+
```
140+
141+
Alternatively, you can use the `cargo flash` while inside the board's directory.
142+
143+
If you did everything correctly, you should be able to use the `tockloader listen` command to interact with the kernel. When prompted to select a serial port, pick the one that ends with `KitProg3 CMSIS-DAP`.
144+
145+
:::note NixOS VM users
146+
Currently, `tockloader` doesn't work on NixOS, but we have included the program `picocom`
147+
which you can use with the following command: `picocom -b 115200 /dev/ttyACM0`. (use `sudo` if it gives an error about permissions)
148+
:::
149+
132150
cargo flash
133151
```
134152
@@ -149,7 +167,7 @@ Which option? [0] 1
149167
[INFO ] Using "/dev/cu.usbmodem1103 - KitProg3 CMSIS-DAP".
150168
[INFO ] Listening for serial output
151169
152-
$tock
170+
tock$
153171
```
154172

155173
### Compiling an application
@@ -161,6 +179,12 @@ git clone https://github.com/ipworkshop/libtock-c.git --branch=remove-risc
161179
cd libtock-c
162180
```
163181

182+
:::note NixOS VM users
183+
You don't have to clone the libtock-c repository, it is already cloned in the home directory.
184+
You will have to run `nix-shell` once you enter the `libtock-c` directory.
185+
Make sure you don't run that command if you already ran `nix-shell` inside another directory (either run `exit` before, or use another shell).
186+
:::
187+
164188
Navigate to the `examples/blink` folder and take a look at the C application structure found in `main.c`. To compile the application, simply run `make`. This command will built the example applications for all target architectures supported by the library. Apps are compiled into TBFs (Tock Binary Format), and can be found in the `build/<arch>` sub-directories. Tock also generates an archive of the same app, compiled for multiple architectures, for ease of use and portability, called a TAB(Tock Application Bundle) which can be loaded using the `tockloader` utility.
165189

166190
### Flashing the application
@@ -186,7 +210,7 @@ Which option? [0] 1
186210
[INFO ] Using "/dev/cu.usbmodem1103 - KitProg3 CMSIS-DAP".
187211
[INFO ] Listening for serial output
188212

189-
$tock list
213+
tock$ list
190214
PID ShortID Name Quanta Syscalls Restarts Grants State
191215
0 Unique blink 0 84 0 1/ 8 Yielded
192216
```
@@ -203,9 +227,9 @@ use kernel::{
203227
ErrorCode,
204228
};
205229

206-
const DRIVER_NUM: usize = 0x9000A;
230+
pub const DRIVER_NUM: usize = 0x9000A;
207231

208-
struct MockCapsule;
232+
pub struct MockCapsule;
209233

210234
impl SyscallDriver for MockCapsule {
211235
fn command(
@@ -457,6 +481,10 @@ impl<A: 'static + Alarm<'static>> Component for MockCapsuleComponent<A> {
457481
}
458482
```
459483

484+
:::note Module definition
485+
Do not forget to add `pub mod mock;` in `boards/components/src/lib.rs`.
486+
:::
487+
460488
The allocation of the memory segments is usually done through a marco. It is out of this workshop's scope to dive into writing macros, but the macro bellow takes a `type` that must implement the `hil::time::Alarm` trait and returns a tuple of static mutable references to `MaybeUninit` wrappers of the `VirtualMuxAlarm` nad the `MockCapsule`.
461489

462490
```rust title="boards/components/src/mock.rs"
@@ -744,8 +772,7 @@ impl<'a, A: adc::AdcChannel<'a>> adc::Client for Cy8cprotoThermistor<'a, A> {
744772

745773
#### Defining the component
746774

747-
As before, we need to ensure the capsule can be easily configured by implementing a new `Component`. You can name the module `cyc8cproto_thermistor.rs`.
748-
775+
As before, we need to ensure the capsule can be easily configured by implementing a new `Component`. You can name the module `cy8cproto_thermistor.rs`.
749776
We should start from the bottom up, considering what should be needed to instantiate this capsule. These are the `AdcChannel`s and an `MuxAdc`, to be able to multiplex an ADC peripheral to sample multiple channels.
750777

751778
```rust title="boards/components/src/cyc8proto_thermistor.rs"
@@ -776,7 +803,7 @@ impl<A: 'static + adc::Adc<'static>> Cy8cprotoThermistorComponent<A> {
776803

777804
The `finalize` implementation of the `Component` trait will need to create the two virtual `AdcDevices` that multiplex the peripheral, and therefore, the static memory needed must accommodate the two devices, and the thermistor capsule.
778805

779-
```rust title="boards/components/src/cyc8proto_thermistor.rs"
806+
```rust title="boards/components/src/cy8cproto_thermistor.rs"
780807
impl<A: 'static + adc::Adc<'static>> Component for Cy8cprotoThermistorComponent<A> {
781808
type StaticInput = (
782809
&'static mut MaybeUninit<AdcDevice<'static, A>>,
@@ -808,7 +835,7 @@ impl<A: 'static + adc::Adc<'static>> Component for Cy8cprotoThermistorComponent<
808835

809836
The macro should look like this:
810837

811-
```rust title="boards/components/src/cyc8proto_thermistor.rs"
838+
```rust title="boards/components/src/cy8cproto_thermistor.rs"
812839
#[macro_export]
813840
macro_rules! cy8cproto_thermistor_component_static {
814841
($A:ty $(,)?) => {{

0 commit comments

Comments
 (0)