Rahix / atdf2svd

Converter from Atmel's atdf format to CMSIS SVD
GNU General Public License v3.0
17 stars 10 forks source link

Peripherials missing addressBlock element #25

Closed evilmav closed 3 years ago

evilmav commented 3 years ago

According to CMSIS-SVD docs:

addressBlock:| Specify an address range uniquely mapped to this peripheral. A peripheral must have at least one address block, but can allocate multiple distinct address ranges. If a peripheral is derived from another peripheral, the addressBlock is not mandatory.

It seems that generated SVDs are generally missing this element. This breaks e.g. PlatformIO Debugger.

Rahix commented 3 years ago

You're right, atdf2svd is violating the spec here... Can you please try out whether #26 yields SVD files that fix usage with the PlatformIO Debugger?

evilmav commented 3 years ago

Thank you for your effort! Vscode parser does not crash any more, but does not show peripherials either... I would not bet it's the svd at fault though: I've cut out reduced a sample from the generated SVD for testing:

Chunk of XML ```xml Atmel ATmega1284P 8 8 read-write 0 0xff AC Analog Comparator 0x50 0x0 0x1 registers ACSR Analog Comparator Control And Status Register 0x0 read-write ACIS Analog Comparator Interrupt Mode Select bits [1:0] read-write true VAL_0x00 Interrupt on Toggle 0 VAL_0x01 Reserved 1 VAL_0x02 Interrupt on Falling Edge 2 VAL_0x03 Interrupt on Rising Edge 3 ACIC Analog Comparator Input Capture Enable [2:2] read-write ACIE Analog Comparator Interrupt Enable [3:3] read-write ACI Analog Comparator Interrupt Flag [4:4] read-write ACO Analog Compare Output [5:5] read-write ACBG Analog Comparator Bandgap Select [6:6] read-write ACD Analog Comparator Disable [7:7] read-write ```

Peripherials view stays empty, but it starts working if I set addressBlock.size to 0x4 or above. Unless there is some metadata missing and defaulting to 32bits, this seems more like vscode bug then SVD - chances are it was never tested with anything but ARM... Unfortunately, I can't figure out where their parser code even is...

Rahix commented 3 years ago

but it starts working if I set addressBlock.size to 0x4 or above.

Yeah that very much sounds like they hard coded a minimum register size of 32 bits or something similar. Not sure if there's anything we can do about it short of a fix on their side...

evilmav commented 3 years ago

Agree, just would have been nice to validate it in some way. The issue is in platformio-vscode-debug, for which I can not find the source although it's claimed to be open-sourced. I've created an Issue.

BTW, CMSIS provided SVDConv is claimed to be able to verify SVD files. Unfortunately, I couldn't get it to run without segfault on linux so far.

Rahix commented 3 years ago

BTW, CMSIS provided SVDConv is claimed to be able to verify SVD files. Unfortunately, I couldn't get it to run without segfault on linux so far.

Yeah it might be a good idea to validate the output of atdf2svd, I'm sure this isn't the only spec violation... To be honest we built it to barely emit enough output to make svd2rust work, with little regard for the actual SVD spec... Maybe there is a machine-readable schema available somewhere which we could compare against a generated file, if SVDConv really fails to run?

evilmav commented 3 years ago

There is this: CMSIS-SVD Schema File.

I've fed a generated SVD to it, the output is:

ATmega1284P.svd:2: element device: Schemas validity error : Element 'device': The attribute 'schemaVersion' is required but missing.
ATmega1284P.svd:5: element addressUnitBits: Schemas validity error : Element 'addressUnitBits': This element is not expected. Expected is one of ( series, version ).
ATmega1284P.svd fails to validate

Though the latter error seems to be due to sequence, which is unlikely to confuse a real parser.

PS Tried to run SVDConv from latest CMSIS release on windows. No luck either. Doesn't seem like anyone actually uses this thing ^^

maxgerhardt commented 3 years ago

If I can chirp in on this for a brief moment, I think there are good reference SVD files at https://github.com/gicking/STM8_headers for STM8 devices which also have lots of 8-bit registers as the AVR, and these ones were explicitly validated using SVDConv by the author to find all errors -- maybe you can find an error in this converter / source files easier with that.

Rahix commented 3 years ago

Interesting. @maxgerhardt, can you confirm that even the registers in register blocks with size less than 4 are showing up from those SVD files?