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

drivers: pinctrl device interface (Linux-like) and STM32F0 driver #5799

Closed
wants to merge 45 commits into from

Conversation

b0661
Copy link
Collaborator

@b0661 b0661 commented Jan 23, 2018

The PR provides a new device interface for pin controllers. As a proof of concept the interface is implemented and tested for the STM32FOx SoC.

The Zephyr pin controller follows the concepts of the Linux PINCTRL (PIN CONTROL) subsystem.

The Zephyr pin controller does not provide the full scope of the Linux PINCTRL subsystem. Also the PINCTRL interface is specific to Zephyr and not compatible (but similar) to the Linux PINCTRL interface.

As a major goal the device tree bindings are kept compatible to the Linux pinctrl bindings as much as possible.

Review

This is the master pull request.

To ease commenting and review several review/ RFC pull requests are available that focus only on specific aspects. Please use these PRs instead of this one. I will do my best to keep them in sync.

Some patches are extracted for independent inclusion into master:

Features

  • The PINCTRL device driver provides applications and other drivers access:

    • to the drivers control properties sich as pins, groups, pinctrl states,
      and functions,
    • to pin configuration,
    • to pin multiplexing, and
    • to pin state setting.
  • The driver also provides initial setup of pin configuration and pin multiplexing controlled by the device tree pinctrl state information (the "default" state). This obsoletes the SoC specific pinmux.c.

  • PINCTRL device driver API and usage documentation is added.

    Relates to device tree: generate pinmux #4830

  • The PINCTRL device interface provides also the PINMUX interface as a generic shim. For more sophisticated configuration the PINCTRL interface can be used directly.

    Fixes Streamline GPIO, Pinmux driver API #2288, api: pinmux/gpio: It isn't possible to set pins as input and output simultaneously #6084

  • The PINCTRL device interface provides a superset to the GPIO configuraton properties with well understood configuration properties. It can be used instead of the GPIO configuration interface.

    Relates to rework GPIO flags #4506.

  • The new GPIO-PINCTRL driver (GPIO that uses the PINCTRL driver as backend) provides GPIO pin number to PINCTRL pin number mapping controlled by device tree info (gpio-ranges).

  • Documentation for PINCTRL API and for extensions to the GPIO API, and PINCTRL and GPIO usage documentation is added.

    Relates to device tree: gpio #4829

Design

PINCTRL driver interface

The PINCTRL driver interface API is added in include/pinctrl.h. Defines that may be used in the device tree and in the interface are in include/pinctrl_common.h. That way they can be included from the interface and from the device tree bindings (e.g include/dt-bindings/pinctrl_stm32.h). Within include/pinctrl.h a generic shim that maps the PINMUX interface to the PINCTRL interface is added.

GPIO driver interface extensions

For GPIO-PINCTRL drivers (GPIO drivers that use the PINCTRL driver as backend) generic PIN number defines are introduced. These PIN number defines allow to describe a set of pins by just or-ing the defines. Such operations on a set of pins of a port can easily be described and implemented.

Due to the new gpio-ranges device tree directive a mapping from GPIO pin numbers to PINCTRL pin numbers is possible.

Extraction of PINCTRL info from device tree

Extraction of device tree info is - as usual - done by the extract_dts_includes.py script. To allow modularization of the monolitic script all global data and functions are factorized to a python module that can be imported by other modules. The extraction of pinctrl directives and gpio-ranges directives is added as separate python modules.

For a pin controller node extract_dts_includes.py extracts five data sets:

  • FUNCTION
    For all active client nodes that reference a pin-controller by pinctrl-x(&pinctrl, ...) FUNCTION defines are generated. The function equals the client node.
  • STATE_NAME
    For all pinctrl names of pinctrl-x directives of active client nodes STATE_NAME defines are generated. This is mostly to allow deduplication of commonly used state names such as e.g. "default".
  • PINCTRL_STATE
    For all pinctrl-x directives of active client nodes PINCTRL_STATE defines are generated. The pinctrl state references the FUNCTION (aka. node) it is given in. The pinctrl state also references the STATE_NAME given in the pinctrl-names directive associated to the pinctrl-x directive. All the pins that a pinctrl state controls are regarded to be a pin group. The name of the pin group is the same as the name of the pinctrl state.
  • PINCTRL
    For all subnodes of pin configurations referenced by active client nodes, pinctrl-x(&xxx, pinconf_a, ...), PINCTRL defines are generated. The pinctrl references the FUNCTION (aka. node) it is referenced from. The pinctrl also references the PINCTRL_STATE it is referenced from.
  • GPIO_RANGE
    For all gpio-ranges directives of active GPIO nodes GPIO_RANGE defines are generated.

