Skip to content

Commit 883ca94

Browse files
authored
Merge branch 'stm32-rs:main' into flash_patches
2 parents b6466d7 + 362c099 commit 883ca94

35 files changed

+852
-317
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/target/
22
**/*.orig
33
**/*.rs.bk
4-
Cargo.lock
4+
Cargo.lock
5+
6+
# Remove idea files
7+
.idea/

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "MIT/Apache-2.0"
99
name = "stm32g4xx-hal"
1010
readme = "README.md"
1111
repository = "https://github.com/stm32-rs/stm32g4xx-hal"
12-
version = "0.0.1"
12+
version = "0.0.2"
1313

1414
[dependencies]
1515
nb = "0.1.1"
@@ -18,6 +18,7 @@ paste = "1.0"
1818
bitflags = "1.2"
1919
vcell = "0.1"
2020
static_assertions = "1.1"
21+
fugit = "0.3.5"
2122

2223
[dependencies.cortex-m]
2324
version = "0.7.7"
@@ -67,8 +68,6 @@ lazy_static = { version = "1.4", features = ["spin_no_std"] }
6768
log = "0.4.11"
6869
cortex-m-log = { version = "0.7", features = ["log-integration"] }
6970
cfg-if = "0.1.10"
70-
rtt-target = { version = "0.3.0", features = ["cortex-m"] }
71-
panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] }
7271
mpu6050 = "0.1.4"
7372
bme680 = "0.6.0"
7473
embedded-sdmmc = "0.3.0"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Examples can be built and run using `cargo run`. It is necessary to provide any
3838
required features followed by the name of the chip.
3939

4040
```
41-
cargo run --example usb_serial --features stm32g473 --features usb_fs --release -- --chip STM32G473RETx
41+
cargo run --example blinky_delay --features stm32g474,log-rtt,defmt --release -- --chip STM32G474RBTx
4242
```
4343

4444
A list of chips supported by probe-rs can be found by running

examples/blinky.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ use hal::stm32;
88
use stm32g4xx_hal as hal;
99

1010
use cortex_m_rt::entry;
11-
use log::info;
1211

1312
#[macro_use]
1413
mod utils;
1514

