<?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>Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20934/problem-using-gpio--and-bsp-module-simultaneously</link><description>Hello, 
 last week I was trying to integrate a wake-on-motion-functionality for my hardware using some interrupt-handling. While that problem is solved, I came across some kind of interdependency between initializing the GPIO- and the BSP-module simultaneaously</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Apr 2017 19:13:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20934/problem-using-gpio--and-bsp-module-simultaneously" /><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81779?ContentTypeID=1</link><pubDate>Tue, 11 Apr 2017 19:13:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19fe04b5-a3b9-408e-b432-dc5cc3cdc15b</guid><dc:creator>Ray Breslin</dc:creator><description>&lt;p&gt;Problem finally solved... :)&lt;/p&gt;
&lt;p&gt;This issue was caused by a missing adaption for handling the bsp-module in SDK v12.2.0, that required a change in the Makefile and the project-structure within Eclipse.&lt;/p&gt;
&lt;p&gt;Previously in SDK v12.0.0 the bsp-sources where available through the examples/bsp-folder, while in SDK v12.2.0 they got moved to components/libraries/bsp. Since the SDK-structure for v12.2.0 didnt got setup properly with deleting all previous content of SDK v12.0.0, it caused an indexing-error in Eclipse so that the bsp-module-source still got referenced to the examples/bsp-location.&lt;/p&gt;
&lt;p&gt;Somehow that also created a problem with handling the BOARD_PCA10040-flag properly, which basically made the functions in bsp_config() doing nothing at all. In addition to that the Makefile obviously needed certain changes in the SRC_FILES- and INC_FOLDERS-section (also including boards.c as new file).&lt;/p&gt;
&lt;p&gt;Thanks again for your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81788?ContentTypeID=1</link><pubDate>Mon, 10 Apr 2017 13:19:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad1f440f-626a-49eb-8683-bcfad30f5a4f</guid><dc:creator>Ray Breslin</dc:creator><description>&lt;p&gt;Now I did run the test with disabling bsp_btn_ble_init(), but there was no change in the behaviour!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81784?ContentTypeID=1</link><pubDate>Fri, 31 Mar 2017 23:07:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18b9083e-2a4b-4e02-b6ef-8be302b59fa3</guid><dc:creator>Ray Breslin</dc:creator><description>&lt;p&gt;I will do that asap, but I cant do it during the next week, since I am on a business-trip! I will get back to you - thank you very much for your efforts so far!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81783?ContentTypeID=1</link><pubDate>Fri, 31 Mar 2017 14:17:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a763ab6-ac0d-49d4-99a6-53666f1d0c86</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;It is quite likely the timer has nothing to do with your errors, I just want to eliminate any possibility to be sure. What happens if you comment away the bsp_btn_ble_init function? Any change in behavior?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81782?ContentTypeID=1</link><pubDate>Fri, 31 Mar 2017 13:41:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9cd004b6-2475-40e9-b92a-0d2331e646d6</guid><dc:creator>Ray Breslin</dc:creator><description>&lt;p&gt;Well I actually do need the timer_clk to be initialized first, since I do want to have reliable timestamps for my log-messages and that was never a problem before! But I tried it as you said and it just made the entire situation worse, so that the log-output showed everything till the 2nd additional log-message in bsp_config() and then I even got a reset, which keeps repeating on the same spot everytime. It has to be something within bsp_config() because without it everything else runs fine, except the advertising...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81781?ContentTypeID=1</link><pubDate>Fri, 31 Mar 2017 08:45:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d766d7e5-2c94-41b9-b0c7-47c7596ec239</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;I see you enable the timer at the end of the timer_clk_init function. This is not optimal as the timer could potentially trigger events while your system is still running inits. Enabling timers is one of the last things you should do before entering your main while loop. Just to be sure it is not interfering with anything, could you try moving the timer enable to after all initialize functions are run?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81786?ContentTypeID=1</link><pubDate>Thu, 30 Mar 2017 14:47:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de2dca9d-bd60-443b-961d-c5ca78da6313</guid><dc:creator>Ray Breslin</dc:creator><description>&lt;p&gt;I even added additional log-messages inside bsp_config() - one before bsp_init() and one more directly after bsp_btn_ble_init(), but before the previous &amp;quot;initialized&amp;quot;-message posted above. While the first one is displayed normally, the 2nd is also displayed but without the &amp;quot;initialized&amp;quot;-message afterwards!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81787?ContentTypeID=1</link><pubDate>Thu, 30 Mar 2017 14:42:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a9cddd5-b40e-4374-a806-1895ff521713</guid><dc:creator>Ray Breslin</dc:creator><description>&lt;p&gt;Thats precisely my problem!&lt;/p&gt;
&lt;p&gt;I did comment out everything related to GPIOTE and wake-on-motion, but I am not seeing any error-message at all... It is that just nothing happens after bsp_config() - no log output, just nothing!&lt;/p&gt;
&lt;p&gt;Here is also my check_error_code()-function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void check_error_code(const char* function_name, uint32_t err_code, int8_t err_position)
{
	#ifdef DEBUG_APP_ERROR_CODE
		if (err_code != NRF_SUCCESS) {
			printf(&amp;quot;%s(): Error &amp;#39;%#04lx&amp;#39; [%d]\r\n&amp;quot;, function_name, err_code, err_position);
		}// if (err_code != NRF_SUCCESS)
	#endif /* DEBUG_APP_ERROR_CODE */

	APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81785?ContentTypeID=1</link><pubDate>Thu, 30 Mar 2017 14:29:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9496944c-8a02-4b3c-a892-a3655d45b693</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;Could you comment out the gpio_config function, or change the pin to one not used by the bsp_init function, to remove the GPIOTE conflict, and then run debug? It would be helpful to know exactly which error you are getting, and what part of the bsp_init function is triggering it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81780?ContentTypeID=1</link><pubDate>Thu, 30 Mar 2017 14:12:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23867a24-6bee-42ad-8e0c-14a1c9b43d8a</guid><dc:creator>Ray Breslin</dc:creator><description>&lt;p&gt;Thank you for your replay Jorn and for doing the tests with my code!&lt;/p&gt;
&lt;p&gt;While I do understand the behaviour for a) (which does make sense), I still cant get bsp_config() to run properly even if its standalone in b).&lt;/p&gt;
&lt;p&gt;Here are some additional code-snippets from before and after the bsp_config()-call!&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Contents of system-startup()    [before]&lt;/p&gt;
&lt;p&gt;static void timer_clk_init(void)
{
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
// Time(in milliseconds) between consecutive compare events
uint32_t time_ms = 1;
uint32_t time_ticks;
uint32_t err_code = NRF_SUCCESS;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; APP_TIMER_INIT(...);

 err_code = nrf_drv_timer_init(...);

 time_ticks = nrf_drv_timer_ms_to_ticks(...);
 nrf_drv_timer_extended_compare(...);

 nrf_drv_timer_enable(&amp;amp;TIMER_CLK);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;static void uart_init(void)
{
uint8_t uart_mode = NRF_LOG_ENABLED;
uint32_t err_code = NRF_SUCCESS;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; if (uart_mode == 1)
 {
     err_code = NRF_LOG_INIT(NULL);
     check_error_code(__func__, err_code, 1);
 }
 else
 {
     ...

     APP_UART_FIFO_INIT(&amp;amp;comm_params,
                        UART_RX_BUF_SIZE,
                        UART_TX_BUF_SIZE,
                        uart_evt_handler,
                        APP_IRQ_PRIORITY_LOW,
                        err_code);
     check_error_code(__func__, err_code, 1);
 }// if (uart_mode == 1)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Contents of pm_config()  [after]&lt;/p&gt;
&lt;p&gt;static void pm_config(bool erase_bonds)
{
ble_gap_sec_params_t sec_param;
ret_code_t err_code;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; printf(&amp;quot;%s(): Peer Manager initializing...\r\n&amp;quot;, __func__);

 err_code = pm_init();
 check_error_code(__func__, err_code, 1);

 if (erase_bonds)
 {
     pm_peers_delete();
 }// if (erase_bonds)

 memset(&amp;amp;sec_param, 0, sizeof(ble_gap_sec_params_t));

 // Security parameters to be used for all security procedures
 ...

 err_code = pm_sec_params_set(&amp;amp;sec_param);
 check_error_code(__func__, err_code, 2);

 err_code = pm_register(pm_evt_handler);
 check_error_code(__func__, err_code, 3);

 printf(&amp;quot;%s(): Peer Manager initialized\r\n&amp;quot;, __func__);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81789?ContentTypeID=1</link><pubDate>Thu, 30 Mar 2017 13:10:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5858266-e3ae-432f-b9b8-7e797a95313e</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;Hello Ray Breslin&lt;/p&gt;
&lt;p&gt;I copied your code and did a couple of tests.
First a comment on the error you received from bsp_config(). I believe the NRF_ERROR_INVALID_STATE arises due to a conflict in GPIOTE channel assignments. You said in your comment that you use pin P0.16 for the wake up functionality. In your gpio_config function you assign a GPIOTE channel to this pin.&lt;/p&gt;
&lt;p&gt;The bsp_config() function initializes the leds and buttons of the development kit. So when bsp_config() is called it too tries to assign a GPIOTE channel to pin 16, which is wired to button 4 on the development kit. The function performs a check, and notices the pin is already in use. It then generates the NRF_ERROR_INVALID_STATE error.&lt;/p&gt;
&lt;p&gt;If I remove the gpio_config function in my test, everything functions as normal. If you still get errors when you comment away your gpio_config function, then there might be a problem in parts of your code, which you have not posted here.
Now on to your questions&lt;/p&gt;
&lt;p&gt;a) when initializing the bsp module, it configures pins P0.13 to P0.20 for leds and buttons. If you configure any of these pins before that, chances are they&amp;#39;re gonna be overridden. As mentioned above, the bsp module uses GPIOTE for the pins, so keep that in mind when initializing your GPIOTE. In your case I think the best way would be to first initialize the bsp module, and then change the configurations for pin 16, and any other pin you use, to suit your needs. That way the bsp module is allowed to initialize as it should, before you change the functionality of the buttons or leds.&lt;/p&gt;
&lt;p&gt;b) To my knowledge, it should not be necessary to make any adjustments to the bsp module or the order of initializations when changing from SDK 12.0.0 to SDK 12.2.0&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Jørn Frøysa&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81778?ContentTypeID=1</link><pubDate>Thu, 30 Mar 2017 12:44:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e9452ff-11af-4ee6-8b5f-40c496b2a411</guid><dc:creator>Ray Breslin</dc:creator><description>&lt;p&gt;I used this definement here &lt;code&gt;#define MOTION_IRQ_PIN	16&lt;/code&gt; - but like I said the wake-on-motion-functionality isnt my problem! Even if I uncomment everything related to gpio_config() then I still got the same errors (which I cant see) for bsp_config()...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using GPIO- and BSP-module simultaneously</title><link>https://devzone.nordicsemi.com/thread/81777?ContentTypeID=1</link><pubDate>Thu, 30 Mar 2017 12:13:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06a68cb8-3ad7-444a-80c3-561fe4672f03</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;What pin have you assigned to the MOTION_IRQ_PIN?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>