ziutek / emgo

Emgo: Bare metal Go (language for programming embedded systems)
BSD 3-Clause "New" or "Revised" License
1.07k stars 69 forks source link

adding dsi peripheral support #22

Closed ianmcmahon closed 5 years ago

ianmcmahon commented 5 years ago

I've got an stm32f469 discovery board, I've added preliminary support for the chip and can successfully run blinky.

I'm trying to write a driver for the dsi display peripheral, and stm32xgen doesn't seem to handle its registers properly, along with perhaps a lot of other registers. The common factor seems to be registers which expose individual bits I think? like this:

 7591 #define DSI_GPDR_DATA1_Pos            (0U)
 7592 #define DSI_GPDR_DATA1_Msk            (0xFFU << DSI_GPDR_DATA1_Pos)            /*!< 0x000000FF */
 7593 #define DSI_GPDR_DATA1                DSI_GPDR_DATA1_Msk                       /*!< Payload Byte 1 */
 7594 #define DSI_GPDR_DATA1_0              (0x01U << DSI_GPDR_DATA1_Pos)            /*!< 0x00000001 */
 7595 #define DSI_GPDR_DATA1_1              (0x02U << DSI_GPDR_DATA1_Pos)            /*!< 0x00000002 */
 7596 #define DSI_GPDR_DATA1_2              (0x04U << DSI_GPDR_DATA1_Pos)            /*!< 0x00000004 */
 7597 #define DSI_GPDR_DATA1_3              (0x08U << DSI_GPDR_DATA1_Pos)            /*!< 0x00000008 */
 7598 #define DSI_GPDR_DATA1_4              (0x10U << DSI_GPDR_DATA1_Pos)            /*!< 0x00000010 */
 7599 #define DSI_GPDR_DATA1_5              (0x20U << DSI_GPDR_DATA1_Pos)            /*!< 0x00000020 */
 7600 #define DSI_GPDR_DATA1_6              (0x40U << DSI_GPDR_DATA1_Pos)            /*!< 0x00000040 */
 7601 #define DSI_GPDR_DATA1_7              (0x80U << DSI_GPDR_DATA1_Pos)            /*!< 0x00000080 */
Bad bitmask 0x01U << DSI_GPDR_DATA1_Pos : strconv.ParseUint: parsing "0x01U << DSI_GPDR_DATA1_Pos": invalid syntax
Bad bitmask 0x02U << DSI_GPDR_DATA1_Pos : strconv.ParseUint: parsing "0x02U << DSI_GPDR_DATA1_Pos": invalid syntax
Bad bitmask 0x04U << DSI_GPDR_DATA1_Pos : strconv.ParseUint: parsing "0x04U << DSI_GPDR_DATA1_Pos": invalid syntax
Bad bitmask 0x08U << DSI_GPDR_DATA1_Pos : strconv.ParseUint: parsing "0x08U << DSI_GPDR_DATA1_Pos": invalid syntax
Bad bitmask 0x10U << DSI_GPDR_DATA1_Pos : strconv.ParseUint: parsing "0x10U << DSI_GPDR_DATA1_Pos": invalid syntax
Bad bitmask 0x20U << DSI_GPDR_DATA1_Pos : strconv.ParseUint: parsing "0x20U << DSI_GPDR_DATA1_Pos": invalid syntax
Bad bitmask 0x40U << DSI_GPDR_DATA1_Pos : strconv.ParseUint: parsing "0x40U << DSI_GPDR_DATA1_Pos": invalid syntax
Bad bitmask 0x80U << DSI_GPDR_DATA1_Pos : strconv.ParseUint: parsing "0x80U << DSI_GPDR_DATA1_Pos": invalid syntax

The generated dsi.go has a bunch of constants with the same name, and I get a ton of errors:

src/stm32/hal/raw/dsi/f469xx--dsi.go:110:2:     other declaration of VCID
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:192:2: VCID0 redeclared in this block
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:111:2:   other declaration of VCID0
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:193:2: VCID1 redeclared in this block
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:112:2:   other declaration of VCID1
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:197:2: VCIDn redeclared in this block
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:116:2:   other declaration of VCIDn
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:509:2: VCID redeclared in this block
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:110:2:   other declaration of VCID
src/github.com/ianmcmahon/emgo/egpath/src/stm32/hal/raw/dsi/f469xx--dsi.go:510:2: VCID0 redeclared in this block

etc

I'm looking at stm32xgen's parser and trying to understand how to correct this, but it's a bit hard to follow. Any suggestions?

ianmcmahon commented 5 years ago

One thing I found is that it doesn't handle bare named registers, for instance DSI has a register called simply "VR", and there's a define for "DSIVR"; stm32xgen looks for a register called "VR" and fails to find anything, so the bits don't get added to it.

I put in code to skip any register bitmasks that end in _\d, they were failing to parse

The issue of redefined constants seems to be unrelated; I don't think stm32xgen has any provision to deal with register bits that have the same name in different registers.

ianmcmahon commented 5 years ago

I got a handle on the tweaks code in stm32xgen, came up with solutions to the issues and made a pull request:

https://github.com/ziutek/emgo/pull/23