<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105749/thingy91-how-to-manually-configure-spi-chip-select-pin-as-gpio-output-pin</link><description>I am having some issues with the Thingy91 and SPI. I want to configure GPIO0 8 as GPIO_OUTPUT pin. 
 This is my source code: 
 
 You can also access my code at github: 
 https://github.com/krupis/thingy91_spi_test 
 gpio_configure_bug branch. 
 
 
 It</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Nov 2023 09:16:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105749/thingy91-how-to-manually-configure-spi-chip-select-pin-as-gpio-output-pin" /><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456622?ContentTypeID=1</link><pubDate>Tue, 21 Nov 2023 09:16:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f48eb02d-d54f-4ebc-827c-93c2eb9b5523</guid><dc:creator>zazas321</dc:creator><description>&lt;p&gt;Yeah I figured that could be the case. The reason why I believe it could be somehow related to the Thingy 91 is because it does not support logging via UART from the nRF9160 by default. You need to have connectivity bridge application running on the nRF52840 so all the logs from the nRF9160 are transfered the nRF52840 and then being transfered to serial monitor.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Perhaps that has to do something why it acts so weird.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456621?ContentTypeID=1</link><pubDate>Tue, 21 Nov 2023 09:13:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a058c5ee-d811-4f48-8c30-f8e1aaf082b6</guid><dc:creator>runsiv</dc:creator><description>&lt;p&gt;I tested on a different DK. Working from home today, so will update the case tomorrow when I have my thing91&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Runar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456605?ContentTypeID=1</link><pubDate>Tue, 21 Nov 2023 08:26:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b3fc9fc-207e-457c-9103-c11d91ed5096</guid><dc:creator>zazas321</dc:creator><description>&lt;p&gt;Please clarify if you are testing this on the Thingy 91 or some other DK?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After adding CONFIG_LOG_MODE_IMMEDIATE=y&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;it now prints printf and printk before the crash:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1700555081292v1.png" /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;I think that special character is just some serial data getting flushed out after I program the device. It only appears after I program the device while having the serial port open. It will not appear if I just reboot the device so I dont think that should be an issue.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;It is also very concerning why would you not see the printf being printed. You should definately see printf being printed before the crash if you are using Thingy 91 as there is no reason why you would not.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;Can you confirm if the order of your print statements are as following:&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;printk&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Program started printk&lt;/span&gt;&lt;span&gt;\n&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;printf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Program started pritnf &lt;/span&gt;&lt;span&gt;\n&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;LOG_DBG&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;Program started log_dbg&lt;/span&gt;&lt;span&gt;\n&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;[quote userid="122502" url="~/f/nordic-q-a/105749/thingy91-how-to-manually-configure-spi-chip-select-pin-as-gpio-output-pin/456603"]We have also in the past seen usb hubs might affect thing also.&amp;nbsp;[/quote]&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;I plug the Thing91 directly to my laptop so expansion hubs should not be a problem.&lt;br /&gt;&lt;br /&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size:inherit;"&gt;It is very interesting why we both see different results on our identical setups (I assume you tried my project on the Thingy91).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;If you did not try my specific project, could you please try it to ensure you are not able to reproduce the issue with my particular prj.conf and etc...&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;You need:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Thingy 91 (Connectivity Bridge application running on the nRF52840 and my program running on the nRF9160)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456603?ContentTypeID=1</link><pubDate>Tue, 21 Nov 2023 08:13:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95697ccc-c388-49bf-b324-a2211b235a91</guid><dc:creator>runsiv</dc:creator><description>&lt;p&gt;Hi Lukas&lt;/p&gt;
&lt;p&gt;I tested your setup on my part. I was not able to recreate what you are seeing. At my side only the printk was printed before the crash.&amp;nbsp;&lt;br /&gt;On your end it looks like it might be some corruption since you have the special sign before the printf line. You could also try with an CONFIG_LOG_IMMEDIATE to make it print the log at once.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We have also in the past seen usb hubs might affect thing also.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There is also a known bug in jlink that can affect you, we have a workaround for it &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.0/zephyr/develop/flash_debug/nordic_segger.html#disabling-the-mass-storage-device-functionality"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Runar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456217?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2023 15:47:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b27de8ba-769c-4ebf-abb9-ed2c1472f92a</guid><dc:creator>zazas321</dc:creator><description>&lt;p&gt;Since you mentioned printf and log_dbg, I have tried something out. Please see the source code below:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;

#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include &amp;lt;zephyr/logging/log.h&amp;gt;
LOG_MODULE_REGISTER(main);


// Define the CS pin
#define CS_PIN 8
const struct device *gpio_dev;

