aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-07-22 14:18:48 -0400
committerBob McWhirter <[email protected]>2021-07-22 14:18:48 -0400
commitd68f2617e663c933c11d5406c7ae12abc5e82938 (patch)
treee5f6ac816921ef0eca6118a331147af028465ecc
parent3655ceff279159b757d7a04ffac3483a7bf5c7b4 (diff)
Add a `Dbgmcu` struct capable of enabling all relevant DBGMCU.cr fields.
Includes the addition of a `dbgmcu!(...)` macro table which currently takes the form of (cr, $fn_name:ident) where `$fn_name` is something like `set_dbgsleep_d1` etc. The method is unsafe, since it's performing unsafe PAC operations. Two examples modified to demonstrate its usage.
-rw-r--r--embassy-stm32/src/dbgmcu/mod.rs13
-rw-r--r--embassy-stm32/src/lib.rs2
-rw-r--r--examples/stm32f4/src/bin/spi.rs7
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs11
-rw-r--r--stm32-metapac-gen/src/lib.rs29
5 files changed, 50 insertions, 12 deletions
diff --git a/embassy-stm32/src/dbgmcu/mod.rs b/embassy-stm32/src/dbgmcu/mod.rs
new file mode 100644
index 000000000..8dc4cc53f
--- /dev/null
+++ b/embassy-stm32/src/dbgmcu/mod.rs
@@ -0,0 +1,13 @@
1pub struct Dbgmcu {}
2
3impl Dbgmcu {
4 pub unsafe fn enable_all() {
5 crate::pac::DBGMCU.cr().modify(|cr| {
6 crate::pac::dbgmcu! {
7 (cr, $fn_name:ident) => {
8 cr.$fn_name(true);
9 };
10 }
11 });
12 }
13}
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index c10310e2d..07f8b9f3b 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -31,6 +31,8 @@ pub mod adc;
31pub mod clock; 31pub mod clock;
32#[cfg(dac)] 32#[cfg(dac)]
33pub mod dac; 33pub mod dac;
34#[cfg(dbgmcu)]
35pub mod dbgmcu;
34#[cfg(all(eth, feature = "net"))] 36#[cfg(all(eth, feature = "net"))]
35pub mod eth; 37pub mod eth;
36#[cfg(exti)] 38#[cfg(exti)]
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index 7cf391394..f8c9997ed 100644
--- a/examples/stm32f4/src/bin/spi.rs
+++ b/examples/stm32f4/src/bin/spi.rs
@@ -18,17 +18,14 @@ use embassy_stm32::pac;
18use embassy_stm32::spi::{Config, Spi}; 18use embassy_stm32::spi::{Config, Spi};
19use embassy_stm32::time::Hertz; 19use embassy_stm32::time::Hertz;
20use embedded_hal::blocking::spi::Transfer; 20use embedded_hal::blocking::spi::Transfer;
21use embassy_stm32::dbgmcu::Dbgmcu;
21 22
22#[entry] 23#[entry]
23fn main() -> ! { 24fn main() -> ! {
24 info!("Hello World, dude!"); 25 info!("Hello World, dude!");
25 26
26 unsafe { 27 unsafe {
27 pac::DBGMCU.cr().modify(|w| { 28 Dbgmcu::enable_all();
28 w.set_dbg_sleep(true);
29 w.set_dbg_standby(true);
30 w.set_dbg_stop(true);
31 });
32 29
33 pac::RCC.ahb1enr().modify(|w| { 30 pac::RCC.ahb1enr().modify(|w| {
34 w.set_gpioaen(true); 31 w.set_gpioaen(true);
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
index 0073d5c66..097466cea 100644
--- a/examples/stm32h7/src/bin/usart_dma.rs
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -14,6 +14,7 @@ use embassy::time::Clock;
14use embassy::util::Forever; 14use embassy::util::Forever;
15use embassy_stm32::dma::NoDma; 15use embassy_stm32::dma::NoDma;
16use embassy_stm32::usart::{Config, Uart}; 16use embassy_stm32::usart::{Config, Uart};
17use embassy_stm32::dbgmcu::Dbgmcu;
17use example_common::*; 18use example_common::*;
18use embassy_traits::uart::Write as _Write; 19use embassy_traits::uart::Write as _Write;
19 20
@@ -72,13 +73,9 @@ fn main() -> ! {
72 73
73 let pp = unsafe { pac::Peripherals::steal() }; 74 let pp = unsafe { pac::Peripherals::steal() };
74 75
75 pp.DBGMCU.cr.modify(|_, w| { 76 unsafe {
76 w.dbgsleep_d1().set_bit(); 77 Dbgmcu::enable_all();
77 w.dbgstby_d1().set_bit(); 78 }
78 w.dbgstop_d1().set_bit();
79 w.d1dbgcken().set_bit();
80 w
81 });
82 79
83 pp.RCC.ahb4enr.modify(|_, w| { 80 pp.RCC.ahb4enr.modify(|_, w| {
84 w.gpioaen().set_bit(); 81 w.gpioaen().set_bit();
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs
index fee991111..bfc2384cd 100644
--- a/stm32-metapac-gen/src/lib.rs
+++ b/stm32-metapac-gen/src/lib.rs
@@ -10,6 +10,7 @@ use std::path::Path;
10use std::path::PathBuf; 10use std::path::PathBuf;
11 11
12use chiptool::{generate, ir, transform}; 12use chiptool::{generate, ir, transform};
13use chiptool::util::ToSanitizedSnakeCase;
13 14
14#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] 15#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
15pub struct Chip { 16pub struct Chip {
@@ -245,6 +246,21 @@ pub fn gen(options: Options) {
245 peripherals: Vec::new(), 246 peripherals: Vec::new(),
246 }; 247 };
247 248
249 // Load DBGMCU register for chip
250 let mut dbgmcu: Option<ir::IR> = core.peripherals.iter().find_map(|(name, p)| {
251 if name == "DBGMCU" {
252 p.block.as_ref().map(|block| {
253 let bi = BlockInfo::parse(block);
254 let dbgmcu_reg_path = data_dir
255 .join("registers")
256 .join(&format!("{}_{}.yaml", bi.module, bi.version));
257 serde_yaml::from_reader(File::open(dbgmcu_reg_path).unwrap()).unwrap()
258 })
259 } else {
260 None
261 }
262 });
263
248 // Load RCC register for chip 264 // Load RCC register for chip
249 let rcc = core.peripherals.iter().find_map(|(name, p)| { 265 let rcc = core.peripherals.iter().find_map(|(name, p)| {
250 if name == "RCC" { 266 if name == "RCC" {
@@ -270,12 +286,24 @@ pub fn gen(options: Options) {
270 let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new(); 286 let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
271 let mut peripheral_counts: HashMap<String, u8> = HashMap::new(); 287 let mut peripheral_counts: HashMap<String, u8> = HashMap::new();
272 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();
273 290
274 let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; 291 let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
275 let gpio_stride = 0x400; 292 let gpio_stride = 0x400;
276 293
277 let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap(); 294 let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap();
278 295
296 if let Some(ref mut reg) = dbgmcu {
297 if let Some(ref cr) = reg.fieldsets.get("CR") {
298 for field in cr.fields.iter().filter(|e| e.name.contains("DBG")) {
299 let mut fn_name = String::new();
300 fn_name.push_str("set_");
301 fn_name.push_str( &field.name.to_sanitized_snake_case() );
302 dbgmcu_table.push( vec!( "cr".into(), fn_name ));
303 }
304 }
305 }
306
279 let mut has_bdma = false; 307 let mut has_bdma = false;
280 let mut has_dma = false; 308 let mut has_dma = false;
281 309
@@ -559,6 +587,7 @@ pub fn gen(options: Options) {
559 ); 587 );
560 make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); 588 make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
561 make_table(&mut extra, "dma_channels", &dma_channels_table); 589 make_table(&mut extra, "dma_channels", &dma_channels_table);
590 make_table(&mut extra, "dbgmcu", &dbgmcu_table);
562 make_peripheral_counts(&mut extra, &peripheral_counts); 591 make_peripheral_counts(&mut extra, &peripheral_counts);
563 make_dma_channel_counts(&mut extra, &dma_channel_counts); 592 make_dma_channel_counts(&mut extra, &dma_channel_counts);
564 593