Skip to content

Commit 40db112

Browse files
bors[bot]arjanmels
andauthored
Merge #445
445: Add ESP32 support r=therealprof a=arjanmels Adding support for ESP32 as used in new pull requests on https://github.com/esp-rs. ESP32 has 2 level interrupt handling. First level in the cores. Second level in the periphery/software. Co-authored-by: Arjan Mels <43108771+arjanmels@users.noreply.github.com>
2 parents 99b5c17 + 5b55a1c commit 40db112

File tree

10 files changed

+76
-10
lines changed

10 files changed

+76
-10
lines changed

.github/workflows/ci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ jobs:
3636
TARGET: x86_64-unknown-linux-gnu
3737
TRAVIS_OS_NAME: linux
3838

39+
# Use nightly for architectures which don't support stable
40+
- rust: nightly
41+
experimental: true
42+
VENDOR: Espressif
43+
TARGET: x86_64-unknown-linux-gnu
44+
TRAVIS_OS_NAME: linux
45+
3946
# OSX
4047
- rust: stable
4148
TARGET: x86_64-apple-darwin

ci/script.sh

100644100755
+11
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,17 @@ main() {
692692
# OK
693693
test_svd M061
694694
;;
695+
696+
Espressif)
697+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
698+
echo 'version = "0.2.0"' >> $td/Cargo.toml
699+
700+
echo '[dependencies.xtensa-lx6-rt]' >> $td/Cargo.toml
701+
echo 'git = "https://github.com/esp-rs/xtensa-lx6-rt.git"' >> $td/Cargo.toml
702+
703+
test_svd_for_target esp32 https://raw.githubusercontent.com/arjanmels/esp32/add-output-svd/svd/esp32.svd
704+
;;
705+
695706
esac
696707

697708
rm -rf $td

ci/svd2rust-regress/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ FLAGS:
6060
6161
OPTIONS:
6262
-a, --architecture <arch>
63-
Filter by architecture, case sensitive, may be combined with other filters Options are: "CortexM", "RiscV",
64-
and "Msp430"
63+
Filter by architecture, case sensitive, may be combined with other filters Options are: "CortexM", "RiscV", "Msp430" and "ESP32"
6564
-p, --svd2rust-path <bin_path>
6665
Path to an `svd2rust` binary, relative or absolute. Defaults to `target/release/svd2rust[.exe]` of this
6766
repository (which must be already built)

ci/svd2rust-regress/src/svd_test.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ static CRATES_ALL: &[&str] = &["bare-metal = \"0.2.0\"", "vcell = \"0.1.0\""];
1010
static CRATES_MSP430: &[&str] = &["msp430 = \"0.1.0\""];
1111
static CRATES_CORTEX_M: &[&str] = &["cortex-m = \"0.5.0\"", "cortex-m-rt = \"0.5.0\""];
1212
static CRATES_RISCV: &[&str] = &["riscv = \"0.4.0\"", "riscv-rt = \"0.4.0\""];
13+
static CRATES_ESP32: &[&str] =
14+
&["xtensa-lx6-rt = {git=\"https://github.com/esp-rs/xtensa-lx6-rt\"}"];
1315
static PROFILE_ALL: &[&str] = &["[profile.dev]", "incremental = false"];
1416
static FEATURES_ALL: &[&str] = &["[features]"];
1517
static FEATURES_CORTEX_M: &[&str] =
@@ -133,6 +135,7 @@ pub fn test(
133135
CortexM => CRATES_CORTEX_M.iter(),
134136
RiscV => CRATES_RISCV.iter(),
135137
Msp430 => CRATES_MSP430.iter(),
138+
ESP32 => CRATES_ESP32.iter(),
136139
})
137140
.chain(PROFILE_ALL.iter())
138141
.chain(FEATURES_ALL.iter())
@@ -165,6 +168,7 @@ pub fn test(
165168
CortexM => "cortex-m",
166169
Msp430 => "msp430",
167170
RiscV => "riscv",
171+
ESP32 => "esp32",
168172
};
169173
let mut svd2rust_bin = Command::new(bin_path);
170174
if nightly {
@@ -180,14 +184,15 @@ pub fn test(
180184
output.capture_outputs(
181185
true,
182186
"svd2rust",
183-
Some(&lib_rs_file).filter(|_| (t.arch != CortexM) && (t.arch != Msp430)),
187+
Some(&lib_rs_file)
188+
.filter(|_| (t.arch != CortexM) && (t.arch != Msp430) && (t.arch != ESP32)),
184189
Some(&svd2rust_err_file),
185190
&[],
186191
)?;
187192
process_stderr_paths.push(svd2rust_err_file);
188193

189194
match t.arch {
190-
CortexM | Msp430 => {
195+
CortexM | Msp430 | ESP32 => {
191196
// TODO: Give error the path to stderr
192197
fs::rename(path_helper_base(&chip_dir, &["lib.rs"]), &lib_rs_file)
193198
.chain_err(|| "While moving lib.rs file")?

ci/svd2rust-regress/src/tests.rs

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub enum Architecture {
77
CortexM,
88
Msp430,
99
RiscV,
10+
ESP32,
1011
}
1112

1213
#[derive(Debug)]
@@ -24,6 +25,7 @@ pub enum Manufacturer {
2425
Toshiba,
2526
SiFive,
2627
TexasInstruments,
28+
Espressif,
2729
}
2830

2931
#[derive(Debug)]
@@ -4226,4 +4228,14 @@ pub const TESTS: &[&TestCase] = &[
42264228
should_pass: true,
42274229
run_when: Always,
42284230
},
4231+
&TestCase {
4232+
arch: ESP32,
4233+
mfgr: Espressif,
4234+
chip: "esp32",
4235+
svd_url: Some(
4236+
"https://raw.githubusercontent.com/arjanmels/esp32/add-output-svd/svd/esp32.svd",
4237+
),
4238+
should_pass: true,
4239+
run_when: Always,
4240+
},
42294241
];

src/generate/device.rs

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ pub fn render(
9797
extern crate riscv_rt;
9898
});
9999
}
100+
Target::ESP32 => {
101+
out.extend(quote! {
102+
extern crate xtensa_lx6_rt;
103+
});
104+
}
100105
Target::None => {}
101106
}
102107

@@ -226,6 +231,7 @@ pub fn render(
226231
Target::CortexM => Some(Ident::new("cortex_m", span)),
227232
Target::Msp430 => Some(Ident::new("msp430", span)),
228233
Target::RISCV => Some(Ident::new("riscv", span)),
234+
Target::ESP32 => Some(Ident::new("xtensa_lx6_rt", span)),
229235
Target::None => None,
230236
}
231237
.map(|krate| {

src/generate/interrupt.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ pub fn render(
125125
});
126126
}
127127
Target::RISCV => {}
128+
Target::ESP32 => {
129+
for name in &names {
130+
writeln!(device_x, "PROVIDE({} = DefaultHandler);", name)?;
131+
}
132+
133+
root.extend(quote! {
134+
#[cfg(feature = "rt")]
135+
extern "C" {
136+
#(fn #names();)*
137+
}
138+
139+
#[doc(hidden)]
140+
pub union Vector {
141+
pub _handler: unsafe extern "C" fn(),
142+
_reserved: u32,
143+
}
144+
145+
#[cfg(feature = "rt")]
146+
#[doc(hidden)]
147+
pub static __INTERRUPTS: [Vector; #n] = [
148+
#elements
149+
];
150+
});
151+
}
128152
Target::None => {}
129153
}
130154

