<?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>configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/23367/configuring-gpio-pin-stops-lfxo-and-rtc-counter</link><description>I found that blindly configuring all GPIO pins can stop the LFXO and RTC counter. I am reporting this as: something to be aware of, not obvious to everyone. Not a question, just saying &amp;quot;don&amp;#39;t do that, or do it in a different order.&amp;quot; 
 After starting</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 17 Jul 2017 19:32:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/23367/configuring-gpio-pin-stops-lfxo-and-rtc-counter" /><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91859?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2017 19:32:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a31b84a-603f-4380-9685-602385d0f597</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;I was compiling without optimization.  Again, this is low priority for me now considering that I can&amp;#39;t replicate it (at least when not using the debugger) and I have removed the suspect code (the GPIO config) anyway.  But I am curious whether the spurious behavior is caused by timing or sleep, so I think a different test would be your code with an infinite loop but where you configure GPIO pins in every loop iteration.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91858?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2017 11:12:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fdc443d-115a-4165-824c-112f36c44f6a</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;I haven&amp;#39;t tried with GDB but tested on Keil it worked fine when stepping in debug mode.
Suspect it may have something to do with optimization level or other compile flag, could you check ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91857?ContentTypeID=1</link><pubDate>Fri, 14 Jul 2017 12:59:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6130b4e-9ff3-4c1e-a81c-e8d4d1e567d7</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;I tried to replicate.  My code is below.  When I step into the code on the debugger, it doesn&amp;#39;t complete (infinite loop at the last waitOneTick()) meaning the RTC0 counter has stopped.  If I don&amp;#39;t step, but just resume the debugger, main() does complete. I don&amp;#39;t understand why it behaves differently depending on whether I am single-stepping.  The RTC and clocks should still be running while debugging.  My environment is Eclipse/GCC ARM/C++.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/*
 * Test whether configuring GPIO pins stops LFXO and RTC0 counter.
 * As alleged in Nordic Devzone thread.
 */

#include &amp;quot;nrf_clock.h&amp;quot;
#include &amp;quot;nrf_rtc.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;



unsigned int ticks(){
	return nrf_rtc_counter_get(NRF_RTC0);
}

// spin until RTC0 counter increments at least once
void waitOneTick(){
	unsigned int firstTime, nextTime;

	firstTime = ticks();
	do {
		nextTime = ticks();
	}
	while (nextTime == firstTime);
}

void configureAllGpioPins() {
	for (uint32_t pin = 0; pin &amp;lt; 32; pin++) {

		/*
		 * This configuration is same as POR state except:
		 * 1. high current output (max 5mA) instead of normal
		 * 2. pulldown instead of no pull
		 */
		nrf_gpio_cfg(
				pin,
				NRF_GPIO_PIN_DIR_INPUT,
				NRF_GPIO_PIN_INPUT_DISCONNECT,
				NRF_GPIO_PIN_PULLDOWN,	// !!! pulldown
				NRF_GPIO_PIN_H0H1,	// !!! high current
				NRF_GPIO_PIN_NOSENSE);
	}
}