For the clients of pin controllers extract_dts_includes.py extracts two data sets:

  • PINCTRL_CONTROLLER
    For all pin controllers that are referenced in a pinctrl-x directive PINCTRL_CONTROLLER defines are generated.
  • PINCTRL
    For all subnodes of pin configurations referenced by active client nodes, pinctrl-x(&xxx, pinconf_a, ...), PINCTRL defines are generated. The pinctrl references the PINCTRL_CONTROLLER given in the pinctrl-x directive. The pinctrl also references the PINCTRL_STATE the pin controller associates to this pinctrl.

Generic PINCTRL driver template

To simplify driver implementation a template for the hardware independent pinctrl driver functions and all driver data structures and content is added.

The pin controller template provides the equivalent to a C++ template for pin controller driver implementation. The template parameters are given by simple python global variables. The template is expanded by the inline code generator with the help of Python. The template generates the appropriate data structures and fills them using the information provided in generated_dts_board.h.

The usage of the PINCTRL template itself is optional.

STM32F0 Driver Implementation

  • New STM32 PINCTRL driver
    Driver implementation in pinctrl_stm32.[ch].

  • Extended STM32 GPIO driver using the pinctrl driver as a backend
    The driver implementation for gpio_pinctrl_stm32.[ch] starts with a copy of the gpio_stm32 driver to enable easy tracking of changes. The driver is currently only used for STM32F0x SoCs. At the end it shall become the only driver for STM32Fx SoCs.

  • Extended STM32 SPI driver using the new pinctrl device tree directives.
    The driver implementation for spi_stm32.[ch] starts with a copy of the spi_ll_stm32 driver to enable easy tracking of changes. The driver is currently only used for STM32F0x SoCs. At the end it shall become the only driver for STM32Fx SoCs.

Testing

Samples were executed sucessfully on the NUCLEO F091RC board:

  • samples/hello_world
  • samples/basic/blinky
  • samples/basic/button

Driver tests were also executed on the NUCLEO F091RC board:

  • tests/drivers/gpio/gpio_basic_api
  • tests/drivers/spi/spi_loopback
  • tests/drivers/uart/uart_basic_api

Unit tests were created and executed for:

  • tests/unit/scripts/extract_dts_includes
  • tests/unit/drivers/pinctrl

Transition Strategy

Pinctrl Driver

The pinctrl interface and driver is independent from other drivers.

STM32F0x is switched to the pinctrl driver. Others may switch at any time.

Other Drivers

Strategy is to have two driver variants during transition time. The new/enhanced driver is started as a pure copy of the current one to enable easy tracking of changes. After all driver users have switched to the new driver variant it should replace the current one and only one driver should be there to maintain.

