aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-06-22 14:53:19 -0400
committerBob McWhirter <[email protected]>2021-06-29 11:01:45 -0400
commit1732551db48c5788502221b96f3ec6f8fe76ada3 (patch)
treeb7219ec5e2143c2213316343143bb774695d9ae0
parentd49adc98beebe5b7982204150ebdc0a485fefab2 (diff)
Generate dma-related macro tables.
m---------stm32-data0
-rw-r--r--stm32-metapac/gen/src/lib.rs67
2 files changed, 57 insertions, 10 deletions
diff --git a/stm32-data b/stm32-data
Subproject eb76ee900ac67b51497196572250323e82666b4 Subproject 9856b11172ae27ffa60d339ac271d2d06c19075
diff --git a/stm32-metapac/gen/src/lib.rs b/stm32-metapac/gen/src/lib.rs
index 9e7add452..408865e31 100644
--- a/stm32-metapac/gen/src/lib.rs
+++ b/stm32-metapac/gen/src/lib.rs
@@ -27,6 +27,7 @@ pub struct Core {
27 pub name: String, 27 pub name: String,
28 pub peripherals: HashMap<String, Peripheral>, 28 pub peripherals: HashMap<String, Peripheral>,
29 pub interrupts: HashMap<String, u32>, 29 pub interrupts: HashMap<String, u32>,
30 pub dma_channels: HashMap<String, DmaChannel>,
30} 31}
31 32
32#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] 33#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@@ -46,6 +47,10 @@ pub struct Peripheral {
46 pub clock: Option<String>, 47 pub clock: Option<String>,
47 #[serde(default)] 48 #[serde(default)]
48 pub pins: Vec<Pin>, 49 pub pins: Vec<Pin>,
50 #[serde(default)]
51 pub dma_channels: HashMap<String, Vec<String>>,
52 #[serde(default)]
53 pub dma_requests: HashMap<String, u32>,
49} 54}
50 55
51#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] 56#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@@ -55,6 +60,12 @@ pub struct Pin {
55 pub af: Option<String>, 60 pub af: Option<String>,
56} 61}
57 62
63#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
64pub struct DmaChannel {
65 pub dma: String,
66 pub channel: u32,
67}
68
58struct BlockInfo { 69struct BlockInfo {
59 /// usart_v1/USART -> usart 70 /// usart_v1/USART -> usart
60 module: String, 71 module: String,
@@ -123,7 +134,7 @@ macro_rules! {} {{
123", 134",
124 name, name 135 name, name
125 ) 136 )
126 .unwrap(); 137 .unwrap();
127 138
128 for row in data { 139 for row in data {
129 write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap(); 140 write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap();
@@ -134,7 +145,7 @@ macro_rules! {} {{
134 " }}; 145 " }};
135}}" 146}}"
136 ) 147 )
137 .unwrap(); 148 .unwrap();
138} 149}
139 150
140pub struct Options { 151pub struct Options {
@@ -220,6 +231,9 @@ pub fn gen(options: Options) {
220 let mut peripherals_table: Vec<Vec<String>> = Vec::new(); 231 let mut peripherals_table: Vec<Vec<String>> = Vec::new();
221 let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); 232 let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new();
222 let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); 233 let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new();
234 let mut dma_channels_table: Vec<Vec<String>> = Vec::new();
235 let mut dma_requests_table: Vec<Vec<String>> = Vec::new();
236 let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
223 237
224 let dma_base = core 238 let dma_base = core
225 .peripherals 239 .peripherals
@@ -231,6 +245,14 @@ pub fn gen(options: Options) {
231 let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; 245 let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
232 let gpio_stride = 0x400; 246 let gpio_stride = 0x400;
233 247
248 for (id, channel_info) in &core.dma_channels {
249 let mut row = Vec::new();
250 row.push(id.clone());
251 row.push(channel_info.dma.clone() );
252 row.push(channel_info.channel.to_string());
253 dma_channels_table.push(row);
254 }
255
234 for (name, p) in &core.peripherals { 256 for (name, p) in &core.peripherals {
235 let mut ir_peri = ir::Peripheral { 257 let mut ir_peri = ir::Peripheral {
236 name: name.clone(), 258 name: name.clone(),
@@ -257,13 +279,35 @@ pub fn gen(options: Options) {
257 peripheral_pins_table.push(row); 279 peripheral_pins_table.push(row);
258 } 280 }
259 281
282 for dma_request in &p.dma_requests {
283 let mut row = Vec::new();
284 row.push(name.clone());
285 row.push(dma_request.0.clone());
286 row.push(dma_request.1.to_string());
287 dma_requests_table.push(row);
288 }
289
290 for (event, dma_channels) in &p.dma_channels {
291 for channel in dma_channels.iter() {
292 let mut row = Vec::new();
293 row.push(name.clone());
294 row.push( bi.module.clone() );
295 row.push( bi.block.clone() );
296 row.push(event.clone());
297 row.push( channel.clone() );
298 row.push( core.dma_channels[channel].dma.clone() );
299 row.push( core.dma_channels[channel].channel.to_string() );
300 peripheral_dma_channels_table.push(row);
301 }
302 }
303
260 let mut peripheral_row = Vec::new(); 304 let mut peripheral_row = Vec::new();
261 peripheral_row.push(bi.module.clone()); 305 peripheral_row.push(bi.module.clone());
262 peripheral_row.push(name.clone()); 306 peripheral_row.push(name.clone());
263 peripherals_table.push(peripheral_row); 307 peripherals_table.push(peripheral_row);
264 308
265 if let Some(old_version) = 309 if let Some(old_version) =
266 peripheral_versions.insert(bi.module.clone(), bi.version.clone()) 310 peripheral_versions.insert(bi.module.clone(), bi.version.clone())
267 { 311 {
268 if old_version != bi.version { 312 if old_version != bi.version {
269 panic!( 313 panic!(
@@ -402,7 +446,10 @@ pub fn gen(options: Options) {
402 make_table(&mut extra, "peripherals", &peripherals_table); 446 make_table(&mut extra, "peripherals", &peripherals_table);
403 make_table(&mut extra, "peripheral_versions", &peripheral_version_table); 447 make_table(&mut extra, "peripheral_versions", &peripheral_version_table);
404 make_table(&mut extra, "peripheral_pins", &peripheral_pins_table); 448 make_table(&mut extra, "peripheral_pins", &peripheral_pins_table);
449 make_table(&mut extra, "peripheral_dma_channels", &peripheral_dma_channels_table);
405 make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); 450 make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
451 make_table(&mut extra, "dma_channels", &dma_channels_table);
452 make_table(&mut extra, "dma_requests", &dma_requests_table);
406 453
407 for (module, version) in peripheral_versions { 454 for (module, version) in peripheral_versions {
408 all_peripheral_versions.insert((module.clone(), version.clone())); 455 all_peripheral_versions.insert((module.clone(), version.clone()));
@@ -411,7 +458,7 @@ pub fn gen(options: Options) {
411 "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n", 458 "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n",
412 module, version, module 459 module, version, module
413 ) 460 )
414 .unwrap(); 461 .unwrap();
415 } 462 }
416 463
417 // Cleanups! 464 // Cleanups!
@@ -449,7 +496,7 @@ pub fn gen(options: Options) {
449 "PROVIDE({} = DefaultHandler);\n", 496 "PROVIDE({} = DefaultHandler);\n",
450 name.to_ascii_uppercase() 497 name.to_ascii_uppercase()
451 ) 498 )
452 .unwrap(); 499 .unwrap();
453 } 500 }
454 501
455 File::create(chip_dir.join("device.x")) 502 File::create(chip_dir.join("device.x"))
@@ -477,7 +524,7 @@ pub fn gen(options: Options) {
477 transform::NameKind::Enum => format!("vals::{}", s), 524 transform::NameKind::Enum => format!("vals::{}", s),
478 _ => s.to_string(), 525 _ => s.to_string(),
479 }) 526 })
480 .unwrap(); 527 .unwrap();
481 528
482 transform::sort::Sort {}.run(&mut ir).unwrap(); 529 transform::sort::Sort {}.run(&mut ir).unwrap();
483 transform::Sanitize {}.run(&mut ir).unwrap(); 530 transform::Sanitize {}.run(&mut ir).unwrap();
@@ -488,7 +535,7 @@ pub fn gen(options: Options) {
488 .join("src/peripherals") 535 .join("src/peripherals")
489 .join(format!("{}_{}.rs", module, version)), 536 .join(format!("{}_{}.rs", module, version)),
490 ) 537 )
491 .unwrap(); 538 .unwrap();
492 let data = items.to_string().replace("] ", "]\n"); 539 let data = items.to_string().replace("] ", "]\n");
493 540
494 // Remove inner attributes like #![no_std] 541 // Remove inner attributes like #![no_std]
@@ -511,14 +558,14 @@ pub fn gen(options: Options) {
511 "#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]", 558 "#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]",
512 x, c, x, c 559 x, c, x, c
513 ) 560 )
514 .unwrap(); 561 .unwrap();
515 } else { 562 } else {
516 write!( 563 write!(
517 &mut paths, 564 &mut paths,
518 "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]", 565 "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]",
519 x, x 566 x, x
520 ) 567 )
521 .unwrap(); 568 .unwrap();
522 } 569 }
523 } 570 }
524 let mut contents: Vec<u8> = Vec::new(); 571 let mut contents: Vec<u8> = Vec::new();
@@ -541,7 +588,7 @@ pub fn gen(options: Options) {
541 out_dir.join("src").join("common.rs"), 588 out_dir.join("src").join("common.rs"),
542 generate::COMMON_MODULE, 589 generate::COMMON_MODULE,
543 ) 590 )
544 .unwrap(); 591 .unwrap();
545 592
546 // Generate Cargo.toml 593 // Generate Cargo.toml
547 const BUILDDEP_BEGIN: &[u8] = b"# BEGIN BUILD DEPENDENCIES"; 594 const BUILDDEP_BEGIN: &[u8] = b"# BEGIN BUILD DEPENDENCIES";