EmbeddedNim / svd2nim

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

Improvement suggestions for increased compatibility #1

Closed erazor-de closed 1 year ago

erazor-de commented 1 year ago

I have the manufacturers svd for a STM32F103 here and I have 2 issues:

The svd defines a register named LOAD_ which is obviously a typo. The problem is that svd2nim creates an invalid object member which is also used in procedures but the type itself is created with only one underscore:

type STK_LOAD_Type = object
  loc: uint

type STK_Type = object
  CTRL*: STK_CTRL_Type
  LOAD*: STK_LOAD__Type
  VAL*: STK_VAL_Type
  CALIB*: STK_CALIB_Type

Error message from the compiler: Error: invalid token: trailing underscore. The invalid chars need to be filtered out consistently.

Also the svd is full of multi-line descriptions like

          <description>USB High Priority or CAN TX
        interrupts</description>

svd2nim ignores most descriptions, but the ones for interrupts are converted to normal comments

  USB_HP_CAN_TX_IRQn = 19,                                  # USB High Priority or CAN TX
        interrupts

Which does not work. These should be converted to multi-line comments or the newlines filtered out.

erazor-de commented 1 year ago

Addendum: The svd also defines interrupt 22 double and svd2nim puts this twice in the enum. Maybe using a set like container should help making the entries unique.

erazor-de commented 1 year ago

Another one: The base address of FSMC peripheral is at 0xa0000000. This gets translated to

type FSMC_BCR1_Type = object
  loc: uint

const FSMC* = FSMC_Type(
  BCR1: FSMC_BCR1_Type(loc: 0xa0000000),

The compiler complains Error: type mismatch: got 'int64' for '0x00000000A0000000'i64' but expected 'uint'. Maybe a cast to unsigned would help.

I'm still a noob with nim that's why I'm not attempting a pull request. I uploaded the unmodified svd as txt because svd is not supported by github: STM32F103.txt

auxym commented 1 year ago

Hey, just noticed this issue. Thanks for pointing out this stuff, I haven't tested on many SVD files so far. I'll have a look, most of what you pointed out shouldn't be too hard to fix.

auxym commented 1 year ago

See : #3

There's a few other things I want to add/check before merging, but you can try the branch right away, it should produce (at least) a valid nim file. Let me know if you find other issues.