15+
use utils::logger::info;
16+
1617
#[entry]
1718
fn main() -> ! {
1819
utils::logger::init();
@@ -27,11 +28,12 @@ fn main() -> ! {
2728

2829
loop {
2930
info!("Set Led low");
30-
for _ in 0..100_000 {
31+
for _ in 0..10_000_000 {
3132
led.set_low().unwrap();
3233
}
34+
3335
info!("Set Led High");
34-
for _ in 0..100_000 {
36+
for _ in 0..10_000_000 {
3537
led.set_high().unwrap();
3638
}
3739
}

examples/blinky_delay.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use hal::delay::DelayFromCountDownTimer;
77
use hal::prelude::*;
88
use hal::rcc::Config;
99
use hal::stm32;
10+
use hal::time::ExtU32;
1011
use hal::timer::Timer;
1112
use stm32g4xx_hal as hal;
1213

1314
use cortex_m_rt::entry;
14-
use log::info;
15+
use utils::logger::info;
1516

1617
#[macro_use]
1718
mod utils;
@@ -34,13 +35,13 @@ fn main() -> ! {
3435

3536
info!("Init Timer2 delay");
3637
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
37-
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.ms()));
38+
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
3839

3940
loop {
4041
info!("Toggle");
4142
led.toggle().unwrap();
4243
info!("SYST delay");
43-
delay_syst.delay(1000.ms());
44+
delay_syst.delay(1000.millis());
4445
info!("Toggle");
4546
led.toggle().unwrap();
4647
info!("TIM2 delay");

examples/button.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![no_main]
22
#![no_std]
33

4-
use panic_rtt_target as _;
5-
64
use stm32g4xx_hal::{
75
//delay::{DelayExt, SYSTDelayExt},
86
gpio::{gpioc, ExtiPin, GpioExt, Input, PullDown, SignalEdge},
@@ -18,24 +16,27 @@ use cortex_m::{asm::wfi, interrupt::Mutex};
1816
use cortex_m_rt::entry;
1917
use embedded_hal::digital::v2::OutputPin;
2018

21-
use rtt_target::{rprintln, rtt_init_print};
22-
2319
type ButtonPin = gpioc::PC13<Input<PullDown>>;
2420

2521
// Make LED pin globally available
2622
static G_BUTTON: Mutex<RefCell<Option<ButtonPin>>> = Mutex::new(RefCell::new(None));
2723
static G_LED_ON: AtomicBool = AtomicBool::new(true);
2824

25+
#[macro_use]
26+
mod utils;
27+
28+
use utils::logger::println;
29+
2930
// Define an interupt handler, i.e. function to call when interrupt occurs.
3031
// This specific interrupt will "trip" when the button is pressed
3132
#[interrupt]
3233
fn EXTI15_10() {
3334
static mut BUTTON: Option<ButtonPin> = None;
3435

35-
rprintln!("Got IRQ!");
36+
println!("Got IRQ!");
3637

3738
let button = BUTTON.get_or_insert_with(|| {
38-
rprintln!("Transfer Button into EXTI interrupt");
39+
println!("Transfer Button into EXTI interrupt");
3940
cortex_m::interrupt::free(|cs| {
4041
// Move LED pin here, leaving a None in its place
4142
G_BUTTON.borrow(cs).replace(None).unwrap()
@@ -49,45 +50,43 @@ fn EXTI15_10() {
4950

5051
#[entry]
5152
fn main() -> ! {
52-
rtt_init_print!();
53-
5453
let mut dp = stm32::Peripherals::take().expect("cannot take peripherals");
5554
let mut rcc = dp.RCC.constrain();
5655
let mut syscfg = dp.SYSCFG.constrain();
5756

58-
rprintln!("Led Init");
57+
println!("Led Init");
5958
// Configure PA5 pin to blink LED
6059
let gpioa = dp.GPIOA.split(&mut rcc);
6160
let mut led = gpioa.pa5.into_push_pull_output();
6261

63-
rprintln!("Button Init");
62+
println!("Button Init");
6463
let gpioc = dp.GPIOC.split(&mut rcc);
6564
let mut button = gpioc.pc13.into_pull_down_input();
6665
button.make_interrupt_source(&mut syscfg);
6766
button.trigger_on_edge(&mut dp.EXTI, SignalEdge::Rising);
6867
button.enable_interrupt(&mut dp.EXTI);
6968

70-
rprintln!("Set Button into Global Mutex");
69+
println!("Set Button into Global Mutex");
7170
// Move the pin into our global storage
7271
cortex_m::interrupt::free(|cs| *G_BUTTON.borrow(cs).borrow_mut() = Some(button));
7372

74-
rprintln!("Enable EXTI Interrupt");
73+
println!("Enable EXTI Interrupt");
7574
unsafe {
7675
cortex_m::peripheral::NVIC::unmask(Interrupt::EXTI15_10);
7776
}
7877

7978
//let mut delay = cp.SYST.delay(&rcc.clocks);
8079

81-
rprintln!("Start Loop");
80+
println!("Start Loop");
8281
loop {
8382
wfi();
84-
rprintln!("Check");
83+
println!("Check");
8584

8685
if G_LED_ON.load(Ordering::Relaxed) {
87-
rprintln!("Turn Led On!");
86+
println!("Turn Led On!");
8887
led.set_high().unwrap();
8988
} else {
90-
rprintln!("Turn Led Off!");
89+
println!("Turn Led Off!");
9190
led.set_low().unwrap();
9291
}
9392
}

examples/can-echo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::hal::{
77
nb::block,
88
rcc::{Config, RccExt, SysClockSrc},
99
stm32::Peripherals,
10-
time::U32Ext,
10+
time::RateExtU32,
1111
};
1212
use fdcan::{
1313
config::NominalBitTiming,
@@ -47,7 +47,7 @@ fn main() -> ! {
4747
let dp = Peripherals::take().unwrap();
4848
let _cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
4949
let rcc = dp.RCC.constrain();
50-
let mut rcc = rcc.freeze(Config::new(SysClockSrc::HSE(24.mhz())));
50+
let mut rcc = rcc.freeze(Config::new(SysClockSrc::HSE(24.MHz())));
5151

5252
info!("Split GPIO");
5353

examples/hello.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55

66
extern crate cortex_m;
77
extern crate cortex_m_rt as rt;
8-
extern crate panic_semihosting;
98
extern crate stm32g4xx_hal as hal;
109

11-
use cortex_m_semihosting::hprintln;
1210
use rt::entry;
1311

12+
#[macro_use]
13+
mod utils;
14+
15+
use utils::logger::println;
16+
1417
#[entry]
1518
fn main() -> ! {
16-
hprintln!("Hello, STM32G4!").unwrap();
19+
let _ = println!("Hello, STM32G4!");
1720

1821
#[allow(clippy::empty_loop)]
1922
loop {}

examples/i2c-bme680.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use hal::delay::DelayFromCountDownTimer;
1010
use hal::i2c::Config;
1111
use hal::prelude::*;
1212
use hal::stm32;
13+
use hal::time::{ExtU32, RateExtU32};
1314
use hal::timer::Timer;
1415
use stm32g4xx_hal as hal;
1516

@@ -32,11 +33,11 @@ fn main() -> ! {
3233
let sda = gpiob.pb9.into_alternate_open_drain();
3334
let scl = gpiob.pb8.into_alternate_open_drain();
3435

35-
let i2c = dp.I2C1.i2c(sda, scl, Config::new(100.khz()), &mut rcc);
36+
let i2c = dp.I2C1.i2c(sda, scl, Config::new(100.kHz()), &mut rcc);
3637

3738
let mut delayer = cp.SYST.delay(&rcc.clocks);
3839
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
39-
let mut delay = DelayFromCountDownTimer::new(timer2.start_count_down(100.ms()));
40+
let mut delay = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
4041

4142
let mut dev =
4243
Bme680::init(i2c, &mut delayer, I2CAddress::Secondary).expect("Init function failed");

examples/i2c-mpu6050.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use hal::i2c::Config;
77
use hal::prelude::*;
88
use hal::stm32;
9+
use hal::time::{ExtU32, RateExtU32};
910
use stm32g4xx_hal as hal;
1011

1112
use cortex_m_rt::entry;
@@ -28,7 +29,7 @@ fn main() -> ! {
2829
let sda = gpiob.pb9.into_alternate_open_drain();
2930
let scl = gpiob.pb8.into_alternate_open_drain();
3031

31-
let i2c = dp.I2C1.i2c(sda, scl, Config::new(100.khz()), &mut rcc);
32+
let i2c = dp.I2C1.i2c(sda, scl, Config::new(100.kHz()), &mut rcc);
3233

3334
let mut mpu = Mpu6050::new(i2c);
3435
let mut delay = cp.SYST.delay(&rcc.clocks);
@@ -39,6 +40,6 @@ fn main() -> ! {
3940
let gyro = mpu.get_gyro().expect("cannot read gyro");
4041
let temp = mpu.get_temp().expect("cannot read temperature");
4142
info!("acc: {:?}, gyro: {:?}, temp: {:?}C", acc, gyro, temp);
42-
delay.delay(250.ms());
43+
delay.delay(250.millis());
4344
}
4445
}

0 commit comments

Comments
 (0)