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

Add stm32h7-exti driver for binding gpio changes to interrupts #1066

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/demo-stm32h7-nucleo/app-h743.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ uses = ["rcc", "gpios1", "gpios2", "gpios3"]
start = true
task-slots = ["jefe"]

[tasks.exti_driver]
name = "drv-stm32h7-exti-server"
features = ["h743"]
priority = 2
max-sizes = {flash = 16384, ram = 4096}
uses = ["exti", "syscfg"]
start = true
interrupts = {"exti.exti0" = 0b1, "exti.exti1" = 0b10, "exti.exti2" = 0b100, "exti.exti3" = 0b1000, "exti.exti4" = 0b1_0000, "exti.exti9_5" = 0b10_0000, "exti.exti15_10" = 0b100_0000}
task-slots = ["sys"]

[tasks.i2c_driver]
name = "drv-stm32xx-i2c-server"
features = ["h743"]
Expand Down
10 changes: 10 additions & 0 deletions app/demo-stm32h7-nucleo/app-h753.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ uses = ["rcc", "gpios1", "gpios2", "gpios3"]
start = true
task-slots = ["jefe"]

[tasks.exti_driver]
name = "drv-stm32h7-exti-server"
features = ["h743"]
priority = 2
max-sizes = {flash = 16384, ram = 4096}
uses = ["exti", "syscfg"]
start = true
interrupts = {"exti.exti0" = 0b1, "exti.exti1" = 0b10, "exti.exti2" = 0b100, "exti.exti3" = 0b1000, "exti.exti4" = 0b1_0000, "exti.exti9_5" = 0b10_0000, "exti.exti15_10" = 0b100_0000}
task-slots = ["sys"]

[tasks.i2c_driver]
name = "drv-stm32xx-i2c-server"
features = ["h753"]
Expand Down
8 changes: 8 additions & 0 deletions chips/stm32h7/chip.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,11 @@ size = 0x8000
address = 0x38000000
size = 0x10000

[exti]
address = 0x58000000
size = 1024
interrupts = { exti0 = 6, exti1 = 7, exti2 = 8, exti3 = 9, exti4 = 10, exti9_5 = 23, exti15_10 = 40 }

[syscfg]
address = 0x58000400
size = 1024
28 changes: 28 additions & 0 deletions drv/stm32h7-exti-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "drv-stm32h7-exti-api"
version = "0.1.0"
edition = "2021"

[dependencies]
bitflags = {workspace = true}
num-traits = { workspace = true }
zerocopy = { workspace = true }

derive-idol-err = {path = "../../lib/derive-idol-err" }
drv-stm32xx-gpio-common = {path = "../stm32xx-gpio-common"}
userlib = {path = "../../sys/userlib"}

[features]
family-stm32h7 = ["drv-stm32xx-gpio-common/family-stm32h7"]
h743 = ["drv-stm32xx-gpio-common/model-stm32h743"]
#h747cm7 = ["drv-stm32xx-gpio-common/model-stm32h747cm7"]
h753 = ["drv-stm32xx-gpio-common/model-stm32h753"]

# This section is here to discourage RLS/rust-analyzer from doing test builds,
# since test builds don't work for cross compilation.
[lib]
test = false
bench = false

[build-dependencies]
idol = { workspace = true }
8 changes: 8 additions & 0 deletions drv/stm32h7-exti-api/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

fn main() -> Result<(), Box<dyn std::error::Error>> {
idol::client::build_client_stub("../../idl/stm32h7-exti.idol", "client_stub.rs")?;
Ok(())
}
41 changes: 41 additions & 0 deletions drv/stm32h7-exti-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Client API for the EXTI server

#![no_std]

use bitflags::bitflags;
use derive_idol_err::IdolError;
use drv_stm32xx_gpio_common::Port;
use userlib::*;

#[derive(Copy, Clone, Debug, FromPrimitive, Eq, PartialEq, IdolError)]
#[repr(u32)]
pub enum ExtiError {
AlreadyRegistered = 1,
InvalidIndex,
NotOwner,
NotRegistered,
}

bitflags! {

pub struct Edge: u8 {
const RISING = 0b01;
const FALLING = 0b10;
const RISING_AND_FALLING = Self::RISING.bits | Self::FALLING.bits;
}

}

impl Exti {

pub fn enable_gpio(&self, port: Port, index: usize, edges: Edge, notification: u32) -> Result<(), ExtiError> {
self.enable_gpio_raw(port, index, edges.bits, notification)
}

}

include!(concat!(env!("OUT_DIR"), "/client_stub.rs"));
32 changes: 32 additions & 0 deletions drv/stm32h7-exti-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "drv-stm32h7-exti-server"
version = "0.1.0"
edition = "2021"

[dependencies]
idol-runtime = { workspace = true }
num-traits = { workspace = true }
stm32h7 = { workspace = true }
zerocopy = { workspace = true }

drv-stm32h7-exti = { path = "../stm32h7-exti" }
drv-stm32h7-exti-api = { path = "../stm32h7-exti-api" }
drv-stm32xx-gpio-common = {path = "../stm32xx-gpio-common"}
ringbuf = { path = "../../lib/ringbuf" }
userlib = { path = "../../sys/userlib", features = ["panic-messages"] }

[build-dependencies]
idol = { workspace = true }

[features]
family-stm32h7 = ["drv-stm32xx-gpio-common/family-stm32h7"]
h743 = ["stm32h7/stm32h743", "drv-stm32h7-exti/h743", "drv-stm32xx-gpio-common/model-stm32h743"]
#h747cm7 = ["stm32h7/stm32h747cm7", "drv-stm32h7-exti/h747cm7", "drv-stm32xx-gpio-common/model-stm32h747cm7"]
h753 = ["stm32h7/stm32h753", "drv-stm32h7-exti/h753", "drv-stm32xx-gpio-common/model-stm32h753"]

# This section is here to discourage RLS/rust-analyzer from doing test builds,
# since test builds don't work for cross compilation.
[[bin]]
name = "drv-stm32h7-exti-server"
test = false
bench = false
12 changes: 12 additions & 0 deletions drv/stm32h7-exti-server/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

fn main() -> Result<(), Box<dyn std::error::Error>> {
idol::server::build_server_support(
"../../idl/stm32h7-exti.idol",
"server_stub.rs",
idol::server::ServerStyle::InOrder,
)?;
Ok(())
}
Loading