diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-07-17 07:35:59 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-07-17 07:35:59 +0200 |
| commit | 54b5012c568f5b952fefe50ad6a032b54172dabd (patch) | |
| tree | 0ebe9cff419d8dd0d9715b00562b1a21bda0b77e | |
| parent | dff4b42a33aa4d7c6a21bcd5017249f4de5c44b1 (diff) | |
stm32/dma: update codegen+macrotables for new stm32-data
| -rw-r--r-- | embassy-stm32/src/dma/bdma.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/dma.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/dmamux.rs | 35 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 26 | ||||
| m--------- | stm32-data | 0 | ||||
| -rw-r--r-- | stm32-metapac-gen/src/lib.rs | 84 |
6 files changed, 41 insertions, 110 deletions
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 26adda089..3d9ff9eb0 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs | |||
| @@ -150,8 +150,8 @@ pub(crate) unsafe fn init() { | |||
| 150 | } | 150 | } |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | pac::bdma_channels! { | 153 | pac::dma_channels! { |
| 154 | ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { | 154 | ($channel_peri:ident, $dma_peri:ident, bdma, $channel_num:expr, $dmamux:tt) => { |
| 155 | impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {} | 155 | impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {} |
| 156 | impl Channel for crate::peripherals::$channel_peri | 156 | impl Channel for crate::peripherals::$channel_peri |
| 157 | { | 157 | { |
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 1d6f7aee8..9b1c11606 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs | |||
| @@ -153,7 +153,7 @@ pub(crate) unsafe fn init() { | |||
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | pac::dma_channels! { | 155 | pac::dma_channels! { |
| 156 | ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { | 156 | ($channel_peri:ident, $dma_peri:ident, dma, $channel_num:expr, $dmamux:tt) => { |
| 157 | impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {} | 157 | impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {} |
| 158 | impl Channel for crate::peripherals::$channel_peri | 158 | impl Channel for crate::peripherals::$channel_peri |
| 159 | { | 159 | { |
diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs index e9fa48231..186ec2471 100644 --- a/embassy-stm32/src/dma/dmamux.rs +++ b/embassy-stm32/src/dma/dmamux.rs | |||
| @@ -24,40 +24,11 @@ pub(crate) trait MuxChannel { | |||
| 24 | const DMAMUX_REGS: pac::dmamux::Dmamux; | 24 | const DMAMUX_REGS: pac::dmamux::Dmamux; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | macro_rules! dma_num { | ||
| 28 | (DMA1) => { | ||
| 29 | 0 | ||
| 30 | }; | ||
| 31 | (DMA2) => { | ||
| 32 | 1 | ||
| 33 | }; | ||
| 34 | } | ||
| 35 | |||
| 36 | #[cfg(not(rcc_h7))] | ||
| 37 | pac::bdma_channels! { | ||
| 38 | ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { | ||
| 39 | impl MuxChannel for peripherals::$channel_peri { | ||
| 40 | const DMAMUX_CH_NUM: u8 = (dma_num!($dma_peri) * 8) + $channel_num; | ||
| 41 | const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX1; | ||
| 42 | } | ||
| 43 | }; | ||
| 44 | } | ||
| 45 | |||
| 46 | #[cfg(rcc_h7)] | ||
| 47 | pac::dma_channels! { | 27 | pac::dma_channels! { |
| 48 | ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { | 28 | ($channel_peri:ident, $dma_peri:ident, $version:ident, $channel_num:expr, {dmamux: $dmamux:ident, dmamux_channel: $dmamux_channel:expr}) => { |
| 49 | impl MuxChannel for peripherals::$channel_peri { | ||
| 50 | const DMAMUX_CH_NUM: u8 = (dma_num!($dma_peri) * 8) + $channel_num; | ||
| 51 | const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX1; | ||
| 52 | } | ||
| 53 | }; | ||
| 54 | } | ||
| 55 | #[cfg(rcc_h7)] | ||
| 56 | pac::bdma_channels! { | ||
| 57 | ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { | ||
| 58 | impl MuxChannel for peripherals::$channel_peri { | 29 | impl MuxChannel for peripherals::$channel_peri { |
| 59 | const DMAMUX_CH_NUM: u8 = $channel_num; | 30 | const DMAMUX_CH_NUM: u8 = $dmamux_channel; |
| 60 | const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX2; | 31 | const DMAMUX_REGS: pac::dmamux::Dmamux = pac::$dmamux; |
| 61 | } | 32 | } |
| 62 | }; | 33 | }; |
| 63 | } | 34 | } |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index bf6fa9131..92021d0af 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -171,7 +171,7 @@ crate::pac::peripheral_pins!( | |||
| 171 | ); | 171 | ); |
| 172 | 172 | ||
| 173 | macro_rules! impl_dma { | 173 | macro_rules! impl_dma { |
| 174 | ($inst:ident, ALL, $signal:ident, $request:expr) => { | 174 | ($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => { |
| 175 | impl<T: crate::dma::Channel> sealed::$signal<peripherals::$inst> for T { | 175 | impl<T: crate::dma::Channel> sealed::$signal<peripherals::$inst> for T { |
| 176 | fn request(&self) -> dma::Request { | 176 | fn request(&self) -> dma::Request { |
| 177 | $request | 177 | $request |
| @@ -180,7 +180,7 @@ macro_rules! impl_dma { | |||
| 180 | 180 | ||
| 181 | impl<T: crate::dma::Channel> $signal<peripherals::$inst> for T {} | 181 | impl<T: crate::dma::Channel> $signal<peripherals::$inst> for T {} |
| 182 | }; | 182 | }; |
| 183 | ($inst:ident, $channel:ident, $signal:ident, $request:expr) => { | 183 | ($inst:ident, {channel: $channel:ident}, $signal:ident, $request:expr) => { |
| 184 | impl sealed::$signal<peripherals::$inst> for peripherals::$channel { | 184 | impl sealed::$signal<peripherals::$inst> for peripherals::$channel { |
| 185 | fn request(&self) -> dma::Request { | 185 | fn request(&self) -> dma::Request { |
| 186 | $request | 186 | $request |
| @@ -192,30 +192,16 @@ macro_rules! impl_dma { | |||
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | crate::pac::peripheral_dma_channels! { | 194 | crate::pac::peripheral_dma_channels! { |
| 195 | ($peri:ident, usart, $kind:ident, RX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => { | 195 | ($peri:ident, usart, $kind:ident, RX, $channel:tt, $request:expr) => { |
| 196 | impl_dma!($peri, $channel, RxDma, $request); | 196 | impl_dma!($peri, $channel, RxDma, $request); |
| 197 | }; | 197 | }; |
| 198 | ($peri:ident, usart, $kind:ident, TX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => { | 198 | ($peri:ident, usart, $kind:ident, TX, $channel:tt, $request:expr) => { |
| 199 | impl_dma!($peri, $channel, TxDma, $request); | 199 | impl_dma!($peri, $channel, TxDma, $request); |
| 200 | }; | 200 | }; |
| 201 | ($peri:ident, uart, $kind:ident, RX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => { | 201 | ($peri:ident, uart, $kind:ident, RX, $channel:tt, $request:expr) => { |
| 202 | impl_dma!($peri, $channel, RxDma, $request); | 202 | impl_dma!($peri, $channel, RxDma, $request); |
| 203 | }; | 203 | }; |
| 204 | ($peri:ident, uart, $kind:ident, TX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => { | 204 | ($peri:ident, uart, $kind:ident, TX, $channel:tt, $request:expr) => { |
| 205 | impl_dma!($peri, $channel, TxDma, $request); | 205 | impl_dma!($peri, $channel, TxDma, $request); |
| 206 | }; | 206 | }; |
| 207 | } | 207 | } |
| 208 | crate::pac::dma_requests! { | ||
| 209 | (usart, $peri:ident, RX, $request:expr) => { | ||
| 210 | impl_dma!($peri, ALL, RxDma, $request); | ||
| 211 | }; | ||
| 212 | (usart, $peri:ident, TX, $request:expr) => { | ||
| 213 | impl_dma!($peri, ALL, TxDma, $request); | ||
| 214 | }; | ||
| 215 | (uart, $peri:ident, RX, $request:expr) => { | ||
| 216 | impl_dma!($peri, ALL, RxDma, $request); | ||
| 217 | }; | ||
| 218 | (uart, $peri:ident, TX, $request:expr) => { | ||
| 219 | impl_dma!($peri, ALL, TxDma, $request); | ||
| 220 | }; | ||
| 221 | } | ||
diff --git a/stm32-data b/stm32-data | |||
| Subproject d285fced6573703be875436409f8c83dd80ae18 | Subproject 8702a3a3bb83a59515dab2cf9f75952fa6edae8 | ||
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 5c2d605b9..fee991111 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs | |||
| @@ -49,8 +49,6 @@ pub struct Peripheral { | |||
| 49 | pub pins: Vec<Pin>, | 49 | pub pins: Vec<Pin>, |
| 50 | #[serde(default)] | 50 | #[serde(default)] |
| 51 | pub dma_channels: HashMap<String, Vec<PeripheralDmaChannel>>, | 51 | pub dma_channels: HashMap<String, Vec<PeripheralDmaChannel>>, |
| 52 | #[serde(default)] | ||
| 53 | pub dma_requests: HashMap<String, PeripheralDmaRequest>, | ||
| 54 | } | 52 | } |
| 55 | 53 | ||
| 56 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] | 54 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] |
| @@ -64,20 +62,17 @@ pub struct Pin { | |||
| 64 | pub struct DmaChannel { | 62 | pub struct DmaChannel { |
| 65 | pub dma: String, | 63 | pub dma: String, |
| 66 | pub channel: u32, | 64 | pub channel: u32, |
| 65 | pub dmamux: Option<String>, | ||
| 66 | pub dmamux_channel: Option<u32>, | ||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)] | 69 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)] |
| 70 | pub struct PeripheralDmaChannel { | 70 | pub struct PeripheralDmaChannel { |
| 71 | pub channel: String, | 71 | pub channel: Option<String>, |
| 72 | pub dmamux: Option<String>, | ||
| 72 | pub request: Option<u32>, | 73 | pub request: Option<u32>, |
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)] | ||
| 76 | pub struct PeripheralDmaRequest { | ||
| 77 | pub dmamux: String, | ||
| 78 | pub request: u32, | ||
| 79 | } | ||
| 80 | |||
| 81 | struct BlockInfo { | 76 | struct BlockInfo { |
| 82 | /// usart_v1/USART -> usart | 77 | /// usart_v1/USART -> usart |
| 83 | module: String, | 78 | module: String, |
| @@ -272,19 +267,10 @@ pub fn gen(options: Options) { | |||
| 272 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); | 267 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); |
| 273 | let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); | 268 | let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); |
| 274 | let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); | 269 | let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); |
| 275 | let mut bdma_channels_table: Vec<Vec<String>> = Vec::new(); | ||
| 276 | let mut dma_requests_table: Vec<Vec<String>> = Vec::new(); | ||
| 277 | let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new(); | 270 | let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new(); |
| 278 | let mut peripheral_counts: HashMap<String, u8> = HashMap::new(); | 271 | let mut peripheral_counts: HashMap<String, u8> = HashMap::new(); |
| 279 | let mut dma_channel_counts: HashMap<String, u8> = HashMap::new(); | 272 | let mut dma_channel_counts: HashMap<String, u8> = HashMap::new(); |
| 280 | 273 | ||
| 281 | let dma_base = core | ||
| 282 | .peripherals | ||
| 283 | .get(&"DMA".to_string()) | ||
| 284 | .unwrap_or_else(|| core.peripherals.get(&"DMA1".to_string()).unwrap()) | ||
| 285 | .address; | ||
| 286 | let dma_stride = 0x400; | ||
| 287 | |||
| 288 | let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; | 274 | let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; |
| 289 | let gpio_stride = 0x400; | 275 | let gpio_stride = 0x400; |
| 290 | 276 | ||
| @@ -336,26 +322,20 @@ pub fn gen(options: Options) { | |||
| 336 | peripheral_pins_table.push(row); | 322 | peripheral_pins_table.push(row); |
| 337 | } | 323 | } |
| 338 | 324 | ||
| 339 | for dma_request in &p.dma_requests { | 325 | for (request, dma_channels) in &p.dma_channels { |
| 340 | let mut row = Vec::new(); | ||
| 341 | row.push(bi.module.clone()); | ||
| 342 | row.push(name.clone()); | ||
| 343 | row.push(dma_request.0.clone()); | ||
| 344 | row.push(dma_request.1.request.to_string()); | ||
| 345 | // TODO add the `dmamux` column | ||
| 346 | dma_requests_table.push(row); | ||
| 347 | } | ||
| 348 | |||
| 349 | for (event, dma_channels) in &p.dma_channels { | ||
| 350 | for channel in dma_channels.iter() { | 326 | for channel in dma_channels.iter() { |
| 351 | let mut row = Vec::new(); | 327 | let mut row = Vec::new(); |
| 352 | row.push(name.clone()); | 328 | row.push(name.clone()); |
| 353 | row.push(bi.module.clone()); | 329 | row.push(bi.module.clone()); |
| 354 | row.push(bi.block.clone()); | 330 | row.push(bi.block.clone()); |
| 355 | row.push(event.clone()); | 331 | row.push(request.clone()); |
| 356 | row.push(channel.channel.clone()); | 332 | if let Some(channel) = &channel.channel { |
| 357 | row.push(core.dma_channels[&channel.channel].dma.clone()); | 333 | row.push(format!("{{channel: {}}}", channel)); |
| 358 | row.push(core.dma_channels[&channel.channel].channel.to_string()); | 334 | } else if let Some(dmamux) = &channel.dmamux { |
| 335 | row.push(format!("{{dmamux: {}}}", dmamux)); | ||
| 336 | } else { | ||
| 337 | unreachable!(); | ||
| 338 | } | ||
| 359 | if let Some(request) = channel.request { | 339 | if let Some(request) = channel.request { |
| 360 | row.push(request.to_string()); | 340 | row.push(request.to_string()); |
| 361 | } else { | 341 | } else { |
| @@ -399,15 +379,6 @@ pub fn gen(options: Options) { | |||
| 399 | ]); | 379 | ]); |
| 400 | } | 380 | } |
| 401 | } | 381 | } |
| 402 | "dma" => { | ||
| 403 | let dma_num = if name == "DMA" { | ||
| 404 | 0 | ||
| 405 | } else { | ||
| 406 | let dma_letter = name.chars().skip(3).next().unwrap(); | ||
| 407 | dma_letter as u32 - '1' as u32 | ||
| 408 | }; | ||
| 409 | assert_eq!(p.address, dma_base + dma_stride * dma_num); | ||
| 410 | } | ||
| 411 | _ => {} | 382 | _ => {} |
| 412 | } | 383 | } |
| 413 | 384 | ||
| @@ -507,21 +478,25 @@ pub fn gen(options: Options) { | |||
| 507 | 478 | ||
| 508 | for (id, channel_info) in &core.dma_channels { | 479 | for (id, channel_info) in &core.dma_channels { |
| 509 | let mut row = Vec::new(); | 480 | let mut row = Vec::new(); |
| 510 | let dma_peri = core.peripherals.get(&channel_info.dma); | 481 | let dma_peri = core.peripherals.get(&channel_info.dma).unwrap(); |
| 482 | let bi = BlockInfo::parse(dma_peri.block.as_ref().unwrap()); | ||
| 483 | |||
| 511 | row.push(id.clone()); | 484 | row.push(id.clone()); |
| 512 | row.push(channel_info.dma.clone()); | 485 | row.push(channel_info.dma.clone()); |
| 486 | row.push(bi.module.clone()); | ||
| 513 | row.push(channel_info.channel.to_string()); | 487 | row.push(channel_info.channel.to_string()); |
| 514 | if let Some(dma_peri) = dma_peri { | 488 | if let Some(dmamux) = &channel_info.dmamux { |
| 515 | if let Some(ref block) = dma_peri.block { | 489 | let dmamux_channel = channel_info.dmamux_channel.unwrap(); |
| 516 | let bi = BlockInfo::parse(block); | 490 | row.push(format!( |
| 517 | if bi.module == "bdma" { | 491 | "{{dmamux: {}, dmamux_channel: {}}}", |
| 518 | bdma_channels_table.push(row); | 492 | dmamux, dmamux_channel |
| 519 | } else { | 493 | )); |
| 520 | dma_channels_table.push(row); | 494 | } else { |
| 521 | } | 495 | row.push("{}".to_string()); |
| 522 | } | ||
| 523 | } | 496 | } |
| 524 | 497 | ||
| 498 | dma_channels_table.push(row); | ||
| 499 | |||
| 525 | let dma_peri_name = channel_info.dma.clone(); | 500 | let dma_peri_name = channel_info.dma.clone(); |
| 526 | dma_channel_counts.insert( | 501 | dma_channel_counts.insert( |
| 527 | dma_peri_name.clone(), | 502 | dma_peri_name.clone(), |
| @@ -548,7 +523,8 @@ pub fn gen(options: Options) { | |||
| 548 | } | 523 | } |
| 549 | } | 524 | } |
| 550 | 525 | ||
| 551 | if name.starts_with("BDMA_") || name.starts_with("BDMA1_") || name.starts_with("BDMA2_") { | 526 | if name.starts_with("BDMA_") || name.starts_with("BDMA1_") || name.starts_with("BDMA2_") |
| 527 | { | ||
| 552 | interrupt_table.push(vec!["BDMA".to_string(), name.clone()]); | 528 | interrupt_table.push(vec!["BDMA".to_string(), name.clone()]); |
| 553 | } | 529 | } |
| 554 | 530 | ||
| @@ -583,8 +559,6 @@ pub fn gen(options: Options) { | |||
| 583 | ); | 559 | ); |
| 584 | make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); | 560 | make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); |
| 585 | make_table(&mut extra, "dma_channels", &dma_channels_table); | 561 | make_table(&mut extra, "dma_channels", &dma_channels_table); |
| 586 | make_table(&mut extra, "bdma_channels", &bdma_channels_table); | ||
| 587 | make_table(&mut extra, "dma_requests", &dma_requests_table); | ||
| 588 | make_peripheral_counts(&mut extra, &peripheral_counts); | 562 | make_peripheral_counts(&mut extra, &peripheral_counts); |
| 589 | make_dma_channel_counts(&mut extra, &dma_channel_counts); | 563 | make_dma_channel_counts(&mut extra, &dma_channel_counts); |
| 590 | 564 | ||
