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/periph_gpio_ll: change API to access GPIO ports #20639

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Apr 30, 2024

  1. drivers/periph_gpio_ll: change API to access GPIO ports

    The API was based on the assumption that GPIO ports are mapped in memory
    sanely, so that a `GPIO_PORT(num)` macro would work allow for constant
    folding when `num` is known and still be efficient when it is not.
    
    Some MCUs, however, will need a look up tables to efficiently translate
    GPIO port numbers to the port's base address. This will prevent the use
    of such a `GPIO_PORT(num)` macro in constant initializers.
    
    As a result, we rather provide `GPIO_PORT_0`, `GPIO_PORT_1`, etc. macros
    for each GPIO port present (regardless of MCU naming scheme), as well as
    `GPIO_PORT_A`, `GPIO_PORT_B`, etc. macros if (and only if) the MCU port
    naming scheme uses letters rather than numbers.
    
    These can be defined as macros to the peripheral base address even when
    those are randomly mapped into the address space. In addition, a C
    function `gpio_port()` replaces the role of the `GPIO_PORT()` and
    `gpio_port_num()` the `GPIO_PORT_NUM()` macro. Those functions will
    still be implemented as efficient as possible and will allow constant
    folding where it was formerly possible. Hence, there is no downside for
    MCUs with sane peripheral memory mapping, but it is highly beneficial
    for the crazy ones.
    
    There are also two benefits for the non-crazy MCUs:
    1. We can now test for valid port numbers with `#ifdef GPIO_PORT_<NUM>`
        - This directly benefits the test in `tests/periph/gpio_ll`, which
          can now provide a valid GPIO port for each and every board
        - Writing to invalid memory mapped I/O addresses was treated as
          triggering undefined behavior by the compiler and used as a
          optimization opportunity
    2. We can now detect at compile time if the naming scheme of the MCU
       uses letters or numbers, and produce more user friendly output.
        - This is directly applied in the test app
    maribu committed Apr 30, 2024
    Configuration menu
    Copy the full SHA
    6ac165a View commit details
    Browse the repository at this point in the history
  2. boards/stm32: use GPIO LL for LEDs

    This fixes a race in `LED<NUM>_TOGGLE`, which is a read-copy-write
    operation. Any access to a GPIO pin on the same GPIO port that
    happens concurrently could result in data corruption. Using the
    GPIO LL API, which is thread-safe, fixes the issue.
    
    Note: The used GPIO LL functions will work even in when the GPIO LL
          module is not used.
    maribu committed Apr 30, 2024
    Configuration menu
    Copy the full SHA
    09e8d9e View commit details
    Browse the repository at this point in the history