Skip to content

F4 GPIO #186

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
11 changes: 3 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"rust-analyzer.check.allTargets": false,
"rust-analyzer.check.extraArgs": [
"--examples",
],
"rust-analyzer.check.extraArgs": ["--examples"],
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
"rust-analyzer.cargo.features": [
"stm32g473",
"defmt",
]
}
"rust-analyzer.cargo.features": ["stm32g473", "defmt"]
}
15 changes: 15 additions & 0 deletions .zed/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"lsp": {
"rust-analyzer": {
"initialization_options": {
"cargo": {
"features": ["defmt", "stm32g473"]
},
"check": {
"allTargets": false,
"targets": "thumbv7em-none-eabihf"
}
}
}
}
}
235 changes: 224 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Vitaly Domnikov <oss@vitaly.codes>"]
categories = ["embedded", "hardware-support", "no-std"]
description = "Peripheral access API for STM32G4 series microcontrollers"
documentation = "https://docs.rs/stm32g4xx-hal"
edition = "2018"
edition = "2021"
keywords = ["arm", "cortex-m", "stm32g4xx", "hal"]
license = "MIT/Apache-2.0"
name = "stm32g4xx-hal"
Expand Down Expand Up @@ -86,19 +86,232 @@ usbd-serial = "0.2.2"
default = ["rt"]
rt = ["stm32g4/rt"]
usb = ["dep:stm32-usbd"]
stm32g431 = ["stm32g4/stm32g431"]
stm32g441 = ["stm32g4/stm32g441"]
stm32g471 = ["stm32g4/stm32g471"]
stm32g473 = ["stm32g4/stm32g473"]
stm32g474 = ["stm32g4/stm32g474"]
stm32g483 = ["stm32g4/stm32g483"]
stm32g484 = ["stm32g4/stm32g484"]
stm32g491 = ["stm32g4/stm32g491"]
stm32g4a1 = ["stm32g4/stm32g4a1"]
stm32g431 = ["stm32g4/stm32g431", "gpio-g43x"]
stm32g441 = ["stm32g4/stm32g441", "gpio-g43x"]
stm32g471 = ["stm32g4/stm32g471", "gpio-g47x"]
stm32g473 = ["stm32g4/stm32g473", "gpio-g47x"]
stm32g474 = ["stm32g4/stm32g474", "gpio-g47x"]
stm32g483 = ["stm32g4/stm32g483", "gpio-g47x"]
stm32g484 = ["stm32g4/stm32g484", "gpio-g47x"]
stm32g491 = ["stm32g4/stm32g491", "gpio-g49x"]
stm32g4a1 = ["stm32g4/stm32g4a1", "gpio-g49x"]

gpio-g43x = [
"comp1",
"comp2",
"comp3",
"comp4",
"crs",
"fdcan1",
"gpioa",
"gpiob",
"gpioc",
"gpiod",
"gpioe",
"gpiof",
"gpiog",
"i2c1",
"i2c2",
"i2c3",
"i2s",
"i2s2",
"i2s3",
"ir",
"lptim1",
"lpuart1",
"rcc",
"rtc",
"sai1",
"spi1",
"spi2",
"spi3",
"sys",
"tim1",
"tim15",
"tim16",
"tim17",
"tim2",
"tim3",
"tim4",
"tim8",
"uart4",
"ucpd1",
"usart1",
"usart2",
"usart3",
]
gpio-g47x = [
"comp1",
"comp2",
"comp3",
"comp4",
"comp5",
"comp6",
"comp7",
"crs",
"fdcan1",
"fdcan2",
"fdcan3",
"fmc",
"gpioa",
"gpiob",
"gpioc",
"gpiod",
"gpioe",
"gpiof",
"gpiog",
"hrtim1",
"i2c1",
"i2c2",
"i2c3",
"i2c4",
"i2s",
"i2s2",
"i2s3",
"ir",
"lptim1",
"lpuart1",
"quadspi1",
"rcc",
"rtc",
"sai1",
"spi1",
"spi2",
"spi3",
"spi4",
"sys",
"tim1",
"tim15",
"tim16",
"tim17",
"tim2",
"tim20",
"tim3",
"tim4",
"tim5",
"tim8",
"uart4",
"uart5",
"ucpd1",
"usart1",
"usart2",
"usart3",
]
gpio-g49x = [
"comp1",
"comp2",
"comp3",
"comp4",
"crs",
"fdcan1",
"fdcan2",
"gpioa",
"gpiob",
"gpioc",
"gpiod",
"gpioe",
"gpiof",
"gpiog",
"i2c1",
"i2c2",
"i2c3",
"i2s",
"i2s2",
"i2s3",
"ir",
"lptim1",
"lpuart1",
"quadspi1",
"rcc",
"rtc",
"sai1",
"spi1",
"spi2",
"spi3",
"sys",
"tim1",
"tim15",
"tim16",
"tim17",
"tim2",
"tim20",
"tim3",
"tim4",
"tim8",
"uart4",
"uart5",
"ucpd1",
"usart1",
"usart2",
"usart3",
]

