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

GPIO Pin as INPUT in NRF5340

Hello ,

I am playing with PDK NRF 5340, I am trying to write a simple code to configure a PIN (0.10) which is not already in use by PDK.

When I print it's state it always says "LOW". here is my code.

#include <zephyr.h>
#include <sys/printk.h>
#include <device.h>
#include <drivers/gpio.h>

unsigned int status=1,old=1;

void main(void)
{
    struct device* port0 = device_get_binding("GPIO_0");
    int result=1;
	
	result = gpio_pin_configure(port0, 10, GPIO_DIR_IN);
	
	printk("Hello World! %s, %x \r\n", CONFIG_BOARD,result);

    while (1) 
	{
      gpio_pin_read(port0,10,&status);
		if(old != status)
		{
			if(status==1) { printk("HIGH"); }
			if(status==0) { printk("LOW");	}
			old = status;
		}
                
	}
}

what my serial output says is - 

*** Booting Zephyr OS build v2.1.99-ncs1  ***
Flash regionDomainPermissions
00 0x00000 0x08000 Securerwxl
01 0x08000 0x10000 Non-Securerwxl
02 0x10000 0x18000 Non-Securerwxl
03 0x18000 0x20000 Non-Securerwxl
04 0x20000 0x28000 Non-Securerwxl
05 0x28000 0x30000 Non-Securerwxl
06 0x30000 0x38000 Non-Securerwxl
07 0x38000 0x40000 Non-Securerwxl
08 0x40000 0x48000 Non-Securerwxl
09 0x48000 0x50000 Non-Securerwxl
10 0x50000 0x58000 Non-Securerwxl
11 0x58000 0x60000 Non-Securerwxl
12 0x60000 0x68000 Non-Securerwxl
13 0x68000 0x70000 Non-Securerwxl
14 0x70000 0x78000 Non-Securerwxl
15 0x78000 0x80000 Non-Securerwxl
16 0x80000 0x88000 Non-Securerwxl
17 0x88000 0x90000 Non-Securerwxl
18 0x90000 0x98000 Non-Securerwxl
19 0x98000 0xa0000 Non-Securerwxl
20 0xa0000 0xa8000 Non-Securerwxl
21 0xa8000 0xb0000 Non-Securerwxl
22 0xb0000 0xb8000 Non-Securerwxl
23 0xb8000 0xc0000 Non-Securerwxl
24 0xc0000 0xc8000 Non-Securerwxl
25 0xc8000 0xd0000 Non-Securerwxl
26 0xd0000 0xd8000 Non-Securerwxl
27 0xd8000 0xe0000 Non-Securerwxl
28 0xe0000 0xe8000 Non-Securerwxl
29 0xe8000 0xf0000 Non-Securerwxl
30 0xf0000 0xf8000 Non-Securerwxl
31 0xf8000 0x100000 Non-Securerwxl
Non-secure callable region 0 placed in flash region 0 with size 32.


SRAM regionDomainPermissions
00 0x00000 0x02000Securerwxl
01 0x02000 0x04000Securerwxl
02 0x04000 0x06000Securerwxl
03 0x06000 0x08000Securerwxl
04 0x08000 0x0a000Securerwxl
05 0x0a000 0x0c000Securerwxl
06 0x0c000 0x0e000Securerwxl
07 0x0e000 0x10000Securerwxl
08 0x10000 0x12000Non-Securerwxl
09 0x12000 0x14000Non-Securerwxl
10 0x14000 0x16000Non-Securerwxl
11 0x16000 0x18000Non-Securerwxl
12 0x18000 0x1a000Non-Securerwxl
13 0x1a000 0x1c000Non-Securerwxl
14 0x1c000 0x1e000Non-Securerwxl
15 0x1e000 0x20000Non-Securerwxl
16 0x20000 0x22000Non-Securerwxl
17 0x22000 0x24000Non-Securerwxl
18 0x24000 0x26000Non-Securerwxl
19 0x26000 0x28000Non-Securerwxl
20 0x28000 0x2a000Non-Securerwxl
21 0x2a000 0x2c000Non-Securerwxl
22 0x2c000 0x2e000Non-Securerwxl
23 0x2e000 0x30000Non-Securerwxl
24 0x30000 0x32000Non-Securerwxl
25 0x32000 0x34000Non-Securerwxl
26 0x34000 0x36000Non-Securerwxl
27 0x36000 0x38000Non-Securerwxl
28 0x38000 0x3a000Non-Securerwxl
29 0x3a000 0x3c000Non-Securerwxl
30 0x3c000 0x3e000Non-Securerwxl
31 0x3e000 0x40000Non-Securerwxl

PeripheralDomainStatus
00 NRF_P0               Non-SecureOK
01 NRF_CLOCK            Non-SecureOK
02 NRF_RTC0             Non-SecureOK
03 NRF_RTC1             Non-SecureOK
04 NRF_NVMC             Non-SecureOK
05 NRF_UARTE1           Non-SecureOK
06 NRF_UARTE2           SecureSKIP
07 NRF_TWIM2            Non-SecureOK
08 NRF_SPIM3            Non-SecureOK
09 NRF_TIMER0           Non-SecureOK
10 NRF_TIMER1           Non-SecureOK
11 NRF_TIMER2           Non-SecureOK
12 NRF_SAADC            Non-SecureOK
13 NRF_PWM0             Non-SecureOK
14 NRF_PWM1             Non-SecureOK
15 NRF_PWM2             Non-SecureOK
16 NRF_PWM3             Non-SecureOK
17 NRF_IPC              Non-SecureOK
18 NRF_VMC              Non-SecureOK
19 NRF_FPU              Non-SecureOK
20 NRF_EGU1             Non-SecureOK
21 NRF_EGU2             Non-SecureOK
22 NRF_DPPIC            Non-SecureOK
23 NRF_GPIOTE1          Non-SecureOK
24 NRF_REGULATORS       Non-SecureOK

SPM: NS image at 0x8000
SPM: NS MSP at 0x200111e0
SPM: NS reset vector at 0x8c31
SPM: prepare to jump to Non-Secure image.
*** Booting Zephyr OS build v2.1.99-ncs1  ***
Hello World! nrf5340_dk_nrf5340_cpuapp, 0
LOW

and that's it It stays LOW no matter how I connect Pin 0.10 to GND or to 3.3v (vcc) from PDK itself.

I am using SES (nordic edition) v4.52

OS windows 7 64 bit

NCS_TAG is v1.2.0

Thanks and Regards

Related