aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-07-23 11:38:53 -0400
committerGitHub <[email protected]>2021-07-23 11:38:53 -0400
commitec5d44333ab6c0711424699efb2e782baf0124c7 (patch)
tree8886c16519ef3eb164bb16f5125e97b566fb4ed4
parente91c04a6730fc90df296bd0bee0c7262262fbbda (diff)
parent650f867b1cb364a514d9e5145b0244bb7223c387 (diff)
Merge pull request #311 from bobmcwhirter/gpio_enable
Auto-enable all GPIOs during init().
-rw-r--r--embassy-stm32/src/gpio.rs14
-rw-r--r--embassy-stm32/src/lib.rs1
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs12
-rw-r--r--stm32-metapac-gen/src/lib.rs53
4 files changed, 47 insertions, 33 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index bf8400ca9..5145bd689 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -449,3 +449,17 @@ crate::pac::pins!(
449 } 449 }
450 }; 450 };
451); 451);
452
453pub(crate) unsafe fn init() {
454 crate::pac::gpio_rcc! {
455 ($en_reg:ident) => {
456 crate::pac::RCC.$en_reg().modify(|reg| {
457 crate::pac::gpio_rcc! {
458 ($name:ident, $clock:ident, $en_reg, $rst_reg:ident, $en_fn:ident, $rst_fn:ident) => {
459 reg.$en_fn(true);
460 };
461 }
462 });
463 };
464 }
465}
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 07f8b9f3b..89fd86448 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -89,6 +89,7 @@ pub fn init(config: Config) -> Peripherals {
89 let p = Peripherals::take(); 89 let p = Peripherals::take();
90 90
91 unsafe { 91 unsafe {
92 gpio::init();
92 dma::init(); 93 dma::init();
93 #[cfg(exti)] 94 #[cfg(exti)]
94 exti::init(); 95 exti::init();
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
index 097466cea..907356500 100644
--- a/examples/stm32h7/src/bin/usart_dma.rs
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -71,22 +71,10 @@ fn main() -> ! {
71 .pll1_q_ck(48.mhz()) 71 .pll1_q_ck(48.mhz())
72 .freeze(pwrcfg, &pp.SYSCFG); 72 .freeze(pwrcfg, &pp.SYSCFG);
73 73
74 let pp = unsafe { pac::Peripherals::steal() };
75
76 unsafe { 74 unsafe {
77 Dbgmcu::enable_all(); 75 Dbgmcu::enable_all();
78 } 76 }
79 77
80 pp.RCC.ahb4enr.modify(|_, w| {
81 w.gpioaen().set_bit();
82 w.gpioben().set_bit();
83 w.gpiocen().set_bit();
84 w.gpioden().set_bit();
85 w.gpioeen().set_bit();
86 w.gpiofen().set_bit();
87 w
88 });
89
90 unsafe { embassy::time::set_clock(&ZeroClock) }; 78 unsafe { embassy::time::set_clock(&ZeroClock) };
91 79
92 let executor = EXECUTOR.put(Executor::new()); 80 let executor = EXECUTOR.put(Executor::new());
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs
index bfc2384cd..203d943de 100644
--- a/stm32-metapac-gen/src/lib.rs
+++ b/stm32-metapac-gen/src/lib.rs
@@ -287,6 +287,8 @@ pub fn gen(options: Options) {
287 let mut peripheral_counts: HashMap<String, u8> = HashMap::new(); 287 let mut peripheral_counts: HashMap<String, u8> = HashMap::new();
288 let mut dma_channel_counts: HashMap<String, u8> = HashMap::new(); 288 let mut dma_channel_counts: HashMap<String, u8> = HashMap::new();
289 let mut dbgmcu_table: Vec<Vec<String>> = Vec::new(); 289 let mut dbgmcu_table: Vec<Vec<String>> = Vec::new();
290 let mut gpio_rcc_table: Vec<Vec<String>> = Vec::new();
291 let mut gpio_regs: HashSet<String> = HashSet::new();
290 292
291 let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; 293 let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
292 let gpio_stride = 0x400; 294 let gpio_stride = 0x400;
@@ -465,29 +467,33 @@ pub fn gen(options: Options) {
465 clock.to_ascii_lowercase() 467 clock.to_ascii_lowercase()
466 }; 468 };
467 469
470 let mut row = Vec::with_capacity(6);
471 row.push(name.clone());
472 row.push(clock);
473 row.push(enable_reg.to_ascii_lowercase());
474
475 if let Some((reset_reg, reset_field)) = reset_reg_field {
476 row.push(reset_reg.to_ascii_lowercase());
477 row.push(format!(
478 "set_{}",
479 enable_field.to_ascii_lowercase()
480 ));
481 row.push(format!(
482 "set_{}",
483 reset_field.to_ascii_lowercase()
484 ));
485 } else {
486 row.push(format!(
487 "set_{}",
488 enable_field.to_ascii_lowercase()
489 ));
490 }
491
468 if !name.starts_with("GPIO") { 492 if !name.starts_with("GPIO") {
469 let mut row = Vec::with_capacity(6);
470 row.push(name.clone());
471 row.push(clock);
472 row.push(enable_reg.to_ascii_lowercase());
473
474 if let Some((reset_reg, reset_field)) = reset_reg_field {
475 row.push(reset_reg.to_ascii_lowercase());
476 row.push(format!(
477 "set_{}",
478 enable_field.to_ascii_lowercase()
479 ));
480 row.push(format!(
481 "set_{}",
482 reset_field.to_ascii_lowercase()
483 ));
484 } else {
485 row.push(format!(
486 "set_{}",
487 enable_field.to_ascii_lowercase()
488 ));
489 }
490 peripheral_rcc_table.push(row); 493 peripheral_rcc_table.push(row);
494 } else {
495 gpio_rcc_table.push(row);
496 gpio_regs.insert( enable_reg.to_ascii_lowercase() );
491 } 497 }
492 } 498 }
493 (None, Some(_)) => { 499 (None, Some(_)) => {
@@ -504,6 +510,10 @@ pub fn gen(options: Options) {
504 dev.peripherals.push(ir_peri); 510 dev.peripherals.push(ir_peri);
505 } 511 }
506 512
513 for reg in gpio_regs {
514 gpio_rcc_table.push( vec!( reg ) );
515 }
516
507 for (id, channel_info) in &core.dma_channels { 517 for (id, channel_info) in &core.dma_channels {
508 let mut row = Vec::new(); 518 let mut row = Vec::new();
509 let dma_peri = core.peripherals.get(&channel_info.dma).unwrap(); 519 let dma_peri = core.peripherals.get(&channel_info.dma).unwrap();
@@ -586,6 +596,7 @@ pub fn gen(options: Options) {
586 &peripheral_dma_channels_table, 596 &peripheral_dma_channels_table,
587 ); 597 );
588 make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); 598 make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
599 make_table(&mut extra, "gpio_rcc", &gpio_rcc_table);
589 make_table(&mut extra, "dma_channels", &dma_channels_table); 600 make_table(&mut extra, "dma_channels", &dma_channels_table);
590 make_table(&mut extra, "dbgmcu", &dbgmcu_table); 601 make_table(&mut extra, "dbgmcu", &dbgmcu_table);
591 make_peripheral_counts(&mut extra, &peripheral_counts); 602 make_peripheral_counts(&mut extra, &peripheral_counts);