Merge pull request #310 from bobmcwhirter/dbg
Add a `Dbgmcu` struct capable of enabling all relevant DBGMCU.cr fields.
This commit is contained in:
commit
e91c04a673
5 changed files with 50 additions and 12 deletions
13
embassy-stm32/src/dbgmcu/mod.rs
Normal file
13
embassy-stm32/src/dbgmcu/mod.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
pub struct Dbgmcu {}
|
||||||
|
|
||||||
|
impl Dbgmcu {
|
||||||
|
pub unsafe fn enable_all() {
|
||||||
|
crate::pac::DBGMCU.cr().modify(|cr| {
|
||||||
|
crate::pac::dbgmcu! {
|
||||||
|
(cr, $fn_name:ident) => {
|
||||||
|
cr.$fn_name(true);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,8 @@ pub mod adc;
|
||||||
pub mod clock;
|
pub mod clock;
|
||||||
#[cfg(dac)]
|
#[cfg(dac)]
|
||||||
pub mod dac;
|
pub mod dac;
|
||||||
|
#[cfg(dbgmcu)]
|
||||||
|
pub mod dbgmcu;
|
||||||
#[cfg(all(eth, feature = "net"))]
|
#[cfg(all(eth, feature = "net"))]
|
||||||
pub mod eth;
|
pub mod eth;
|
||||||
#[cfg(exti)]
|
#[cfg(exti)]
|
||||||
|
|
|
@ -18,17 +18,14 @@ use embassy_stm32::pac;
|
||||||
use embassy_stm32::spi::{Config, Spi};
|
use embassy_stm32::spi::{Config, Spi};
|
||||||
use embassy_stm32::time::Hertz;
|
use embassy_stm32::time::Hertz;
|
||||||
use embedded_hal::blocking::spi::Transfer;
|
use embedded_hal::blocking::spi::Transfer;
|
||||||
|
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
info!("Hello World, dude!");
|
info!("Hello World, dude!");
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
pac::DBGMCU.cr().modify(|w| {
|
Dbgmcu::enable_all();
|
||||||
w.set_dbg_sleep(true);
|
|
||||||
w.set_dbg_standby(true);
|
|
||||||
w.set_dbg_stop(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
pac::RCC.ahb1enr().modify(|w| {
|
pac::RCC.ahb1enr().modify(|w| {
|
||||||
w.set_gpioaen(true);
|
w.set_gpioaen(true);
|
||||||
|
|
|
@ -14,6 +14,7 @@ use embassy::time::Clock;
|
||||||
use embassy::util::Forever;
|
use embassy::util::Forever;
|
||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::usart::{Config, Uart};
|
use embassy_stm32::usart::{Config, Uart};
|
||||||
|
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
use embassy_traits::uart::Write as _Write;
|
use embassy_traits::uart::Write as _Write;
|
||||||
|
|
||||||
|
@ -72,13 +73,9 @@ fn main() -> ! {
|
||||||
|
|
||||||
let pp = unsafe { pac::Peripherals::steal() };
|
let pp = unsafe { pac::Peripherals::steal() };
|
||||||
|
|
||||||
pp.DBGMCU.cr.modify(|_, w| {
|
unsafe {
|
||||||
w.dbgsleep_d1().set_bit();
|
Dbgmcu::enable_all();
|
||||||
w.dbgstby_d1().set_bit();
|
}
|
||||||
w.dbgstop_d1().set_bit();
|
|
||||||
w.d1dbgcken().set_bit();
|
|
||||||
w
|
|
||||||
});
|
|
||||||
|
|
||||||
pp.RCC.ahb4enr.modify(|_, w| {
|
pp.RCC.ahb4enr.modify(|_, w| {
|
||||||
w.gpioaen().set_bit();
|
w.gpioaen().set_bit();
|
||||||
|
|
|
@ -10,6 +10,7 @@ use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use chiptool::{generate, ir, transform};
|
use chiptool::{generate, ir, transform};
|
||||||
|
use chiptool::util::ToSanitizedSnakeCase;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
pub struct Chip {
|
pub struct Chip {
|
||||||
|
@ -245,6 +246,21 @@ pub fn gen(options: Options) {
|
||||||
peripherals: Vec::new(),
|
peripherals: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Load DBGMCU register for chip
|
||||||
|
let mut dbgmcu: Option<ir::IR> = core.peripherals.iter().find_map(|(name, p)| {
|
||||||
|
if name == "DBGMCU" {
|
||||||
|
p.block.as_ref().map(|block| {
|
||||||
|
let bi = BlockInfo::parse(block);
|
||||||
|
let dbgmcu_reg_path = data_dir
|
||||||
|
.join("registers")
|
||||||
|
.join(&format!("{}_{}.yaml", bi.module, bi.version));
|
||||||
|
serde_yaml::from_reader(File::open(dbgmcu_reg_path).unwrap()).unwrap()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Load RCC register for chip
|
// Load RCC register for chip
|
||||||
let rcc = core.peripherals.iter().find_map(|(name, p)| {
|
let rcc = core.peripherals.iter().find_map(|(name, p)| {
|
||||||
if name == "RCC" {
|
if name == "RCC" {
|
||||||
|
@ -270,12 +286,24 @@ pub fn gen(options: Options) {
|
||||||
let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
|
let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
|
||||||
let mut peripheral_counts: HashMap<String, u8> = HashMap::new();
|
let mut peripheral_counts: HashMap<String, u8> = HashMap::new();
|
||||||
let mut dma_channel_counts: HashMap<String, u8> = HashMap::new();
|
let mut dma_channel_counts: HashMap<String, u8> = HashMap::new();
|
||||||
|
let mut dbgmcu_table: Vec<Vec<String>> = Vec::new();
|
||||||
|
|
||||||
let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
|
let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
|
||||||
let gpio_stride = 0x400;
|
let gpio_stride = 0x400;
|
||||||
|
|
||||||
let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap();
|
let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap();
|
||||||
|
|
||||||
|
if let Some(ref mut reg) = dbgmcu {
|
||||||
|
if let Some(ref cr) = reg.fieldsets.get("CR") {
|
||||||
|
for field in cr.fields.iter().filter(|e| e.name.contains("DBG")) {
|
||||||
|
let mut fn_name = String::new();
|
||||||
|
fn_name.push_str("set_");
|
||||||
|
fn_name.push_str( &field.name.to_sanitized_snake_case() );
|
||||||
|
dbgmcu_table.push( vec!( "cr".into(), fn_name ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut has_bdma = false;
|
let mut has_bdma = false;
|
||||||
let mut has_dma = false;
|
let mut has_dma = false;
|
||||||
|
|
||||||
|
@ -559,6 +587,7 @@ pub fn gen(options: Options) {
|
||||||
);
|
);
|
||||||
make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
|
make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
|
||||||
make_table(&mut extra, "dma_channels", &dma_channels_table);
|
make_table(&mut extra, "dma_channels", &dma_channels_table);
|
||||||
|
make_table(&mut extra, "dbgmcu", &dbgmcu_table);
|
||||||
make_peripheral_counts(&mut extra, &peripheral_counts);
|
make_peripheral_counts(&mut extra, &peripheral_counts);
|
||||||
make_dma_channel_counts(&mut extra, &dma_channel_counts);
|
make_dma_channel_counts(&mut extra, &dma_channel_counts);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue