This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Thingy:91 GPIO configuration

Hi, 

I am trying to configure a GPIO pin P0.21(as this is exposed pin on Thingy:91) from nRF9160 on Thingy:91.

I am using nRF Connect SDK 1.4.1 with Nordic version of SES.

I tried using from zephyr documented here.

#include <drivers/gpio.h>

void main()
{ 
	gpio = device_get_binding("GPIO_0");
	gpio_pin_configure(gpio, 21, GPIO_OUTPUT_ACTIVE);
	gpio_pin_set(gpio, 21, 1);
}

But I can't see the pin going high after power bootup.

Is there anything I am missing like editing .dts file, because thingy91_nrf9160_common.dts found at \nrf\boards\arm\thingy91_nrf9160 is like this

/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

/ {
	model = "Nordic Thingy91 nRF9160";
	compatible = "nordic,thingy91-nrf9160";

	chosen {
		zephyr,console = &uart0;
		zephyr,shell-uart = &uart0;
		zephyr,uart-mcumgr = &uart0;
	};

	buttons {
		compatible = "gpio-keys";

		button0: button_0 {
			gpios = <&gpio0 26 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
			label = "Button 1";
		};
	};

	leds {
		compatible = "gpio-leds";
		red_led: led_1 {
			gpios = <&gpio0 29 0>;
			label = "RGB red channel";
		};
		green_led: led_2 {
			gpios = <&gpio0 30 0>;
			label = "RGB green channel";
		};
		blue_led: led_3 {
			gpios = <&gpio0 31 0>;
			label = "RGB blue channel";
		};
		sense_red_led: led_4 {
			gpios = <&gpio0 0 0>;
			label = "RGB red channel";
		};
		sense_green_led: led_5 {
			gpios = <&gpio0 1 0>;
			label = "RGB green channel";
		};
		sense_blue_led: led_6 {
			gpios = <&gpio0 2 0>;
			label = "RGB blue channel";
		};
	};

	aliases {
		sw0 = &button0;
		led0 = &red_led;
		led1 = &green_led;
		led2 = &blue_led;
		sense-led0 = &sense_red_led;
		sense-led1 = &sense_green_led;
		sense-led2 = &sense_blue_led;
		rgb-pwm = &pwm0;
		buzzer-pwm = &pwm1;
		nmos-pwm = &pwm2;
	};
};

&adc {
	status = "okay";
};

&gpiote {
	status = "okay";
};

&gpio0 {
	status = "okay";
};

/* PWM0 is intended for RGB LED control */
&pwm0 {
	status = "okay";
	ch0-pin = <29>;
	ch1-pin = <30>;
	ch2-pin = <31>;
};

/* PWM1 is intended for buzzer control */
&pwm1 {
	status = "okay";
	ch0-pin = <28>;
};

/* PWM2 is intended for NMOS transistor control */
&pwm2 {
	status = "okay";
	ch0-pin = <13>;
	ch1-pin = <14>;
	ch2-pin = <15>;
	ch3-pin = <16>;
};

&pwm3 {
	status = "okay";
};

&i2c2 {
	compatible = "nordic,nrf-twim";
	status = "okay";
	sda-pin = <11>;
	scl-pin = <12>;
	clock-frequency = <I2C_BITRATE_FAST>;

	bme680@76 {
		compatible = "bosch,bme680";
		label = "BME680";
		reg = <0x76>;
	};

	bh1749@38 {
			compatible = "rohm,bh1749";
			label = "BH1749";
			reg = <0x38>;
			int-gpios = <&gpio0 27 0>;
	};
};

&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <3>;
	mosi-pin = <4>;
	miso-pin = <5>;
	cs-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>, <&gpio0 7 GPIO_ACTIVE_LOW>;

	adxl362@0 {
		compatible = "adi,adxl362";
		label = "ADXL362";
		spi-max-frequency = <8000000>;
		reg = <0>;
		int1-gpios = <&gpio0 9 0>;
	};

	adxl372@1 {
		compatible = "adi,adxl372";
		label = "ADXL372";
		spi-max-frequency = <8000000>;
		reg = <1>;
		int1-gpios = <&gpio0 6 0>;
	};
};

&timer0 {
	status = "okay";
};

&timer1 {
	status = "okay";
};

&timer2 {
	status = "okay";
};

&uart0 {
	compatible = "nordic,nrf-uarte";
	current-speed = <115200>;
	status = "okay";
	tx-pin = <23>;
	rx-pin = <24>;
	rts-pin = <22>;
	cts-pin = <25>;
};

&uart1 {
	current-speed = <1000000>;
	status = "okay";
	tx-pin = <21>;
	rx-pin = <19>;
	rts-pin = <20>;
	cts-pin = <18>;
};

&flash0 {
	/*
	 * For more information, see:
	 * http://docs.zephyrproject.org/devices/dts/flash_partitions.html
	 */
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x00000000 0x10000>;
		};
		slot0_partition: partition@10000 {
			label = "image-0";
		};
		slot0_ns_partition: partition@40000 {
			label = "image-0-nonsecure";
		};
		slot1_partition: partition@80000 {
			label = "image-1";
		};
		slot1_ns_partition: partition@b0000 {
			label = "image-1-nonsecure";
		};
		scratch_partition: partition@f0000 {
			label = "image-scratch";
			reg = <0x000f0000 0xa000>;
		};
		storage_partition: partition@fa000 {
			label = "storage";
			reg = <0x000fa000 0x00006000>;
		};
	};
};

/ {

	reserved-memory {
		#address-cells = <1>;
		#size-cells = <1>;
		ranges;

		sram0_s: image_s@20000000 {
			/* Secure image memory */
		};

		sram0_bsd: image_bsd@20010000 {
			/* BSD (shared) memory */
		};

		sram0_ns: image_ns@20020000 {
			/* Non-Secure image memory */
		};
	};
};

/* Include partition configuration file */
#include "thingy91_nrf9160_partition_conf.dts"

I will appreciate any insight on this.

Thanks!

  • Hello Shivek,

    I’m not quite sure what you mean by pin P0.21 is the exposed one on the Thingy:91. Can you elaborate?

    Anyway, as you can see in the pin mapping of the Thingy:91, P0.21 is used as MCU_IF3. This means that the pin is part of the interface mapping towards the nRF52840, as you can see in the picture below (for more information please check the Hardware files section on the Thingy:91 Download page).

    If you have a look at the file ../build/zephyr/zephyr.dts (in your application root folder), you can find the details on the usage of this pin, as shown here:

    uart0: uart@8000 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0x8000 0x1000 >;
    				interrupts = < 0x8 0x1 >;
    				status = "okay";
    				label = "UART_0";
    				current-speed = < 0x1c200 >;
    				tx-pin = < 0x12 >;
    				rx-pin = < 0x13 >;
    				rts-pin = < 0x14 >;
    				cts-pin = < 0x15 >;
    			};

    This is probably reason why the pin is not going high after power-up, because it is used as the cts-pin by the UART0 peripheral. You might wanna disable the UART0:

    &uart0 {
        status = "disabled";
    };

    or at least remove the pin assignment from it:

    &uart0 {
        /delete-property/ cts-pin;
    };

    To do so, you can create a file in your application root folder named: thingy91_nrf9160.overlay (or thingy91_nrf9160ns.overlay, depending on what you are building your application for), and add the above mentioned content.

    Alternatively, just to check if your code works, you could use the pins 29, 30 and 31 as they will fire up the lightwell LEDs in different colours.

    I hope this will help you!

    Regards,

    Markus

  • Thanks for responding. I will try that once I am finished with other task.

  • Hi Markus,

    I tried making overlay file. But it didn't help me. I disabled the uart and I deleted the cts-pin property. Just one thing I did differently is I deleted P0.21 property in  thingy91_nrf9160_common.dts files. Below is the screenshot of the updated dts file.

    So, as mentioned in the schematics of Thingy91. P0.21 is attached to cts-pin of the uart1(as opposed to what you suggested me). But still I am not getting the control of the GPIO pin.

    Can you please make sure that I don't have to add the overlay file to tell the compiler about it. I mean I just make a text file and added those lines which  you told me to. Is that enough for the purpose?

    Thanks again.

  • Have you just tried to fire up one of the lightwell LEDs to confirm that the snippet works in general?

    It is possible to change properties in the .dts files, but I’m not recommending you to do so. What you are trying to achieve is exactly the purpose of an overlay file, as you can read more about here.

    How are you building your application? Via SES or a bash/terminal?

    Regards,

    Markus

  • Hi Markus,

    I have gone through the link you mentioned in your last post. So, I am assuming that we don't have to tell compiler if we just add a text file and rename it as thingy91_nrf9160ns.overlay.

    I tried switching the red light ON, its working fine with the same code:

    struct device *gpio;
    
    gpio = device_get_binding("GPIO_0");
    printf("\r\nfunction return:%d",err);
    
    err = gpio_pin_configure(gpio, 21, GPIO_OUTPUT_ACTIVE);
    err = gpio_pin_configure(gpio, 29, GPIO_OUTPUT_ACTIVE);
    
    k_sleep(K_SECONDS(5));
    err = gpio_pin_set(uart, 21, 1);
    err = gpio_pin_set(gpio, 29, 1);

    After 5 sec, I can see the red LED ON but nothing on GPIO P0.21. I tried cutting the SB7 to disconnect from nRF52840, didn't make any difference. 

    How are you building your application? Via SES or a bash/terminal?

    I am building my application using SESv5.10d Nordic edition.

    This is disappointing to me as our next target is to build custom application using nRF9160 and nRF52840.

    Thanks for keeping up with me.

    Regards,

    Shivek

Related