Skip to content

Commit 79867ef

Browse files
usbalbinAdinAcktechmccat
authored
Merge from main (#173)
* Export pac as pac (#156) * rm remaining fdcan files (#160) * defmt format for rcc clocks (#163) * export PwrExt in prelude (#164) * e-hal-v1 (#172) * Implement SpiBus from embedded-hal 1 * i2c: implement embedded-hal traits * gpio: implement embedded-hal 1 digital traits * pwm: implement SetDutyCycle from embedded-hal 1 * delay: temporary DelayNs impl (μs-resolution) * serial: implement embedded-io traits for UART * bump hal-1, remove ToggleableOutputPin impls * remove embedded-hal 0.2 from prelude, rename hals embedded-hal 1.0 renamed from embedded-hal-one to embedded-hal embedded-hal 0.2 renamed from embedded-hal to embedded-hal-old, still re-exported as hal-02 * pwm: use set_duty_cycle_percent in example * run cargo fmt * remove unused dependencies I had added them by accident for an example that didn't end up in the PR * time: fix duration variable names, add doc * docs: fix cargo doc warnings * Try to make syst delay work as before * Cleanup examples --------- Co-authored-by: techmccat <alessioa02004@gmail.com> --------- Co-authored-by: AdinAck <adinackerman@gmail.com> Co-authored-by: techmccat <alessioa02004@gmail.com>
1 parent e8ac42d commit 79867ef

32 files changed

+862
-301
lines changed

Cargo.toml

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repository = "https://github.com/stm32-rs/stm32g4xx-hal"
1212
version = "0.0.2"
1313

1414
[dependencies]
15-
nb = "0.1.1"
15+
nb = "1"
1616
#stm32g4 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies" } #"0.15.1"
1717
stm32g4 = { version = "0.19.0", package = "stm32g4-staging" }
1818
paste = "1.0"
@@ -22,6 +22,7 @@ static_assertions = "1.1"
2222
fugit = "0.3.7"
2323
stm32-usbd = { version = "0.7.0", optional = true }
2424
fixed = { version = "1.28.0", optional = true }
25+
embedded-io = "0.6"
2526

2627
[dependencies.cortex-m]
2728
version = "0.7.7"
@@ -39,9 +40,13 @@ default-features = false
3940
features = ["const-fn"]
4041
version = "0.2.5"
4142

42-
[dependencies.embedded-hal]
43+
[dependencies.embedded-hal-old]
44+
package = "embedded-hal"
4345
features = ["unproven"]
44-
version = "0.2.4"
46+
version = "0.2.7"
47+
48+
[dependencies.embedded-hal]
49+
version = "1.0.0"
4550

4651
[dependencies.embedded-dma]
4752
version = "0.1.2"
@@ -94,7 +99,7 @@ stm32g4a1 = ["stm32g4/stm32g4a1"]
9499
log-itm = ["cortex-m-log/itm"]
95100
log-rtt = []
96101
log-semihost = ["cortex-m-log/semihosting"]
97-
defmt = ["dep:defmt", "fugit/defmt"]
102+
defmt = ["dep:defmt", "fugit/defmt", "nb/defmt-0-3", "embedded-hal/defmt-03", "embedded-io/defmt-03"]
98103
cordic = ["dep:fixed"]
99104

100105
[profile.dev]

examples/adc-continious-dma.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![no_main]
33

44
mod utils;
5+
use utils::logger::info;
56

67
use crate::hal::{
78
adc::{
@@ -20,7 +21,6 @@ use crate::hal::{
2021
use stm32g4xx_hal as hal;
2122

2223
use cortex_m_rt::entry;
23-
use utils::logger::info;
2424

2525
#[entry]
2626
fn main() -> ! {
@@ -48,6 +48,7 @@ fn main() -> ! {
4848

4949
info!("Setup Adc1");
5050
let mut delay = cp.SYST.delay(&rcc.clocks);
51+
5152
let mut adc = dp
5253
.ADC1
5354
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);

examples/adc-one-shot-dma.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ use crate::hal::{
1717
};
1818
use stm32g4xx_hal as hal;
1919

20-
use log::info;
21-
2220
#[macro_use]
2321
mod utils;
22+
use utils::logger::info;
2423

2524
#[entry]
2625
fn main() -> ! {
@@ -49,6 +48,7 @@ fn main() -> ! {
4948

5049
info!("Setup Adc1");
5150
let mut delay = cp.SYST.delay(&rcc.clocks);
51+
5252
let mut adc = dp
5353
.ADC1
5454
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);

examples/adc-one-shot.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use crate::hal::{
55
adc::{config::SampleTime, AdcClaim},
6-
delay::SYSTDelayExt,
76
pwr::PwrExt,
87
rcc::Config,
98
stm32::Peripherals,
@@ -13,10 +12,9 @@ use stm32g4xx_hal as hal;
1312

1413
use cortex_m_rt::entry;
1514

16-
use log::info;
17-
1815
#[macro_use]
1916
mod utils;
17+
use utils::logger::info;
2018

2119
#[entry]
2220
fn main() -> ! {

examples/blinky_delay.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![no_main]
44
#![no_std]
55

6-
use hal::delay::DelayFromCountDownTimer;
76
use hal::prelude::*;
87
use hal::pwr::PwrExt;
98
use hal::rcc::Config;
@@ -37,7 +36,7 @@ fn main() -> ! {
3736

3837
info!("Init Timer2 delay");
3938
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
40-
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
39+
let mut delay_tim2 = timer2.start_count_down(100.millis()).delay();
4140

4241
loop {
4342
info!("Toggle");
@@ -47,6 +46,6 @@ fn main() -> ! {
4746
info!("Toggle");
4847
led.toggle().unwrap();
4948
info!("TIM2 delay");
50-
delay_tim2.delay_ms(1000_u16);
49+
delay_tim2.delay_ms(1000);
5150
}
5251
}

examples/button.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::cell::RefCell;
1414
use core::sync::atomic::{AtomicBool, Ordering};
1515
use cortex_m::{asm::wfi, interrupt::Mutex};
1616
use cortex_m_rt::entry;
17-
use embedded_hal::digital::v2::OutputPin;
17+
use embedded_hal::digital::OutputPin;
1818

1919
type ButtonPin = gpioc::PC13<Input<PullDown>>;
2020

examples/can-echo.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ use core::num::{NonZeroU16, NonZeroU8};
2222

2323
use cortex_m_rt::entry;
2424

25-
use log::info;
26-
2725
#[macro_use]
2826
mod utils;
27+
use utils::logger::info;
2928

3029
#[entry]
3130
fn main() -> ! {
@@ -116,7 +115,7 @@ fn main() -> ! {
116115
bit_rate_switching: false,
117116
marker: None,
118117
};
119-
info!("Initial Header: {:#X?}", &header);
118+
info!("Initial Header: {:#?}", &header);
120119

121120
info!("Transmit initial message");
122121
block!(can.transmit(header, &buffer)).unwrap();

examples/comp_w_dac.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rt::entry;
1010

1111
#[entry]
1212
fn main() -> ! {
13-
use embedded_hal::Direction;
1413
use hal::comparator::{self, ComparatorExt, ComparatorSplit};
1514
use hal::dac::{Dac1IntSig1, DacExt, DacOut};
1615
use hal::delay::SYSTDelayExt;
@@ -49,6 +48,11 @@ fn main() -> ! {
4948
comp.output_pin(led2);
5049
let _comp1 = comp.enable().lock();
5150

51+
enum Direction {
52+
Upcounting,
53+
Downcounting,
54+
}
55+
5256
let mut dir = Direction::Upcounting;
5357
let mut val = 0;
5458

examples/dac.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#![no_main]
99
#![no_std]
1010

11-
use embedded_hal::Direction;
1211
use hal::dac::{DacExt, DacOut, GeneratorConfig};
1312
use hal::delay::SYSTDelayExt;
1413
use hal::gpio::GpioExt;
@@ -37,6 +36,11 @@ fn main() -> ! {
3736
// dac_generator will have its value set automatically from its internal noise generator
3837
let mut dac_generator = dac1ch2.enable_generator(GeneratorConfig::noise(11));
3938

39+
enum Direction {
40+
Upcounting,
41+
Downcounting,
42+
}
43+
4044
let mut dir = Direction::Upcounting;
4145
let mut val = 0;
4246

examples/i2c-bme680.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use bme680::*;
77
use core::time::Duration;
8-
use embedded_hal::blocking::delay::DelayMs;
8+
use embedded_hal::delay::DelayNs;
99
use hal::delay::DelayFromCountDownTimer;
1010
use hal::i2c::Config;
1111
use hal::prelude::*;
@@ -15,10 +15,10 @@ use hal::timer::Timer;
1515
use stm32g4xx_hal as hal;
1616

1717
use cortex_m_rt::entry;
18-
use log::info;
1918

2019
#[macro_use]
2120
mod utils;
21+
use utils::logger::info;
2222

2323
#[entry]
2424
fn main() -> ! {

examples/i2c-mpu6050.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use hal::time::{ExtU32, RateExtU32};
1010
use stm32g4xx_hal as hal;
1111

1212
use cortex_m_rt::entry;
13-
use log::info;
1413
use mpu6050::*;
1514

1615
#[macro_use]
1716
mod utils;
17+
use utils::logger::info;
1818

1919
#[entry]
2020
fn main() -> ! {

examples/i2c.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use hal::time::RateExtU32;
1010
use stm32g4xx_hal as hal;
1111

1212
use cortex_m_rt::entry;
13-
use log::info;
1413

1514
#[macro_use]
1615
mod utils;
16+
use utils::logger::info;
1717

1818
#[entry]
1919
fn main() -> ! {
@@ -35,7 +35,7 @@ fn main() -> ! {
3535

3636
let buf: [u8; 1] = [0];
3737
loop {
38-
match i2c.write(0x3c, &buf) {
38+
match i2c.write(0x3Cu8, &buf) {
3939
Ok(_) => info!("ok"),
4040
Err(err) => info!("error: {:?}", err),
4141
}

examples/pwm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use hal::stm32;
1111
use hal::time::RateExtU32;
1212
use stm32g4xx_hal as hal;
1313
extern crate cortex_m_rt as rt;
14+
use hal::prelude::SetDutyCycle;
1415

1516
#[macro_use]
1617
mod utils;
@@ -26,7 +27,7 @@ fn main() -> ! {
2627

2728
let mut pwm = dp.TIM1.pwm(pin, 100.Hz(), &mut rcc);
2829

29-
pwm.set_duty(pwm.get_max_duty() / 2);
30+
let _ = pwm.set_duty_cycle_percent(50);
3031
pwm.enable();
3132

3233
loop {

examples/spi-dma.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use stm32g4xx_hal::dma::TransferExt;
2828

2929
#[macro_use]
3030
mod utils;
31+
// use utils::logger::info;
3132

3233
const BUFFER_SIZE: usize = 254;
3334

@@ -69,6 +70,6 @@ fn main() -> ! {
6970
);
7071
transfer_dma.start(|_spi| {});
7172
loop {
72-
delay_tim2.delay_ms(1000_u16);
73+
delay_tim2.delay_ms(1000);
7374
}
7475
}

examples/spi-example.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
#![no_main]
66
#![no_std]
77

8-
use crate::hal::{
9-
block,
8+
use hal::{
109
delay::DelayFromCountDownTimer,
1110
gpio::gpioa::PA5,
1211
gpio::gpioa::PA6,
1312
gpio::gpioa::PA7,
1413
gpio::Alternate,
1514
gpio::AF5,
15+
hal_02::spi::FullDuplex,
1616
prelude::*,
1717
pwr::PwrExt,
1818
rcc::Config,
@@ -59,11 +59,11 @@ fn main() -> ! {
5959
for byte in message.iter() {
6060
cs.set_low().unwrap();
6161
spi.send(*byte as u8).unwrap();
62-
received_byte = block!(spi.read()).unwrap();
62+
received_byte = nb::block!(FullDuplex::read(&mut spi)).unwrap();
6363
cs.set_high().unwrap();
6464

6565
info!("{}", received_byte as char);
6666
}
67-
delay_tim2.delay_ms(1000_u16);
67+
delay_tim2.delay_ms(1000);
6868
}
6969
}

examples/uart-dma-tx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use hal::{rcc, stm32};
1616
use stm32g4xx_hal as hal;
1717

1818
use cortex_m_rt::entry;
19-
use log::info;
2019

2120
#[macro_use]
2221
mod utils;
22+
use utils::logger::info;
2323

2424
#[entry]
2525
fn main() -> ! {

examples/uart-fifo.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ extern crate cortex_m_rt as rt;
77

88
use core::fmt::Write;
99

10+
use embedded_io::{Read, ReadReady};
1011
use hal::prelude::*;
1112
use hal::pwr::PwrExt;
1213
use hal::serial::*;
1314
use hal::{rcc, stm32};
1415
use stm32g4xx_hal as hal;
1516

1617
use cortex_m_rt::entry;
17-
use log::info;
1818

1919
#[macro_use]
2020
mod utils;
21+
use utils::logger::info;
2122

2223
#[entry]
2324
fn main() -> ! {
@@ -50,23 +51,24 @@ fn main() -> ! {
5051

5152
let (mut tx1, mut rx1) = usart.split();
5253

54+
let mut buffer = [0; 4];
5355
let mut cnt = 0;
5456
loop {
5557
if rx1.fifo_threshold_reached() {
5658
loop {
57-
match rx1.read() {
58-
Err(nb::Error::WouldBlock) => {
59-
// no more data available in fifo
60-
break;
61-
}
62-
Err(nb::Error::Other(_err)) => {
59+
match rx1.read_ready() {
60+
Ok(true) => (),
61+
Ok(false) => break, // no more data available in fifo
62+
Err(e) => {
6363
// Handle other error Overrun, Framing, Noise or Parity
64-
}
65-
Ok(byte) => {
66-
writeln!(tx1, "{}: {}\r", cnt, byte).unwrap();
67-
cnt += 1;
64+
utils::logger::error!("Error: {:?}", e);
6865
}
6966
}
67+
68+
let count = rx1.read(&mut buffer).unwrap();
69+
let bytes = &buffer[count];
70+
writeln!(tx1, "{}: {}\r", cnt, bytes).unwrap();
71+
cnt += count;
7072
}
7173
}
7274
}

0 commit comments

Comments
 (0)