Patches

  • PINCTRL driver interface and related GPIO driver interface

    • drivers: pinctrl: Add pinctrl driver interface
    • drivers: pinctrl: Add pinctrl driver userspace interface
  • Extraction of PINCTRL and related info from device tree
    (with some preparatory work)

    • dts: bindings: add generic binding for pinctrl devices
    • dts: bindings: extend device bindings by pinctrl
    • scripts: extract_dts_includes.py: new pinctrl and related directives
    • scripts: prepare Zephyr inline code generation
    • scripts: add Zephyr inline code generation
  • Template specifically for pinctrl driver implementations

    • drivers: pinctrl: add pinctrl driver template
  • STM32F0 pinctrl driver implementation as proof of concept

    • drivers: pinctrl: Add STM32 pinctrl driver and DTS
  • STM32F0 GPIO driver with PINCTRL driver backend as proof of concept

    • drivers: gpio: Prepare STM32 GPIO driver with pinctrl backend
    • drivers: gpio: Add STM32 GPIO-PINCTRL driver and DTS
  • STM32F0 SPI driver with device tree support as proof of concept

    • drivers: spi: Prepare STM32 SPI driver with pinctrl DTS support
    • drivers: spi: Add STM32 SPI driver with pinctrl DTS support
  • STM32FO device tree

    • dts: STM32F0: extend gpio, spi, i2c, pinctrl nodes
  • STM32F0x based boards configuration set to pinctrl as proof of concept

    • boards: STM32F0x: switch to usage of pinctrl, gpio-pinctrl
  • Testing - Unit Tests

    • cmake: dts: allow default dts bindings dir to be overwritten
    • test: scripts: extract_dts_includes.py pinctrl directive
    • test: drivers: unit test pinctrl template API
  • Testing - Drivers

    • tests: drivers: gpio: support NUCLEO F091RC and F030R8 boards
    • tests: drivers: spi: support NUCLEO F0x boards
  • Testing - Samples

    • samples: button: support gpio pinctrl pin definition
    • samples: can: support gpio pinctrl pin definition
  • General tools for documentation

    • doc: doxygen: predefine DOXYGEN to enable ifdef guards for docu
  • Documentation

    • doc: api: add pinctrl and gpio-pinctrl interface
    • doc: pinctrl: Add pinctrl driver documentation
    • doc: pinctrl: Add STM32 pinctrl driver documentation
    • doc: subsystems: add inline code generation documentation
    • doc: boards: update NUCLEO F091RC doc
    • doc: boards: update STM32F072B DISCO doc

Todo

  • -- NEXT --
    • todo: squash xxx-prepare patches after acceptance
    • todo: indent parameters properly (indent against last '(' + 1 space)
    • TBD: scripts: codegen: add function for device_declare and device_init.
    • TBD: pinctrl: constify some references in the pinctrl interface

