Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • pmrust/pmrust.pages.upb.ro
  • genan.omer/pmrust.pages.upb.ro
  • vladut.chintoiu/pmrust.pages.upb.ro
  • petru.nania/website-pmrust-fork
  • sofia.huzan/pmrust.pages.upb.ro
  • ionut.pruteanu2308/arcade-game
  • luana.militaru/pong-game
  • sebastian.scrob/project
  • matei.bejinaru/website-bejinaru-matei
  • adragomir2806/website-dragomir-alexandru
  • fatemehsadat/pmrust.pages.upb.ro
  • razvan.costea2205/pmrust.pages.upb.ro
  • darius_gabriel.iuga/pm-website
  • andrei.neagu1910/pmrust.pages.upb.ro
  • irina.chiorean/pmrust.pages.upb.ro
  • adrian_costin.lungu/pmrust.pages.upb.ro
  • andrei.salavastru/pmrust.pages.upb.ro
  • maria_elena.tudor/pmrust.pages.upb.ro
  • vlad.preda2503/electric-piano
  • delia_alexa.dragan/website-music-player
  • francisc.niss/automatic-guitar-tuner
  • mihnea.sandulache/pmrust.pages.upb.ro
  • dragos_andrei.rosu/pmrust.pages.upb.ro
  • armin.shafiei/the-tone-corrector
  • vladyslav.kiselar/pmrust.pages.upb.ro
  • carla_maria.rusu/pmrust.pages.upb.ro
