Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: target board generation [PROPOSAL]#4999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mikesmitty wants to merge3 commits intotinygo-org:dev
base:dev
Choose a base branch
Loading
frommikesmitty:ms/board-refactor-test

Conversation

@mikesmitty
Copy link
Contributor

@mikesmittymikesmitty commentedAug 16, 2025
edited
Loading

At the networking SIG meeting the other day we got a little off topic, but one of the things that came up was reducing initial user friction and the relative difficulty of adding support for a new board. One idea that was mentioned was the fact that the-target flag can be used to specify an external json file and at least in my mind is the obvious choice for board-definitions. Its purpose is already to store board-specific information and passing in external json target files would make custom board definitions very easily accessible (a very popular request, of course:#3288,#3152,#2607,#2239)

I took a look over the various board definitions and the vast majority of the code boils down to just a few things:

  • Constants associating board labels, on-board LED(s), etc. to MCU pins
  • Constants or variables specifying the default UART/I2C/SPI pins to be configured
  • Variables specifying USB vendor/product id

All that can be reduced to a template generated from a JSON target file very easily so I put this together and converted a handful of targets as a demo.

The way this works is to take in the board section added to a target definition that contains the pin aliases, usb variables, etc. and templates out a file that is added to the cached TINYGOROOT for that target. I chose to put it into the cache because I wanted to avoid requiring that the TINYGOROOT be writable, but that can be changed pretty easily.

As a handy side-effect, this also makes auto-generating board definitions for already-supported MCUs fairly simple and would further reduce new-user friction if they find that their favorite board is already supported.

@mikesmitty
Copy link
ContributorAuthor

mikesmitty commentedAug 16, 2025
edited
Loading

As an example, here is the file generated for ametro-rp2350 target:
$TINYGOROOT/goroot-$HASHKEY/src/machine/boardgen_metro-rp2350.go

// Code generated by board-generator. DO NOT EDIT.//go:build cortexm && baremetal && linux && arm && rp2350 && rp && rp2350b && metro_rp2350package machine// Pin aliases for the Adafruit Metro RP2350.const (GP0                 = GPIO0GP1                 = GPIO1GP2                 = GPIO2GP3                 = GPIO3GP4                 = GPIO4GP5                 = GPIO5GP6                 = GPIO6GP7                 = GPIO7GP8                 = GPIO8GP9                 = GPIO9GP10                = GPIO10GP11                = GPIO11GP12                = GPIO12GP13                = GPIO13GP14                = GPIO14GP15                = GPIO15GP16                = GPIO16GP17                = GPIO17GP18                = GPIO18GP19                = GPIO19GP20                = GPIO20GP21                = GPIO21GP22                = GPIO22GP23                = GPIO23GP24                = GPIO24GP25                = GPIO25GP26                = GPIO26GP27                = GPIO27GP28                = GPIO28GP29                = GPIO29GP30                = GPIO30GP31                = GPIO31GP32                = GPIO32GP33                = GPIO33GP34                = GPIO34GP35                = GPIO35GP36                = GPIO36GP37                = GPIO37GP38                = GPIO38GP39                = GPIO39GP40                = GPIO40GP41                = GPIO41GP42                = GPIO42GP43                = GPIO43GP44                = GPIO44GP45                = GPIO45GP46                = GPIO46BUTTON              = GPIO24LED                 = GPIO23NEOPIXEL            = GPIO25WS2812              = GPIO25RX                  = GPIO1TX                  = GPIO0D2                  = GPIO2D3                  = GPIO3D4                  = GPIO4D5                  = GPIO5D6                  = GPIO6D7                  = GPIO7D8                  = GPIO8D9                  = GPIO9D10                 = GPIO10D11                 = GPIO11D22                 = GPIO22D23                 = GPIO23A0                  = GPIO41A1                  = GPIO42A2                  = GPIO43A3                  = GPIO44A4                  = GPIO45A5                  = GPIO46I2C0_SDA_PIN        = GP20I2C0_SCL_PIN        = GP21I2C1_SDA_PIN        = GP2I2C1_SCL_PIN        = GP3SPI0_SCK_PIN        = GPIO18SPI0_SDO_PIN        = GPIO19SPI0_SDI_PIN        = GPIO16SPI1_SCK_PIN        = GPIO30SPI1_SDO_PIN        = GPIO31SPI1_SDI_PIN        = GPIO28MOSI                = SPI1_SDO_PINMISO                = SPI1_SDI_PINSCK                 = SPI1_SCK_PINSD_SCK              = GPIO34SD_MOSI             = GPIO35SD_MISO             = GPIO36SDIO_DATA1          = GPIO37SDIO_DATA2          = GPIO38SD_CS               = GPIO39SD_CARD_DETECT      = GPIO40CKN                 = GPIO15CKP                 = GPIO14D0N                 = GPIO19D0P                 = GPIO18D1N                 = GPIO17D1P                 = GPIO16D2N                 = GPIO13D2P                 = GPIO12D26                 = GPIO26D27                 = GPIO27SCL                 = GPIO21SDA                 = GPIO20USB_HOST_DATA_PLUS  = GPIO32USB_HOST_DATA_MINUS = GPIO33USB_HOST_5V_POWER   = GPIO29UART0_TX_PIN        = GPIO0UART0_RX_PIN        = GPIO1UART1_TX_PIN        = GPIO8UART1_RX_PIN        = GPIO9UART_TX_PIN         = UART0_TX_PINUART_RX_PIN         = UART0_RX_PIN)const (xoscFreq                = 12usb_STRING_MANUFACTURER = "Adafruit"usb_STRING_PRODUCT      = "Metro RP2350")var (DefaultUART        = UART0usb_VID     uint16 = 0x239Ausb_PID     uint16 = 0x814E)

@aykevl
Copy link
Member

Oh this is an interesting approach!
Does this mean the cached GOROOT is board specific now?

@aykevl
Copy link
Member

I have been thinking about another approach, that is not necessarily competing with this PR but related. It's to provide some configurations (such as clock frequency / crystal selection / USB VID+PID / other configs) through flags set in the JSON file. One issue I have is that I make custom hardware and I run it at a low frequency to reduce current consumption. Right now I basically just reconfigure the clock, but it would be more convenient if I can just set a flag on the command line.

Something like:

{// ..."configs": {"main-clock": ["LSI-131kHz","LSI-262kHz","LSI-524kHz","HSI-16MHz","HSI-32MHz",...],    }}

And then the clock can be set either in a JSON file or via a command line flag (-config-main-clock=LSI-131kHz etc).

This could then be used in the runtime like so (switch should get optimized at compile time):

switchtinygo.getConfig("main-clock") {case"LSI-131kHz":// configure with main clock set to 131kHz// etc}

Something similar could be used for USB VID/PID pairs.

Anyway, this is somewhat off-topic but perhaps another way some configuration could be done. It wouldn't work for pin constants, obviously.

@mikesmitty
Copy link
ContributorAuthor

Oh this is an interesting approach! Does this mean the cached GOROOT is board specific now?

Yep, I made sure a file with the target name is added to the hash key to make sure it would split the caches out and avoid inter-mixing.

I really like those ideas you mentioned. I'll do some thinking about how they could be integrated

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@mikesmitty@aykevl

[8]ページ先頭

©2009-2025 Movatter.jp