Change History

  • 2018-06-23

    • scripts: extract_dts_includes.py: fix false info message - new try
    • test: scripts: amended extract test to use state id for expected value definition and find out correct pin configuration index for expected values
  • 2018-06-15

    • dts: bindings: add generic binding for clock consumer and provider
    • scripts: extract_dts_includes.py: fix false info message
    • scripts: extract_dts_includes.py: refactor for better maintenance
    • scripts: extract_dts_includes.py: split enhancements in single commits
  • 2018-06-15

    • dts: bindings: removed xxx-controller directives that are not in linux
    • scripts: extract_dts_includes.py: added heuristics to generate xxx-controller without explicit directive given.
    • scripts: extract_dts_includes.py: improved/ extended clock related directive extraction.
    • scripts: extract_dts_includes.py: moved interrupts directive to an extra module
    • scripts: codegen: moved code generation to build time (from configuration time).
    • scripts: codegen: improved error reporting, fixed off by one for line numbers.
    • scripts: codegen: made most of codegen device tree code a codegen template.
    • scripts: codegen: added template for simple driver initialisation.
    • drivers: pinctrl: moved pinctrl_tmpl.c to codegen templates.
    • drivers: pinctrl: adapted userspace to Z_SYSCALL macros.
    • drivers: serial: make STM32 UART use codegen simple driver template
    • test: drivers: adapted pinctrl unit test to build time codegen invocation
    • doc: codegen: update codegen templates doc
    • sanitycheck: fix false passed on localized error message
    • dts: bindings: fix NXP generation value structure
    • removed - scripts: extract_dts_includes.py: fix multiple include in bindings - now upstream
  • 2018-05-21

    • samples: can: adapt to pinctrl GPIO pin definition
    • dts: bindings: adapt can related bindings for pinctrl
    • boards: STM32F0x: provide CAN also to nucleo_f091rc, add CAN pinctrl to stm32f072b_disco.
    • test: scripts: extract_dts_includes.py change test to get rid of shippable error
    • scripts: extract_dts_includes.py change exchange generic data variable by explicit data structures to prevent key collision.
  • 2018-05-18

    • doc: gpio: indentation correction moved to gpio doc commit
    • codegen: adapted CMake codegen functions to follow zephyr_include/ zephyr functions
    • codegen: describe build commands for code generation
    • scripts: extract_dts_includes.py: fix multiple include in bindings
  • 2018-05-10

    • drivers: spi: adapted STM32 driver to upstream changes
    • test: scripts: extract_dts_includes.py pinctrl directive - make test independent of armv7-m.dtsi, skeleton.dtsi
    • doc: pinctrl: cleanup rst and indentation in gpio.rst
    • doc: codegen: correct typos and add code generation usage rules
  • 2018-04-03

    • drivers: pinctrl: split interface in a basic and an extended interface. The extended interface is selected by CONFIG_PINCTRL_RUNTIME_DTS.
    • drivers: pinctrl: updated userspace interface and made it an extra commit
    • drivers: pinctrl: update pinctrl driver template
    • drivers: gpio: enable generic GPIO pin defines in case CONFIG_PINCTRL is set.
    • scripts: codegen: replaced CMakeCache.txt access by the implementation from zephyr_run.py
    • test: scripts: extract_dts_includes.py pinctrl directive - make test independent of gpio_common.h
    • test: scripts: extract_dts_includes.py pinctrl directive - removed .indent.pro
    • doc: pinctrl: update pinctrl documentation for basic and extended interface, clarify GPIO pin definitions.
    • doc: codegen: update intro
  • 2018-03-27

    • doc: usage documentation for GPIO improved
    • removed - doc: sphinx: Add Pygment lexer for DTS - now upstream
    • removed - scripts: extract_dts_includes.py: factorize globals for module usage - now upstream
  • 2018-03-22

    • Created extra PRs for review: drivers: add pinctrl device interface #6760 [WIP] scripts: extract_dts_includes.py: enhance #6761 scripts: add Zephyr inline code generation with Python #6762
    • scripts: prepare Zephyr inline code generation
    • scripts: add Zephyr inline code generation using Python - replaces CHAOS preprocessor library
    • scripts: improve DTDirective to provide general label formatting
    • drivers: pinctrl: add pinctrl driver template
    • drivers: convert proof of concept drivers to inline code generation - replaces CHAOS preprocessor library
    • test: drivers: unit test pinctrl template API
    • doc: subsystems: add inline code generation documentation
    • doc: pinctrl: mark internal functions @internal
    • doc: pinctrl: update pinctrl driver documentation by inline code generation
    • removed - drivers: add driver library - replaced by inline code generation
    • removed - drivers: pinctrl: add pinctrl driver library - replaced by template for inline code generation
    • removed - ext: lib: Add Chaos preprocessor library - replaced by inline code generation with Python
    • removed - ext: lib: Update build system to support Chaos preprocessor lib
    • removed - ext: lib: Add Chaos preprocessor library documentation
    • removed - ext: lib: Fix typo in Chaos preprocessor library documentation
    • removed - test: drivers: unit test pinctrl lib API - library is replaced by pinctrl driver template
    • removed - doc: subsystems: Add Chaos preprocessor library documentation - replaced by inline code generation
  • 2018-02-25

    • extract_dts_includes: handle compatible directive
    • driver_lib: added macros for check against compatible directive
    • kconfig: replaced GPIO_LEGACY_API config by check against GPIO compatible string
    • spi_stm32: guarded driver source compilation by compatible check and squashed DTS and driver patches
    • pinctrl_stm32: guarded driver source compilation by compatible check and squashed DTS and driver patches
    • gpio_pinctrl_stm32: guarded driver source compilation by compatible check and squashed DTS and driver patches
    • pinctrl: moved kconfig pinctrl infrastructure setup to STM32 pinctrl driver patch.
    • boards: NUCLEO F030R8: fix spi requesting the same pin as usart2
  • 2018-02-21

    • boards: completely switch STM32F0x boards to pinctrl (removed any board specific pinmux.c)
    • pinctrl_stm32: fix gpio data initialization if intermediate GPIO is missing (e.g. GPIOE of STM32F030)
    • doc: chaos: fix file open with pathlib object in python 3.5 in chaos_pp sphinx directive
    • doc: chaos: sort documentation files before generating documentation
  • 2018-02-20

    • driver: Add generic driver implementation support macro library driver_lib.h
    • pinctrl: Add convenience functions to distinguish function numbers for device and pinmux.
    • spi_stm32: Generate driver variant spi_stm32 for STM32F0x and keep stm32_spi_ll for all other.
    • gpio_pinctrl_stm32: Base driver on gpio_stm32 to allow easy tracking of changes.
    • gpio: Use GPIO_LEGACY_API kconfig similar to SPI
    • doc: Generate CHAOS preprocessor lib documentation by sphinx directive
    • doc: Support DTS in code-block directives, fixes doc: Zephyr sphinx/pygments support DTS #6029
  • 2018-01-28

    • dts bindings: extend generic bindings for pinctrl, gpio-pinctrl, and spi to make the device-controller directives mandatory.
    • dts bindings: extend STM32 specific bindings for pinctrl, gpio-pinctrl, and spi to include the device-controller directive.
    • extract_dts_includes: extract device-controller directives
    • extract_dts_includes: unit test also device-controller directive extraction
    • pinctrl_lib: make checkpatch happy about some unusual macros.
    • pinctrl_lib: make enable mux request a library parameter.
    • pinctrl_stm32: use the pin-controller directives. This obsoletes the respective defines in soc.h.
    • gpio_pinctrl_stm32: use the gpio-controller directives. This obsoletes the respective defines in soc.h.
    • gpio_pinctrl_stm32: no need to check for active nodes anymore, the information is now provided by the gpio-controller directive.
    • spi_ll_stm32: use the spi-controller directives. This obsoletes the respective defines in soc.h.
    • stm32f0: gpio: added st,bank-name DTS directive to get a port (bank) indication that is independent from the label directive.
    • stm32f0: moved default configuration to Kconfig.defconfig.series
    • nucleo_f091rc: moved default configuration to Kconfig.defconfig
    • nucleo_f091rc: made documentation updates a separate commit
    • doc: updated pinctrl and gpio usage docs to describe new device-controller directive usage.
  • 2018-01-24

    • Initial PR