@@ -137,7 +161,7 @@ pub fn render(
137161

138162
let interrupt_enum = quote! {
139163
///Enumeration of all the interrupts
140-
#[derive(Copy, Clone, Debug)]
164+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
141165
#enum_repr
142166
pub enum Interrupt {
143167
#variants
@@ -178,7 +202,7 @@ pub fn render(
178202
_ => "C",
179203
};
180204

181-
if target != Target::CortexM && target != Target::Msp430 {
205+
if target != Target::CortexM && target != Target::Msp430 && target != Target::ESP32 {
182206
mod_items.extend(quote! {
183207
#[cfg(feature = "rt")]
184208
#[macro_export]

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
//!
1919
//! # Usage
2020
//!
21-
//! `svd2rust` supports Cortex-M, MSP430 and RISCV microcontrollers. The generated crate can be
22-
//! tailored for either architecture using the `--target` flag. The flag accepts "cortex-m",
23-
//! "msp430", "riscv" and "none" as values. "none" can be used to generate a crate that's
21+
//! `svd2rust` supports Cortex-M, MSP430, RISCV and ESP32 microcontrollers. The generated crate can
22+
//! be tailored for either architecture using the `--target` flag. The flag accepts "cortex-m",
23+
//! "msp430", "riscv", "esp32" and "none" as values. "none" can be used to generate a crate that's
2424
//! architecture agnostic and that should work for architectures that `svd2rust` doesn't currently
2525
//! know about like the Cortex-A architecture.
2626
//!

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn run() -> Result<()> {
103103
file.write_all(data.as_ref())
104104
.expect("Could not write code to lib.rs");
105105

106-
if target == Target::CortexM || target == Target::Msp430 {
106+
if target == Target::CortexM || target == Target::Msp430 || target == Target::ESP32 {
107107
writeln!(File::create("device.x")?, "{}", device_x)?;
108108
writeln!(File::create("build.rs")?, "{}", build_rs())?;
109109
}

src/util.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub enum Target {
1818
CortexM,
1919
Msp430,
2020
RISCV,
21+
ESP32,
2122
None,
2223
}
2324

@@ -27,6 +28,7 @@ impl Target {
2728
"cortex-m" => Target::CortexM,
2829
"msp430" => Target::Msp430,
2930
"riscv" => Target::RISCV,
31+
"esp32" => Target::ESP32,
3032
"none" => Target::None,
3133
_ => bail!("unknown target {}", s),
3234
})

0 commit comments

Comments
 (0)