Re: Syntax in dts file for defining a GPIO output based on nxp,kinetis-gpio.yaml #defines


Andrei Gansari
 

Hello Bo,

 

 

We have a general help page for Device Tree: https://docs.zephyrproject.org/latest/guides/dts/index.html

 

In your particular case, you need to set port b pin 22 as output.

 

Device Tree:

The purpose of DT is to describe the HW of the board (boot time @ Linux, compile time @ Zephyr).

K64F’s DT file is found in: boards/arm/frdm_k64f/frdm_k64f.dts I expect this is what you are looking at. It also includes file dts/arm/nxp/nxp_k6x.dtsi where port b is set using nxp,kinetis-gpio.yaml. Dtsi file is a generic dts include file that describes the SoC (we may have another board with the same SoC on it).

Add the following to frdm_k64f.dts to use gpiob from nxp_k6x.dtsi:

&gpiob {

    status = "ok";

};

You can comment out/remove the following to remove he led configuration on the same pin:

        red_led: led_0 {

            gpios = <&gpiob 22 0>;

            label = "User LD1";

        };

 

Code:

You can’t configure a pin as in/out, using DT, we have board’s pinmux.c (in boards/arm/frdm_k64f) to do that. This is because GPIO should be dynamic during the application.

pinmux_pin_set(portb, 22, PORT_PCR_MUX(kPORT_MuxAsGpio));

The code above sets pin as GPIO (for the led in the case above). Then set pin to output and send a signal:

#include <gpio.h>

 

    pinmux_pin_set(portb, 22, PORT_PCR_MUX(kPORT_MuxAsGpio));

 

    struct device *gpiob =

           device_get_binding(DT_NXP_KINETIS_GPIO_GPIO_B_LABEL);

 

    gpio_pin_configure(gpiob, 22, GPIO_DIR_OUT);

    gpio_pin_write(gpiob, 22, 0);

 

DT_NXP_KINETIS_GPIO_GPIO_B_LABEL can be found in files zephyr/include/generated/generated_dts_board*** (relative to build folder) this is the effect of setting portb in dts.

 

 

Regards,

Andrei Gânsari

 

From: devel@... <devel@...> On Behalf Of Bo.Kragelund via Lists.Zephyrproject.Org
Sent: Thursday, March 28, 2019 12:57 PM
To: devel@...
Cc: devel@...
Subject: [Zephyr-devel] Syntax in dts file for defining a GPIO output based on nxp,kinetis-gpio.yaml #defines

 

Hello developers!

I have difficulties finding any documentation/examples of how to define a simple GPIO as an e.g. output in the frdm_k64f.dts file for the frdm_k64f board.

As long as we talk about defining the outputs for LEDS on the board, this is done very nice based on the gpio-keys.yaml specific for this purpose.
As seen below, which is copied from the frdm_k64f.dts file, you simply define the port, pin number, and flags in one line like this: gpios = <&gpiob 22 0>, which means port b, pin 22, and no flags.

leds {

compatible = "gpio-leds";

red_led: led_0 {

gpios = <&gpiob 22 0>;

label = "User LD1";

};

};

 

But in general, I believe the idea is to define GPIO in the dts file based on the nxp,kinetis-gpio.yaml file created for this purpose, instead of the gpio-keys.yaml file.
But this file has a completely different way/syntax for defining a GPIO compared to the gpio-keys.yaml file.
It doesn't have the gpios property, but reg and interrupt instead. It also includes the below lines, which I guess I should use in some way:

"#cells":

  - pin

  - flags

 

Since I am rather new in dts and yaml syntax, I hope someone can help me with the syntax for setting port b, pin 22, and no flags, based on the nxp,kinetis-gpio.yaml file...

As written before, I haven't been able to find any examples so far in either the zephyr repository or zephyr documentation.

Thank you for your help.

Best regards,
Bo Kragelund

I hope someone can help me,

Join devel@lists.zephyrproject.org to automatically receive all group messages.