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: nrf: Add support for setting initial pin state #61280

Conversation

awojasinski
Copy link
Collaborator

The nRF pinctrl driver did not allow for setting the initial state of the pins. This issue specifically affected the SPI SPIM driver, which caused an invalid SCK state when configured with CPOL (Clock Polarity).

With the introduction of the power-optimized SPIM driver, it disables the peripheral instance once the transfer is completed. As a result, the GPIO takes control over the SCK pin and drive it based on its own configuration. However, the pinctrl configures pins for SPIM incorrectly when CPOL is set. This causes that GPIO sets the SCK pin to 0 instead of the expected 1 when idle after SPI transaction is finished.

To address this issue, a patch was introduced.
Now, when an SPIM instance is configured with CPOL, the pinctrl node must have the 'output-high' property set to ensure the correct initial pin state.

Example devicetree fragment:

    spi1_default: spi1_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 5)>;
            output-high;
        };
        group2 {
            psels = <NRF_PSEL(SPIM_MISO, 0, 6)>,
                    <NRF_PSEL(SPIM_MOSI, 0, 7)>;
        };
    };

The nRF pinctrl driver did not allow for setting the initial state
of the pins. This issue specifically affected the SPI SPIM driver,
which caused an invalid SCK state when configured with CPOL
(Clock Polarity).

With the introduction of the power-optimized SPIM driver,
it disables the peripheral instance once the transfer is completed.
As a result, the GPIO takes control over the SCK pin and drive it
based on its own configuration. However, the pinctrl configures pins
for SPIM incorrectly when CPOL is set. This causes that GPIO
sets the SCK pin to 0 instead of the expected 1 when idle after SPI
transaction is finished.

To address this issue, a patch was introduced.
Now, when an SPIM instance is configured with CPOL,
the pinctrl node must have the 'output-high' property set
to ensure the correct initial pin state.

Example devicetree fragment:

    spi1_default: spi1_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 5)>;
            output-high;
        };
        group2 {
            psels = <NRF_PSEL(SPIM_MISO, 0, 6)>,
                    <NRF_PSEL(SPIM_MOSI, 0, 7)>;
        };
    };

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
@awojasinski
Copy link
Collaborator Author

The described issue has been observed in the nrf_desktop app on a nrf52840gmouse_nrf52840 board while integrating new hal_nordic revision nrfconnect/sdk-nrf#11800

@anangl
Copy link
Member

anangl commented Aug 8, 2023

Now, when an SPIM instance is configured with CPOL, the pinctrl node must have the 'output-high' property set to ensure the correct initial pin state.

CPOL is configured at runtime per transfer, so the value set in devicetree may still be incorrect.
Why not just set the proper value for the SCK pin when the SPIM peripheral is configured for a particular transfer, somewhere around:

config.mode = get_nrf_spim_mode(spi_cfg->operation);

@awojasinski
Copy link
Collaborator Author

Choose a different solution (#61294). This one can be closed

@awojasinski awojasinski closed this Aug 9, 2023
@awojasinski awojasinski deleted the nrf-pinctrl-init-state branch January 9, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Pinctrl platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants