Skip to content

Commit 1fcc53b

Browse files
authored
Merge pull request #69 from Wassasin/metapac-extract
Move towards clap-based CLI tool with explicit metapac extract and generate commands
2 parents 4489a84 + 9b23747 commit 1fcc53b

44 files changed

Lines changed: 960 additions & 751 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 94 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,38 @@ If you want to regenerate the pac, you need to clone with `--recursive`.
88

99
If you forgot this, you can use `git submodule update --checkout --init` to fetch the submodules.
1010

11+
## PAC vs MetaPAC
12+
13+
This crate is in transition from generating the PAC from the NXP provided SVD files, to a metapac approach where the SVD is only used to extract general peripheral definition files.
14+
A metapac definition file then specifies which peripherals are included in the chip.
15+
This is very useful when a vendor has used similar peripheral IPs across their portfolio.
16+
This allows HAL authors to write drivers for these peripheral IPs, instead of having to copy-paste them for each supported chipset.
17+
18+
Because the crate is in transition, some of them use the PAC method, and some of them are part of the metapac.
19+
20+
## Supported chips
21+
22+
| Chip | Type |
23+
|------|------|
24+
| MIMXRT1011 | PAC |
25+
| MIMXRT1062 | PAC |
26+
| MIMXRT1064 | PAC |
27+
| MIMXRT685S | PAC |
28+
| LPC55S16 | PAC |
29+
| LPC55S69 | PAC |
30+
| MCXN947 | PAC |
31+
| MCXA256 | MetaPAC |
32+
| MCXA577 | MetaPAC |
33+
1134
## Tour
1235

13-
The `data` directory contains the SVD files, board metadata, and chiptool transformations needed to
36+
The [`data`](/data) directory contains the SVD files, board metadata, and chiptool transformations needed to
1437
generate the nxp-pac crate. This data is used by the code generation tool.
1538

16-
The `generator` directory contains the code generation tool for generating the code in the `nxp-pac` crate.
17-
If you want change the way the `nxp-pac` crate is generated please see this directory.
18-
Run it using `cargo run -p generator -- <CHIP>`.
39+
The [`generator`](/generator) directory contains the code generation tool for generating the code in the [`nxp-pac`](/nxp-pac) crate.
40+
If you want change the way the [`nxp-pac`](/nxp-pac) crate is generated please see this directory.
1941

20-
The `nxp-pac` directory contains the nxp-pac crate. If you are looking for a peripheral access crate for
42+
The [`nxp-pac`](/nxp-pac) directory contains the nxp-pac crate. If you are looking for a peripheral access crate for
2143
an NXP microcontroller, please see this directory. You should never need to manually edit the source
2244
code in this directory. The metadata will need to be updated to support new microcontrollers.
2345

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1-
The generator will put transformed SVD data into the `raw` folder.
2-
This is not used for anything later on, but serves for debugging purposes.
1+
# Metapac peripherals
2+
This directory contains the register and type definitions for peripheral IPs that are included in NXP chipsets.
3+
4+
NXP does not give us the internal name of these peripheral IPs. (for example: Synopsis USB-OTG rev. 2)
5+
It's up to us to create some sort of consistency there.
6+
7+
These files are manually curated and considered to be the 'source of truth' when generating the metapac Rust source code.
8+
Even though they are assembled by hand, they are derived from the SVD files provided by the vendor.
9+
10+
This derivation ideally happens through chiptool transforms, but manual changes to these files are also allowed.
11+
When adding manual changes, please note them with appropriate comments in the YAML files.
12+
13+
14+
15+
## Updating
16+
The generator when using the `extract` command will put transformed SVD data into the `raw` folder.
17+
Anything in this folder is not used directly, but can be used by you as a start to define metapac peripherals and chips.
18+
319
This is per device:
420

5-
- A YAML per peripheral, directly from the SVD
6-
- A `_debug_ir.yaml` that represents the non-metapac version of the pac. It's the result of running the SVD through the transforms.
7-
This is a good source when porting over a pac to the metapac.
21+
- A YAML per peripheral, with transforms applied and namespaces stripped. These files are suitable to base your metapac peripheral definition files on.
22+
- Everything in the `raw/original` folder, which are the same files but without the namespaces stripped. These files are the direct output of the transforms, and thus useful when developing the transforms.
823
- `_addresses.json`: A list of all peripherals and their addresses, taken from the SVD. Handy for adding it to the metadata.
924
- `_interrupts.json`: A list of all interrupts and their numbers, taken from the SVD. Handy for adding it to the metadata.
1025

