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

Can the SPI pins be used as GPIO on Thingy:91?

Hello,

I am trying to understand if I am able to use the SPI pins as GPIO when SPI is not being used. This post says that we could be able to use I2C and SPI pins besides normal GPIO pins, but if there is a way, I can't seem to find it.

Thank you,

Aleix.

Parents
  • Hello Aleix,

    Sorry for the late reply.

    Theoretically I too would say this is possible, due to the pin crossbar in both the nRF52840 and the nRF9160 SoC - however, on the Thingy:91 there are some dependencies that might cause troubles when doing this.
    For example, the PMIC that controls the different regulators is connected to the I2C, and it is configured during boot of the Thingy. I would think that this could potentially cause problems, depending on whatever you would have connected to these pins - since the I2C lines are pulled up.

    For reference, you can download the hardware schematics here.

    On the other hand, the SPI bus are not pulled up, and only connected to the two axelerometers. I would therefore think you could use the SPI pins however you would like, as long as the CS pins for the axelerometers are left alone. To do this, you should only have to make a connection to the pins, and reconfigure them in your software.

    To avoid the potential issues of using the I2C / SPI pins, I would instead suggest using some of the other alternatives:

    - There are 8 pins connected to the nRF52840 on the Thingy:91 ( see page 3 of the schematics ) labeled "nRF52_SPARE". These are connected to the unpopulated P6 pin header, and test points TP25 and TP26 ( page 6 ). Both the nRF52840 and nRF9160 chips are connected to the same I2C bus, so the nRF52840 can function as a GPIO-extender for the nRF9160. This is the option I recommend looking into first.

    - The pins controlling the NMOS transistors on page 2, two of which are accessible through TP 32 ( P0.13 ) and TP 33 ( P0.16 ).

    If you require even more GPIOS available, we could look into re-configuring the RTS and CTS pins of the two UART instances connecting the chips, or by disabling UART1 entirely, since it is only used for modem tracing. This would yield at least 4 additional GPIO pins.

    Please do not hesitate to let me know if something is unclear, or if you have any additional questions!

    Best regards,
    Karl

  • Hi Karl,

    First of all thank you very much for your extended reply. Slight smile

    Now that I know that theoretically it is possible, I give you additional information:

    -For consumption purposes, we have disabled the power supply for the nRF52840 and therefore all SPARE pins are unavailable.
    -We are already using all of the NMOS pins to control the power supply towards 3 different external sensors.
    -To communicate with the sensors we are using I2C so using them is not an option either.
    -We are interested in using the SPI pins because we created a little PCB that has a connection to TP34 which if I remember correctly is the SPI-SCK by default, P0.03.
    -If this was not possible, we would have a plan B: trying to get rid of the necessity of using this pin. Even a plan C: getting a cable towards pin P0.10 which I think is an additional free (or partially free, with a little hardware change) GPIO.

    But I have had trouble trying to configure this SCK-SPI (P0.03) to work as a GPIO. Could you give me some advice on how to do it? I have tried the following:

    gpio_dev = device_get_binding("GPIO_0");
    gpio_pin_configure(gpio_dev, #pinSCK-SPI(P0.03)#, GPIO_OUTPUT_HIGH);

    But I don't see the pin rising.

    I have also tried to change the .overlay file redirecting the sck pin to another one, making it "free". But I guess that since I don't have any configuration related to SPI in the proj.conf file, the spi configuration does not update because it is disabled. Just in case, I add my configuration file:

    #CONFIG_UART_0_NRF_UARTE=y
    
    # General config
    CONFIG_ASSERT=y
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    
    # BSD library
    CONFIG_BSD_LIBRARY=y
    
    # AT host library
    CONFIG_AT_HOST_LIBRARY=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    
    # Stacks and heaps
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_HEAP_MEM_POOL_SIZE=4096
    
    # i2c
    CONFIG_LOG=y
    CONFIG_I2C_LOG_LEVEL_DBG=y
    CONFIG_LOG_BACKEND_UART=n
    CONFIG_I2C=y
    CONFIG_I2C_NRFX=y
    CONFIG_I2C_2=y
    #CONFIG_I2C_2_NRF_TWIM=y
    
    # Enabling printf and floats
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    
    # Enabling JSON
    CONFIG_CJSON_LIB=y
    
    #gpio
    CONFIG_GPIO=y
    
    #debug RTT
    CONFIG_CONSOLE=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_UART_CONSOLE=n
    CONFIG_SERIAL=y
    CONFIG_LOG_IMMEDIATE=y
    
    
    #wdt
    CONFIG_WATCHDOG=y

    Thanks for your time,

    Aleix.

  • Hello again Aleix,

    Krawlow said:
    First of all thank you very much for your extended reply.

    No problem at all, I am happy to help! Slight smile

    Krawlow said:
    -For consumption purposes, we have disabled the power supply for the nRF52840 and therefore all SPARE pins are unavailable.
    -We are already using all of the NMOS pins to control the power supply towards 3 different external sensors.
    -To communicate with the sensors we are using I2C so using them is not an option either.

    Thank you for the additional information, this is very helpful!
    You say that you are using all the NMOS pins, but only mention 3 external sensors - do you mean that you are using all four NMOS? I am just asking to avoid any misunderstandings.

    Krawlow said:
    -We are interested in using the SPI pins because we created a little PCB that has a connection to TP34 which if I remember correctly is the SPI-SCK by default, P0.03.

    You remember correctly, TP34 accesses SPI-SCK at P0.03.

    My suggestion would be to instead use the UART1 rts and cts ( hardware flow control pins ), since they are unused anyways, so that you do not loose the SPI.
    This can be done like the following:

    &uart1 {
     /delete-property/ rts-pin;
     /delete-property/ cts-pin;
    };


    Krawlow said:
    But I don't see the pin rising.

    I would think that you should be able to control P0.03 using the modifications you have described.
    How did you disable the SPI, something like this: ?

    &spi3 {
     status = "disabled";
    };


    Could you also make sure that you are compiling with the correct .overlay file? Typically, this would be thingy91_nrf9160ns.overlay for non-secure Thingy:91-build.

    Krawlow said:
    plan B: trying to get rid of the necessity of using this pin.

    If you do not mind telling me, what will the pin be used for?

    Krawlow said:
    plan C: getting a cable towards pin P0.10 which I think is an additional free (or partially free, with a little hardware change) GPIO.

    Yes, if you are neither using the nRF52840 nor the INT2 of the ADXL's then you may use this pin as GPIO also, this is correct.

    Best regards,
    Karl

  • Hello Karl,

    I will copy you in the way of answering if you don't mind Slight smile

    You say that you are using all the NMOS pins, but only mention 3 external sensors - do you mean that you are using all four NMOS? I am just asking to avoid any misunderstandings.

    Yes, that was a mistake of mine. We are using all of the NMOS, 3 of them as a power supply switch for 3 different sensors and for the fourth we are using its associated GPIO for an external magnetic switch.

    My suggestion would be to instead use the UART1 rts and cts ( hardware flow control pins ), since they are unused anyways, so that you do not loose the SPI.

    We could also consider this, but was not able to find any suitable location on the Thingy where we could connect to these pins, I think they don't appear on the User Guide.

    I would think that you should be able to control P0.03 using the modifications you have described.
    How did you disable the SPI, something like this: ?

    When I put this lines in "thingy91_nrf9160ns.overlay" I get the following error trying to load the project:

    If you do not mind telling me, what will the pin be used for?

    No problem: we will use the additional GPIO to trigger the enable pin of a voltage converter up to 5 volts. We are trying to control power consumption here. To avoid using an additional GPIO we would connect the enable pin directly to the NMOS pins which would have some disadvantages in terms of power consumption:

    -We would have to mantain this pin up, and subsequently the sensor of that pin throughout all of the read of the remaining sensors.
    -Adding up-time to the first sensor for the necessary waiting of the power converter prior to having an stable voltage.

    Thanks for the help!

    Aleix.

  • Hello Aleix,

    Krawlow said:
    I will copy you in the way of answering if you don't mind

    I do not mind at all! I personally find it far easier to trace the different questions when formatted in this manner, thank you for increasing the readability of your comments even further! :) 

    Krawlow said:
    Yes, that was a mistake of mine. We are using all of the NMOS, 3 of them as a power supply switch for 3 different sensors and for the fourth we are using its associated GPIO for an external magnetic switch.

    No problem at all, thank you for telling me. This is helpful to know.

    Krawlow said:
    We could also consider this, but was not able to find any suitable location on the Thingy where we could connect to these pins, I think they don't appear on the User Guide.

    Yes, this part is a bit trickier - sorry for not mentioning it in my last comment.
    To use these pins, it will require that you cut the Solderbridges 10 and 11 ( please see the Hardware schematics ) and solder a connection to only 1 end of the now-cut solder bridge.
    This will require some steady hands to do the soldering, since the SB pads are quite small, but its absolutely doable.

    Krawlow said:
    When I put this lines in "thingy91_nrf9160ns.overlay" I get the following error trying to load the project:

    Hm.. Could you share what you have ( had ) previously done to disable the SPI? You mentioned earlier that you had disabled it, but not how you had done it - I just wanted to verify what you had done to achieve this, since you were not able to control the pin using the code snippet you posted. Could you perhaps also share the relevant parts of your .overlay file?

    Krawlow said:

    No problem: we will use the additional GPIO to trigger the enable pin of a voltage converter up to 5 volts. We are trying to control power consumption here. To avoid using an additional GPIO we would connect the enable pin directly to the NMOS pins which would have some disadvantages in terms of power consumption:

    -We would have to mantain this pin up, and subsequently the sensor of that pin throughout all of the read of the remaining sensors.
    -Adding up-time to the first sensor for the necessary waiting of the power converter prior to having an stable voltage.

    Thank you for the explanation. I concur that having them on the same pin will cause some unnecessary power draw. Could you attempt to solder onto the cut solder-bridge, and let me know if you then get the functionality you were seeking? 

    Best regards,
    Karl

  • Hi Karl,

    Yes, this part is a bit trickier - sorry for not mentioning it in my last comment.
    To use these pins, it will require that you cut the Solderbridges 10 and 11 ( please see the Hardware schematics ) and solder a connection to only 1 end of the now-cut solder bridge.
    This will require some steady hands to do the soldering, since the SB pads are quite small, but its absolutely doable.

    This information is very useful, but we can't consider this approach at the moment, because a cable to P0.10 would be easier to solder. Also, the advantage of having a test point at the top is that we can use pins with springs to connect to them, but that wouldn't be possible with half of a solder bridge, unfortunately.

    Hm.. Could you share what you have ( had ) previously done to disable the SPI? You mentioned earlier that you had disabled it, but not how you had done it - I just wanted to verify what you had done to achieve this, since you were not able to control the pin using the code snippet you posted. Could you perhaps also share the relevant parts of your .overlay file?

    We would much rather achieve this solution. Prior to creating this thread, all I did was try to "disabling" it just like you proposed me before, but got the same error. Then I only tried to redirect the SCK-SPI pin (originally on pin 3) to another pin.

    I also tried to understand why writing "disabled" on the .overlay file would give an error. Tried to confirm if the SPI was disabled or not by having a look on the builded .dts file. I assumed it was already disabled because I think everything is unless you activate it by adding the corresponding CONFIG inside prj.conf.

    All I have in my .overlay file is a change in the speed of the I2C bus, so I don't think its anything related with it. However, above you have my prj.conf file and also here I add the .dts file of my build.

    /dts-v1/;
    
    / {
    	#address-cells = < 0x1 >;
    	#size-cells = < 0x1 >;
    	model = "Nordic Thingy91 nRF9160";
    	compatible = "nordic,thingy91-nrf9160";
    	chosen {
    		zephyr,flash-controller = &flash_controller;
    		zephyr,entropy = &cryptocell_sw;
    		zephyr,console = &uart0;
    		zephyr,shell-uart = &uart0;
    		zephyr,uart-mcumgr = &uart0;
    		zephyr,flash = &flash0;
    		zephyr,sram = &sram0_ns;
    		zephyr,code-partition = &slot0_ns_partition;
    	};
    	aliases {
    		flash-controller = &flash_controller;
    		rtc-0 = &rtc0;
    		rtc-1 = &rtc1;
    		uart-0 = &uart0;
    		uart-1 = &uart1;
    		uart-2 = &uart2;
    		uart-3 = &uart3;
    		adc-0 = &adc;
    		egu-0 = &egu0;
    		egu-1 = &egu1;
    		egu-2 = &egu2;
    		egu-3 = &egu3;
    		egu-4 = &egu4;
    		egu-5 = &egu5;
    		gpio-0 = &gpio0;
    		gpiote-0 = &gpiote;
    		i2c-0 = &i2c0;
    		i2c-1 = &i2c1;
    		i2c-2 = &i2c2;
    		i2c-3 = &i2c3;
    		i2s-0 = &i2s0;
    		pdm-0 = &pdm0;
    		spi-0 = &spi0;
    		spi-1 = &spi1;
    		spi-2 = &spi2;
    		spi-3 = &spi3;
    		pwm-0 = &pwm0;
    		pwm-1 = &pwm1;
    		pwm-2 = &pwm2;
    		pwm-3 = &pwm3;
    		wdt-0 = &wdt;
    		timer-0 = &timer0;
    		timer-1 = &timer1;
    		timer-2 = &timer2;
    		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;
    	};
    	soc {
    		#address-cells = < 0x1 >;
    		#size-cells = < 0x1 >;
    		compatible = "nordic,nRF9160-SICA", "nordic,nRF9160", "nordic,nRF91", "simple-bus";
    		interrupt-parent = < &nvic >;
    		ranges;
    		nvic: interrupt-controller@e000e100 {
    			compatible = "arm,v8m-nvic";
    			reg = < 0xe000e100 0xc00 >;
    			interrupt-controller;
    			#interrupt-cells = < 0x2 >;
    			arm,num-irq-priority-bits = < 0x3 >;
    			phandle = < 0x1 >;
    		};
    		systick: timer@e000e010 {
    			compatible = "arm,armv8m-systick";
    			reg = < 0xe000e010 0x10 >;
    			status = "disabled";
    		};
    		sram0: memory@20000000 {
    			compatible = "mmio-sram";
    			reg = < 0x20000000 0x10000 >;
    		};
    		peripheral@40000000 {
    			#address-cells = < 0x1 >;
    			#size-cells = < 0x1 >;
    			ranges = < 0x0 0x40000000 0x10000000 >;
    			flash_controller: flash-controller@39000 {
    				compatible = "nordic,nrf91-flash-controller";
    				reg = < 0x39000 0x1000 >;
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x1 >;
    				label = "NRF_FLASH_DRV_NAME";
    				flash0: flash@0 {
    					compatible = "soc-nv-flash";
    					label = "NRF_FLASH";
    					erase-block-size = < 0x1000 >;
    					write-block-size = < 0x4 >;
    					reg = < 0x0 0x100000 >;
    					partitions {
    						compatible = "fixed-partitions";
    						#address-cells = < 0x1 >;
    						#size-cells = < 0x1 >;
    						boot_partition: partition@0 {
    							label = "mcuboot";
    							reg = < 0x0 0x10000 >;
    						};
    						slot0_partition: partition@10000 {
    							label = "image-0";
    							reg = < 0x10000 0x30000 >;
    						};
    						slot0_ns_partition: partition@40000 {
    							label = "image-0-nonsecure";
    							reg = < 0x40000 0x40000 >;
    						};
    						slot1_partition: partition@80000 {
    							label = "image-1";
    							reg = < 0x80000 0x30000 >;
    						};
    						slot1_ns_partition: partition@b0000 {
    							label = "image-1-nonsecure";
    							reg = < 0xb0000 0x40000 >;
    						};
    						scratch_partition: partition@f0000 {
    							label = "image-scratch";
    							reg = < 0xf0000 0xa000 >;
    						};
    						storage_partition: partition@fa000 {
    							label = "storage";
    							reg = < 0xfa000 0x6000 >;
    						};
    					};
    				};
    			};
    			adc: adc@e000 {
    				compatible = "nordic,nrf-saadc";
    				reg = < 0xe000 0x1000 >;
    				interrupts = < 0xe 0x1 >;
    				status = "okay";
    				label = "ADC_0";
    				#io-channel-cells = < 0x1 >;
    			};
    			dppic: dppic@17000 {
    				compatible = "nordic,nrf-dppic";
    				reg = < 0x17000 0x1000 >;
    				status = "okay";
    				label = "DPPIC";
    			};
    			egu0: egu@1b000 {
    				compatible = "nordic,nrf-egu";
    				reg = < 0x1b000 0x1000 >;
    				interrupts = < 0x1b 0x1 >;
    				status = "okay";
    			};
    			egu1: egu@1c000 {
    				compatible = "nordic,nrf-egu";
    				reg = < 0x1c000 0x1000 >;
    				interrupts = < 0x1c 0x1 >;
    				status = "okay";
    			};
    			egu2: egu@1d000 {
    				compatible = "nordic,nrf-egu";
    				reg = < 0x1d000 0x1000 >;
    				interrupts = < 0x1d 0x1 >;
    				status = "okay";
    			};
    			egu3: egu@1e000 {
    				compatible = "nordic,nrf-egu";
    				reg = < 0x1e000 0x1000 >;
    				interrupts = < 0x1e 0x1 >;
    				status = "okay";
    			};
    			egu4: egu@1f000 {
    				compatible = "nordic,nrf-egu";
    				reg = < 0x1f000 0x1000 >;
    				interrupts = < 0x1f 0x1 >;
    				status = "okay";
    			};
    			egu5: egu@20000 {
    				compatible = "nordic,nrf-egu";
    				reg = < 0x20000 0x1000 >;
    				interrupts = < 0x20 0x1 >;
    				status = "okay";
    			};
    			i2s0: i2s@28000 {
    				compatible = "nordic,nrf-i2s";
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0x28000 0x1000 >;
    				interrupts = < 0x28 0x1 >;
    				status = "disabled";
    				label = "I2S_0";
    			};
    			kmu: kmu@39000 {
    				compatible = "nordic,nrf-kmu";
    				reg = < 0x39000 0x1000 >;
    				interrupts = < 0x39 0x1 >;
    				status = "okay";
    			};
    			pdm0: pdm@26000 {
    				compatible = "nordic,nrf-pdm";
    				reg = < 0x26000 0x1000 >;
    				interrupts = < 0x26 0x1 >;
    				status = "disabled";
    				label = "PDM_0";
    			};
    			regulators: regulator@4000 {
    				compatible = "nordic,nrf-regulators";
    				reg = < 0x4000 0x1000 >;
    				status = "okay";
    			};
    			vmc: vmc@3a000 {
    				compatible = "nordic,nrf-vmc";
    				reg = < 0x3a000 0x1000 >;
    				status = "okay";
    			};
    			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 >;
    			};
    			uart1: uart@9000 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0x9000 0x1000 >;
    				interrupts = < 0x9 0x1 >;
    				status = "okay";
    				label = "UART_1";
    				current-speed = < 0xf4240 >;
    				tx-pin = < 0x16 >;
    				rx-pin = < 0x17 >;
    				rts-pin = < 0x18 >;
    				cts-pin = < 0x19 >;
    			};
    			uart2: uart@a000 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0xa000 0x1000 >;
    				interrupts = < 0xa 0x1 >;
    				status = "disabled";
    				label = "UART_2";
    			};
    			uart3: uart@b000 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0xb000 0x1000 >;
    				interrupts = < 0xb 0x1 >;
    				status = "disabled";
    				label = "UART_3";
    			};
    			i2c0: i2c@8000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0x8000 0x1000 >;
    				clock-frequency = < 0x186a0 >;
    				interrupts = < 0x8 0x1 >;
    				status = "disabled";
    				label = "I2C_0";
    			};
    			i2c1: i2c@9000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0x9000 0x1000 >;
    				clock-frequency = < 0x186a0 >;
    				interrupts = < 0x9 0x1 >;
    				status = "disabled";
    				label = "I2C_1";
    			};
    			i2c2: i2c@a000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0xa000 0x1000 >;
    				clock-frequency = < 0x186a0 >;
    				interrupts = < 0xa 0x1 >;
    				status = "okay";
    				label = "I2C_2";
    				compatible = "nordic,nrf-twim";
    				sda-pin = < 0xb >;
    				scl-pin = < 0xc >;
    				bme680@76 {
    					compatible = "bosch,bme680";
    					label = "BME680";
    					reg = < 0x76 >;
    				};
    				bh1749@38 {
    					compatible = "rohm,bh1749";
    					label = "BH1749";
    					reg = < 0x38 >;
    					int-gpios = < &gpio0 0x1b 0x0 >;
    				};
    			};
    			i2c3: i2c@b000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0xb000 0x1000 >;
    				clock-frequency = < 0x186a0 >;
    				interrupts = < 0xb 0x1 >;
    				status = "disabled";
    				label = "I2C_3";
    			};
    			spi0: spi@8000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0x8000 0x1000 >;
    				interrupts = < 0x8 0x1 >;
    				status = "disabled";
    				label = "SPI_0";
    			};
    			spi1: spi@9000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0x9000 0x1000 >;
    				interrupts = < 0x9 0x1 >;
    				status = "disabled";
    				label = "SPI_1";
    			};
    			spi2: spi@a000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0xa000 0x1000 >;
    				interrupts = < 0xa 0x1 >;
    				status = "disabled";
    				label = "SPI_2";
    			};
    			spi3: spi@b000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0xb000 0x1000 >;
    				interrupts = < 0xb 0x1 >;
    				status = "okay";
    				label = "SPI_3";
    				compatible = "nordic,nrf-spim";
    				sck-pin = < 0x3 >;
    				mosi-pin = < 0x4 >;
    				miso-pin = < 0x5 >;
    				cs-gpios = < &gpio0 0x8 0x0 >, < &gpio0 0x7 0x0 >;
    				adxl362@0 {
    					compatible = "adi,adxl362";
    					label = "ADXL362";
    					spi-max-frequency = < 0x7a1200 >;
    					reg = < 0x0 >;
    					int1-gpios = < &gpio0 0x9 0x0 >;
    				};
    				adxl372@1 {
    					compatible = "adi,adxl372";
    					label = "ADXL372";
    					spi-max-frequency = < 0x7a1200 >;
    					reg = < 0x1 >;
    					int1-gpios = < &gpio0 0x6 0x0 >;
    				};
    			};
    			pwm0: pwm@21000 {
    				compatible = "nordic,nrf-pwm";
    				reg = < 0x21000 0x1000 >;
    				interrupts = < 0x21 0x1 >;
    				status = "okay";
    				label = "PWM_0";
    				#pwm-cells = < 0x1 >;
    				ch0-pin = < 0x1d >;
    				ch1-pin = < 0x1e >;
    				ch2-pin = < 0x1f >;
    			};
    			pwm1: pwm@22000 {
    				compatible = "nordic,nrf-pwm";
    				reg = < 0x22000 0x1000 >;
    				interrupts = < 0x22 0x1 >;
    				status = "okay";
    				label = "PWM_1";
    				#pwm-cells = < 0x1 >;
    				ch0-pin = < 0x1c >;
    			};
    			pwm2: pwm@23000 {
    				compatible = "nordic,nrf-pwm";
    				reg = < 0x23000 0x1000 >;
    				interrupts = < 0x23 0x1 >;
    				status = "okay";
    				label = "PWM_2";
    				#pwm-cells = < 0x1 >;
    				ch0-pin = < 0xd >;
    				ch1-pin = < 0xe >;
    				ch2-pin = < 0xf >;
    				ch3-pin = < 0x10 >;
    			};
    			pwm3: pwm@24000 {
    				compatible = "nordic,nrf-pwm";
    				reg = < 0x24000 0x1000 >;
    				interrupts = < 0x24 0x1 >;
    				status = "okay";
    				label = "PWM_3";
    				#pwm-cells = < 0x1 >;
    			};
    			gpio0: gpio@842500 {
    				compatible = "nordic,nrf-gpio";
    				gpio-controller;
    				reg = < 0x842500 0x300 >;
    				#gpio-cells = < 0x2 >;
    				label = "GPIO_0";
    				status = "okay";
    				phandle = < 0x2 >;
    			};
    			rtc0: rtc@14000 {
    				compatible = "nordic,nrf-rtc";
    				reg = < 0x14000 0x1000 >;
    				interrupts = < 0x14 0x1 >;
    				status = "okay";
    				clock-frequency = < 0x8000 >;
    				prescaler = < 0x1 >;
    				label = "RTC_0";
    			};
    			rtc1: rtc@15000 {
    				compatible = "nordic,nrf-rtc";
    				reg = < 0x15000 0x1000 >;
    				interrupts = < 0x15 0x1 >;
    				status = "okay";
    				clock-frequency = < 0x8000 >;
    				prescaler = < 0x1 >;
    				label = "RTC_1";
    			};
    			clock: clock@5000 {
    				compatible = "nordic,nrf-clock";
    				reg = < 0x5000 0x1000 >;
    				interrupts = < 0x5 0x1 >;
    				status = "okay";
    				label = "CLOCK";
    			};
    			power: power@5000 {
    				compatible = "nordic,nrf-power";
    				reg = < 0x5000 0x1000 >;
    				interrupts = < 0x5 0x1 >;
    				status = "okay";
    			};
    			wdt: wdt0: watchdog@18000 {
    				compatible = "nordic,nrf-watchdog";
    				reg = < 0x18000 0x1000 >;
    				interrupts = < 0x18 0x1 >;
    				status = "okay";
    				label = "WDT";
    			};
    			timer0: timer@f000 {
    				compatible = "nordic,nrf-timer";
    				status = "okay";
    				reg = < 0xf000 0x1000 >;
    				interrupts = < 0xf 0x1 >;
    				prescaler = < 0x0 >;
    				label = "TIMER_0";
    			};
    			timer1: timer@10000 {
    				compatible = "nordic,nrf-timer";
    				status = "okay";
    				reg = < 0x10000 0x1000 >;
    				interrupts = < 0x10 0x1 >;
    				prescaler = < 0x0 >;
    				label = "TIMER_1";
    			};
    			timer2: timer@11000 {
    				compatible = "nordic,nrf-timer";
    				status = "okay";
    				reg = < 0x11000 0x1000 >;
    				interrupts = < 0x11 0x1 >;
    				prescaler = < 0x0 >;
    				label = "TIMER_2";
    			};
    		};
    		gpiote: gpiote@40031000 {
    			compatible = "nordic,nrf-gpiote";
    			reg = < 0x40031000 0x1000 >;
    			interrupts = < 0x31 0x5 >;
    			status = "okay";
    			label = "GPIOTE_1";
    		};
    		cryptocell_sw: cryptocell-sw {
    			compatible = "nordic,nrf-cc310-sw";
    			#address-cells = < 0x0 >;
    			label = "CRYPTOCELL_SW";
    		};
    	};
    	cpus {
    		#address-cells = < 0x1 >;
    		#size-cells = < 0x0 >;
    		cpu@0 {
    			device_type = "cpu";
    			compatible = "arm,cortex-m33f";
    			reg = < 0x0 >;
    			#address-cells = < 0x1 >;
    			#size-cells = < 0x1 >;
    			mpu: mpu@e000ed90 {
    				compatible = "arm,armv8m-mpu";
    				reg = < 0xe000ed90 0x40 >;
    				arm,num-mpu-regions = < 0x10 >;
    			};
    		};
    	};
    	buttons {
    		compatible = "gpio-keys";
    		button0: button_0 {
    			gpios = < &gpio0 0x1a 0x11 >;
    			label = "Button 1";
    		};
    	};
    	leds {
    		compatible = "gpio-leds";
    		red_led: led_1 {
    			gpios = < &gpio0 0x1d 0x0 >;
    			label = "RGB red channel";
    		};
    		green_led: led_2 {
    			gpios = < &gpio0 0x1e 0x0 >;
    			label = "RGB green channel";
    		};
    		blue_led: led_3 {
    			gpios = < &gpio0 0x1f 0x0 >;
    			label = "RGB blue channel";
    		};
    		sense_red_led: led_4 {
    			gpios = < &gpio0 0x0 0x0 >;
    			label = "RGB red channel";
    		};
    		sense_green_led: led_5 {
    			gpios = < &gpio0 0x1 0x0 >;
    			label = "RGB green channel";
    		};
    		sense_blue_led: led_6 {
    			gpios = < &gpio0 0x2 0x0 >;
    			label = "RGB blue channel";
    		};
    	};
    	sram0_bsd: memory@20010000 {
    		device_type = "memory";
    		compatible = "mmio-sram";
    		reg = < 0x20010000 0x10000 >;
    	};
    	sram0_ns: memory@20020000 {
    		device_type = "memory";
    		compatible = "mmio-sram";
    		reg = < 0x20020000 0x20000 >;
    	};
    };
    

    For what I can see, spi3 is in "okay" state, so if we found how to disable it, then it may be possible to use the pins as GPIO. I will try again to redirect the sck pin to another place and confirm my change with this file. I don't understand why that wouldn't work.

    We almost got this Karl!

    Aleix.

  • Hey Karl!

    Wondering on the idea of disabling the SPI I found this post. Where they directly modified the SPI registers to disable it. After doing this I was able to control the SCK as a regular GPIO! I proved that this piece of code did the change, without having to make any change on the prj.conf or the .overlay files:

    void disable_spi() {
        NRF_SPIM3_NS->TASKS_STOP = 1;
        NRF_SPIM3_NS->ENABLE = 0;      // To disable SPI3
        NRF_SPIM3_NS->PSEL.SCK = 0xFFFFFFFF;
        NRF_SPIM3_NS->PSEL.MISO = 0xFFFFFFFF;
        NRF_SPIM3_NS->PSEL.MOSI = 0xFFFFFFFF;
        NRF_P0_NS->OUTCLR = (1 << 3); // P0.03 (SCK)
        NRF_P0_NS->OUTCLR = (1 << 5); // P0.05 (MISO)
        NRF_P0_NS->OUTCLR = (1 << 4); // P0.04 (MOSI)
    }

    Thanks for your help Karl!

    Aleix.