int main(void)
{
	// configure lf clock source is xtal
	nrf_clock_lf_src_set(NRF_CLOCK_LFCLK_Xtal);

	// start lf clock
	nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART);

	// spin until LFXO is stable
	while (! nrf_clock_lf_is_running()) {}

	// RTC0 begin counting (ticks always from LF clock)
	nrf_rtc_task_trigger(NRF_RTC0, NRF_RTC_TASK_START);

	waitOneTick();

	/*
	 * configure all gpio pins
	 * Despite some pins already used by LFXO xtal
	 */
	configureAllGpioPins();

	waitOneTick();
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91856?ContentTypeID=1</link><pubDate>Thu, 13 Jul 2017 15:07:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:544951ce-0d90-4b25-9570-48fbf2b740c1</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Sorry, I should have had put it outside. I updated, the result was the same.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91860?ContentTypeID=1</link><pubDate>Thu, 13 Jul 2017 13:30:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e84b2b5-1657-4589-8c76-babc40ad3a66</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;OK, thanks.  Now I should try and reproduce the problem.  But why do you call &amp;quot;NRF_CLOCK-&amp;gt;LFCLKSRC =1 ;&amp;quot; inside the loop?  In other words, maybe that masks the problem, isn&amp;#39;t that reconfiguring the LF clock to be LFXO AFTER you have configured the GPIO pin?  Please try it without that line in the loop.  (The reason I didn&amp;#39;t send you a small test case is that I discovered the alleged problem inside a complex app, I am not equipped to build small test cases every day.  Again, thanks for your attention.  I hope I have not wasted your time.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91855?ContentTypeID=1</link><pubDate>Thu, 13 Jul 2017 12:54:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3441a3dc-16eb-4eb6-a661-c7648d82ea22</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;You are right butch, we should test it. But I couldn&amp;#39;t reproduce the issue here. Here is my code, I modified the rtc example in the SDK:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void)
{


    lfclk_config();
    leds_config();
    rtc_config();
    NRF_CLOCK-&amp;gt;LFCLKSRC =1 ;
    for (uint32_t pin = 0; pin &amp;lt; 32; pin++) {
    // Configure high current output (max 5mA)
    nrf_gpio_cfg(
            pin,
            NRF_GPIO_PIN_DIR_INPUT,
            NRF_GPIO_PIN_INPUT_DISCONNECT,
            NRF_GPIO_PIN_PULLDOWN,
            NRF_GPIO_PIN_H0H1,  // !!! high current
            NRF_GPIO_PIN_NOSENSE);
    }
    nrf_gpio_cfg_output(21); //(for the LED)
    while (true)
    {
        __SEV();
        __WFE();
        __WFE();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Can still see the LED blinking.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91861?ContentTypeID=1</link><pubDate>Wed, 12 Jul 2017 14:43:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87015e2c-f525-487d-a3db-abda9f187db0</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;Yes, maybe it is only the LFXO.  A wild supposition: they implemented a ring oscillator using the GPIO buffers  to save silicon?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91863?ContentTypeID=1</link><pubDate>Wed, 12 Jul 2017 12:51:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a706976-6a86-4f5f-b1fa-8f09e6ef63c6</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;If this is actually the case I&amp;#39;d count it as a silicon bug. If the GPIO is used by the LF crystal then I&amp;#39;d expect them to be disconnected from the GPIO subsystem. Fortunately you&amp;#39;ve given enough information that someone at Nordic can check and see if it&amp;#39;s actually the case and work out whether it needs to be specifically documented or even counts as an erratum.&lt;/p&gt;
&lt;p&gt;In general you can configure GPIO pins even if the pin is used by another peripheral, in fact it&amp;#39;s even recommended that you do exactly that so the pins are in a defined state before and after the peripheral connects. Check for instance the SPI module which recommends how pins should be configured so that sleep mode leaves the pins in an SPI &amp;#39;neutral&amp;#39; state.&lt;/p&gt;
&lt;p&gt;So &amp;quot;don&amp;#39;t configure pins when the corresponding pin is used by another peripheral&amp;quot; is probably too strong a rule.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91862?ContentTypeID=1</link><pubDate>Wed, 12 Jul 2017 12:38:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9edb00a2-cb26-4537-93f8-f97216fc5fc1</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;Sorry, but no I am not interested in that experiment, since I already know a solution: don&amp;#39;t configure a GPIO pin when the corresponding physical pin is used by another peripheral.   Which might seem obvious to most people.  I suggest that the documents be improved.  In the middle of Figure 1 there is a &amp;quot;square&amp;quot; that I presume represents the physical pin, but it should be labeled.  Figure 1 doesn&amp;#39;t show where any other peripheral (such as LFXO) that shares the physical pin is connected to the physical pin (upstream or downstream of the GPIO buffers.)  Figure 1 doesn&amp;#39;t show the pullup and pulldown resistors, only obscurely hints that they might be on the input buffer since that is where CNF.PULL attaches.  Again, I suppose how pin multiplexing works is  the same across all platforms and that most experienced embedded programmers already know.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91854?ContentTypeID=1</link><pubDate>Tue, 11 Jul 2017 09:20:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c40fe020-4259-4cb1-89c9-121c32a0f0d3</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;I also suspect that the pulldown configuration cause the LFCLK crystal to stop. Could you try again with NOPULL ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91853?ContentTypeID=1</link><pubDate>Mon, 10 Jul 2017 14:00:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b5eb8c0-b657-46d4-8d8d-2ff3e02ecd84</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;I thought that this configuration is the same as the POR reset configuration, and that it means that all the logic to the left in Figure 1 is disconnected, i.e. the two switches leading from the physical pin to the two buffers (triangles) are open, so the physical pin (and I presumed the LF clock) is isolated from the GPIO logic.  Figure 1 seems to show the pulldown/up resistors on the input buffer, so they should not be connected to the physical pin either?  Thats why I was configuring all the GPIO&amp;#39;s, other posts suggested you should not leave the pulldown/up configured NOPULL.   I could be wrong, I&amp;#39;m not an electrical engineer.  I refer to the nRF52 documents, but I suspect it&amp;#39;s the same on the nRF51.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: configuring gpio pin stops LFXO and RTC counter</title><link>https://devzone.nordicsemi.com/thread/91852?ContentTypeID=1</link><pubDate>Sun, 09 Jul 2017 21:14:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ac7217b-d470-40b1-9122-14b699004ac5</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Don&amp;#39;t think it has anything to do with ANAEN. You&amp;#39;re force driving one of the LFCLK pins low which stops the oscillator which is then going to stop anything using the oscillator. You&amp;#39;d think that when the pin is used for the crystal the GPIO would be disconnected and configuration changes would have no effect, however it seems that&amp;#39;s not the case.&lt;/p&gt;
&lt;p&gt;You didn&amp;#39;t say which chip.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>