gpio configured as GPIO_OUTPUT_INACTIVE gives same physical read for both logical levels

hello Nordic

i am working with nrf52832, ncs v2.1.0

in my device tree i configure a pgio like so :

and on my app i have an init function and an uiinit function which configure this gpio 

init function : 
{....
 nrfx_err_t result = nrfx_spim_init(&dev_config->spim,
                                       &dev_config->def_config,
                                       spim_handler,
                                       (void *)spi_data);
    if (result != NRFX_SUCCESS)
    {
        LOG_ERR("Failed to initialize nrfx_spim_init. result = %d", result);
        return -EBUSY;
    }

    if (spi_data->cs_set)
    {
        spi_data->cs_gpio_data.gpio_dev = spi_data->cs_cntl.gpio.port;
        spi_data->cs_gpio_data.gpio_pin = spi_data->cs_cntl.gpio.pin;

        int ret = gpio_pin_configure(spi_data->cs_cntl.gpio.port, spi_data->cs_cntl.gpio.pin,
                                     spi_data->cs_cntl.gpio.dt_flags | GPIO_OUTPUT_INACTIVE);
        if (0 != ret)
        {
            LOG_ERR("failed to gpio_pin_configure");
            return ret;
        }
        int val_raw = gpio_pin_get_raw(spi_data->cs_cntl.gpio.port, spi_data->cs_cntl.gpio.pin);
        int val = gpio_pin_get(spi_data->cs_cntl.gpio.port, spi_data->cs_cntl.gpio.pin);
        LOG_INF("augu_spi_init cs configure, gpio phys val %d log val = %d", val_raw, val);
    }
...}

uninit function :
{...
   nrfx_spim_uninit(&dev_config->spim);

    if (true == spi_data->cs_set)
    {
        spi_data->cs_gpio_data.gpio_dev = spi_data->cs_cntl.gpio.port;
        spi_data->cs_gpio_data.gpio_pin = spi_data->cs_cntl.gpio.pin;

        int ret = gpio_pin_configure(spi_data->cs_cntl.gpio.port,
                                     spi_data->cs_cntl.gpio.pin,
                                     GPIO_OUTPUT_INACTIVE);

        int val_raw = gpio_pin_get_raw(spi_data->cs_cntl.gpio.port, spi_data->cs_cntl.gpio.pin);
        int val = gpio_pin_get(spi_data->cs_cntl.gpio.port, spi_data->cs_cntl.gpio.pin);
        LOG_INF("augu_spi_uninit cs configure, gpio phys val %d log val = %d", val_raw, val);

... }

in the log i get this :

"augu_spi_init cs configure, gpio phys val 0 log val = 1"

and  "augu_spi_uninit cs configure, gpio phys val 0 log val = 0"

1. any idea why i get physical level 0 for both logical states ?

2. if i change the uninit function to "GPIO_OUTPUT_ACTIVE" then i get the same logs.

according to this from my ncs  

/** Configures GPIO pin as output and initializes it to a logic 0. */
#define GPIO_OUTPUT_INACTIVE    (GPIO_OUTPUT |			\
				 GPIO_OUTPUT_INIT_LOW |		\
				 GPIO_OUTPUT_INIT_LOGICAL)
/** Configures GPIO pin as output and initializes it to a logic 1. */
#define GPIO_OUTPUT_ACTIVE      (GPIO_OUTPUT |			\
				 GPIO_OUTPUT_INIT_HIGH |	\
				 GPIO_OUTPUT_INIT_LOGICAL)

and also according to https://docs.zephyrproject.org/latest/hardware/peripherals/gpio.html

it does not make sense, what am i missing ?

hope to read you soon

best regardsd 

Ziv

Parents
  • You need to use GPIO flag GPIO_ACTIVE_LOW and GPIO_ACTIVE_HIGH to change that.

    In our hardware design, the LEDs are active low, meaning that writing a logical zero (0) to the output pin illuminates the LED. 

     

    static inline int gpio_pin_get(const struct device *port, gpio_pin_t pin)

    ''Get logical level of an input pin.

    Get logical level of an input pin taking into account GPIO_ACTIVE_LOW flag. If pin is configured as Active High, a low physical level will be interpreted as logical value 0. If pin is configured as Active Low, a low physical level will be interpreted as logical value 1( GPIO — Zephyr Project Documentation )''

  • Hi Kazi

    You need to use GPIO flag GPIO_ACTIVE_LOW and GPIO_ACTIVE_HIGH to change that.

    what i forgot to do is to add the flags from the device tree to the pin configure in the uninit function, like in the init

    spi_data->cs_cntl.gpio.dt_flags | GPIO_OUTPUT_INACTIVE

    in the dts the pin is configured with the flags you mentioned

    	cs-gpios = <&gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
    
     

    another issue that confused me and i will open a new thread on that is that in vs code sometimes even if you do a pristine build you still get the build before your changes, it requires to eras the build and close the vs code (and sometimes the pc) to get it to build with all the new changes.

    one last thing, not directly relevant to this thread, but in my case the GPIO effected the power consumption and when the device is connected via RTT and is communicating on it, it increases power consumption by up to few mA, which is not a small consume and can be confusing to think that the GPIO is not behaving correct.

    best

    regards

    Ziv

Reply
  • Hi Kazi

    You need to use GPIO flag GPIO_ACTIVE_LOW and GPIO_ACTIVE_HIGH to change that.

    what i forgot to do is to add the flags from the device tree to the pin configure in the uninit function, like in the init

    spi_data->cs_cntl.gpio.dt_flags | GPIO_OUTPUT_INACTIVE

    in the dts the pin is configured with the flags you mentioned

    	cs-gpios = <&gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
    
     

    another issue that confused me and i will open a new thread on that is that in vs code sometimes even if you do a pristine build you still get the build before your changes, it requires to eras the build and close the vs code (and sometimes the pc) to get it to build with all the new changes.

    one last thing, not directly relevant to this thread, but in my case the GPIO effected the power consumption and when the device is connected via RTT and is communicating on it, it increases power consumption by up to few mA, which is not a small consume and can be confusing to think that the GPIO is not behaving correct.

    best

    regards

    Ziv

Children
No Data
Related