26 results
Show changes
Showing
with 496 additions and 194 deletions
...@@ -11,18 +11,18 @@ drawings: ...@@ -11,18 +11,18 @@ drawings:
defaults: defaults:
foo: true foo: true
transition: slide-left transition: slide-left
title: MA - 03 - Exceptions and Interrupts title: MA - 07 - Exceptions and Interrupts
mdc: true mdc: true
layout: cover layout: cover
themeConfig: themeConfig:
primary: '#0060df' primary: '#0060df'
download: true download: true
exportFilename: ma-03 exportFilename: ma-07
background: background:
--- ---
# Exceptions and Interrupts # Exceptions and Interrupts
Lecture 3 Lecture 7
--- ---
......
...@@ -119,8 +119,8 @@ Embassy provides four types of channels synchronized using `Mutex`s ...@@ -119,8 +119,8 @@ Embassy provides four types of channels synchronized using `Mutex`s
|-|-| |-|-|
| [`Channel`](https://docs.embassy.dev/embassy-sync/git/default/channel/struct.Channel.html) | A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. | | [`Channel`](https://docs.embassy.dev/embassy-sync/git/default/channel/struct.Channel.html) | A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. |
| [`PriorityChannel`](https://docs.embassy.dev/embassy-sync/git/default/priority_channel/struct.PriorityChannel.html) | A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. Higher priority items are shifted to the front of the channel. | | [`PriorityChannel`](https://docs.embassy.dev/embassy-sync/git/default/priority_channel/struct.PriorityChannel.html) | A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. Higher priority items are shifted to the front of the channel. |
| [`Signal`](https://docs.embassy.dev/embassy-sync/git/default/pubsub/struct.PubSubChannel.html) | Signalling latest value to a single consumer. | | [`Signal`](https://docs.embassy.dev/embassy-sync/git/default/signal/struct.Signal.html) | Signalling latest value to a single consumer. |
| [`PubSubChannel`](https://docs.embassy.dev/embassy-sync/git/default/signal/struct.Signal.html) | A broadcast channel (publish-subscribe) channel. Each message is received by all consumers. | | [`PubSubChannel`](https://docs.embassy.dev/embassy-sync/git/default/pubsub/struct.PubSubChannel.html) | A broadcast channel (publish-subscribe) channel. Each message is received by all consumers. |
--- ---
--- ---
...@@ -129,7 +129,7 @@ sends data from one task to another ...@@ -129,7 +129,7 @@ sends data from one task to another
[`Channel`](https://docs.embassy.dev/embassy-sync/git/default/channel/struct.Channel.html) - A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. [`Channel`](https://docs.embassy.dev/embassy-sync/git/default/channel/struct.Channel.html) - A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer.
[`Signal`](https://docs.embassy.dev/embassy-sync/git/default/pubsub/struct.PubSubChannel.html) - Signalling latest value to a single consumer. [`Signal`](https://docs.embassy.dev/embassy-sync/git/default/signal/struct.Signal.html) - Signalling latest value to a single consumer.
```mermaid ```mermaid
flowchart LR flowchart LR
...@@ -166,7 +166,7 @@ flowchart LR ...@@ -166,7 +166,7 @@ flowchart LR
# PubSubChannel # PubSubChannel
sends data from one task to all receiver tasks sends data from one task to all receiver tasks
[`PubSubChannel`](https://docs.embassy.dev/embassy-sync/git/default/signal/struct.Signal.html) - A broadcast channel (publish-subscribe) channel. Each message is received by all consumers. [`PubSubChannel`](https://docs.embassy.dev/embassy-sync/git/default/pubsub/struct.PubSubChannel.html) - A broadcast channel (publish-subscribe) channel. Each message is received by all consumers.
```mermaid ```mermaid
flowchart LR flowchart LR
...@@ -181,7 +181,7 @@ flowchart LR ...@@ -181,7 +181,7 @@ flowchart LR
# Channel Example # Channel Example
```rust{all|1|2|5,7,14,17-25|5,8-14} ```rust{1|2|5,7,14,17-25|5,8-14|all}
enum LedState { On, Off } enum LedState { On, Off }
static CHANNEL: Channel<ThreadModeRawMutex, LedState, 64> = Channel::new(); static CHANNEL: Channel<ThreadModeRawMutex, LedState, 64> = Channel::new();
......
...@@ -22,7 +22,7 @@ layout: two-cols ...@@ -22,7 +22,7 @@ layout: two-cols
} }
</style> </style>
- MCUs are usually *single core*[^rp2040] - MCUs are usually *single core*[^rp2350]
- Tasks in parallel require an OS[^interrupts] - Tasks in parallel require an OS[^interrupts]
- Tasks can be suspended at any time - Tasks can be suspended at any time
- **Switching** the task is **expensive** - **Switching** the task is **expensive**
...@@ -54,7 +54,7 @@ sequenceDiagram ...@@ -54,7 +54,7 @@ sequenceDiagram
end end
``` ```
[^rp2040]: RP2040 is a dual core MCU, we use only one core [^rp2350]: RP2350 is a dual core MCU, we use only one core
[^interrupts]: Running in an ISR is not considered a normal task [^interrupts]: Running in an ISR is not considered a normal task
--- ---
...@@ -79,7 +79,7 @@ layout: two-cols ...@@ -79,7 +79,7 @@ layout: two-cols
:: right :: :: right ::
```mermaid ```mermaid {scale: 0.6}
sequenceDiagram sequenceDiagram
autonumber autonumber
loop loop
......
...@@ -6,14 +6,13 @@ layout: section ...@@ -6,14 +6,13 @@ layout: section
Direct Memory Access Direct Memory Access
--- ---
---
# Bibliography # Bibliography
for this section for this section
**Raspberry Pi Ltd**, *[RP2040 Datasheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf)* **Raspberry Pi Ltd**, *[RP2350 Datasheet](https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf)*
- Chapter 2 - *System Description* - Chapter 12 - *Peripherals*
- Chapter 2.5 - *DMA* - Chapter 16.6 - *DMA*
--- ---
layout: two-cols layout: two-cols
......
...@@ -9,10 +9,10 @@ of Embassy ...@@ -9,10 +9,10 @@ of Embassy
# Bibliography # Bibliography
for this section for this section
**Embassy Documentation**, *[Embassy executor](https://embassy.dev/book/dev/runtime.html)* **Embassy Documentation**, *[Embassy executor](https://embassy.dev/book/#_embassy_executor)*
--- ---
---
# Tasks # Tasks
<div grid="~ cols-2 gap5"> <div grid="~ cols-2 gap5">
...@@ -32,9 +32,9 @@ for this section ...@@ -32,9 +32,9 @@ for this section
</div> </div>
```rust {all|9-22|1-7|18-21|19|3-6|4|5} ```rust {9-22|1-7|18-21|19|3-6|4|5|all}
#[embassy_executor::task(pool_size = 2)] #[embassy_executor::task(pool_size = 2)]
async fn led_blink(mut led:Output<'static, PIN_X>) { async fn led_blink(mut led: AnyPin) {
loop { loop {
led.toogle(); led.toogle();
Timer::after_secs(1).await; Timer::after_secs(1).await;
...@@ -60,7 +60,7 @@ async fn main(spawner: Spawner) { ...@@ -60,7 +60,7 @@ async fn main(spawner: Spawner) {
</div> </div>
--- ---
---
# Tasks can stop the executor # Tasks can stop the executor
<div grid="~ cols-2 gap5"> <div grid="~ cols-2 gap5">
...@@ -73,9 +73,9 @@ async fn main(spawner: Spawner) { ...@@ -73,9 +73,9 @@ async fn main(spawner: Spawner) {
</div> </div>
``` {all|5-8|3-9} ```rust {5-8|3-9|all}
#[embassy_executor::task] #[embassy_executor::task]
async fn led_blink(mut led:Output<'static, PIN_X>) { async fn led_blink(mut led: AnyPin) {
loop { loop {
led.toogle(); led.toogle();
// this does not execute anything // this does not execute anything
...@@ -114,6 +114,7 @@ async fn main(spawner: Spawner) { ...@@ -114,6 +114,7 @@ async fn main(spawner: Spawner) {
--- ---
layout: two-cols layout: two-cols
--- ---
## Priority Tasks ## Priority Tasks
<style> <style>
...@@ -139,7 +140,7 @@ unsafe fn SWI_IRQ_0() { ...@@ -139,7 +140,7 @@ unsafe fn SWI_IRQ_0() {
:: right :: :: right ::
```rust {all|5,6,22|1,7-10|2,12-15|3,17-21} ```rust {5,6,22|1,7-10|2,12-15|3,17-21|all}
static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new();
static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new();
static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new();
......
...@@ -33,7 +33,7 @@ trait Future { ...@@ -33,7 +33,7 @@ trait Future {
} }
``` ```
```rust {all|5,10|6|6,7|6|6,7|6|6,8|1,8}{lines: false} ```rust {5,10|6|6,7|6|6,7|6|6,8|1,8|all}{lines: false}
fn execute<F>(mut f: F) -> F::Output fn execute<F>(mut f: F) -> F::Output
where where
F: Future F: Future
...@@ -74,7 +74,7 @@ sequenceDiagram ...@@ -74,7 +74,7 @@ sequenceDiagram
<div grid="~ cols-2 gap-5"> <div grid="~ cols-2 gap-5">
```rust {all|1-4|6-9|11-18} ```rust {1-4|6-9|11-18|all}
enum SleepStatus { enum SleepStatus {
SetAlarm, SetAlarm,
WaitForAlarm, WaitForAlarm,
...@@ -97,7 +97,7 @@ impl Sleep { ...@@ -97,7 +97,7 @@ impl Sleep {
<v-click> <v-click>
```rust {all|1,20|1,2,20|4,19|5,18|6-10|11-17|11,12,13|11,14,15}{lines: false} ```rust {1,20|1,2,20|4,19|5,18|6-10|11-17|11,12,13|11,14,15|all}{lines: false}
impl Future for Sleep { impl Future for Sleep {
type Output = (); type Output = ();
...@@ -130,7 +130,7 @@ impl Future for Sleep { ...@@ -130,7 +130,7 @@ impl Future for Sleep {
<div grid="~ cols-2 gap-5"> <div grid="~ cols-2 gap-5">
```rust {all|1,20|1,2,20|4,19|5,18|6-10|11-17|11,12,13|11,14,15}{lines: false} ```rust {1,20|1,2,20|4,19|5,18|6-10|11-17|11,12,13|11,14,15|all}{lines: false}
impl Future for Sleep { impl Future for Sleep {
type Output = (); type Output = ();
...@@ -218,7 +218,7 @@ fn blink(led: Output<'static, PIN_X>) -> Blink { ...@@ -218,7 +218,7 @@ fn blink(led: Output<'static, PIN_X>) -> Blink {
<v-click> <v-click>
```rust {4-23|5-22|5,6-10,22|5,11-17,22|12-14|5,11-17,22|12,14,15,16|5,18-21,22}{lines: false} ```rust {4-23|5-22|5,6-10,22|5,11-17,22|12-14|5,11-17,22|12,14,15,16|5,18-21,22|all}{lines: false}
impl Future for Blink { impl Future for Blink {
type Output = (); type Output = ();
fn poll(&mut self) -> Poll<Self::Output> { fn poll(&mut self) -> Poll<Self::Output> {
...@@ -257,7 +257,7 @@ impl Future for Blink { ...@@ -257,7 +257,7 @@ impl Future for Blink {
- it does not know how to execute them - it does not know how to execute them
- executors are implemented into third party libraries - executors are implemented into third party libraries
```rust {all|12|11,13,15|14} ```rust {12|11,13,15|14|all}
use engine::execute; use engine::execute;
// Rust rewrites the function to a Future // Rust rewrites the function to a Future
...@@ -280,7 +280,7 @@ fn main() -> ! { ...@@ -280,7 +280,7 @@ fn main() -> ! {
--- ---
# Executor # Executor
```rust {all|1|4-16|5-12|14,15} ```rust {1|4-16|5-12|14,15|all}
static TASKS: [Option<impl Future>; N] = [None, N]; static TASKS: [Option<impl Future>; N] = [None, N];
fn executor() { fn executor() {
......
...@@ -20,7 +20,7 @@ A simple GPIO ...@@ -20,7 +20,7 @@ A simple GPIO
<br> <br>
> <b> DDRx - Data Direction Register. </b> If the data direction bit is 1, the pin is an input. 0 is an output. > <b> DDRx - Data Direction Register. </b> If the data direction bit is 0, the pin is an input. 1 is an output.
```c ```c
DDRB &= ~(1<<DDB7); // Makes pin PB7 an input DDRB &= ~(1<<DDB7); // Makes pin PB7 an input
......
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
}, },
{ {
"name": "SDA", "name": "SDA",
"wave": "1..0.1.......0.4.4.7.2.4.4.4.4.4.4.4.4.2.9......|..2.01.", "wave": "1..0.1.......0.4.4.7.2.4.4.4.4.4.4.4.4.2.9..|2.9..|2.01.",
"data": ["a9", "a8", "data": [
"r/w", "a9",
"ack", "a8",
"a7", "r/w",
"ack",
"a7",
"a6", "a6",
"a5", "a5",
"a4", "a4",
...@@ -19,7 +21,9 @@ ...@@ -19,7 +21,9 @@
"a1", "a1",
"a0", "a0",
"ack", "ack",
"byte1 | byte2 ... ", "byte1",
"ack",
"byte2",
"ack" "ack"
], ],
"phase": 1.5 "phase": 1.5
...@@ -31,7 +35,7 @@ ...@@ -31,7 +35,7 @@
"start", "start",
"upper addr", "upper addr",
"cmd", "cmd",
"lower address", "lower address",
"payload bytes", "payload bytes",
"stop" "stop"
], ],
...@@ -41,4 +45,4 @@ ...@@ -41,4 +45,4 @@
"config": { "config": {
"skin": "narrow" "skin": "narrow"
} }
} }
\ No newline at end of file
...@@ -10,9 +10,9 @@ Inter-Integrated Circuit ...@@ -10,9 +10,9 @@ Inter-Integrated Circuit
# Bibliography # Bibliography
for this section for this section
1. **Raspberry Pi Ltd**, *[RP2040 Datasheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf)* 1. **Raspberry Pi Ltd**, *[RP2350 Datasheet](https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf)*
- Chapter 4 - *Peripherals* - Chapter 12 - *Peripherals*
- Chapter 4.3 - *I2C* - Chapter 12.2 - *I2C*
2. **Paul Denisowski**, *[Understanding I2C](https://www.youtube.com/watch?v=CAvawEcxoPU)* 2. **Paul Denisowski**, *[Understanding I2C](https://www.youtube.com/watch?v=CAvawEcxoPU)*
...@@ -196,7 +196,7 @@ Transmission ...@@ -196,7 +196,7 @@ Transmission
- sensors - sensors
- small displays - small displays
- RP2040 has two I2C devices - RP2350 has two I2C devices
<div align="center"> <div align="center">
<img src="./raspberry_pi_pico_pins.jpg" class="rounded m-5 w-120"> <img src="./raspberry_pi_pico_pins.jpg" class="rounded m-5 w-120">
...@@ -205,7 +205,7 @@ Transmission ...@@ -205,7 +205,7 @@ Transmission
--- ---
--- ---
# Embassy API # Embassy API
for RP2040, synchronous for RP2350, synchronous
<div grid="~ cols-3 gap-5"> <div grid="~ cols-3 gap-5">
...@@ -237,12 +237,11 @@ pub enum Error { ...@@ -237,12 +237,11 @@ pub enum Error {
</div> </div>
```rust{all|1|3,4|6|8,9|11,12} ```rust {1|3,4|3-5|7,8|10,11|13|all}
use embassy_rp::i2c::Config as I2cConfig; use embassy_rp::i2c::Config as I2cConfig;
let sda = p.PIN_14; let sda = p.PIN_14;
let scl = p.PIN_15; let scl = p.PIN_15;
let mut i2c = i2c::I2c::new_blocking(p.I2C1, scl, sda, I2cConfig::default()); let mut i2c = i2c::I2c::new_blocking(p.I2C1, scl, sda, I2cConfig::default());
let tx_buf = [0x90]; let tx_buf = [0x90];
...@@ -250,14 +249,16 @@ i2c.write(0x5e, &tx_buf).unwrap(); ...@@ -250,14 +249,16 @@ i2c.write(0x5e, &tx_buf).unwrap();
let mut rx_buf = [0x00u8; 7]; let mut rx_buf = [0x00u8; 7];
i2c.read(0x5e, &mut rx_buf).unwrap(); i2c.read(0x5e, &mut rx_buf).unwrap();
i2c.write_read(0x5e, &tx_buf, &mut rx_buf).unwrap();
``` ```
--- ---
--- ---
# Embassy API # Embassy API
for RP2040, asynchronous for RP2350, asynchronous
```rust{all|1|3-5|7,8|10|12,13|15,16} ```rust {1|3-5|7,8|7-9|11,12|14,15|17|all}
use embassy_rp::i2c::Config as I2cConfig; use embassy_rp::i2c::Config as I2cConfig;
bind_interrupts!(struct Irqs { bind_interrupts!(struct Irqs {
...@@ -266,7 +267,6 @@ bind_interrupts!(struct Irqs { ...@@ -266,7 +267,6 @@ bind_interrupts!(struct Irqs {
let sda = p.PIN_14; let sda = p.PIN_14;
let scl = p.PIN_15; let scl = p.PIN_15;
let mut i2c = i2c::I2c::new_async(p.I2C1, scl, sda, Irqs, I2cConfig::default()); let mut i2c = i2c::I2c::new_async(p.I2C1, scl, sda, Irqs, I2cConfig::default());
let tx_buf = [0x90]; let tx_buf = [0x90];
...@@ -274,4 +274,6 @@ i2c.write(0x5e, &tx_buf).await.unwrap(); ...@@ -274,4 +274,6 @@ i2c.write(0x5e, &tx_buf).await.unwrap();
let mut rx_buf = [0x00u8; 7]; let mut rx_buf = [0x00u8; 7];
i2c.read(0x5e, &mut rx_buf).await.unwrap(); i2c.read(0x5e, &mut rx_buf).await.unwrap();
i2c.write_read(0x5e, &tx_buf, &mut rx_buf).await.unwrap();
``` ```
...@@ -84,11 +84,12 @@ This is how a Rust application would look like ...@@ -84,11 +84,12 @@ This is how a Rust application would look like
<div grid="~ cols-2 gap-4"> <div grid="~ cols-2 gap-4">
```rust{all|1|2|4|6|7,11|10|13-16} ```rust{all|1|2|4,5|7|8,12|11|14-17}
#![no_std] #![no_std]
#![no_main] #![no_main]
use cortex_m_rt::entry; use cortex_m_rt::entry;
use core::panic::PanicInfo;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
...@@ -126,6 +127,7 @@ This is how a Rust application would look like ...@@ -126,6 +127,7 @@ This is how a Rust application would look like
use core::ptr::{read_volatile, write_volatile}; use core::ptr::{read_volatile, write_volatile};
use cortex_m_rt::entry; use cortex_m_rt::entry;
use core::panic::PanicInfo;
const GPIOX_CTRL: u32 = 0x4001_4004; const GPIOX_CTRL: u32 = 0x4001_4004;
const GPIO_OE_SET: *mut u32= 0xd000_0024 as *mut u32; const GPIO_OE_SET: *mut u32= 0xd000_0024 as *mut u32;
...@@ -134,25 +136,25 @@ const GPIO_OUT_CLR:*mut u32= 0xd000_0018 as *mut u32; ...@@ -134,25 +136,25 @@ const GPIO_OUT_CLR:*mut u32= 0xd000_0018 as *mut u32;
#[panic_handler] #[panic_handler]
pub fn panic(_info: &PanicInfo) -> ! { pub fn panic(_info: &PanicInfo) -> ! {
loop { } loop { }
} }
``` ```
```rust {all}{startLine:18} ```rust {all}{startLine:18}
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let gpio_ctrl = GPIOX_CTRL + 8 * pin as *mut u32; let gpio_ctrl = (GPIOX_CTRL + 8 * pin) as *mut u32;
unsafe { unsafe {
write_volatile(gpio_ctrl, 5); write_volatile(gpio_ctrl, 5);
write_volatile(GPIO_OE_SET, 1 << pin); write_volatile(GPIO_OE_SET, 1 << pin);
let reg = match value { let reg = match value {
0 => GPIO_OUT_CLR, 0 => GPIO_OUT_CLR,
_ => GPIO_OUT_SET _ => GPIO_OUT_SET
}; };
write_volatile(reg, 1 << pin); write_volatile(reg, 1 << pin);
}; };
loop { } loop { }
} }
``` ```
......
...@@ -81,7 +81,7 @@ using synchronous/asynchronous SPI to read the `press_lsb` register of BMP280 ...@@ -81,7 +81,7 @@ using synchronous/asynchronous SPI to read the `press_lsb` register of BMP280
<div grid="~ cols-2 gap-5"> <div grid="~ cols-2 gap-5">
```rust{all|1|3,4|6,7|6,7,8|10,11|13,14} ```rust {1|3,4|6,7|6,7,8|10,11|13,14|all}
const REG_ADDR: u8 = 0xf8; const REG_ADDR: u8 = 0xf8;
// enable the sensor // enable the sensor
...@@ -98,7 +98,7 @@ cs.set_high(); ...@@ -98,7 +98,7 @@ cs.set_high();
let pressure_lsb = buf[1]; let pressure_lsb = buf[1];
``` ```
```rust{none|all|1|3,4|6,7,8|6,7,8,9|11,12|14,15} ```rust {none|1|3,4|6,7,8|6,7,8,9|11,12|14,15|all}
const REG_ADDR: u8 = 0xf8; const REG_ADDR: u8 = 0xf8;
// enable the sensor // enable the sensor
...@@ -118,9 +118,8 @@ let pressure_lsb = rx_buf[1]; ...@@ -118,9 +118,8 @@ let pressure_lsb = rx_buf[1];
</div> </div>
---
--- ---
# Writing to a digital sensor # Writing to a digital sensor
using synchronous/asynchronous SPI to set up the `ctrl_meas` register of the BMP280 sensor using synchronous/asynchronous SPI to set up the `ctrl_meas` register of the BMP280 sensor
...@@ -128,7 +127,7 @@ using synchronous/asynchronous SPI to set up the `ctrl_meas` register of the BMP ...@@ -128,7 +127,7 @@ using synchronous/asynchronous SPI to set up the `ctrl_meas` register of the BMP
<div grid="~ cols-2 gap-5"> <div grid="~ cols-2 gap-5">
```rust{all|1|3,4|6,7|9,10|9,10,11|13,14} ```rust {1|3,4|6,7|9,10|9,10,11|13,14|all}
const REG_ADDR: u8 = 0xf4; const REG_ADDR: u8 = 0xf4;
// see subchapters 3.3.2, 3.3.1 and 3.6 // see subchapters 3.3.2, 3.3.1 and 3.6
...@@ -145,7 +144,7 @@ spi.blocking_transfer_in_place(&mut buf); ...@@ -145,7 +144,7 @@ spi.blocking_transfer_in_place(&mut buf);
cs.set_high(); cs.set_high();
``` ```
```rust{none|all|1|3,4|6,7|9,10|9,10,11|9,10,11,12|14,15} ```rust {none|1|3,4|6,7|9,10|9,10,11|9,10,11,12|14,15|all}
const REG_ADDR: u8 = 0xf4; const REG_ADDR: u8 = 0xf4;
// see subchapters 3.3.2, 3.3.1 and 3.6 // see subchapters 3.3.2, 3.3.1 and 3.6
......
...@@ -81,27 +81,29 @@ using synchronous/asynchronous I2C to read the `press_lsb` register of BMP280 ...@@ -81,27 +81,29 @@ using synchronous/asynchronous I2C to read the `press_lsb` register of BMP280
<div grid="~ cols-2 gap-5"> <div grid="~ cols-2 gap-5">
```rust{all|1|1,2|4|6,7|9,10} ```rust {all|1|1,2|4|6,7,8|10,11|all}
const DEVICE_ADDR: u8 = 0x77; const DEVICE_ADDR: u8 = 0x77;
const REG_ADDR: u8 = 0xf8; const REG_ADDR: u8 = 0xf8;
i2c.write(DEVICE_ADDR, &[REG_ADDR]).unwrap();
let mut buf = [0x00u8]; let mut buf = [0x00u8];
i2c.read(DEVICE_ADDR, &mut buf).unwrap();
i2c.write_read(
DEVICE_ADDR, &[REG_ADDR], &mut buf
).unwrap();
// use the value // use the value
let pressure_lsb = buf[1]; let pressure_lsb = buf[1];
``` ```
```rust{none|all||1|1,2|4|6,7|9,10} ```rust {none|1|1,2|4|6,7,8|10,11|all}
const DEVICE_ADDR: u8 = 0x77; const DEVICE_ADDR: u8 = 0x77;
const REG_ADDR: u8 = 0xf8; const REG_ADDR: u8 = 0xf8;
i2c.write(DEVICE_ADDR, &[REG_ADDR]).await.unwrap();
let mut buf = [0x00u8]; let mut buf = [0x00u8];
i2c.read(DEVICE_ADDR, &mut buf).await.unwrap();
i2c.write_read(
DEVICE_ADDR, &[REG_ADDR], &mut buf
).await.unwrap();
// use the value // use the value
let pressure_lsb = buf[1]; let pressure_lsb = buf[1];
...@@ -109,7 +111,6 @@ let pressure_lsb = buf[1]; ...@@ -109,7 +111,6 @@ let pressure_lsb = buf[1];
</div> </div>
--- ---
--- ---
# Writing to a digital sensor # Writing to a digital sensor
...@@ -119,28 +120,24 @@ using synchronous/asynchronous I2C to set up the `ctrl_meas` register of the BMP ...@@ -119,28 +120,24 @@ using synchronous/asynchronous I2C to set up the `ctrl_meas` register of the BMP
<div grid="~ cols-2 gap-5"> <div grid="~ cols-2 gap-5">
```rust{all|1|1,2|4,5|7|9,10} ```rust {1|1,2|4,5|7,8|all}
const DEVICE_ADDR: u8 = 0x77; const DEVICE_ADDR: u8 = 0x77;
const REG_ADDR: u8 = 0xf4; const REG_ADDR: u8 = 0xf4;
// see subchapters 3.3.2, 3.3.1 and 3.6 // see subchapters 3.3.2, 3.3.1 and 3.6
let value = 0b100_010_11; let value = 0b100_010_11;
i2c.write(DEVICE_ADDR, &[REG_ADDR]);
let buf = [REG_ADDR, value]; let buf = [REG_ADDR, value];
i2c.write(DEVICE_ADDR, &buf).unwrap(); i2c.write(DEVICE_ADDR, &buf).unwrap();
``` ```
```rust{none|all|1|1,2|4,5|7|9,10} ```rust {none|1|1,2|4,5|7,8|all}
const DEVICE_ADDR: u8 = 0x77; const DEVICE_ADDR: u8 = 0x77;
const REG_ADDR: u8 = 0xf4; const REG_ADDR: u8 = 0xf4;
// see subchapters 3.3.2, 3.3.1 and 3.6 // see subchapters 3.3.2, 3.3.1 and 3.6
let value = 0b100_010_11; let value = 0b100_010_11;
i2c.write(DEVICE_ADDR, &[REG_ADDR]);
let buf = [REG_ADDR, value]; let buf = [REG_ADDR, value];
i2c.write(DEVICE_ADDR, &buf).await.unwrap(); i2c.write(DEVICE_ADDR, &buf).await.unwrap();
``` ```
......
...@@ -4,15 +4,14 @@ layout: section ...@@ -4,15 +4,14 @@ layout: section
# SPI # SPI
Serial Peripheral Interface Serial Peripheral Interface
---
--- ---
# Bibliography # Bibliography
for this section for this section
1. **Raspberry Pi Ltd**, *[RP2040 Datasheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf)* 1. **Raspberry Pi Ltd**, *[RP2350 Datasheet](https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf)*
- Chapter 4 - *Peripherals* - Chapter 12 - *Peripherals*
- Chapter 4.4 - *SPI* - Chapter 12.3 - *SPI*
2. **Paul Denisowski**, *[Understanding SPI](https://www.youtube.com/watch?v=0nVNwozXsIc)* 2. **Paul Denisowski**, *[Understanding SPI](https://www.youtube.com/watch?v=0nVNwozXsIc)*
...@@ -213,21 +212,21 @@ activate all the **sub** devices ...@@ -213,21 +212,21 @@ activate all the **sub** devices
| Speed | *no limit* | does not have any limit, it is limited by the **main** clock and the electronics wirings | | Speed | *no limit* | does not have any limit, it is limited by the **main** clock and the electronics wirings |
--- ---
---
# Usage # Usage
- EEPROMs / Flash (usually in *QSPI* mode) - EEPROMs / Flash (usually in *QSPI* mode)
- Raspberry Pi Pico has its 2MB Flash connected using *QSPI* - Raspberry Pi Pico has its 2MB Flash connected using *QSPI*
- sensors - sensors
- small displays - small displays
- RP2040 has two SPI devices - RP2350 has two SPI devices
<div align="center"> <div align="center">
<img src="./raspberry_pi_pico_pins.jpg" class="rounded m-5 w-120"> <img src="../rp2350/pico2w-pinout.svg" class="rounded m-5 w-100">
</div> </div>
--- ---
---
# Embassy API # Embassy API
for RP2040, synchronous for RP2040, synchronous
...@@ -257,7 +256,7 @@ pub enum Polarity { ...@@ -257,7 +256,7 @@ pub enum Polarity {
</div> </div>
```rust{all|1|2|2,3|5-7|5-8|10,11|13|13,14|13,14,15|13,14,15,16} ```rust {1|2|2,3|5-7|5-8|10,11|13|13,14|13,14,15|13,14,15,16|all}
use embassy_rp::spi::Config as SpiConfig; use embassy_rp::spi::Config as SpiConfig;
let mut config = SpiConfig::default(); let mut config = SpiConfig::default();
config.frequency = 2_000_000; config.frequency = 2_000_000;
...@@ -277,11 +276,11 @@ cs.set_high(); ...@@ -277,11 +276,11 @@ cs.set_high();
``` ```
--- ---
---
# Embassy API # Embassy API
for RP2040, asynchronous for RP2040, asynchronous
```rust{all|1|2|2,3|5-7|5-8|10,11|13|13,14,15|13,14,15,16|13,14,15,16,17} ```rust {1|2|2,3|5-7|5-8|10,11|13|13,14,15|13,14,15,16|13,14,15,16,17|all}
use embassy_rp::spi::Config as SpiConfig; use embassy_rp::spi::Config as SpiConfig;
let mut config = SpiConfig::default(); let mut config = SpiConfig::default();
config.frequency = 2_000_000; config.frequency = 2_000_000;
......
...@@ -212,7 +212,7 @@ read the number of elapsed μs since reset ...@@ -212,7 +212,7 @@ read the number of elapsed μs since reset
#### Reading the time elapsed since restart #### Reading the time elapsed since restart
```rust{1,5|2,6|4,7,8|all} ```rust {1,5|2,6|4,7,8|all}
const TIMERLR: *const u32 = 0x400b_000c; const TIMERLR: *const u32 = 0x400b_000c;
const TIMERHR: *const u32 = 0x400b_0008; const TIMERHR: *const u32 = 0x400b_0008;
...@@ -228,7 +228,7 @@ The **reading order maters** as reading `TIMELR` latches the value in `TIMEHR` ( ...@@ -228,7 +228,7 @@ The **reading order maters** as reading `TIMELR` latches the value in `TIMEHR` (
:: right :: :: right ::
<div align="center"> <div align="center">
<img src="./rp2350_timer_registers_1.png" class="rounded w-100"> <img src="./rp2350_timer_registers_1.png" class="rounded w-90">
</div> </div>
--- ---
......
...@@ -5,13 +5,13 @@ layout: section ...@@ -5,13 +5,13 @@ layout: section
Universal Asynchronous Receiver and Transmitter Universal Asynchronous Receiver and Transmitter
--- ---
---
# Bibliography # Bibliography
for this section for this section
1. **Raspberry Pi Ltd**, *[RP2040 Datasheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf)* 1. **Raspberry Pi Ltd**, *[RP2350 Datasheet](https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf)*
- Chapter 4 - *Peripherals* - Chapter 12 - *Peripherals*
- Chapter 4.2 - *UART* - Chapter 12.1 - *UART*
2. **Paul Denisowski**, *[Understanding Serial Protocols](https://www.youtube.com/watch?v=LEz5UCN3aHA)* 2. **Paul Denisowski**, *[Understanding Serial Protocols](https://www.youtube.com/watch?v=LEz5UCN3aHA)*
3. **Paul Denisowski**, *[Understanding UART](https://www.youtube.com/watch?v=sTHckUyxwp8)* 3. **Paul Denisowski**, *[Understanding UART](https://www.youtube.com/watch?v=sTHckUyxwp8)*
...@@ -193,21 +193,21 @@ using the 8N1 data format ...@@ -193,21 +193,21 @@ using the 8N1 data format
</div> </div>
--- ---
---
# Usage # Usage
- print debug information - print debug information
- device console - device console
- RP2040 has two USART devices - RP2350 has two USART devices
<div align="center"> <div align="center">
<img src="../rp2040/rp2040_adafruit_pinout.png" class="rounded m-5 w-100"> <img src="../rp2350/pico2w-pinout.svg" class="rounded m-5 w-100">
</div> </div>
--- ---
# Embassy API # Embassy API
for RP2040, synchronous for RP2350, synchronous
<div grid="~ cols-4 gap-5"> <div grid="~ cols-4 gap-5">
...@@ -250,7 +250,7 @@ pub enum Parity { ...@@ -250,7 +250,7 @@ pub enum Parity {
</div> </div>
```rust{all|1|1,2|4,5|6,7|9,10,11} ```rust {1|1,2|4,5|6,7|9,10,11|all}
use embassy_rp::uart::Config as UartConfig; use embassy_rp::uart::Config as UartConfig;
let config = UartConfig::default(); let config = UartConfig::default();
...@@ -264,13 +264,12 @@ let mut buf = [0; 5]; ...@@ -264,13 +264,12 @@ let mut buf = [0; 5];
uart.blocking_read(&mut buf); uart.blocking_read(&mut buf);
``` ```
--- ---
# Embassy API # Embassy API
for RP2040, asynchronous for RP2350, asynchronous
```rust{all|1|3-5|7|9,10|12,13|15,16,17} ```rust {1|3-5|7|9,10|12,13|15,16,17|all}
use embassy_rp::uart::Config as UartConfig; use embassy_rp::uart::Config as UartConfig;
bind_interrupts!(struct Irqs { bind_interrupts!(struct Irqs {
......
This diff is collapsed.
...@@ -72,7 +72,7 @@ fn main() { ...@@ -72,7 +72,7 @@ fn main() {
let age = 26; let age = 26;
println!("Hello, {}. You are {} years old", name, age); println!("Hello, {}. You are {} years old", name, age);
// if the replacements are only variable, one can use the inline version // if the replacements are only variables, one can use the inline version
println!("Hello, {name}. You are {age} years old"); println!("Hello, {name}. You are {age} years old");
} }
``` ```
...@@ -155,7 +155,7 @@ let y: u16 = 25; ...@@ -155,7 +155,7 @@ let y: u16 = 25;
| 32-bit | `i32` | `u32` | `int` / `Integer`[^java_unsigned] | `int` / `unsigned int` | | 32-bit | `i32` | `u32` | `int` / `Integer`[^java_unsigned] | `int` / `unsigned int` |
| 64-bit | `i64` | `u64` | `long` / `Long`[^java_unsigned] | `long long` / `unsigned long long` | | 64-bit | `i64` | `u64` | `long` / `Long`[^java_unsigned] | `long long` / `unsigned long long` |
| 128-bit | `i128` | `u128` | N/A | N/A | | 128-bit | `i128` | `u128` | N/A | N/A |
| arch | `isize` | `usize` | N/A | `int` / `unsigned int` | | arch | `isize` | `usize` | N/A | `intptr_t` / `uintptr_t` |
**Floating Point** → Rust's floating point types are `f32` and `f64`, which are 32-bit and 64-bit in size, respectively. The default type is `f64` because on modern CPUs it is about the same speed as `f32` but is capable of more precision. All floating point types are **signed**. **Floating Point** → Rust's floating point types are `f32` and `f64`, which are 32-bit and 64-bit in size, respectively. The default type is `f64` because on modern CPUs it is about the same speed as `f32` but is capable of more precision. All floating point types are **signed**.
...@@ -341,7 +341,7 @@ To format the `Debug` nicely use `{:#?}`. ...@@ -341,7 +341,7 @@ To format the `Debug` nicely use `{:#?}`.
### Tuple structures ### Tuple structures
Tuples are the same construct as structures, just that instead of using names for their field, they use numbers (indexes). Tuples are the same as structures, just that instead of using names for their fields, they use numbers (indexes).
```rust ```rust
struct Color(i32, i32, i32); struct Color(i32, i32, i32);
......
...@@ -287,6 +287,7 @@ pin.set_high(); ...@@ -287,6 +287,7 @@ pin.set_high();
pin.set_low(); pin.set_low();
``` ```
:::tip :::tip
While the device initialization is specific to every hardware device (the example uses the While the device initialization is specific to every hardware device (the example uses the
...@@ -407,9 +408,15 @@ as they are connected to the lab board's debugger chip. ...@@ -407,9 +408,15 @@ as they are connected to the lab board's debugger chip.
The board provides four single colored LEDs, red, green, blue and yellow. Each one of them The board provides four single colored LEDs, red, green, blue and yellow. Each one of them
uses one pin for control. Each LED connector has one single hole on the board, uses one pin for control. Each LED connector has one single hole on the board,
marked with `RED`, `GREEN', `BLUE` and `YELLOW` respectively. These are located in the **Connectors** marked with `RED`, `GREEN`, `BLUE` and `YELLOW` respectively. These are located in the **Connectors**
section of the board. section of the board.
:::warning
The LEDs are connected so they will light up if the pin is set to `Level::Low` and turn off if the pin is set to `Level::High`.
:::
The four switches that the lab board provides are signaled with labels The four switches that the lab board provides are signaled with labels
`SW4`, `SW5`, `SW6` and `SW7` in the connectors section. `SW4`, `SW5`, `SW6` and `SW7` in the connectors section.
...@@ -457,6 +464,15 @@ Make sure you follow these steps: ...@@ -457,6 +464,15 @@ Make sure you follow these steps:
Please make sure you comment out (using `#` in from of the line) all the Embassy's crates Please make sure you comment out (using `#` in from of the line) all the Embassy's crates
that you do not plan to use. that you do not plan to use.
:::warning
Please make sure the `embassy_rp` crate is included in your build either:
- by importing it with `use embassy_rp as _;`
- or by initialising the peripherals
This crate provides the `.start_block` section that is needed by the RP2350 to boot. Not including
this crate will prevent this section from being added and will prevent the RP2350 to boot.
:::
:::info :::info
For sure, you will not use USB and WiFi. This is a trial For sure, you will not use USB and WiFi. This is a trial
and error job, just comment out all the creates that you think you won't use and and error job, just comment out all the creates that you think you won't use and
......
website/lab/03/images/board_photoresistor.png

246 KiB