Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pinctrl: introduce pin configuration autogenerator #1

Closed
wants to merge 18 commits into from

Conversation

gmarull
Copy link
Member

@gmarull gmarull commented Oct 11, 2021

This PR adds support for autogenerating valid pin configurations for GD32 devices based on a set of configuration files build from datasheets/reference manuals. The script supports both, devices using the remap model, e.g. GD32F103 and devices using the alternate function model, e.g. GD32F450.

The autogenerated definitions contain the following information:

Remap/AFIO model:

  • Port (e.g. A, B, C...)
  • Pin number (0...15)
  • Mode (input, alternate, analog)
  • AFIO configuration (PCF0/1, PCFx position, PCFx width, PCFx selection)

AF model:

  • Port (e.g. A, B, C...)
  • Pin number (0...15)
  • Mode (ANALOG, AFx, x=0..15)

The definitions can be used later in a pinctrl driver like this:

#include <dt-bindings/pinctrl/gd32vf103c(b-8)xx-pinctrl.h>

&pinctrl {
    usart1_default: usart1_default {
        pins1 {
            pinmux = <USART1_TX_PD5_RMP>, <USART1_CTS_PD3_RMP>;
        };
        pins2 {
            pinmux = <USART1_RX_PD6_RMP>, <USART1_RTS_PD4_RMP>;
            bias-pull-up;
        };
    };
};

Considerations:

  • Remap suffix is added for signals that can be remapped (AFIO model). This makes it easier to spot misconfigurations (all signals need to have the same suffix on a peripheral, since remap happens to all peripheral signals)
  • Linux model for STM32 is considered for representation. This model is quite flexible and allows solving problems like this which can't be solved in a node-based approach. Node-based approach also requires to generate a node per supported state, making it harder to extend to future states.
  • No "defaults" are introduced as in STM32 (not possible with defines anyway). While it's true that in some cases some settings will always be applied, e.g., open-drain for I2C, many others depend on PCB layout or peripheral operating conditions. Therefore, it doesn't make sense to add "defaults".

Files were converted to unix style using dos2unix:
  find . type f -print0 | xargs -0 dos2unix -k

Signed-off-by: Gerson Fernando Budke <[email protected]>
The GigaDevices CAN driver uses similar names defined in Zephyr.  This
moves conflicts to source files.

Signed-off-by: Gerson Fernando Budke <[email protected]>
Zephyr define timer_init function which conflicts with GigaDevice
timer driver API.  This rename timer_init method to timer_initialize
to solve conflict.

Signed-off-by: Gerson Fernando Budke <[email protected]>
@gmarull gmarull force-pushed the pinctrl-autogen branch 6 times, most recently from 07d4914 to 862f41c Compare October 14, 2021 20:46
Signed-off-by: Gerard Marull-Paretas <[email protected]>
@gmarull gmarull force-pushed the pinctrl-autogen branch 2 times, most recently from 0be8ff8 to bbb02b1 Compare October 14, 2021 21:55
Add common AFIO utilities, e.g. config bit field and helper macros.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Add details on the format of the pin configuration files.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
The gd32pinctrl script autogenerates valid pinctrl definitions from a
configuration file.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Add pin configurations for the GD32VF103XX series. Information has been
taken from datasheet/reference manual.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Add definitions for remap options.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Files autogenerated using gd32pinctrl script.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Add pin configurations for the GD32F450XX series. Information has been
taken from datasheet.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Files autogenerated using gd32pinctrl script.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
The include folder is used to store autogenerated pinctrl headers.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Test that generated content matches reference files.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Add development requirements, including flake8 config file.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Add readme with some usage details (dependencies, tests, etc.)

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Signed-off-by: Gerard Marull-Paretas <[email protected]>
Signed-off-by: Gerard Marull-Paretas <[email protected]>
@gmarull gmarull changed the title [WIP] pinctrl: introduce pin configuration autogenerator pinctrl: introduce pin configuration autogenerator Oct 14, 2021
@gmarull gmarull marked this pull request as ready for review October 14, 2021 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants