EmbeddedNim / svd2nim

Convert CMSIS ARM SVD files to nim register memory mappings
MIT License
19 stars 2 forks source link

Translating patched stm32f429.svd results in exception #10

Open BostonBoston opened 3 months ago

BostonBoston commented 3 months ago

SVD file: https://github.com/tinygo-org/stm32-svd/blob/main/svd/stm32f429.svd Output:

C:\Dev\svd2nim\build>svd2nim stm32f429.svd
C:\Dev\svd2nim\src\svd2nim.nim(110) svd2nim
C:\Dev\svd2nim\src\svd2nim.nim(86) main
C:\Dev\svd2nim\src\svd2nim.nim(34) processSvd
C:\Dev\svd2nim\src\svdparser.nim(319) readSVD
C:\Dev\svd2nim\src\svdparser.nim(287) parsePeripheral
C:\Dev\svd2nim\src\svdparser.nim(227) parseChildRegisters
C:\Dev\svd2nim\src\svdparser.nim(254) parseRegisterTreeNode
C:\Dev\svd2nim\src\svdparser.nim(209) parseField
C:\Dev\svd2nim\src\svdparser.nim(108) parseFieldEnum
Error: unhandled exception: Separate read/write enums not implemented [NotImplementedError]

This caused by field HSIRDY, which is a child of RCC.CR

<!--stm32f429.svd-->
<field>
    <name>HSIRDY</name>
    <description>Internal high-speed clock ready flag</description>
    <bitOffset>1</bitOffset>
    <bitWidth>1</bitWidth>
    <access>read-only</access>
    <enumeratedValues>
        <name>HSIRDYR</name>
        <usage>read</usage>
        <enumeratedValue>
            <name>NotReady</name>
            <description>Clock not ready</description>
            <value>0</value>
        </enumeratedValue>
        <enumeratedValue>
            <name>Ready</name>
            <description>Clock ready</description>
            <value>1</value>
        </enumeratedValue>
    </enumeratedValues>
</field>
auxym commented 3 months ago

Here's a branch with a quick fix as we discussed on discord: https://github.com/EmbeddedNim/svd2nim/tree/ignore_multiple_enums

Seems not to crash. Try it out and let me know

BostonBoston commented 3 months ago

Yes this did seem to do the trick for now.

auxym commented 3 months ago

I merged the fix for the svd2nim crash, but re-opening this, because the Nim file generated by svd2nim for the stm32f429 SVD file does not compile. Running nim check on it produces the following output:

C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(440, 3) Error: attempt to redefine: 'BCR1'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(2061, 3) Error: attempt to redefine: 'DIEPTXF0'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(2340, 3) Error: attempt to redefine: 'DIEPCTL0'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(2355, 3) Error: attempt to redefine: 'DOEPCTL0'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(3217, 3) Error: attempt to redefine: 'DIEPCTL0'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(3219, 3) Error: attempt to redefine: 'DIEPTSIZ0'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(3244, 3) Error: attempt to redefine: 'DOEPCTL0'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(3246, 3) Error: attempt to redefine: 'DOEPTSIZ0'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(3831, 7) Error: field initialized twice: 'BCR1'
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(3831, 7) Error: undeclared field: 'BCR1' for type stm32f429.FMC_Type [type declared in C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(435, 6)]
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(3826, 22) Error: expression '' has no type (or is ambiguous)
C:\Users\Francis\source\svd2nim\output_new\stm32f429.nim(3826, 22) Error: illformed AST: