diff options
| author | Ulf Lilleengen <[email protected]> | 2021-06-16 15:12:07 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2021-06-16 15:12:07 +0200 |
| commit | b6a870369834b148d0f307abd37ea246180c89fb (patch) | |
| tree | 2c28097238df39d166436ca3288bdaf2cbbcc10b | |
| parent | c9bf039cae73fb21fa1d2e14d4ce7137df76c8f8 (diff) | |
Add support for generating PAC for dual cores
* Chips that have multiple cores will be exposed as chipname_corename,
i.e. stm32wl55jc_cm4
* Chips that have single cores will use the chip family as feature name
and pick the first and only core from the list
* Add support for stm32wl55 chip family
| -rw-r--r-- | .github/workflows/rust.yml | 2 | ||||
| -rw-r--r-- | embassy-stm32/Cargo.toml | 84 | ||||
| -rw-r--r-- | embassy-stm32/gen.py | 19 | ||||
| -rw-r--r-- | embassy-stm32/gen_features.py | 17 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 9 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/wl55/mod.rs | 213 | ||||
| -rw-r--r-- | examples/stm32l0/src/bin/blinky.rs | 5 | ||||
| -rw-r--r-- | examples/stm32l0/src/bin/button.rs | 6 | ||||
| m--------- | stm32-data | 0 | ||||
| -rw-r--r-- | stm32-metapac/Cargo.toml | 93 | ||||
| -rw-r--r-- | stm32-metapac/gen/src/lib.rs | 89 | ||||
| -rw-r--r-- | stm32-metapac/gen_features.py | 14 |
12 files changed, 462 insertions, 89 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0585b6d3d..f4105230d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml | |||
| @@ -71,7 +71,7 @@ jobs: | |||
| 71 | features: stm32f429zi,log | 71 | features: stm32f429zi,log |
| 72 | - package: embassy-stm32 | 72 | - package: embassy-stm32 |
| 73 | target: thumbv7em-none-eabi | 73 | target: thumbv7em-none-eabi |
| 74 | features: stm32h755zi,defmt | 74 | features: stm32h755zi_cm7,defmt |
| 75 | - package: embassy-stm32 | 75 | - package: embassy-stm32 |
| 76 | target: thumbv7em-none-eabi | 76 | target: thumbv7em-none-eabi |
| 77 | features: stm32l476vg,defmt | 77 | features: stm32l476vg,defmt |
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 8b9a00391..682ebaefc 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -239,23 +239,40 @@ stm32h743xg = [ "stm32-metapac/stm32h743xg",] | |||
| 239 | stm32h743xi = [ "stm32-metapac/stm32h743xi",] | 239 | stm32h743xi = [ "stm32-metapac/stm32h743xi",] |
| 240 | stm32h743zg = [ "stm32-metapac/stm32h743zg",] | 240 | stm32h743zg = [ "stm32-metapac/stm32h743zg",] |
| 241 | stm32h743zi = [ "stm32-metapac/stm32h743zi",] | 241 | stm32h743zi = [ "stm32-metapac/stm32h743zi",] |
| 242 | stm32h745bg = [ "stm32-metapac/stm32h745bg",] | 242 | stm32h745bg_cm7 = [ "stm32-metapac/stm32h745bg_cm7",] |
| 243 | stm32h745bi = [ "stm32-metapac/stm32h745bi",] | 243 | stm32h745bg_cm4 = [ "stm32-metapac/stm32h745bg_cm4",] |
| 244 | stm32h745ig = [ "stm32-metapac/stm32h745ig",] | 244 | stm32h745bi_cm7 = [ "stm32-metapac/stm32h745bi_cm7",] |
| 245 | stm32h745ii = [ "stm32-metapac/stm32h745ii",] | 245 | stm32h745bi_cm4 = [ "stm32-metapac/stm32h745bi_cm4",] |
| 246 | stm32h745xg = [ "stm32-metapac/stm32h745xg",] | 246 | stm32h745ig_cm7 = [ "stm32-metapac/stm32h745ig_cm7",] |
| 247 | stm32h745xi = [ "stm32-metapac/stm32h745xi",] | 247 | stm32h745ig_cm4 = [ "stm32-metapac/stm32h745ig_cm4",] |
| 248 | stm32h745zg = [ "stm32-metapac/stm32h745zg",] | 248 | stm32h745ii_cm7 = [ "stm32-metapac/stm32h745ii_cm7",] |
| 249 | stm32h745zi = [ "stm32-metapac/stm32h745zi",] | 249 | stm32h745ii_cm4 = [ "stm32-metapac/stm32h745ii_cm4",] |
| 250 | stm32h747ag = [ "stm32-metapac/stm32h747ag",] | 250 | stm32h745xg_cm7 = [ "stm32-metapac/stm32h745xg_cm7",] |
| 251 | stm32h747ai = [ "stm32-metapac/stm32h747ai",] | 251 | stm32h745xg_cm4 = [ "stm32-metapac/stm32h745xg_cm4",] |
| 252 | stm32h747bg = [ "stm32-metapac/stm32h747bg",] | 252 | stm32h745xi_cm7 = [ "stm32-metapac/stm32h745xi_cm7",] |
| 253 | stm32h747bi = [ "stm32-metapac/stm32h747bi",] | 253 | stm32h745xi_cm4 = [ "stm32-metapac/stm32h745xi_cm4",] |
| 254 | stm32h747ig = [ "stm32-metapac/stm32h747ig",] | 254 | stm32h745zg_cm7 = [ "stm32-metapac/stm32h745zg_cm7",] |
| 255 | stm32h747ii = [ "stm32-metapac/stm32h747ii",] | 255 | stm32h745zg_cm4 = [ "stm32-metapac/stm32h745zg_cm4",] |
| 256 | stm32h747xg = [ "stm32-metapac/stm32h747xg",] | 256 | stm32h745zi_cm7 = [ "stm32-metapac/stm32h745zi_cm7",] |
| 257 | stm32h747xi = [ "stm32-metapac/stm32h747xi",] | 257 | stm32h745zi_cm4 = [ "stm32-metapac/stm32h745zi_cm4",] |
| 258 | stm32h747zi = [ "stm32-metapac/stm32h747zi",] | 258 | stm32h747ag_cm7 = [ "stm32-metapac/stm32h747ag_cm7",] |
| 259 | stm32h747ag_cm4 = [ "stm32-metapac/stm32h747ag_cm4",] | ||
| 260 | stm32h747ai_cm7 = [ "stm32-metapac/stm32h747ai_cm7",] | ||
| 261 | stm32h747ai_cm4 = [ "stm32-metapac/stm32h747ai_cm4",] | ||
| 262 | stm32h747bg_cm7 = [ "stm32-metapac/stm32h747bg_cm7",] | ||
| 263 | stm32h747bg_cm4 = [ "stm32-metapac/stm32h747bg_cm4",] | ||
| 264 | stm32h747bi_cm7 = [ "stm32-metapac/stm32h747bi_cm7",] | ||
| 265 | stm32h747bi_cm4 = [ "stm32-metapac/stm32h747bi_cm4",] | ||
| 266 | stm32h747ig_cm7 = [ "stm32-metapac/stm32h747ig_cm7",] | ||
| 267 | stm32h747ig_cm4 = [ "stm32-metapac/stm32h747ig_cm4",] | ||
| 268 | stm32h747ii_cm7 = [ "stm32-metapac/stm32h747ii_cm7",] | ||
| 269 | stm32h747ii_cm4 = [ "stm32-metapac/stm32h747ii_cm4",] | ||
| 270 | stm32h747xg_cm7 = [ "stm32-metapac/stm32h747xg_cm7",] | ||
| 271 | stm32h747xg_cm4 = [ "stm32-metapac/stm32h747xg_cm4",] | ||
| 272 | stm32h747xi_cm7 = [ "stm32-metapac/stm32h747xi_cm7",] | ||
| 273 | stm32h747xi_cm4 = [ "stm32-metapac/stm32h747xi_cm4",] | ||
| 274 | stm32h747zi_cm7 = [ "stm32-metapac/stm32h747zi_cm7",] | ||
| 275 | stm32h747zi_cm4 = [ "stm32-metapac/stm32h747zi_cm4",] | ||
| 259 | stm32h750ib = [ "stm32-metapac/stm32h750ib",] | 276 | stm32h750ib = [ "stm32-metapac/stm32h750ib",] |
| 260 | stm32h750vb = [ "stm32-metapac/stm32h750vb",] | 277 | stm32h750vb = [ "stm32-metapac/stm32h750vb",] |
| 261 | stm32h750xb = [ "stm32-metapac/stm32h750xb",] | 278 | stm32h750xb = [ "stm32-metapac/stm32h750xb",] |
| @@ -266,15 +283,24 @@ stm32h753ii = [ "stm32-metapac/stm32h753ii",] | |||
| 266 | stm32h753vi = [ "stm32-metapac/stm32h753vi",] | 283 | stm32h753vi = [ "stm32-metapac/stm32h753vi",] |
| 267 | stm32h753xi = [ "stm32-metapac/stm32h753xi",] | 284 | stm32h753xi = [ "stm32-metapac/stm32h753xi",] |
| 268 | stm32h753zi = [ "stm32-metapac/stm32h753zi",] | 285 | stm32h753zi = [ "stm32-metapac/stm32h753zi",] |
| 269 | stm32h755bi = [ "stm32-metapac/stm32h755bi",] | 286 | stm32h755bi_cm7 = [ "stm32-metapac/stm32h755bi_cm7",] |
| 270 | stm32h755ii = [ "stm32-metapac/stm32h755ii",] | 287 | stm32h755bi_cm4 = [ "stm32-metapac/stm32h755bi_cm4",] |
| 271 | stm32h755xi = [ "stm32-metapac/stm32h755xi",] | 288 | stm32h755ii_cm7 = [ "stm32-metapac/stm32h755ii_cm7",] |
| 272 | stm32h755zi = [ "stm32-metapac/stm32h755zi",] | 289 | stm32h755ii_cm4 = [ "stm32-metapac/stm32h755ii_cm4",] |
| 273 | stm32h757ai = [ "stm32-metapac/stm32h757ai",] | 290 | stm32h755xi_cm7 = [ "stm32-metapac/stm32h755xi_cm7",] |
| 274 | stm32h757bi = [ "stm32-metapac/stm32h757bi",] | 291 | stm32h755xi_cm4 = [ "stm32-metapac/stm32h755xi_cm4",] |
| 275 | stm32h757ii = [ "stm32-metapac/stm32h757ii",] | 292 | stm32h755zi_cm7 = [ "stm32-metapac/stm32h755zi_cm7",] |
| 276 | stm32h757xi = [ "stm32-metapac/stm32h757xi",] | 293 | stm32h755zi_cm4 = [ "stm32-metapac/stm32h755zi_cm4",] |
| 277 | stm32h757zi = [ "stm32-metapac/stm32h757zi",] | 294 | stm32h757ai_cm7 = [ "stm32-metapac/stm32h757ai_cm7",] |
| 295 | stm32h757ai_cm4 = [ "stm32-metapac/stm32h757ai_cm4",] | ||
| 296 | stm32h757bi_cm7 = [ "stm32-metapac/stm32h757bi_cm7",] | ||
| 297 | stm32h757bi_cm4 = [ "stm32-metapac/stm32h757bi_cm4",] | ||
| 298 | stm32h757ii_cm7 = [ "stm32-metapac/stm32h757ii_cm7",] | ||
| 299 | stm32h757ii_cm4 = [ "stm32-metapac/stm32h757ii_cm4",] | ||
| 300 | stm32h757xi_cm7 = [ "stm32-metapac/stm32h757xi_cm7",] | ||
| 301 | stm32h757xi_cm4 = [ "stm32-metapac/stm32h757xi_cm4",] | ||
| 302 | stm32h757zi_cm7 = [ "stm32-metapac/stm32h757zi_cm7",] | ||
| 303 | stm32h757zi_cm4 = [ "stm32-metapac/stm32h757zi_cm4",] | ||
| 278 | stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag",] | 304 | stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag",] |
| 279 | stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai",] | 305 | stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai",] |
| 280 | stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig",] | 306 | stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig",] |
| @@ -554,4 +580,10 @@ stm32wb55vc = [ "stm32-metapac/stm32wb55vc",] | |||
| 554 | stm32wb55ve = [ "stm32-metapac/stm32wb55ve",] | 580 | stm32wb55ve = [ "stm32-metapac/stm32wb55ve",] |
| 555 | stm32wb55vg = [ "stm32-metapac/stm32wb55vg",] | 581 | stm32wb55vg = [ "stm32-metapac/stm32wb55vg",] |
| 556 | stm32wb55vy = [ "stm32-metapac/stm32wb55vy",] | 582 | stm32wb55vy = [ "stm32-metapac/stm32wb55vy",] |
| 583 | stm32wl55cc_cm4 = [ "stm32-metapac/stm32wl55cc_cm4",] | ||
| 584 | stm32wl55cc_cm0p = [ "stm32-metapac/stm32wl55cc_cm0p",] | ||
| 585 | stm32wl55jc_cm4 = [ "stm32-metapac/stm32wl55jc_cm4",] | ||
| 586 | stm32wl55jc_cm0p = [ "stm32-metapac/stm32wl55jc_cm0p",] | ||
| 587 | stm32wl55uc_cm4 = [ "stm32-metapac/stm32wl55uc_cm4",] | ||
| 588 | stm32wl55uc_cm0p = [ "stm32-metapac/stm32wl55uc_cm0p",] | ||
| 557 | # END GENERATED FEATURES | 589 | # END GENERATED FEATURES |
diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 779389cac..b9391d309 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py | |||
| @@ -19,10 +19,17 @@ data_path = '../stm32-data/data' | |||
| 19 | try: | 19 | try: |
| 20 | _, chip_name, output_file = sys.argv | 20 | _, chip_name, output_file = sys.argv |
| 21 | except: | 21 | except: |
| 22 | raise Exception("Usage: gen.py STM32F429ZI path/to/generated.rs") | 22 | raise Exception("Usage: gen.py STM32F429ZI_CM0 path/to/generated.rs") |
| 23 | |||
| 24 | c = chip_name.split('_', 1) | ||
| 25 | |||
| 26 | chip_name = c[0].upper() | ||
| 27 | core_name = None | ||
| 28 | |||
| 29 | if len(c) > 1: | ||
| 30 | core_name = c[1].lower() | ||
| 23 | 31 | ||
| 24 | # ======= load chip | 32 | # ======= load chip |
| 25 | chip_name = chip_name.upper() | ||
| 26 | with open(f'{data_path}/chips/{chip_name}.yaml', 'r') as f: | 33 | with open(f'{data_path}/chips/{chip_name}.yaml', 'r') as f: |
| 27 | chip = yaml.load(f, Loader=SafeLoader) | 34 | chip = yaml.load(f, Loader=SafeLoader) |
| 28 | 35 | ||
| @@ -41,7 +48,13 @@ with open(output_file, 'w') as f: | |||
| 41 | singletons.extend((f'EXTI{x}' for x in range(16))) | 48 | singletons.extend((f'EXTI{x}' for x in range(16))) |
| 42 | num_dmas = 0 | 49 | num_dmas = 0 |
| 43 | 50 | ||
| 44 | for (name, peri) in chip['peripherals'].items(): | 51 | core = chip['cores'][0] |
| 52 | if core_name != None: | ||
| 53 | for c in chip['cores']: | ||
| 54 | if core_name == c['name']: | ||
| 55 | core = c | ||
| 56 | |||
| 57 | for (name, peri) in core['peripherals'].items(): | ||
| 45 | if 'block' not in peri: | 58 | if 'block' not in peri: |
| 46 | continue | 59 | continue |
| 47 | 60 | ||
diff --git a/embassy-stm32/gen_features.py b/embassy-stm32/gen_features.py index 4c46d602e..10dfd7884 100644 --- a/embassy-stm32/gen_features.py +++ b/embassy-stm32/gen_features.py | |||
| @@ -1,7 +1,13 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import toml | 2 | import toml |
| 3 | import yaml | ||
| 3 | from glob import glob | 4 | from glob import glob |
| 4 | 5 | ||
| 6 | try: | ||
| 7 | from yaml import CSafeLoader as SafeLoader | ||
| 8 | except ImportError: | ||
| 9 | from yaml import SafeLoader | ||
| 10 | |||
| 5 | abspath = os.path.abspath(__file__) | 11 | abspath = os.path.abspath(__file__) |
| 6 | dname = os.path.dirname(abspath) | 12 | dname = os.path.dirname(abspath) |
| 7 | os.chdir(dname) | 13 | os.chdir(dname) |
| @@ -12,6 +18,7 @@ supported_families = [ | |||
| 12 | 'STM32L4', | 18 | 'STM32L4', |
| 13 | 'STM32H7', | 19 | 'STM32H7', |
| 14 | 'STM32WB55', | 20 | 'STM32WB55', |
| 21 | 'STM32WL55', | ||
| 15 | ] | 22 | ] |
| 16 | 23 | ||
| 17 | # ======= load chip list | 24 | # ======= load chip list |
| @@ -21,7 +28,15 @@ for f in sorted(glob('../stm32-data/data/chips/*.yaml')): | |||
| 21 | name = os.path.splitext(os.path.basename(f))[0] | 28 | name = os.path.splitext(os.path.basename(f))[0] |
| 22 | if any((family in name for family in supported_families)): | 29 | if any((family in name for family in supported_families)): |
| 23 | name = name.lower() | 30 | name = name.lower() |
| 24 | features[name] = ['stm32-metapac/' + name] | 31 | # ======= load chip |
| 32 | with open(f, 'r') as f: | ||
| 33 | chip = yaml.load(f, Loader=SafeLoader) | ||
| 34 | |||
| 35 | if len(chip['cores']) > 1: | ||
| 36 | for core in chip['cores']: | ||
| 37 | features[name + "_" + core['name']] = ['stm32-metapac/' + name + '_' + core['name']] | ||
| 38 | else: | ||
| 39 | features[name] = ['stm32-metapac/' + name] | ||
| 25 | 40 | ||
| 26 | # ========= Update Cargo features | 41 | # ========= Update Cargo features |
| 27 | 42 | ||
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 7721c2857..70bf675aa 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -16,13 +16,13 @@ pub struct Clocks { | |||
| 16 | #[cfg(any(rcc_l0))] | 16 | #[cfg(any(rcc_l0))] |
| 17 | pub ahb: Hertz, | 17 | pub ahb: Hertz, |
| 18 | 18 | ||
| 19 | #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))] | 19 | #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl55))] |
| 20 | pub ahb1: Hertz, | 20 | pub ahb1: Hertz, |
| 21 | 21 | ||
| 22 | #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))] | 22 | #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl55))] |
| 23 | pub ahb2: Hertz, | 23 | pub ahb2: Hertz, |
| 24 | 24 | ||
| 25 | #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))] | 25 | #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl55))] |
| 26 | pub ahb3: Hertz, | 26 | pub ahb3: Hertz, |
| 27 | 27 | ||
| 28 | #[cfg(any(rcc_h7))] | 28 | #[cfg(any(rcc_h7))] |
| @@ -62,6 +62,9 @@ cfg_if::cfg_if! { | |||
| 62 | } else if #[cfg(rcc_wb55)] { | 62 | } else if #[cfg(rcc_wb55)] { |
| 63 | mod wb55; | 63 | mod wb55; |
| 64 | pub use wb55::*; | 64 | pub use wb55::*; |
| 65 | } else if #[cfg(rcc_wl55)] { | ||
| 66 | mod wl55; | ||
| 67 | pub use wl55::*; | ||
| 65 | } | 68 | } |
| 66 | } | 69 | } |
| 67 | 70 | ||
diff --git a/embassy-stm32/src/rcc/wl55/mod.rs b/embassy-stm32/src/rcc/wl55/mod.rs new file mode 100644 index 000000000..2170b7b72 --- /dev/null +++ b/embassy-stm32/src/rcc/wl55/mod.rs | |||
| @@ -0,0 +1,213 @@ | |||
| 1 | pub use super::types::*; | ||
| 2 | use crate::pac; | ||
| 3 | use crate::peripherals::{self, RCC}; | ||
| 4 | use crate::rcc::{get_freqs, set_freqs, Clocks}; | ||
| 5 | use crate::time::Hertz; | ||
| 6 | use crate::time::U32Ext; | ||
| 7 | use core::marker::PhantomData; | ||
| 8 | use embassy::util::Unborrow; | ||
| 9 | use embassy_extras::unborrow; | ||
| 10 | |||
| 11 | /// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, | ||
| 12 | /// and with the addition of the init function to configure a system clock. | ||
| 13 | |||
| 14 | /// Only the basic setup using the HSE and HSI clocks are supported as of now. | ||
| 15 | |||
| 16 | /// HSI speed | ||
| 17 | pub const HSI_FREQ: u32 = 16_000_000; | ||
| 18 | |||
| 19 | /// System clock mux source | ||
| 20 | #[derive(Clone, Copy)] | ||
| 21 | pub enum ClockSrc { | ||
| 22 | HSE(Hertz), | ||
| 23 | HSI16, | ||
| 24 | } | ||
| 25 | |||
| 26 | impl Into<u8> for APBPrescaler { | ||
| 27 | fn into(self) -> u8 { | ||
| 28 | match self { | ||
| 29 | APBPrescaler::NotDivided => 1, | ||
| 30 | APBPrescaler::Div2 => 0x04, | ||
| 31 | APBPrescaler::Div4 => 0x05, | ||
| 32 | APBPrescaler::Div8 => 0x06, | ||
| 33 | APBPrescaler::Div16 => 0x07, | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | impl Into<u8> for AHBPrescaler { | ||
| 39 | fn into(self) -> u8 { | ||
| 40 | match self { | ||
| 41 | AHBPrescaler::NotDivided => 1, | ||
| 42 | AHBPrescaler::Div2 => 0x08, | ||
| 43 | AHBPrescaler::Div4 => 0x09, | ||
| 44 | AHBPrescaler::Div8 => 0x0a, | ||
| 45 | AHBPrescaler::Div16 => 0x0b, | ||
| 46 | AHBPrescaler::Div64 => 0x0c, | ||
| 47 | AHBPrescaler::Div128 => 0x0d, | ||
| 48 | AHBPrescaler::Div256 => 0x0e, | ||
| 49 | AHBPrescaler::Div512 => 0x0f, | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | /// Clocks configutation | ||
| 55 | pub struct Config { | ||
| 56 | mux: ClockSrc, | ||
| 57 | ahb_pre: AHBPrescaler, | ||
| 58 | apb1_pre: APBPrescaler, | ||
| 59 | apb2_pre: APBPrescaler, | ||
| 60 | } | ||
| 61 | |||
| 62 | impl Default for Config { | ||
| 63 | #[inline] | ||
| 64 | fn default() -> Config { | ||
| 65 | Config { | ||
| 66 | mux: ClockSrc::HSI16, | ||
| 67 | ahb_pre: AHBPrescaler::NotDivided, | ||
| 68 | apb1_pre: APBPrescaler::NotDivided, | ||
| 69 | apb2_pre: APBPrescaler::NotDivided, | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | impl Config { | ||
| 75 | #[inline] | ||
| 76 | pub fn clock_src(mut self, mux: ClockSrc) -> Self { | ||
| 77 | self.mux = mux; | ||
| 78 | self | ||
| 79 | } | ||
| 80 | |||
| 81 | #[inline] | ||
| 82 | pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self { | ||
| 83 | self.ahb_pre = pre; | ||
| 84 | self | ||
| 85 | } | ||
| 86 | |||
| 87 | #[inline] | ||
| 88 | pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self { | ||
| 89 | self.apb1_pre = pre; | ||
| 90 | self | ||
| 91 | } | ||
| 92 | |||
| 93 | #[inline] | ||
| 94 | pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self { | ||
| 95 | self.apb2_pre = pre; | ||
| 96 | self | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | /// RCC peripheral | ||
| 101 | pub struct Rcc<'d> { | ||
| 102 | _rb: peripherals::RCC, | ||
| 103 | phantom: PhantomData<&'d mut peripherals::RCC>, | ||
| 104 | } | ||
| 105 | |||
| 106 | impl<'d> Rcc<'d> { | ||
| 107 | pub fn new(rcc: impl Unborrow<Target = peripherals::RCC> + 'd) -> Self { | ||
| 108 | unborrow!(rcc); | ||
| 109 | Self { | ||
| 110 | _rb: rcc, | ||
| 111 | phantom: PhantomData, | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | // Safety: RCC init must have been called | ||
| 116 | pub fn clocks(&self) -> &'static Clocks { | ||
| 117 | unsafe { get_freqs() } | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | /// Extension trait that freezes the `RCC` peripheral with provided clocks configuration | ||
| 122 | pub trait RccExt { | ||
| 123 | fn freeze(self, config: Config) -> Clocks; | ||
| 124 | } | ||
| 125 | |||
| 126 | impl RccExt for RCC { | ||
| 127 | #[inline] | ||
| 128 | fn freeze(self, cfgr: Config) -> Clocks { | ||
| 129 | let rcc = pac::RCC; | ||
| 130 | let (sys_clk, sw) = match cfgr.mux { | ||
| 131 | ClockSrc::HSI16 => { | ||
| 132 | // Enable HSI16 | ||
| 133 | unsafe { | ||
| 134 | rcc.cr().write(|w| w.set_hsion(true)); | ||
| 135 | while !rcc.cr().read().hsirdy() {} | ||
| 136 | } | ||
| 137 | |||
| 138 | (HSI_FREQ, 0x01) | ||
| 139 | } | ||
| 140 | ClockSrc::HSE(freq) => { | ||
| 141 | // Enable HSE | ||
| 142 | unsafe { | ||
| 143 | rcc.cr().write(|w| w.set_hseon(true)); | ||
| 144 | while !rcc.cr().read().hserdy() {} | ||
| 145 | } | ||
| 146 | |||
| 147 | (freq.0, 0x02) | ||
| 148 | } | ||
| 149 | }; | ||
| 150 | |||
| 151 | unsafe { | ||
| 152 | rcc.cfgr().modify(|w| { | ||
| 153 | w.set_sw(sw.into()); | ||
| 154 | w.set_hpre(cfgr.ahb_pre.into()); | ||
| 155 | w.set_ppre1(cfgr.apb1_pre.into()); | ||
| 156 | w.set_ppre2(cfgr.apb2_pre.into()); | ||
| 157 | }); | ||
| 158 | } | ||
| 159 | |||
| 160 | let ahb_freq: u32 = match cfgr.ahb_pre { | ||
| 161 | AHBPrescaler::NotDivided => sys_clk, | ||
| 162 | pre => { | ||
| 163 | let pre: u8 = pre.into(); | ||
| 164 | let pre = 1 << (pre as u32 - 7); | ||
| 165 | sys_clk / pre | ||
| 166 | } | ||
| 167 | }; | ||
| 168 | |||
| 169 | let (apb1_freq, apb1_tim_freq) = match cfgr.apb1_pre { | ||
| 170 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | ||
| 171 | pre => { | ||
| 172 | let pre: u8 = pre.into(); | ||
| 173 | let pre: u8 = 1 << (pre - 3); | ||
| 174 | let freq = ahb_freq / pre as u32; | ||
| 175 | (freq, freq * 2) | ||
| 176 | } | ||
| 177 | }; | ||
| 178 | |||
| 179 | let (apb2_freq, apb2_tim_freq) = match cfgr.apb2_pre { | ||
| 180 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | ||
| 181 | pre => { | ||
| 182 | let pre: u8 = pre.into(); | ||
| 183 | let pre: u8 = 1 << (pre - 3); | ||
| 184 | let freq = ahb_freq / (1 << (pre as u8 - 3)); | ||
| 185 | (freq, freq * 2) | ||
| 186 | } | ||
| 187 | }; | ||
| 188 | |||
| 189 | Clocks { | ||
| 190 | sys: sys_clk.hz(), | ||
| 191 | ahb1: ahb_freq.hz(), | ||
| 192 | ahb2: ahb_freq.hz(), | ||
| 193 | ahb3: ahb_freq.hz(), | ||
| 194 | apb1: apb1_freq.hz(), | ||
| 195 | apb2: apb2_freq.hz(), | ||
| 196 | apb1_tim: apb1_tim_freq.hz(), | ||
| 197 | apb2_tim: apb2_tim_freq.hz(), | ||
| 198 | } | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | pub unsafe fn init(config: Config) { | ||
| 203 | let r = <peripherals::RCC as embassy::util::Steal>::steal(); | ||
| 204 | let rcc = pac::RCC; | ||
| 205 | rcc.ahb2enr().write(|w| { | ||
| 206 | w.set_gpioaen(true); | ||
| 207 | w.set_gpioben(true); | ||
| 208 | w.set_gpiocen(true); | ||
| 209 | w.set_gpiohen(true); | ||
| 210 | }); | ||
| 211 | let clocks = r.freeze(config); | ||
| 212 | set_freqs(clocks); | ||
| 213 | } | ||
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs index e7433c26f..ab0a2bdb2 100644 --- a/examples/stm32l0/src/bin/blinky.rs +++ b/examples/stm32l0/src/bin/blinky.rs | |||
| @@ -8,7 +8,10 @@ | |||
| 8 | 8 | ||
| 9 | #[path = "../example_common.rs"] | 9 | #[path = "../example_common.rs"] |
| 10 | mod example_common; | 10 | mod example_common; |
| 11 | use embassy_stm32::{rcc::*, gpio::{Level, Output}}; | 11 | use embassy_stm32::{ |
| 12 | gpio::{Level, Output}, | ||
| 13 | rcc::*, | ||
| 14 | }; | ||
| 12 | use embedded_hal::digital::v2::OutputPin; | 15 | use embedded_hal::digital::v2::OutputPin; |
| 13 | use example_common::*; | 16 | use example_common::*; |
| 14 | 17 | ||
diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs index 1a2e20b14..04c48112a 100644 --- a/examples/stm32l0/src/bin/button.rs +++ b/examples/stm32l0/src/bin/button.rs | |||
| @@ -8,13 +8,15 @@ | |||
| 8 | 8 | ||
| 9 | #[path = "../example_common.rs"] | 9 | #[path = "../example_common.rs"] |
| 10 | mod example_common; | 10 | mod example_common; |
| 11 | use embassy_stm32::{rcc::*, gpio::{Input, Level, Output, Pull}}; | 11 | use embassy_stm32::{ |
| 12 | gpio::{Input, Level, Output, Pull}, | ||
| 13 | rcc::*, | ||
| 14 | }; | ||
| 12 | use embedded_hal::digital::v2::{InputPin, OutputPin}; | 15 | use embedded_hal::digital::v2::{InputPin, OutputPin}; |
| 13 | use example_common::*; | 16 | use example_common::*; |
| 14 | 17 | ||
| 15 | use cortex_m_rt::entry; | 18 | use cortex_m_rt::entry; |
| 16 | 19 | ||
| 17 | |||
| 18 | #[entry] | 20 | #[entry] |
| 19 | fn main() -> ! { | 21 | fn main() -> ! { |
| 20 | info!("Hello World!"); | 22 | info!("Hello World!"); |
diff --git a/stm32-data b/stm32-data | |||
| Subproject 67b2029a7f203e52f6e1f68c71c7d0aacfef579 | Subproject e104fc21fea271a5d407086ac7ff19e448ac1b3 | ||
diff --git a/stm32-metapac/Cargo.toml b/stm32-metapac/Cargo.toml index 4a434b17e..bed772c81 100644 --- a/stm32-metapac/Cargo.toml +++ b/stm32-metapac/Cargo.toml | |||
| @@ -778,23 +778,40 @@ stm32h743xg = [] | |||
| 778 | stm32h743xi = [] | 778 | stm32h743xi = [] |
| 779 | stm32h743zg = [] | 779 | stm32h743zg = [] |
| 780 | stm32h743zi = [] | 780 | stm32h743zi = [] |
| 781 | stm32h745bg = [] | 781 | stm32h745bg_cm7 = [] |
| 782 | stm32h745bi = [] | 782 | stm32h745bg_cm4 = [] |
| 783 | stm32h745ig = [] | 783 | stm32h745bi_cm7 = [] |
| 784 | stm32h745ii = [] | 784 | stm32h745bi_cm4 = [] |
| 785 | stm32h745xg = [] | 785 | stm32h745ig_cm7 = [] |
| 786 | stm32h745xi = [] | 786 | stm32h745ig_cm4 = [] |
| 787 | stm32h745zg = [] | 787 | stm32h745ii_cm7 = [] |
| 788 | stm32h745zi = [] | 788 | stm32h745ii_cm4 = [] |
| 789 | stm32h747ag = [] | 789 | stm32h745xg_cm7 = [] |
| 790 | stm32h747ai = [] | 790 | stm32h745xg_cm4 = [] |
| 791 | stm32h747bg = [] | 791 | stm32h745xi_cm7 = [] |
| 792 | stm32h747bi = [] | 792 | stm32h745xi_cm4 = [] |
| 793 | stm32h747ig = [] | 793 | stm32h745zg_cm7 = [] |
| 794 | stm32h747ii = [] | 794 | stm32h745zg_cm4 = [] |
| 795 | stm32h747xg = [] | 795 | stm32h745zi_cm7 = [] |
| 796 | stm32h747xi = [] | 796 | stm32h745zi_cm4 = [] |
| 797 | stm32h747zi = [] | 797 | stm32h747ag_cm7 = [] |
| 798 | stm32h747ag_cm4 = [] | ||
| 799 | stm32h747ai_cm7 = [] | ||
| 800 | stm32h747ai_cm4 = [] | ||
| 801 | stm32h747bg_cm7 = [] | ||
| 802 | stm32h747bg_cm4 = [] | ||
| 803 | stm32h747bi_cm7 = [] | ||
| 804 | stm32h747bi_cm4 = [] | ||
| 805 | stm32h747ig_cm7 = [] | ||
| 806 | stm32h747ig_cm4 = [] | ||
| 807 | stm32h747ii_cm7 = [] | ||
| 808 | stm32h747ii_cm4 = [] | ||
| 809 | stm32h747xg_cm7 = [] | ||
| 810 | stm32h747xg_cm4 = [] | ||
| 811 | stm32h747xi_cm7 = [] | ||
| 812 | stm32h747xi_cm4 = [] | ||
| 813 | stm32h747zi_cm7 = [] | ||
| 814 | stm32h747zi_cm4 = [] | ||
| 798 | stm32h750ib = [] | 815 | stm32h750ib = [] |
| 799 | stm32h750vb = [] | 816 | stm32h750vb = [] |
| 800 | stm32h750xb = [] | 817 | stm32h750xb = [] |
| @@ -805,15 +822,24 @@ stm32h753ii = [] | |||
| 805 | stm32h753vi = [] | 822 | stm32h753vi = [] |
| 806 | stm32h753xi = [] | 823 | stm32h753xi = [] |
| 807 | stm32h753zi = [] | 824 | stm32h753zi = [] |
| 808 | stm32h755bi = [] | 825 | stm32h755bi_cm7 = [] |
| 809 | stm32h755ii = [] | 826 | stm32h755bi_cm4 = [] |
| 810 | stm32h755xi = [] | 827 | stm32h755ii_cm7 = [] |
| 811 | stm32h755zi = [] | 828 | stm32h755ii_cm4 = [] |
| 812 | stm32h757ai = [] | 829 | stm32h755xi_cm7 = [] |
| 813 | stm32h757bi = [] | 830 | stm32h755xi_cm4 = [] |
| 814 | stm32h757ii = [] | 831 | stm32h755zi_cm7 = [] |
| 815 | stm32h757xi = [] | 832 | stm32h755zi_cm4 = [] |
| 816 | stm32h757zi = [] | 833 | stm32h757ai_cm7 = [] |
| 834 | stm32h757ai_cm4 = [] | ||
| 835 | stm32h757bi_cm7 = [] | ||
| 836 | stm32h757bi_cm4 = [] | ||
| 837 | stm32h757ii_cm7 = [] | ||
| 838 | stm32h757ii_cm4 = [] | ||
| 839 | stm32h757xi_cm7 = [] | ||
| 840 | stm32h757xi_cm4 = [] | ||
| 841 | stm32h757zi_cm7 = [] | ||
| 842 | stm32h757zi_cm4 = [] | ||
| 817 | stm32h7a3ag = [] | 843 | stm32h7a3ag = [] |
| 818 | stm32h7a3ai = [] | 844 | stm32h7a3ai = [] |
| 819 | stm32h7a3ig = [] | 845 | stm32h7a3ig = [] |
| @@ -1204,11 +1230,16 @@ stm32wb55ve = [] | |||
| 1204 | stm32wb55vg = [] | 1230 | stm32wb55vg = [] |
| 1205 | stm32wb55vy = [] | 1231 | stm32wb55vy = [] |
| 1206 | stm32wb5mmg = [] | 1232 | stm32wb5mmg = [] |
| 1207 | stm32wl54cc = [] | 1233 | stm32wl54cc_cm4 = [] |
| 1208 | stm32wl54jc = [] | 1234 | stm32wl54cc_cm0p = [] |
| 1209 | stm32wl55cc = [] | 1235 | stm32wl54jc_cm4 = [] |
| 1210 | stm32wl55jc = [] | 1236 | stm32wl54jc_cm0p = [] |
| 1211 | stm32wl55uc = [] | 1237 | stm32wl55cc_cm4 = [] |
| 1238 | stm32wl55cc_cm0p = [] | ||
| 1239 | stm32wl55jc_cm4 = [] | ||
| 1240 | stm32wl55jc_cm0p = [] | ||
| 1241 | stm32wl55uc_cm4 = [] | ||
| 1242 | stm32wl55uc_cm0p = [] | ||
| 1212 | stm32wle4c8 = [] | 1243 | stm32wle4c8 = [] |
| 1213 | stm32wle4cb = [] | 1244 | stm32wle4cb = [] |
| 1214 | stm32wle4cc = [] | 1245 | stm32wle4cc = [] |
diff --git a/stm32-metapac/gen/src/lib.rs b/stm32-metapac/gen/src/lib.rs index 5a021569c..a5c061009 100644 --- a/stm32-metapac/gen/src/lib.rs +++ b/stm32-metapac/gen/src/lib.rs | |||
| @@ -16,11 +16,16 @@ pub struct Chip { | |||
| 16 | pub name: String, | 16 | pub name: String, |
| 17 | pub family: String, | 17 | pub family: String, |
| 18 | pub line: String, | 18 | pub line: String, |
| 19 | pub core: String, | 19 | pub cores: Vec<Core>, |
| 20 | pub flash: u32, | 20 | pub flash: u32, |
| 21 | pub ram: u32, | 21 | pub ram: u32, |
| 22 | pub gpio_af: String, | 22 | pub gpio_af: String, |
| 23 | pub packages: Vec<Package>, | 23 | pub packages: Vec<Package>, |
| 24 | } | ||
| 25 | |||
| 26 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] | ||
| 27 | pub struct Core { | ||
| 28 | pub name: String, | ||
| 24 | pub peripherals: HashMap<String, Peripheral>, | 29 | pub peripherals: HashMap<String, Peripheral>, |
| 25 | pub interrupts: HashMap<String, u32>, | 30 | pub interrupts: HashMap<String, u32>, |
| 26 | } | 31 | } |
| @@ -153,13 +158,41 @@ pub fn gen(options: Options) { | |||
| 153 | println!("cwd: {:?}", env::current_dir()); | 158 | println!("cwd: {:?}", env::current_dir()); |
| 154 | 159 | ||
| 155 | let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new(); | 160 | let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new(); |
| 161 | let mut chip_cores: HashMap<String, Option<String>> = HashMap::new(); | ||
| 156 | 162 | ||
| 157 | for chip_name in &options.chips { | 163 | for chip_name in &options.chips { |
| 164 | let mut s = chip_name.split('_'); | ||
| 165 | let chip_name: &str = s.next().unwrap(); | ||
| 166 | let core_name: Option<&str> = s.next(); | ||
| 167 | |||
| 168 | chip_cores.insert( | ||
| 169 | chip_name.to_string(), | ||
| 170 | core_name.map(|s| s.to_ascii_lowercase().to_string()), | ||
| 171 | ); | ||
| 172 | |||
| 158 | let chip_path = data_dir.join("chips").join(&format!("{}.yaml", chip_name)); | 173 | let chip_path = data_dir.join("chips").join(&format!("{}.yaml", chip_name)); |
| 159 | println!("chip_path: {:?}", chip_path); | 174 | println!("chip_path: {:?}", chip_path); |
| 160 | let chip = fs::read(chip_path).unwrap(); | 175 | let chip = fs::read(chip_path).unwrap(); |
| 161 | let chip: Chip = serde_yaml::from_slice(&chip).unwrap(); | 176 | let chip: Chip = serde_yaml::from_slice(&chip).unwrap(); |
| 162 | 177 | ||
| 178 | println!("looking for core {:?}", core_name); | ||
| 179 | let core: Option<&Core> = if let Some(core_name) = core_name { | ||
| 180 | let core_name = core_name.to_ascii_lowercase(); | ||
| 181 | let mut c = None; | ||
| 182 | for core in chip.cores.iter() { | ||
| 183 | if core.name == core_name { | ||
| 184 | c = Some(core); | ||
| 185 | break; | ||
| 186 | } | ||
| 187 | } | ||
| 188 | c | ||
| 189 | } else { | ||
| 190 | Some(&chip.cores[0]) | ||
| 191 | }; | ||
| 192 | |||
| 193 | let core = core.unwrap(); | ||
| 194 | let core_name = &core.name; | ||
| 195 | |||
| 163 | let mut ir = ir::IR::new(); | 196 | let mut ir = ir::IR::new(); |
| 164 | 197 | ||
| 165 | let mut dev = ir::Device { | 198 | let mut dev = ir::Device { |
| @@ -168,7 +201,7 @@ pub fn gen(options: Options) { | |||
| 168 | }; | 201 | }; |
| 169 | 202 | ||
| 170 | // Load RCC register for chip | 203 | // Load RCC register for chip |
| 171 | let rcc = chip.peripherals.iter().find_map(|(name, p)| { | 204 | let rcc = core.peripherals.iter().find_map(|(name, p)| { |
| 172 | if name == "RCC" { | 205 | if name == "RCC" { |
| 173 | p.block.as_ref().map(|block| { | 206 | p.block.as_ref().map(|block| { |
| 174 | let bi = BlockInfo::parse(block); | 207 | let bi = BlockInfo::parse(block); |
| @@ -189,17 +222,17 @@ pub fn gen(options: Options) { | |||
| 189 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); | 222 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); |
| 190 | let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); | 223 | let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); |
| 191 | 224 | ||
| 192 | let dma_base = chip | 225 | let dma_base = core |
| 193 | .peripherals | 226 | .peripherals |
| 194 | .get(&"DMA".to_string()) | 227 | .get(&"DMA".to_string()) |
| 195 | .unwrap_or_else(|| chip.peripherals.get(&"DMA1".to_string()).unwrap()) | 228 | .unwrap_or_else(|| core.peripherals.get(&"DMA1".to_string()).unwrap()) |
| 196 | .address; | 229 | .address; |
| 197 | let dma_stride = 0x400; | 230 | let dma_stride = 0x400; |
| 198 | 231 | ||
| 199 | let gpio_base = chip.peripherals.get(&"GPIOA".to_string()).unwrap().address; | 232 | let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; |
| 200 | let gpio_stride = 0x400; | 233 | let gpio_stride = 0x400; |
| 201 | 234 | ||
| 202 | for (name, p) in &chip.peripherals { | 235 | for (name, p) in &core.peripherals { |
| 203 | let mut ir_peri = ir::Peripheral { | 236 | let mut ir_peri = ir::Peripheral { |
| 204 | name: name.clone(), | 237 | name: name.clone(), |
| 205 | array: None, | 238 | array: None, |
| @@ -338,7 +371,7 @@ pub fn gen(options: Options) { | |||
| 338 | dev.peripherals.push(ir_peri); | 371 | dev.peripherals.push(ir_peri); |
| 339 | } | 372 | } |
| 340 | 373 | ||
| 341 | for (name, &num) in &chip.interrupts { | 374 | for (name, &num) in &core.interrupts { |
| 342 | dev.interrupts.push(ir::Interrupt { | 375 | dev.interrupts.push(ir::Interrupt { |
| 343 | name: name.clone(), | 376 | name: name.clone(), |
| 344 | description: None, | 377 | description: None, |
| @@ -386,9 +419,17 @@ pub fn gen(options: Options) { | |||
| 386 | transform::sort::Sort {}.run(&mut ir).unwrap(); | 419 | transform::sort::Sort {}.run(&mut ir).unwrap(); |
| 387 | transform::Sanitize {}.run(&mut ir).unwrap(); | 420 | transform::Sanitize {}.run(&mut ir).unwrap(); |
| 388 | 421 | ||
| 389 | let chip_dir = out_dir | 422 | let chip_dir = if chip.cores.len() > 1 { |
| 390 | .join("src/chips") | 423 | out_dir.join("src/chips").join(format!( |
| 391 | .join(chip_name.to_ascii_lowercase()); | 424 | "{}_{}", |
| 425 | chip_name.to_ascii_lowercase(), | ||
| 426 | core_name.to_ascii_lowercase() | ||
| 427 | )) | ||
| 428 | } else { | ||
| 429 | out_dir | ||
| 430 | .join("src/chips") | ||
| 431 | .join(chip_name.to_ascii_lowercase()) | ||
| 432 | }; | ||
| 392 | fs::create_dir_all(&chip_dir).unwrap(); | 433 | fs::create_dir_all(&chip_dir).unwrap(); |
| 393 | 434 | ||
| 394 | let items = generate::render(&ir, &generate_opts).unwrap(); | 435 | let items = generate::render(&ir, &generate_opts).unwrap(); |
| @@ -403,7 +444,7 @@ pub fn gen(options: Options) { | |||
| 403 | 444 | ||
| 404 | let mut device_x = String::new(); | 445 | let mut device_x = String::new(); |
| 405 | 446 | ||
| 406 | for (name, _) in &chip.interrupts { | 447 | for (name, _) in &core.interrupts { |
| 407 | write!( | 448 | write!( |
| 408 | &mut device_x, | 449 | &mut device_x, |
| 409 | "PROVIDE({} = DefaultHandler);\n", | 450 | "PROVIDE({} = DefaultHandler);\n", |
| @@ -462,14 +503,24 @@ pub fn gen(options: Options) { | |||
| 462 | let librs = include_bytes!("assets/lib_inner.rs"); | 503 | let librs = include_bytes!("assets/lib_inner.rs"); |
| 463 | let i = bytes_find(librs, PATHS_MARKER).unwrap(); | 504 | let i = bytes_find(librs, PATHS_MARKER).unwrap(); |
| 464 | let mut paths = String::new(); | 505 | let mut paths = String::new(); |
| 465 | for chip_name in &options.chips { | 506 | |
| 466 | let x = chip_name.to_ascii_lowercase(); | 507 | for (chip, cores) in chip_cores.iter() { |
| 467 | write!( | 508 | let x = chip.to_ascii_lowercase(); |
| 468 | &mut paths, | 509 | if let Some(c) = cores { |
| 469 | "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]", | 510 | write!( |
| 470 | x, x | 511 | &mut paths, |
| 471 | ) | 512 | "#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]", |
| 472 | .unwrap(); | 513 | x, c, x, c |
| 514 | ) | ||
| 515 | .unwrap(); | ||
| 516 | } else { | ||
| 517 | write!( | ||
| 518 | &mut paths, | ||
| 519 | "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]", | ||
| 520 | x, x | ||
| 521 | ) | ||
| 522 | .unwrap(); | ||
| 523 | } | ||
| 473 | } | 524 | } |
| 474 | let mut contents: Vec<u8> = Vec::new(); | 525 | let mut contents: Vec<u8> = Vec::new(); |
| 475 | contents.extend(&librs[..i]); | 526 | contents.extend(&librs[..i]); |
diff --git a/stm32-metapac/gen_features.py b/stm32-metapac/gen_features.py index ee92bd763..29cbd85a0 100644 --- a/stm32-metapac/gen_features.py +++ b/stm32-metapac/gen_features.py | |||
| @@ -8,6 +8,11 @@ import toml | |||
| 8 | from collections import OrderedDict | 8 | from collections import OrderedDict |
| 9 | from glob import glob | 9 | from glob import glob |
| 10 | 10 | ||
| 11 | try: | ||
| 12 | from yaml import CSafeLoader as SafeLoader | ||
| 13 | except ImportError: | ||
| 14 | from yaml import SafeLoader | ||
| 15 | |||
| 11 | abspath = os.path.abspath(__file__) | 16 | abspath = os.path.abspath(__file__) |
| 12 | dname = os.path.dirname(abspath) | 17 | dname = os.path.dirname(abspath) |
| 13 | os.chdir(dname) | 18 | os.chdir(dname) |
| @@ -19,8 +24,13 @@ features = {} | |||
| 19 | for f in sorted(glob('../stm32-data/data/chips/*.yaml')): | 24 | for f in sorted(glob('../stm32-data/data/chips/*.yaml')): |
| 20 | # Use the filename to get the chip name. Ultra fast, we don't have to read YAML! | 25 | # Use the filename to get the chip name. Ultra fast, we don't have to read YAML! |
| 21 | name = os.path.splitext(os.path.basename(f))[0].lower() | 26 | name = os.path.splitext(os.path.basename(f))[0].lower() |
| 22 | features[name] = [] | 27 | with open(f, 'r') as f: |
| 23 | 28 | chip = yaml.load(f, Loader=SafeLoader) | |
| 29 | if len(chip['cores']) > 1: | ||
| 30 | for core in chip['cores']: | ||
| 31 | features[name + "_" + core['name']] = [] | ||
| 32 | else: | ||
| 33 | features[name] = [] | ||
| 24 | 34 | ||
| 25 | # ========= Update Cargo features | 35 | # ========= Update Cargo features |
| 26 | 36 | ||