Signed-off-by: Bobby Noelte b0661n0e17e@gmail.com

@codecov-io
Copy link

codecov-io commented Jan 23, 2018

Codecov Report

Merging #5799 into master will increase coverage by 11.99%.
The diff coverage is 50.33%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #5799       +/-   ##
===========================================
+ Coverage   52.17%   64.16%   +11.99%     
===========================================
  Files         215      432      +217     
  Lines       26013    41308    +15295     
  Branches     5594     6938     +1344     
===========================================
+ Hits        13572    26506    +12934     
- Misses      10183    11640     +1457     
- Partials     2258     3162      +904
Impacted Files Coverage Δ
include/gpio.h 0% <0%> (ø)
include/pinctrl.h 41.66% <41.66%> (ø)
tests/unit/scripts/extract_dts_includes/main.c 61.33% <61.33%> (ø)
include/net/ethernet_mgmt.h 0% <0%> (-50%) ⬇️
boards/posix/native_posix/cmdline.c 16.21% <0%> (-44.66%) ⬇️
include/misc/rb.h 60% <0%> (-40%) ⬇️
include/entropy.h 33.33% <0%> (-33.34%) ⬇️
drivers/entropy/fake_entropy_native_posix.c 70.58% <0%> (-29.42%) ⬇️
kernel/stack.c 67.3% <0%> (-26.93%) ⬇️
kernel/msg_q.c 77.77% <0%> (-16.96%) ⬇️
... and 355 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 96784df...af673d5. Read the comment docs.

@b0661 b0661 force-pushed the pinctrl_test branch 2 times, most recently from 76611e9 to efa7ae1 Compare January 23, 2018 21:13
Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one suggestion and a couple of questions

==============================

There are 2 samples that allow you to test that the button and LED on
the board are working properly with Zephyr:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd delete the code block below and just say here:

 ... with Zephyr:  :ref:`blinky-sample` and :ref:`button-sample`

Copy link
Collaborator Author

@b0661 b0661 Jan 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

+--------+--------+--------------------+
| Signal | GPIO | Connection on CN10 |
+========+========+====================+
| IN | PB4 | 27 <- 29 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the arrow indicates here for a jumper? Can you explain?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrow shows signal from output to input.

