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

Unable to toggle GPIO P0.0 or P0.1 with Zephyr

Working with nrf52832_mdk and using basic GPIO functionality, I am unable to toggle the GPIO pins P0.0 or P0.1.   The code I am using is quite simple and I am able to toggle the LED's on a nrf52840_pca10056 when compiled in that environment.  When compiling on with nrf52932_mdk, I expect to see some activity on the pins P0.0 or P0.01 when I specify pin 0 or 1, however, there appears to be no activity.  My code is below:

nt 
gpio_set( 
    int pin, 
    bool set )
{
    int err;
    struct device *dev;

    dev = device_get_binding("GPIO_0");


    gpio_pin_configure( dev, pin, GPIO_OUTPUT_ACTIVE );


    if( verbose == true ){
        if ( set == true ) {
            printk("Set GPIO Pin %d - %d", pin,set);
        }else{
            printk("Clear GPIO Pin %d - %d", pin,set );
        }
    }

    err = gpio_pin_set(dev, pin, set);


    if ( verbose == true ) {
        if (err == 0) {
            printk("SUCCESS\n");
        }else{
            printk("FAILED\n");
        }                      
    }

    return( err );
}

Any clues as to why my pins are not toggles would be greatly appreciated.
Tom

  • Interesting,

    I tried your program, had to make modifications in the following.

    CMakeLists.txt

    #
    # Copyright (c) 2020 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    #

    cmake_minimum_required(VERSION 3.8.2)

    set(NRF_SUPPORTED_BOARDS
    nrf5340pdk_nrf5340_cpunet
    nrf52dk_nrf52832
    nrf52840dk_nrf52840
    )

    #find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

    include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
    project(peripheral_dis)

    FILE(GLOB app_sources src/*.c)
    target_sources(app PRIVATE
    ${app_sources}
    )

    and in main.c

    gpio_dev = device_get_binding("GPIO_0" ); //DT_LABEL(DT_NODELABEL(gpio0)));
    if (gpio_dev == NULL) {
    printk("GPIO_0 bind error");
    return;
    }

    I have GPIO 6 toggling every second, but nothing on 7 and 8.

  • tscribne said:
    I have GPIO 6 toggling every second, but nothing on 7 and 8.

    I took a look at the nrf52832-mdk schematic, but I did not see any reason for why pin 7 and 8 should not work.

    Unfortunately, I do not have a nrf52832-mdk. Since it's Makerdiary that created this board, I recommend asking about this issue in the Makerdiary community forum: https://community.makerdiary.com/ , or send them a message from this page: https://makerdiary.com/pages/faqs

  • I took your sample and created a test program very similar to yours.  Unfortunately, I am getting the same response as before with P0.06 toggling and P0.07 and P0.08 with no response.  I am using the nrf52dk_nrf52832 dts with slight modifications for my UART

    #include <zephyr.h>
    #include <sys/printk.h>
    #include <stdio.h>
    #include <string.h>
    #include <shell/shell.h>
    #include <shell/shell_uart.h>
    #include <version.h>
    #include <logging/log.h>
    #include <stdlib.h>
    #include <device.h>
    #include <drivers/gpio.h>
    #include <console/console.h>
    
    #define WATCHDOG_STACK_SIZE		500
    #define WATCHDOG_PRIORITY		5
    
    #define WATCHDOG_WAKE			1000
    
    struct device *watchdog_dev;
    
    K_THREAD_STACK_DEFINE( watchdog_stack_area, WATCHDOG_STACK_SIZE );
    struct k_thread watchdog_thread_data;
    k_tid_t	watchdog_tid;								// ThreadID
    
    
    #define PIN_1 6
    #define PIN_2 7
    #define PIN_3 8
    
    static struct device *gpio_dev;
    
    /* 
    ** Function: 		watchdog
    ** Description: 	Actual watchdog thread routine.
    */
    void 
    watchdog( 
    	void *unused1, 
    	void *unused2, 
    	void *unused3 )
    {
    	while (1) {
    		printk("+");	
    		gpio_pin_toggle(gpio_dev,PIN_1);
    		gpio_pin_toggle(gpio_dev,PIN_2);
    		gpio_pin_toggle(gpio_dev,PIN_3);
    		k_sleep( WATCHDOG_WAKE );
    
    	}
    }
    
    /*
    ** Function:		start_watchdog Description: 	Starts the
    ** watchdog routine thread
    */
    int 
    start_watchdog()
    {
    
    	//watchdog_dev = device_get_binding("GPIO_0");
    //
    //	ret = gpio_pin_configure(watchdog_dev, LED_PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
    //	if (ret < 0) {
    //		return(1);
    //	}
    //	gpio_pin_set( watchdog_dev, LED_PIN, (int)false);
    //
    
    	watchdog_tid = k_thread_create(&watchdog_thread_data, 
    								   watchdog_stack_area,
    								   K_THREAD_STACK_SIZEOF( watchdog_stack_area ),
    								   watchdog,
    								   NULL, NULL, NULL,
    								   WATCHDOG_PRIORITY,
    								   0,
    								   K_NO_WAIT );
    
    
    	return(0);
    }
    
    
    /*
    ** Function:		stop_watchdog
    ** Description: 	Stop the watchdog function thread
    */
    int
    stop_watchdog()
    {
    	return(0);
    }
    
    
    void main( void )
    {
    	int err;
    	console_init();
    
    	printk("GPIO Test Program\n");
    
    	gpio_dev = device_get_binding(DT_LABEL(DT_NODELABEL(gpio0)));
    	if (gpio_dev == NULL) {
    		printk("GPIO_0 bind error");
    		return;
    	}
    	
    	
    	err = gpio_pin_configure(gpio_dev, PIN_1,
    				GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW);	
    	if (err) {
    		printk("PIN_1 config error: %d", err);
    	}
    	
    	err = gpio_pin_configure(gpio_dev, PIN_2,
    				GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW);	
    	if (err) {
    		printk("PIN_2 config error: %d", err);
    	}
    	
    	err = gpio_pin_configure(gpio_dev, PIN_3,
    				GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW);	
    	if (err) {
    		printk("PIN_3 config error: %d", err);
    	}
    
    	start_watchdog();
    
    	for(;;)
    	{
    		printk("-");
    		k_sleep(500);
    
    	}
    }

    I am at a loss as to what is happening.  Based on my schematic and all the gathered information, there should be no reason why P0.07 and P0.08 should be unresponsive.

    Tom

  • It's a long shot, but you could you try to print the values of UART RTS and CTS pins, and see if 7 and 8 is printed. If not, it might be a HW issue with this board.

        printk("Value of NRF_UART0->PSELCTS: %d \n",NRF_UART0->PSELCTS);
    	printk("Value of NRF_UART0->PSELRTS: %d \n",NRF_UART0->PSELRTS);

  • Interesting, you got me thinking about the other pins, so I printed out all the others.  The only pins connected right now are UART Tx & Rx.  

    *** Booting Zephyr OS build v2.3.0-rc1-ncs1 ***
    GPIO Test Program

    GPIO Registers
    GPIO DetectMode 0x00
    GPIO Direction Register 0x11c0
    GPIO DIR Clear Register 0x11c0
    GPIO DIR Set Register 0x11c0
    GPIO Latch Register 0x00
    GPIO OUT Clear Register 0x1000
    GPIO OUT Set Register 0x1000
    GPIO PinCnf
    00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    02 02 02 02 02 02 03 03 03 02 02 00 03 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
    NRF_UART0->PSELTXD: 12
    NRF_UART0->PSELRXD: 11
    NRF_UART0->PSELCTS: -1
    NRF_UART0->PSELRTS: -1
    NRF_UARTE0->PSELTXD: 12
    NRF_UARTE0->PSELRXD: 11
    NRF_UARTE0->PSELCTS: -1
    NRF_UARTE0->PSELRTS: -1
    PWM0->PSEL.OUT[0]: -1
    PWM0->PSEL.OUT[1]: -1
    PWM0->PSEL.OUT[2]: -1
    PWM0->PSEL.OUT[3]: -1
    PWM1->PSEL.OUT[0]: -1
    PWM1->PSEL.OUT[1]: -1
    PWM1->PSEL.OUT[2]: -1
    PWM1->PSEL.OUT[3]: -1
    NRF_SPI0->PSEL.SCK: -1
    NRF_SPI0->PSEL.MOSI: -1
    NRF_SPI0->PSEL.MISO: -1
    NRF_SPI1->PSEL.SCK: -1
    NRF_SPI1->PSEL.MOSI: -1
    NRF_SPI1->PSEL.MISO: -1
    NRF_SPI2->PSEL.SCK: -1
    NRF_SPI2->PSEL.MOSI: -1
    NRF_SPI2->PSEL.MISO: -1
    NRF_SPIS0->PSELSCK: -1
    NRF_SPIS0->PSELMOSI: -1
    NRF_SPIS0->PSELMISO: -1
    NRF_SPIS1->PSELSCK: -1
    NRF_SPIS1->PSELMOSI: -1
    NRF_SPIS1->PSELMISO: -1
    NRF_SPIS2->PSELSCK: -1
    NRF_SPIS2->PSELMOSI: -1
    NRF_SPIS2->PSELMISO: -1
    NRF_TWIM0->PSEL.SCL: -1
    NRF_TWIM0->PSEL.SDA: -1
    NRF_TWIM1->PSEL.SCL: -1
    NRF_TWIM1->PSEL.SDA: -1
    NRF_TWIS0->PSEL.SCL: -1
    NRF_TWIS0->PSEL.SDA: -1
    NRF_TWIS1->PSEL.SCL: -1
    NRF_TWIS1->PSEL.SDA: -1
    NRF_PDM->PSEL.CLK: -1
    NRF_PDM->PSEL.DIN: -1
    NRF_I2S->PSEL.MCK: -1
    NRF_I2S->PSEL.SCK: -1
    NRF_I2S->PSEL.LRCK: -1
    NRF_I2S->PSEL.SDIN: -1
    NRF_I2S->PSEL.SDOUT: -1
    NRF_QDEC->PSEL.LED: -1
    NRF_QDEC->PSEL.A: -1
    NRF_QDEC->PSEL.B: -1

Related