int main(void)
{
	int err;
	printk(&amp;quot;Program started printk\n&amp;quot;);
	printf(&amp;quot;Program started pritnf \n&amp;quot;);
	LOG_DBG(&amp;quot;Program started log_dbg\n&amp;quot;);
	gpio_pin_configure(gpio_dev, CS_PIN, GPIO_OUTPUT);

	if (err &amp;lt; 0)
	{
		printk(&amp;quot;GPIO pin configure failed with error %d\n&amp;quot;, err);
		return 0;
	}
	k_msleep(1000);
	printk(&amp;quot;getting into while loop \n&amp;quot;);
	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;with the following prj.conf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_LOG=y
CONFIG_SPI=y
CONFIG_GPIO=y

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As you can see from the code above, I am trying 3 different print methods (printf, printk, and log_dbg).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;From the serial terminal I see that only printf is being printed before the CPU crashed at the function gpio_pin_configure&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1700236032150v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This tells me that printf prints to the console instantly whereas log_dbg and printk is not.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456180?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2023 13:49:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2323a9a5-2aab-4e34-8914-2696ebc02dc6</guid><dc:creator>runsiv</dc:creator><description>&lt;p&gt;Update:&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;The reason &amp;quot;printk&amp;quot; works is that it is included as a part of&amp;nbsp;&lt;span&gt;&lt;span dir="ltr"&gt;zephyr/include/zephyr/kernel_includes.h&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span dir="ltr"&gt;Regards&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span dir="ltr"&gt;Runar&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456174?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2023 13:39:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e756eb21-f6a6-4c51-a218-e68a7a6c42e0</guid><dc:creator>runsiv</dc:creator><description>&lt;p&gt;It might be that there are some default include for printk in for board. I will have to check, but I know that in our devAcademy course we write that you need to include printk.h.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;we also write the following &amp;quot;&lt;span&gt;The output of the&amp;nbsp;&lt;/span&gt;&lt;code&gt;printk()&lt;/code&gt;&lt;span&gt;&amp;nbsp;is not deferred, meaning the output is sent immediately to the console without any mutual exclusion or buffering&amp;quot;.&amp;nbsp; I have replicated the behavior&amp;nbsp;on my end I will need to investigate as it does not make sense for me. I will update the case when I understand why.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In your case you are not using any logging, just printk which is a less powerful version of printf. I would recommend using &amp;quot;log_inf/log_err..&amp;quot; as I normally find it more powerful during debugging. I specifically&amp;nbsp;really like the log_dbg do to this &amp;quot;&amp;quot;If you use LOG_DBG(), you can choose not to include that level of logging when you compile the production version of your code.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Runar&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456164?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2023 13:02:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:099274a4-1413-4890-9b8d-34ba5ce0fb9f</guid><dc:creator>zazas321</dc:creator><description>&lt;p&gt;Thanks for a quick response.&lt;/p&gt;
&lt;p&gt;I was not aware that printk statement requires any include.&lt;/p&gt;
&lt;p&gt;Could it be because I am using&amp;nbsp;&lt;span&gt;CONFIG_LOG_MODE_DEFERRED (i think its the default mode)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and it simply does not have enough time to process the print statement and send it out to the console as the CPU crashes too fast?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/456149?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2023 12:32:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55190c52-f17e-46a9-b5cb-3f91263a3425</guid><dc:creator>runsiv</dc:creator><description>&lt;p&gt;Glad to&amp;nbsp;hear it works now.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regarding question two. Did you include the header file for printk? I could not see it when I looked over the code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will take a look at the case you linked. From a short glance the verified response was not from a Nordic employee and was verified by another user&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Runar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 How to manually configure SPI chip select pin as GPIO output pin</title><link>https://devzone.nordicsemi.com/thread/455984?ContentTypeID=1</link><pubDate>Thu, 16 Nov 2023 13:21:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fcbe7d3f-7eed-4f95-a2eb-02c47f2c8fc9</guid><dc:creator>zazas321</dc:creator><description>&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I have tried different method of configuring GPIO pin. Check the code below:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;

#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include &amp;lt;zephyr/logging/log.h&amp;gt;
LOG_MODULE_REGISTER(main);


// Define the CS pin
// #define CS_PIN 8
// const struct device *gpio_dev;

#define MY_GPIO0 DT_NODELABEL(gpio0)
#define GPIO0_8_CS 8
const struct device* gpio0_dev = DEVICE_DT_GET(MY_GPIO0);

int main(void)
{
	int err;
	printk(&amp;quot;Program started \n&amp;quot;);
	gpio_pin_configure(gpio0_dev, GPIO0_8_CS, GPIO_OUTPUT);

	if (err &amp;lt; 0)
	{
		printk(&amp;quot;GPIO pin configure failed with error %d\n&amp;quot;, err);
		return 0;
	}
	k_msleep(1000);
	printk(&amp;quot;getting into while loop \n&amp;quot;);
	return 0;
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The above code seem to work fine and no longer crashed at gpio_pin_conifigure call.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I believe the method that has been suggested in the post below&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/102820/is-it-possible-to-control-spi-chip-select-pin-with-zephyr-gpio-api"&gt;Is it possible to control SPI chip select pin with Zephyr GPIO API?&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;is not even a valid method and should not be used. In the above method, it is not even specified which gpio port to use (gpio0 or gpio1 or others)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>