rust-embedded / svd

A CMSIS-SVD file parser
Apache License 2.0
71 stars 55 forks source link

M302: Size of Register must be 8, 16 or 32 Bits #237

Open kossnikita opened 1 year ago

kossnikita commented 1 year ago

From CMSIS SVDConv docs

Message Number | Type | Message Text -- | -- | -- M302 | ERROR | Size of Register 'NAME':'NUM' must be 8, 16 or 32 Bits

This limitation is not obvious to me. For example, it is easier to create a 12-bit register for a 12-bit ADC than a 32-bit register with only one field. svd2rust handles this by creating an unsafe method for working with such registers. But CMSIS prohibits such svd files. Should utilities handle this error?

kossnikita commented 1 year ago

I think this issue for rust-embedded/svd. Feel free to move it.

burrbull commented 1 year ago

This limitation is not obvious to me. For example, it is easier to create a 12-bit register for a 12-bit ADC than a 32-bit register with only one field.

Register is how CPU reads/writes memory. It does it by u8,u16,u32, u64 depending on architecture. Even if it physically only 12 lines are connected to register mapped on memory. Field is abstraction which you can push/pop from register.

burrbull commented 1 year ago

P.S. Even if you create u8 or u16 register on 32-bit arch, first you need to check in reference manual can this register or all registers of peripheral be manipulated in byte or word mode

kossnikita commented 1 year ago

Do you mean that there are modes in which the processor can read or write registers differently? I thought that the data bus always has a fixed width. For example, a 32bit processor will always read/write all 32bits.

burrbull commented 1 year ago

Do you mean that there are modes in which the processor can read or write registers differently?

Yes (at least for ARM), depending on asm command you are using to read/write register microprocessor can react differently.

Usually this is allowed for data registers, for example SPI DR, TIM ARR, etc. This is what <size> tag about.

изображение

kossnikita commented 1 year ago

Thank you, it's clear now. So should introduce this limitation into the svdtool or into the svd?

burrbull commented 1 year ago

Yes, make sense in svd.

burrbull commented 11 months ago

related to #247