zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.69k stars 6.53k forks source link

For pinctrl on STM32 pin cannot be defined as push-pull with low level #53141

Closed r2r0 closed 1 year ago

r2r0 commented 1 year ago

Describe the bug Following pinctrl pin definition for STM32WB55 does not set pin as push-pull (and sets pin as digital input):

/omit-if-no-ref/ pph_rst_init: gpio_pb0 {
        pinmux = <STM32_PINMUX('B', 0, GPIO)>;
        drive-push-pull;
        output-low;
    };

In the pinctrl_configure_pins function in pinctrl_stm32.c there is following code:

        } else if (STM32_DT_PINMUX_FUNC(mux) == STM32_GPIO) {
            uint32_t gpio_out = pins[i].pincfg &
                        (STM32_ODR_MASK << STM32_ODR_SHIFT);
            if (gpio_out != 0) {
                pin_cgf = pins[i].pincfg | STM32_MODER_OUTPUT_MODE;
            } else {
                pin_cgf = pins[i].pincfg | STM32_MODER_INPUT_MODE;
            }
        } else {

The bit under STM32_ODR_MASK << STM32_ODR_SHIFT is based on DT pin definition and it encodes if output pin should have low or high level. This means that if there is defined low level (encoded as 0) then if (gpio_out != 0) will cause configuration of pin as input.

To Reproduce Steps to reproduce the behavior: Build application with pinctrl pin definition like above and observerve pin behaviour.

Expected behavior For the GPIO pin the pin direction should be deduced basing on drive-push-pull or drive-open-drain atributes.

Impact showstopper

Logs and console output

Environment (please complete the following information):

Additional context

erwango commented 1 year ago

@r2r0, please check https://github.com/zephyrproject-rtos/zephyr/pull/53211

LuxLuthor commented 1 year ago

@r2r0, @erwango alternative solution in #53217