comp1 = []
comp2 = []
comp3 = []
comp4 = []
comp5 = []
comp6 = []
comp7 = []
crs = []
fdcan1 = []
fdcan2 = []
fdcan3 = []
fmc = []
gpioa = []
gpiob = []
gpioc = []
gpiod = []
gpioe = []
gpiof = []
gpiog = []
hrtim1 = []
i2c1 = []
i2c2 = []
i2c3 = []
i2c4 = []
i2s = []
i2s2 = []
i2s3 = []
ir = []
lptim1 = []
lpuart1 = []
quadspi1 = []
rcc = []
rtc = []
sai1 = []
spi1 = []
spi2 = []
spi3 = []
spi4 = []
sys = []
tim1 = []
tim15 = []
tim16 = []
tim17 = []
tim2 = []
tim20 = []
tim3 = []
tim4 = []
tim5 = []
tim8 = []
uart4 = []
uart5 = []
ucpd1 = []
usart1 = []
usart2 = []
usart3 = []

log-itm = ["cortex-m-log/itm"]
log-rtt = []
log-semihost = ["cortex-m-log/semihosting"]
defmt = ["dep:defmt", "fugit/defmt", "nb/defmt-0-3", "embedded-hal/defmt-03", "embedded-io/defmt-03"]
defmt = [
"dep:defmt",
"fugit/defmt",
"nb/defmt-0-3",
"embedded-hal/defmt-03",
"embedded-io/defmt-03",
]
cordic = ["dep:fixed"]

[profile.dev]
Expand Down
4 changes: 2 additions & 2 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ fn main() -> ! {
loop {
info!("Set Led low");
for _ in 0..10_000_000 {
led.set_low().unwrap();
led.set_low();
}

info!("Set Led High");
for _ in 0..10_000_000 {
led.set_high().unwrap();
led.set_high();
}
}
}
4 changes: 2 additions & 2 deletions examples/blinky_delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ fn main() -> ! {

loop {
info!("Toggle");
led.toggle().unwrap();
led.toggle();
info!("SYST delay");
delay_syst.delay(1000.millis());
info!("Toggle");
led.toggle().unwrap();
led.toggle();
info!("TIM2 delay");
delay_tim2.delay_ms(1000);
}
Expand Down
9 changes: 4 additions & 5 deletions examples/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use stm32g4xx_hal::{
//delay::{DelayExt, SYSTDelayExt},
gpio::{gpioc, ExtiPin, GpioExt, Input, PullDown, SignalEdge},
gpio::{self, ExtiPin, GpioExt, Input, SignalEdge},
rcc::RccExt,
stm32,
stm32::{interrupt, Interrupt},
Expand All @@ -14,9 +14,8 @@ 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::OutputPin;

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

// Make LED pin globally available
static G_BUTTON: Mutex<RefCell<Option<ButtonPin>>> = Mutex::new(RefCell::new(None));
Expand Down Expand Up @@ -86,10 +85,10 @@ fn main() -> ! {

if G_LED_ON.load(Ordering::Relaxed) {
println!("Turn Led On!");
led.set_high().unwrap();
led.set_high();
} else {
println!("Turn Led Off!");
led.set_low().unwrap();
led.set_low();
}
}
}
8 changes: 4 additions & 4 deletions examples/can-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ fn main() -> ! {

let can1 = {
info!("Init CAN 1");
let rx = gpiob.pb8.into_alternate().set_speed(Speed::VeryHigh);
let tx = gpiob.pb9.into_alternate().set_speed(Speed::VeryHigh);
let rx = gpiob.pb8.into_alternate().speed(Speed::VeryHigh);
let tx = gpiob.pb9.into_alternate().speed(Speed::VeryHigh);

info!("-- Create CAN 1 instance");
let mut can = dp.FDCAN1.fdcan(tx, rx, &rcc);
Expand All @@ -82,8 +82,8 @@ fn main() -> ! {

// let can2 = {
// info!("Init CAN 2");
// let rx = gpiob.pb5.into_alternate().set_speed(Speed::VeryHigh);
// let tx = gpiob.pb13.into_alternate().set_speed(Speed::VeryHigh);
// let rx = gpiob.pb5.into_alternate().speed(Speed::VeryHigh);
// let tx = gpiob.pb13.into_alternate().speed(Speed::VeryHigh);

// info!("-- Create CAN 2 instance");
// let mut can = dp.FDCAN2.fdcan(tx, rx, &rcc);
Expand Down
5 changes: 2 additions & 3 deletions examples/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use rt::entry;
fn main() -> ! {
use hal::comparator::{ComparatorExt, ComparatorSplit, Config, Hysteresis, RefintInput};
use hal::gpio::GpioExt;
use hal::prelude::OutputPin;
use hal::rcc::RccExt;
use hal::stm32;
use stm32g4xx_hal as hal;
Expand Down Expand Up @@ -55,8 +54,8 @@ fn main() -> ! {
loop {
// Read comp1 output and update led1 accordingly
match comp1.output() {
true => led1.set_high().unwrap(),
false => led1.set_low().unwrap(),
true => led1.set_high(),
false => led1.set_low(),
}
}
}
Loading
Loading