+========+========+====================+
| SCK | PB3 | 31 (open) |
+--------+--------+--------------------+
| MISO | PB4 | 27 <- 29 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question, what does the arrow mean for a jumper?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrow shows signal from output to input

Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hit submit way to early on that previous review. Looks like we're bringing in a whole set of Chaos subsystem documentation into the Zephyr project's documentation set here, and it's an external component, yes? Would seem better to refer to their documentation rather than duplicating it here...

@@ -0,0 +1,316 @@
..
Copyright (c) 2017 Bobby Noelte
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't been putting copyright or SPDX tags on documentation...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing the documentation for pinctrl I had a major problem to figure out whether I can re-use the pinctrl docs from linux. In the end, after your advise in an email, I just reference the documentation and otherwise somehow re-invented the wheel. I would not mind somebody else re-using my documentation. So I pledge to have the copyright notice also in the documentation. Al least not to remove it in my documentation.

Pin Multiplexing
****************

Pin Initialisation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

American spelling please (Initialization)


Pin Multiplexing
****************

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... more coming I presume?


An active argument is an argument that expands each time that it is scanned by the preprocessor.

* `Active Arguments <file:../../../../../ext/lib/preprocessor/chaos/built-docs/active-arguments.html>`_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... we need to figure out a better way to link to this documentation...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to copy the html files to the sphinx html output directory during make htmldocs? Sorry there is no offical web site that can be referenced.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not feeling good about using the Zephyr project as the home for documenting an (unrelated) external component (Chaos preprocessor library). I'll let @nashif advise how to proceed here.


.. _chaos_pp:

Chaos Preprocessor Library
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my. Not sure we want to document a component in /ext like this. Isn't there an external repo/site we can refer to rather than, what looks like, duplicating the library documentation here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, there is no external documentation site.

@erwango
Copy link
Member

erwango commented Jan 24, 2018

Hi @b0661, this is quite a work! It'll require some time to review in deep.
We'll also need review from people with knowledge from other arch/SoCs to see how the propsed API fits.

#define PINCTRL_STM32_GPIO_COUNT 8
#elif defined(GPIOG)
#define PINCTRL_STM32_GPIO_COUNT 7
#elif defined(GPIOF)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some series (stm32f401 for instance), GPIOH w/o GPIOF and GPIOG.
So PINCTRL_STM32_GPIO_COUNT will be 8 while it should actually be 6.
So either it should be computed in a different way, either you should consider not to use it with care.