11-
The other folders contain the manually curated YAMLs of the peripherals.
12-
The exact names are not prescribed. NXP doesn't give us names, so it's up to us to create some sort of consistency there.
13-
The metadata points to those YAMLs.
26+
Thus the workflow to add or change a peripheral is as follows: (change MCXA577 to your chipset)
27+
* Run `cargo run -p generator -- extract MCXA577`
28+
* Open `/data/metadata/peripherals/raw/MCXA577/<peripheral>.yaml`
29+
* Check if it is correct, if not change the transforms in `/data/transforms` and re-run `extract` until it is.
30+
* Copy the file over, and check the changes compared to what was already committed when relevant.
31+
* It is also allowed to change the file by hand at this point, but please use comments to denote what and why you changed (and why you didn't use a transform).
32+
* Generate the new nxp-pac code by running `cargo run -p generator -- generate MCXA577`
33+
* Check the code changes and commit both the nxp-pac code and the metadata definitions.

data/metadata/peripherals/mcxa/TRNG.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ block/Trng:
111111
description: Statistical Check Run Length 6+ Count Register.
112112
byte_offset: 56
113113
access: Read
114-
fieldset: SCr6pc
114+
fieldset: Scr6pc
115115
- name: scr6pl
116116
description: Statistical Check Run Length 6+ Limit Register.
117117
byte_offset: 56

data/transforms/mcxa/adc.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,46 @@ transforms:
33
from: hsadc::(.*)
44
to: adc::$1
55
type: All
6-
6+
77
- !Rename
88
from: adc::Hsadc
99
to: adc::Adc
1010
type: Block
1111

1212
- !MergeEnums
13-
from: adc::vals::Cmdl(\d+)(.+)
14-
to: adc::vals::$2
13+
from: adc::Cmdl(\d+)(.+)
14+
to: adc::$2
1515

1616
- !MergeFieldsets
17-
from: adc::regs::Cmdl(\d+)
18-
to: adc::regs::Cmdl
17+
from: adc::Cmdl(\d+)
18+
to: adc::Cmdl
1919

2020
- !MakeRegisterArray
2121
blocks: adc::Adc
2222
from: cmdl(\d+)
2323
to: cmdl
2424

2525
- !MergeEnums
26-
from: adc::vals::Cmdh(\d+)(.+)
27-
to: adc::vals::$2
26+
from: adc::Cmdh(\d+)(.+)
27+
to: adc::$2
2828

2929
- !MergeFieldsets
30-
from: adc::regs::Cmdh(\d+)
31-
to: adc::regs::Cmdh
32-
30+
from: adc::Cmdh(\d+)
31+
to: adc::Cmdh
32+
3333
- !MakeRegisterArray
3434
blocks: adc::Adc
3535
from: cmdh(\d+)
3636
to: cmdh
3737

3838
- !DeleteEnums
39-
from: adc::vals::Swt(\d+)
39+
from: adc::Swt(\d+)
4040

4141
# ADC channel select is not correct at all, better use bare u8.
4242
- !DeleteEnums
43-
from: adc::vals::Adch
43+
from: adc::Adch
4444

4545
- !MakeFieldArray
46-
fieldsets: adc::regs::Swtrig
46+
fieldsets: adc::Swtrig
4747
from: swt(\d+)
4848
to: swt

data/transforms/mcxa/can.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
transforms:
22
- !MergeFieldsets
3-
from: can::regs::(Cs|Id)(\d+)
4-
to: can::regs::$1
3+
from: can::(Cs|Id)(\d+)
4+
to: can::$1
55

66
- !MergeFieldsets
7-
from: can::regs::Mb(\d+)b(Cs|Id)
8-
to: can::regs::Mbb$2
7+
from: can::Mb(\d+)b(Cs|Id)
8+
to: can::Mbb$2
99

1010
- !DeleteFieldsets
11-
from: can::regs::Mb(\d+)bWord(\d+)
12-
11+
from: can::Mb(\d+)bWord(\d+)
12+
1313
- !DeleteFieldsets
14-
from: can::regs::Word(\d+)
14+
from: can::Word(\d+)
1515

1616
- !MakeRegisterArray
1717
blocks: can::Can
1818
from: word(0|1)(\d+)
1919
to: word$1
20-
20+
2121
- !MakeRegisterArray
2222
blocks: can::Can
2323
from: id(\d+)
@@ -27,22 +27,22 @@ transforms:
2727
blocks: can::Can
2828
from: cs(\d+)
2929
to: cs
30-
30+
3131
- !MakeRegisterArray
3232
blocks: can::Can
3333
from: mb(\d+)_8b_cs
3434
to: mb_8b_cs
35-
35+
3636
- !MakeRegisterArray
3737
blocks: can::Can
3838
from: mb(\d+)_16b_cs
3939
to: mb_16b_cs
40-
40+
4141
- !MakeRegisterArray
4242
blocks: can::Can
4343
from: mb(\d+)_32b_cs
4444
to: mb_32b_cs
45-
45+
4646
- !MakeRegisterArray
4747
blocks: can::Can
4848
from: mb(\d+)_64b_cs
@@ -52,22 +52,22 @@ transforms:
5252
blocks: can::Can
5353
from: mb(\d+)_8b_id
5454
to: mb_8b_id
55-
55+
5656
- !MakeRegisterArray
5757
blocks: can::Can
5858
from: mb(\d+)_16b_id
5959
to: mb_16b_id
60-
60+
6161
- !MakeRegisterArray
6262
blocks: can::Can
6363
from: mb(\d+)_32b_id
6464
to: mb_32b_id
65-
65+
6666
- !MakeRegisterArray
6767
blocks: can::Can
6868
from: mb(\d+)_64b_id
6969
to: mb_64b_id
70-
70+
7171
# For now delete all extra word registers.
7272
# Can be re-added when needed for HAL implementation.
7373
- !DeleteRegisters

data/transforms/mcxa/cdog.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
transforms:
22
- !MergeEnums
3-
from: cdog::vals::(Timeout|Miscompare|Sequence|State|Address)Ctrl
4-
to: cdog::vals::Ctrl
3+
from: cdog::(Timeout|Miscompare|Sequence|State|Address)Ctrl
4+
to: cdog::Ctrl

data/transforms/mcxa/ctimer.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
transforms:
22
- !RenameEnumVariants
3-
enum: ctimer::vals::([A-Za-z]+)(\d+)(.+)
3+
enum: ctimer::([A-Za-z]+)(\d+)(.+)
44
from: ([A-Z]+)[0-9O]([A-Z]+)_([0-9])
55
to: $1$2$3
66

77
- !RenameEnumVariants
8-
enum: ctimer::vals::Mr[0-9]s
8+
enum: ctimer::Mr[0-9]s
99
from: ([A-Z_]+)([0-9])
1010
to: MRS$2
1111

1212
- !MergeEnums
13-
from: ctimer::vals::Cap(\d+)(.+)
14-
to: ctimer::vals::Cap$2
13+
from: ctimer::Cap(\d+)(.+)
14+
to: ctimer::Cap$2
1515
skip_unmergeable: false
1616

1717
- !MergeEnums
18-
from: ctimer::vals::Em(\d+)
19-
to: ctimer::vals::Em
18+
from: ctimer::Em(\d+)
19+
to: ctimer::Em
2020
skip_unmergeable: false
2121

2222
- !MergeEnums
23-
from: ctimer::vals::Emc(\d+)
24-
to: ctimer::vals::Emc
23+
from: ctimer::Emc(\d+)
24+
to: ctimer::Emc
2525
skip_unmergeable: false
2626

2727
- !MergeEnums
28-
from: ctimer::vals::Mr(\d+)i
29-
to: ctimer::vals::Mri
28+
from: ctimer::Mr(\d+)i
29+
to: ctimer::Mri
3030
skip_unmergeable: false
3131

3232
- !MergeEnums
33-
from: ctimer::vals::Mr(\d+)r
34-
to: ctimer::vals::Mrr
33+
from: ctimer::Mr(\d+)r
34+
to: ctimer::Mrr
3535
skip_unmergeable: false
3636

3737
- !MergeEnums
38-
from: ctimer::vals::Mr(\d+)rl
39-
to: ctimer::vals::Mrrl
38+
from: ctimer::Mr(\d+)rl
39+
to: ctimer::Mrrl
4040
skip_unmergeable: false
4141

4242
- !MergeEnums
43-
from: ctimer::vals::Mr(\d+)s
44-
to: ctimer::vals::Mrs
43+
from: ctimer::Mr(\d+)s
44+
to: ctimer::Mrs
4545
skip_unmergeable: false
4646

4747
- !MergeEnums
48-
from: ctimer::vals::Pwmen(\d+)
49-
to: ctimer::vals::Pwmen
48+
from: ctimer::Pwmen(\d+)
49+
to: ctimer::Pwmen
5050
skip_unmergeable: false

data/transforms/mcxa/dma.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ transforms:
22
- !RenamePeripherals
33
from: EDMA0_TCD0
44
to: EDMA_0_TCD0
5-
5+
66
- !Rename
77
from: edma0_tcd0::(.*)
88
to: edma_0_tcd0::$1
99
type: All
1010

1111
- !Rename
12-
from: edma_0_tcd0::vals::Ssize
13-
to: edma_0_tcd0::vals::Size
12+
from: edma_0_tcd0::Ssize
13+
to: edma_0_tcd0::Size
1414

1515
- !ModifyFieldsEnum
16-
fieldset: edma_0_tcd0::regs::TcdAttr
16+
fieldset: edma_0_tcd0::TcdAttr
1717
field: dsize
18-
enum: edma_0_tcd0::vals::Size
18+
enum: edma_0_tcd0::Size
1919

2020
- !DeleteEnums
21-
from: edma_0_tcd0::vals::Int
21+
from: edma_0_tcd0::Int
2222

2323
- !DeleteEnums
24-
from: edma_0_tcd0::vals::(S|D)mod
24+
from: edma_0_tcd0::(S|D)mod
2525

2626
- !RenameInterrupts
2727
from: DMA0_CH([0-9]+)

0 commit comments

Comments
 (0)