Reply
  • Hey Karl!

    Wondering on the idea of disabling the SPI I found this post. Where they directly modified the SPI registers to disable it. After doing this I was able to control the SCK as a regular GPIO! I proved that this piece of code did the change, without having to make any change on the prj.conf or the .overlay files:

    void disable_spi() {
        NRF_SPIM3_NS->TASKS_STOP = 1;
        NRF_SPIM3_NS->ENABLE = 0;      // To disable SPI3
        NRF_SPIM3_NS->PSEL.SCK = 0xFFFFFFFF;
        NRF_SPIM3_NS->PSEL.MISO = 0xFFFFFFFF;
        NRF_SPIM3_NS->PSEL.MOSI = 0xFFFFFFFF;
        NRF_P0_NS->OUTCLR = (1 << 3); // P0.03 (SCK)
        NRF_P0_NS->OUTCLR = (1 << 5); // P0.05 (MISO)
        NRF_P0_NS->OUTCLR = (1 << 4); // P0.04 (MOSI)
    }

    Thanks for your help Karl!

    Aleix.

Children
  • Hello Aleix,

    It appears that I unfortunately did not see your reply while writing my previous comment.

    Krawlow said:
    After doing this I was able to control the SCK as a regular GPIO! I proved that this piece of code did the change, without having to make any change on the prj.conf or the .overlay files:

    I am happy to hear that you were able to take control of the pins without making changes to the prj.conf or .overlay file!
    This is a good solution in your case.

    Krawlow said:
    Thanks for your help Karl!

    No problem at all, I am happy to help!

    Please do not hesitate to let me know if you should encounter any other issues or questions in the future.

    Best regards,
    Karl

Related