Besides, for footprint optimization purpose, we should let the possibility to only activate a subset
of GPIOs, do you take that option into account? (I didn't parsed everything yet, so this is just a question)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only activated GPIOs will be instantiated. Look for CHAOS_PP_WHEN(_active)

Copy link
Collaborator Author

@b0661 b0661 Jan 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHAOS_PP_WHEN(_active) is not used anymore.

we should let the possibility to only activate a subset

The correct number of activated GPIOs is now provided by SOC_GPIO_CONTROLLER_COUNT. For all activated GPIOs a SOC_GPIO_CONTROLLER_0 ... define is created based on the gpio-controller directive in the device tree.

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to split in at least 2 PR (3 if possible to split stm32 driver from dts based generation):
-Generic new pintrl API and lib (with wide review)
-stm32 pinctrl driver
-dts based generation

@@ -43,6 +43,11 @@
#include <stm32f0xx_ll_system.h>
#endif /* CONFIG_CLOCK_CONTROL_STM32_CUBE */

#ifdef CONFIG_PINCTRL_STM32
#include <stm32f0xx_ll_gpio.h>
#define CONFIG_PINCTRL_STM32_PREFIX ST_STM32_PINCTRL_48000000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed?
Can't we get the prefix from device tree? (derivate from pinctrl node compatible for instance)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I will investigate in using the -controller (e.g. gpio-controller, pin-controller>, ...) directive and create something like #define PIN_CONTROLLER_0 ST_STM32_PINCTRL_48000000.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erwango Partially Out of subject, but couln't we use the aliases to generate the fixups ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current solution generates defines for the SOC node based on device-controller directives. So a device driver gets defines of the form #define DEVICECONTROLLER_0 ST_STM32DEVICE_48000000 and additional there is a define for the total amount of such devices. You can generate also fixups from this, but finally the drivers must be adapted.

# Pinctrl driver
CONFIG_PINCTRL=y
CONFIG_PINCTRL_PINMUX=y
CONFIG_PINCTRL_STM32=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to arch/arm/soc/st/stm32//


# GPIO Controller
CONFIG_GPIO=y
CONFIG_GPIO_PINCTRL=y
CONFIG_GPIO_STM32=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to arch/arm/soc/st/stm32//

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erwango Not quite shure what to do here?

#include <stm32f0xx_ll_exti.h>
#include <stm32f0xx_ll_gpio.h>
#include <stm32f0xx_ll_system.h>
#define CONFIG_GPIO_STM32_GPIOA_PREFIX ST_STM32_GPIO_PINCTRL_48000000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for pinctrl, can it be derived from dts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can. Will change.

#elif defined(GPIOG)
#define GPIO_PINCTRL_STM32_PORTS_COUNT 7
#elif defined(GPIOF)
#define GPIO_PINCTRL_STM32_PORTS_COUNT 6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned for PINCTRL, in some SoCs, GPIOH can be present while GPIOF isn't.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Problem as long as you do not activate the node in the device tree, the device will not be created.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll have a try and see how this all works.

# SPI1 - master
# SPI2 - slave
CONFIG_SPI=y
CONFIG_SPI_1=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to Kconfig.defconfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. will move CONFIG_SPI. CONFIG_SPI_1 will come from DT.

# SPI2 - slave
CONFIG_SPI=y
CONFIG_SPI_1=y
CONFIG_SPI_1_IRQ_PRI=10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that needed? Should come from dts.

CONFIG_SPI_1_IRQ_PRI=10
CONFIG_SPI_2=y
CONFIG_SPI_2_IRQ_PRI=11
CONFIG_SPI_STM32=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed (comes from arch)

CONFIG_SPI_2=y
CONFIG_SPI_2_IRQ_PRI=11
CONFIG_SPI_STM32=y
CONFIG_SPI_STM32_INTERRUPT=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to Kconfig.defconfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. done.

CONFIG_SPI_2_IRQ_PRI=11
CONFIG_SPI_STM32=y
CONFIG_SPI_STM32_INTERRUPT=y
CONFIG_SPI_STM32_HAS_FIFO=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, derived from spi/Kconfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. deleted

@erwango erwango added area: GPIO area: Devicetree area: Pinmux RFC Request For Comments: want input from the community DNM This PR should not be merged (Do Not Merge) labels Jan 24, 2018
@superna9999
Copy link
Collaborator

Very impressive, I will have a look, but there is a lot to review !

}
/* Assure pin is on input before doing configuration
* to prevent damage */
err = pinctrl_mux_set(data->pinctrl, pinctrl_pin,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this... yet I don't know how it should be handled !
But if, let's says the bootloader has already configured the pin and the config is vital to the system, doing this will maybe cause unwanted side effects !
Changing the config won't harm if already in output, meaning it already has been configured somewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, will rethink.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@superna9999

Changing the config won't harm if already in output, meaning it already has been configured somewhere.

Reverted to not switch to input before configuration.

@@ -54,5 +54,8 @@ config PINCTRL_MUX_REQUEST
help
Supports pin allocation management by pinctrl_mux_request() and
pinctrl_mux_free().

source "drivers/pinctrl/Kconfig.stm32"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless empty line

config PINCTRL_STM32
bool "Pinctrl driver for STM32 MCUs"
depends on PINCTRL && SOC_FAMILY_STM32
select HAS_DTS_PINCTRL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select is not aligned

#include <chaos/preprocessor/control/when.h>
#include <chaos/preprocessor/repetition/repeat_from_to.h>


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless empty line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, currently there are a lot of these things. Wanted to get that whole thing out to get feedback. Will look into it. Thank you for reviewing.

pinctrl_stm32_device_init

#include "pinctrl_lib.h"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless empty line

#define CONFIG_PINCTRL_LIB_CONTROLLER_0_DATA &pinctrl_stm32_data
#define CONFIG_PINCTRL_LIB_CONTROLLER_0_PIN_COUNT PINCTRL_STM32_PIN_COUNT
#define CONFIG_PINCTRL_LIB_CONTROLLER_0_DEVICE_INIT \
pinctrl_stm32_device_init
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while it seems a good idea, using defines to pass functions looks ... ugly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@superna9999 Do you have a good option?

Extend pinctrl directive handling to fill EDTS database.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
modules/pincontroller.py:
Support and helper functions for the pin controller template.
Extracts all pin control data of a pin controller from the
EDTS.

templates/drivers/pinctrl_tmpl.c:
The template abstracts away the complex generation of the
generic parts of a pinctrl driver such as:
- compile time initialisation of configuration data from device tree
- access functions to config data
- compile time initialisation of whole driver structs

The driver implementer does only have to implement the necessary
hardware access routines.

The template is to be used by inline code generation.
A driver implementer must only define a set of python
global variables to configure the code generation.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Document the pinctrl template  that can be included
by inline code generation.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
A kernel configuration and build environment for
pinctrl drivers.

Add device tree bindings for the STM32 pin controller.

Add STM32 pin controller driver. The driver uses the
pinctrl library to implement the generic driver
functionality.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Add device tree bindings for the STM32 GPIO drivers
that use the PINCTRL driver as backend (GPIO_PINCTRL).

Add STM32 GPIO driver that uses the PINCTRL driver
as backend.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Enable STM32 driver configuration by device tree.
Set st,gpio-bank for gpio nodes.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Switch STM32F0x based boards configuration to use the pinctrl
and gpio-pinctrl devices.

Provide device tree definitions to allow the default pin
configuration to be initialised by the PINCTRL driver.

Provide correct configuration for samples.

Remove unneeded dts.fixup

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Unit test the pinctrl template API.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
The NUCLEO FO91RC and F030R8 boards use the GPIO driver with PINCTRL
backend by default. The STM32F0 SoC on the board does not support
level interrupts.

The test is adapted to exclude the level interrupt tests and
to correctly set up the GPIO pins for the board and the choosen
GPIO driver with PINCTRL backend.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Use correct pin definition depending on CONFIG_PINCTRL.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Use correct pin definition depending on CONFIG_PINCTRL.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Document the usage of the STM32 pinctrl driver and the related STM32
GPIO driver (with pinctrl backend).

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Extend the board documentation with the PINCTRL peripherial
and a more eleborate flashing example. Add documentation how
to test the board.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Describe CAN and I2C1 pin mapping. I2C1 pin mapping is changed
to allow for CAN pins.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Add generic bindings for clock consumers and clock providers.
Add a common binding for fixed clocks.
To be included by SoC specific bindings.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Support more clocks related directives (besides clocks) and
fill EDTS database
- clock-names
- clock-output-names
- clock-indices
- clock-ranges
- clock-frequency
- clock-accuracy
- oscillator
- assigned-clocks
- assigned-clock-parents
- assigned-clock-rates

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
All flash controllers have a mandatory compatible property.

Add it to the generic binding that is included by all.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Add common bindings for flash devices to be included by
SoC specific bindings.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Extend flash handling to fill the EDTS database.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Extend <device>-controller directive handling to fill EDTS database.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Fix false passed on localized error message in make invocation.

Fixes zephyrproject-rtos#8348

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
@mbolivar mbolivar mentioned this pull request Sep 6, 2018
@b0661 b0661 closed this Oct 16, 2018
@b0661 b0661 deleted the pinctrl_test branch October 16, 2018 16:50
@mbolivar mbolivar added this to In Progress in Architecture Project Apr 30, 2019
@mbolivar mbolivar moved this from In Progress to On Hold / Abandoned in Architecture Project Apr 30, 2019
@erwango erwango removed this from On Hold / Abandoned in Architecture Project Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree area: GPIO area: Pinmux DNM This PR should not be merged (Do Not Merge) RFC Request For Comments: want input from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

doc: Zephyr sphinx/pygments support DTS Streamline GPIO, Pinmux driver API
10 participants