Skip to content

Commit 4e8e10e

Browse files
jannicExplodingWaffle
authored andcommitted
Use wfi in otherwise empty infinite loops in examples
- Clippy warns about empty loops, rust-lang/rust-clippy#6161 - wfi allows to CPU to save some power WFI was avoided in examples for fear of ill interactions with debuggers. However the rp2040 debug port does continue to work, as long as the relevant clocks are not disabled in SLEEP_EN0/SLEEP_EN1. (By default, all clocks stay enabled in sleep mode.) This patch replaces several different workarounds with just calling wfi.
1 parent 7a2a714 commit 4e8e10e

File tree

11 files changed

+19
-23
lines changed

11 files changed

+19
-23
lines changed

boards/rp-pico/examples/pico_i2c_pio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn main() -> ! {
149149
print_temperature(&mut uart, temp);
150150

151151
loop {
152-
cortex_m::asm::nop();
152+
cortex_m::asm::wfi();
153153
}
154154
}
155155

rp2040-hal/examples/dht11.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ fn main() -> ! {
139139
// In this case, we just ignore the result. A real application
140140
// would do something with the measurement.
141141

142-
#[allow(clippy::empty_loop)]
143142
loop {
144-
// Empty loop
143+
cortex_m::asm::wfi();
145144
}
146145
}
147146

rp2040-hal/examples/gpio_irq_example.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ fn main() -> ! {
147147

148148
loop {
149149
// interrupts handle everything else in this example.
150-
// if we wanted low power we could go to sleep. to
151-
// keep this example simple we'll just execute a `nop`.
152-
// the `nop` (No Operation) instruction does nothing,
153-
// but if we have no code here clippy would complain.
154-
cortex_m::asm::nop();
150+
cortex_m::asm::wfi();
155151
}
156152
}
157153

rp2040-hal/examples/i2c.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ fn main() -> ! {
9797

9898
// Demo finish - just loop until reset
9999

100-
#[allow(clippy::empty_loop)]
101100
loop {
102-
// Empty loop
101+
cortex_m::asm::wfi();
103102
}
104103
}
105104

rp2040-hal/examples/lcd_display.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ fn main() -> ! {
113113
lcd.write_str("HD44780!", &mut delay).unwrap();
114114

115115
// Do nothing - we're finished
116-
#[allow(clippy::empty_loop)]
117116
loop {
118-
// Empty loop
117+
cortex_m::asm::wfi();
119118
}
120119
}
121120

rp2040-hal/examples/pio_blink.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fn main() -> ! {
6464
sm.start();
6565

6666
// PIO runs in background, independently from CPU
67-
#[allow(clippy::empty_loop)]
68-
loop {}
67+
loop {
68+
cortex_m::asm::wfi();
69+
}
6970
}

rp2040-hal/examples/pio_proc_blink.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn main() -> ! {
5454
sm.start();
5555

5656
// PIO runs in background, independently from CPU
57-
#[allow(clippy::empty_loop)]
58-
loop {}
57+
loop {
58+
cortex_m::asm::wfi();
59+
}
5960
}

rp2040-hal/examples/pio_side_set.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fn main() -> ! {
5757
sm.start();
5858

5959
// PIO runs in background, independently from CPU
60-
#[allow(clippy::empty_loop)]
61-
loop {}
60+
loop {
61+
cortex_m::asm::wfi();
62+
}
6263
}

rp2040-hal/examples/pio_synchronized.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ fn main() -> ! {
9191
cortex_m::asm::delay(10_000_000);
9292
let _sm2 = sm2.stop();
9393

94-
#[allow(clippy::empty_loop)]
95-
loop {}
94+
loop {
95+
cortex_m::asm::wfi();
96+
}
9697
}

rp2040-hal/examples/rom_funcs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn main() -> ! {
166166

167167
// In case the reboot fails
168168
loop {
169-
cortex_m::asm::nop();
169+
cortex_m::asm::wfi();
170170
}
171171
}
172172

rp2040-hal/examples/spi.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ fn main() -> ! {
121121
Err(_) => {} // handle errors
122122
};
123123

124-
#[allow(clippy::empty_loop)]
125124
loop {
126-
// Empty loop
125+
cortex_m::asm::wfi();
127126
}
128127
}
129128

0 commit comments

Comments
 (0)