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

cpu/stm32/periph_spi: Fix /CS handling #20084

Merged
merged 4 commits into from
Nov 24, 2023
Merged

Commits on Nov 21, 2023

  1. cpu/stm32: always apply /CS settings

    The CR2 register was only written to if the settings differ from the
    reset value. This wasn't actually a bug, since it was cleared in
    `spi_release()` to the reset value again. Still, it looks like a bug,
    may cause a pipeline flush due to the branch, and increased `.text`
    size. So let's get rid of this.
    maribu committed Nov 21, 2023
    Configuration menu
    Copy the full SHA
    097b99f View commit details
    Browse the repository at this point in the history

Commits on Nov 24, 2023

  1. cpu/stm32: Provide spi_mode_t

    This doesn't change the firmware, since for all STM32 MCUs with an
    SPI driver the register setting in the mode did match the SPI mode
    number by chance. But for some STM32 MCUs with no SPI driver yet
    the register layout is indeed different. This will help to provide an
    SPI driver for them as well.
    maribu committed Nov 24, 2023
    Configuration menu
    Copy the full SHA
    7057aa6 View commit details
    Browse the repository at this point in the history
  2. cpu/stm32/periph_spi: Fix /CS handling

    Previously, the /CS signal was performed by enabling / disabling the
    SPI peripheral. This had the disadvantage that clock polarity settings
    where not applied starting with `spi_acquire()`, as assumed by e.g.
    the SPI SD card driver, but only just before transmitting data.
    
    Now the SPI peripheral is enabled on `spi_acquire()` and only disabled
    when calling `spi_release()`, and the `SPI_CR2_SSOE` bit in the `CR2`
    register is used for hardware /CS handling (as supposed to).
    maribu committed Nov 24, 2023
    Configuration menu
    Copy the full SHA
    63a2a50 View commit details
    Browse the repository at this point in the history
  3. cpu/stm32/periph_spi: improve prescaler calculation

    With only 8 possible prescalers, we can just loop over the values
    and shift the clock. In addition to being much easier to read, using
    shifts over divisions can be a lot faster on CPUs without hardware
    division.
    
    In addition an `assert()` is added that checks if the API contract
    regarding the SPI frequency is honored. If the requested clock is too
    low to be generated, we should rather have a blown assertion than
    hard to trace communication errors.
    
    Finally, the term prescaler is used instead of divider, as divider may
    imply that the frequency is divided by the given value n, but
    in fact is divided by 2^(n+1).
    maribu committed Nov 24, 2023
    Configuration menu
    Copy the full SHA
    f4729c2 View commit details
    Browse the repository at this point in the history