Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from main #173

Merged
merged 6 commits into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ repository = "https://github.com/stm32-rs/stm32g4xx-hal"
version = "0.0.2"

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

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

[dependencies.embedded-hal]
[dependencies.embedded-hal-old]
package = "embedded-hal"
features = ["unproven"]
version = "0.2.4"
version = "0.2.7"

[dependencies.embedded-hal]
version = "1.0.0"

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

[profile.dev]
3 changes: 2 additions & 1 deletion examples/adc-continious-dma.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
#![no_main]

mod utils;
use utils::logger::info;

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

use cortex_m_rt::entry;
use utils::logger::info;

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

info!("Setup Adc1");
let mut delay = cp.SYST.delay(&rcc.clocks);

let mut adc = dp
.ADC1
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
4 changes: 2 additions & 2 deletions examples/adc-one-shot-dma.rs
Original file line number Diff line number Diff line change
@@ -17,10 +17,9 @@ use crate::hal::{
};
use stm32g4xx_hal as hal;

use log::info;

#[macro_use]
mod utils;
use utils::logger::info;

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

info!("Setup Adc1");
let mut delay = cp.SYST.delay(&rcc.clocks);

let mut adc = dp
.ADC1
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
4 changes: 1 addition & 3 deletions examples/adc-one-shot.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@

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

use cortex_m_rt::entry;

use log::info;

#[macro_use]
mod utils;
use utils::logger::info;

#[entry]
fn main() -> ! {
5 changes: 2 additions & 3 deletions examples/blinky_delay.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
#![no_main]
#![no_std]

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

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

loop {
info!("Toggle");
@@ -47,6 +46,6 @@ fn main() -> ! {
info!("Toggle");
led.toggle().unwrap();
info!("TIM2 delay");
delay_tim2.delay_ms(1000_u16);
delay_tim2.delay_ms(1000);
}
}
2 changes: 1 addition & 1 deletion examples/button.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ use core::cell::RefCell;
use core::sync::atomic::{AtomicBool, Ordering};
use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;

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

5 changes: 2 additions & 3 deletions examples/can-echo.rs
Original file line number Diff line number Diff line change
@@ -22,10 +22,9 @@ use core::num::{NonZeroU16, NonZeroU8};

use cortex_m_rt::entry;

use log::info;

#[macro_use]
mod utils;
use utils::logger::info;

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

info!("Transmit initial message");
block!(can.transmit(header, &buffer)).unwrap();
6 changes: 5 additions & 1 deletion examples/comp_w_dac.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ use rt::entry;

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

enum Direction {
Upcounting,
Downcounting,
}

let mut dir = Direction::Upcounting;
let mut val = 0;

6 changes: 5 additions & 1 deletion examples/dac.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
#![no_main]
#![no_std]

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

enum Direction {
Upcounting,
Downcounting,
}

let mut dir = Direction::Upcounting;
let mut val = 0;

4 changes: 2 additions & 2 deletions examples/i2c-bme680.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

use bme680::*;
use core::time::Duration;
use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::delay::DelayNs;
use hal::delay::DelayFromCountDownTimer;
use hal::i2c::Config;
use hal::prelude::*;
@@ -15,10 +15,10 @@ use hal::timer::Timer;
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;
use log::info;

#[macro_use]
mod utils;
use utils::logger::info;

#[entry]
fn main() -> ! {
2 changes: 1 addition & 1 deletion examples/i2c-mpu6050.rs
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ use hal::time::{ExtU32, RateExtU32};
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;
use log::info;
use mpu6050::*;

#[macro_use]
mod utils;
use utils::logger::info;

#[entry]
fn main() -> ! {
4 changes: 2 additions & 2 deletions examples/i2c.rs
Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@ use hal::time::RateExtU32;
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;
use log::info;

#[macro_use]
mod utils;
use utils::logger::info;

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

let buf: [u8; 1] = [0];
loop {
match i2c.write(0x3c, &buf) {
match i2c.write(0x3Cu8, &buf) {
Ok(_) => info!("ok"),
Err(err) => info!("error: {:?}", err),
}
3 changes: 2 additions & 1 deletion examples/pwm.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ use hal::stm32;
use hal::time::RateExtU32;
use stm32g4xx_hal as hal;
extern crate cortex_m_rt as rt;
use hal::prelude::SetDutyCycle;

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

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

pwm.set_duty(pwm.get_max_duty() / 2);
let _ = pwm.set_duty_cycle_percent(50);
pwm.enable();

loop {
3 changes: 2 additions & 1 deletion examples/spi-dma.rs
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ use stm32g4xx_hal::dma::TransferExt;

#[macro_use]
mod utils;
// use utils::logger::info;

const BUFFER_SIZE: usize = 254;

@@ -69,6 +70,6 @@ fn main() -> ! {
);
transfer_dma.start(|_spi| {});
loop {
delay_tim2.delay_ms(1000_u16);
delay_tim2.delay_ms(1000);
}
}
8 changes: 4 additions & 4 deletions examples/spi-example.rs
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@
#![no_main]
#![no_std]

use crate::hal::{
block,
use hal::{
delay::DelayFromCountDownTimer,
gpio::gpioa::PA5,
gpio::gpioa::PA6,
gpio::gpioa::PA7,
gpio::Alternate,
gpio::AF5,
hal_02::spi::FullDuplex,
prelude::*,
pwr::PwrExt,
rcc::Config,
@@ -59,11 +59,11 @@ fn main() -> ! {
for byte in message.iter() {
cs.set_low().unwrap();
spi.send(*byte as u8).unwrap();
received_byte = block!(spi.read()).unwrap();
received_byte = nb::block!(FullDuplex::read(&mut spi)).unwrap();
cs.set_high().unwrap();

info!("{}", received_byte as char);
}
delay_tim2.delay_ms(1000_u16);
delay_tim2.delay_ms(1000);
}
}
2 changes: 1 addition & 1 deletion examples/uart-dma-tx.rs
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@ use hal::{rcc, stm32};
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;
use log::info;

#[macro_use]
mod utils;
use utils::logger::info;

#[entry]
fn main() -> ! {
24 changes: 13 additions & 11 deletions examples/uart-fifo.rs
Original file line number Diff line number Diff line change
@@ -7,17 +7,18 @@ extern crate cortex_m_rt as rt;

use core::fmt::Write;

use embedded_io::{Read, ReadReady};
use hal::prelude::*;
use hal::pwr::PwrExt;
use hal::serial::*;
use hal::{rcc, stm32};
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;
use log::info;

#[macro_use]
mod utils;
use utils::logger::info;

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

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

let mut buffer = [0; 4];
let mut cnt = 0;
loop {
if rx1.fifo_threshold_reached() {
loop {
match rx1.read() {
Err(nb::Error::WouldBlock) => {
// no more data available in fifo
break;
}
Err(nb::Error::Other(_err)) => {
match rx1.read_ready() {
Ok(true) => (),
Ok(false) => break, // no more data available in fifo
Err(e) => {
// Handle other error Overrun, Framing, Noise or Parity
}
Ok(byte) => {
writeln!(tx1, "{}: {}\r", cnt, byte).unwrap();
cnt += 1;
utils::logger::error!("Error: {:?}", e);
}
}

let count = rx1.read(&mut buffer).unwrap();
let bytes = &buffer[count];
writeln!(tx1, "{}: {}\r", cnt, bytes).unwrap();
cnt += count;
}
}
}
Loading