{{ message }}
tools/boardgen.py: Make per-pin content output extensible.#19130
Open
agatti wants to merge 1 commit intomicropython:masterfrom
Open
tools/boardgen.py: Make per-pin content output extensible.#19130agatti wants to merge 1 commit intomicropython:masterfrom
agatti wants to merge 1 commit intomicropython:masterfrom
Conversation
This commit lets classes extending the base `PinGenerator` class to override the process of generating extra per-pin content when creating the pins' information source file. There are cases in which one may want to have more control on the part of the source generation process that dumps additional per-pin information to the source file. The current approach works fine if each pin generates self-contained additional data to be placed in the source file, but there is no clean way to provide a prologue or an epilogue to that content. For example, if one wants to emit a single consolidated additional pin data table it is not that convenient to be able to consistently emit the table start definition and the table end markers. With these changes all one has to do to achieve this is to override `PinGenerator.print_pin_source` in their PinGenerator-derived class to either wrap the output or to replace what is being output altogether. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR lets classes extending the base
PinGeneratorclass to override the process of generating extra per-pin content when creating the pins' information source file.There are cases in which one may want to have more control on the part of the source generation process that dumps additional per-pin information to the source file. The current approach works fine if each pin generates self-contained additional data to be placed in the source file, but there is no clean way to provide a prologue or an epilogue to that content.
For example, if one wants to emit a single consolidated additional pin data table it is not that convenient to be able to consistently emit the table start definition and the table end markers. With these changes all one has to do to achieve this is to override
PinGenerator.print_pin_sourcein their PinGenerator-derived class to either wrap the output or to replace what is being output altogether.Testing
The
stm32/PYBV10board firmware was rebuilt from scratch without errors to make sure the changes still output the additional pin data as expected.Trade-offs and Alternatives
This can probably be achieved by overriding
PinGenerator.load_inputsto add the per-pin additional data header at the end of the function and overridingPinGenerator.print_sourceto add the data trailer before the rest of the function executes. It is not really that intuitive or clean.Generative AI
I did not use generative AI tools when creating this PR.
In my CH32V port I'm trying a couple of different approaches to reduce the pin tables' size [1], and the most promising involves consolidating the AFIO pin tables into one single entity, which right now it is not possible with the board generator in a clean way (unless the workaround mentioned in the trade-offs section is used).
Right now the default
tools/boardgen.pyoutput structure for the pins/AFIO.cfile is as such:assuming that PIN has a pointer to a relevant AFIO structure and a byte counting how many entries the AFIO structure contains, for a total of up to 8 bytes (if the count is the last entry in the struct).
With a consolidated AFIO table, in my pin structures I only need to reference the starting index inside the table and the count, with each PIN using an
uint8_tfor each value (count = 0 indicates no AFIOs). With proper structure packing that'd provide some substantial savings in the ROM-ed structures without complicating themachine.Pincode too much. Hence the reason for an AFIO prologue/epilogue extension point.[1] Although the CH32V's main inspiration for peripheral design is the STM32, they don't provide automatic AFIO pin tracking unlike the STM32 does. Nothing stops you from having the same pins shared among several peripherals and then change the pins' values via the GPIO registers - making a mess out of the board state if you're not careful. This means that I have to keep everything in sync myself and do the peripheral pin management in code to make sure pins are claimed/released and used only on one peripheral at a time.
I'm not sure if there's any other port doing all of this, but since some peripherals can have their pins reconfigured at runtime (eg. SPI) this is necessary otherwise pins would retain a stale state (both in the interpreter and in the GPIO registers) and all sort of fun will happen in that case...