Open demotomohiro opened 2 months ago
Thanks for reporting. I'll have to look into it in more detail. I'm also not a very deep expert on low-level stuff, so if someone wants to propose a PR, I'm very open.
The atomic access this microcontroller offers is a neat feature. But there isn't anything in the SVD 1.3 file spec that reliably serves as an indicator for this capability. So, for now, I recommend that support for atomic access be done outside the svd2nim tool.
Here is a snippet from the cited RP2040.svd file for a register that has atomic access:
<register>
<name>GPIO_OUT_SET</name>
<addressOffset>0x00000014</addressOffset>
<description>GPIO output value set</description>
<resetValue>0x00000000</resetValue>
<fields>
<field>
<name>GPIO_OUT_SET</name>
<description>Perform an atomic bit-set on GPIO_OUT, i.e. `GPIO_OUT |= wdata`</description>
<bitRange>[29:0]</bitRange>
<access>write-only</access>
</field>
</fields>
</register>
As you can see, the only mention of "atomic" is in the description. The field access write-only
, which is not indicative of atomic access.
The atomic access this microcontroller offers is a neat feature. But there isn't anything in the SVD 1.3 file spec that reliably serves as an indicator for this capability.
That right. So how about to generate code for RP2040, when svd2nim see that following device name and vendor in the input SVD file?
<vendor>Raspberry Pi</vendor>
<name>RP2040</name>
<series>RP</series>
According to '2.1.2. Atomic Register Access' in RP2040 Datasheet, all registers in RP2040 supports atomic access excepts some registers in SIO.
If it is still not good and should not be merged to svd2nim, I will fork svd2nim and implement the feature.
I don't mind "special case" codegen for the rp2040. I'd accept a PR.
It might be a bit of PITA with the current (poor) organization of the codegen module in svd2nim. One improvement I planned to make at some point was creating some sort of "CodegenOptions" global singleton in the codegen module that would contain all the info necessary for all the procs in there. It could also contain some sort of "rp2040" flag or device name string.
I used svd2nim for SVD file for RP2040 in https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2040/hardware_regs/RP2040.svd But procedures in generated module
rp2040.nim
doesn't write registers atomitically.Please read '2.1.2. Atomic Register Access' in RP2040 Datasheet in https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf This header file in Raspberry Pi Pico SDK wraps atomic memory accesses: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_base/include/hardware/address_mapped.h
modifyIt
templates should not be generated for RP2040 as it seems cannot be atomic. I think following procs should to be added: