<?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>nRF51822 and Zephyr: Use nrfx gpiote for GPIO interrupts</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86276/nrf51822-and-zephyr-use-nrfx-gpiote-for-gpio-interrupts</link><description>Hello, 
 We are using Zephyr v2.6 and nRF51822 SoC in our project. 
 Because we are porting the code from the SDK environment into the Zephyr environment, we decided to use nrfx gpiote drivers instead of Zephyr GPIO drivers. Consequently, our prj.conf</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 28 Mar 2022 12:31:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86276/nrf51822-and-zephyr-use-nrfx-gpiote-for-gpio-interrupts" /><item><title>RE: nRF51822 and Zephyr: Use nrfx gpiote for GPIO interrupts</title><link>https://devzone.nordicsemi.com/thread/360299?ContentTypeID=1</link><pubDate>Mon, 28 Mar 2022 12:31:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfb6b1fd-750d-4038-be85-7f40018b8b65</guid><dc:creator>bojan</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/kenneth"&gt;Kenneth&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thanks for the reply. I was reading the example about using nrfx drivers in Zephyr envorionment. Consequently, I coonnected GPIOTE_0 IRQ to nrfx_gpiote_irq_handler with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
    DT_IRQ(DT_NODELABEL(gpiote), priority),
    nrfx_isr, nrfx_gpiote_irq_handler, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I was also reading the GPIO and GPIOTE chapters from the reference manual. I also tried to manually set up inputs and two GPIOTE channels and use &lt;span style="background-color:#ccffcc;"&gt;&lt;em&gt;&lt;strong&gt;GPIOTE_IRQHandler()&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt; with the following piece of code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void init_gpio_interrupts(void){

    nrf_gpio_cfg_input(PIN_ACCEL_INT1, NRF_GPIO_PIN_PULLDOWN);
    nrf_gpio_cfg_input(PIN_ACCEL_INT2, NRF_GPIO_PIN_PULLUP);

    NVIC_DisableIRQ(GPIOTE_IRQn);
    NVIC_ClearPendingIRQ(GPIOTE_IRQn);
// GPIOTE Channel 0
    NRF_GPIOTE-&amp;gt;CONFIG[0] =  (GPIOTE_CONFIG_POLARITY_LoToHi &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos)
                 | (PIN_ACCEL_INT1 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos)
                 | (GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos);
    NRF_GPIOTE-&amp;gt;INTENSET  = GPIOTE_INTENSET_IN0_Set &amp;lt;&amp;lt; GPIOTE_INTENSET_IN0_Pos;

// GPIOTE Channel 1
    NRF_GPIOTE-&amp;gt;CONFIG[1] =  (GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt;
                  GPIOTE_CONFIG_POLARITY_Pos)
                  | (PIN_ACCEL_INT2 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos)
                  | (GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos);
    NRF_GPIOTE-&amp;gt;INTENSET  = GPIOTE_INTENSET_IN1_Set &amp;lt;&amp;lt; GPIOTE_INTENSET_IN1_Pos;

    __NOP();
    __NOP();
    __NOP();

    /* Clear the event that appears in some cases */
    NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
    NRF_GPIOTE-&amp;gt;EVENTS_IN[1] = 0;

    NRF_GPIOTE-&amp;gt;INTENSET = GPIOTE_INTENSET_IN0_Enabled &amp;lt;&amp;lt; GPIOTE_INTENSET_IN0_Pos;
    NRF_GPIOTE-&amp;gt;INTENSET = GPIOTE_INTENSET_IN1_Enabled &amp;lt;&amp;lt; GPIOTE_INTENSET_IN1_Pos;
    NVIC_EnableIRQ(GPIOTE_IRQn);
}

/**@brief Function for handling the GPIOTE interrupt.
 */
void GPIOTE_IRQHandler(void)
{
    uint32_t pins_state   = NRF_GPIO-&amp;gt;IN;

    // Event causing the interrupt must be cleared.
    if ((NRF_GPIOTE-&amp;gt;EVENTS_IN[0] == 1))
    {
        LOG_INF(&amp;quot;Accel interrupt!&amp;quot;);
        NVIC_DisableIRQ(GPIOTE_IRQn);
        NVIC_ClearPendingIRQ(GPIOTE_IRQn);

        NRF_GPIOTE-&amp;gt;INTENSET = GPIOTE_INTENSET_IN0_Enabled &amp;lt;&amp;lt; GPIOTE_INTENSET_IN0_Pos;

        NVIC_EnableIRQ(GPIOTE_IRQn);

        NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
    }

    // Event causing the interrupt must be cleared.
    if ((NRF_GPIOTE-&amp;gt;EVENTS_IN[1] == 1))
    {
        LOG_INF(&amp;quot;.&amp;quot;);
        NVIC_DisableIRQ(GPIOTE_IRQn);
        NVIC_ClearPendingIRQ(GPIOTE_IRQn);

        NRF_GPIOTE-&amp;gt;INTENSET = GPIOTE_INTENSET_IN1_Enabled &amp;lt;&amp;lt; GPIOTE_INTENSET_IN1_Pos;

        NVIC_EnableIRQ(GPIOTE_IRQn);

        NRF_GPIOTE-&amp;gt;EVENTS_IN[1] = 0;
    }

 }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;There were no compilation errors but I was unable to detect any interrupt with &lt;span style="background-color:#ccffcc;"&gt;&lt;em&gt;&lt;strong&gt;GPIOTE_IRQHandler()&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt; function.&lt;/p&gt;
&lt;p&gt;We are currently using nRF51 because we were unable to buy nRF52 SoCs at the moment. We certainly have a plan to transition to nRF52 but before that happens, we need to temporarily keep using nRF51 SoCs.&lt;/p&gt;
&lt;p&gt;So, the question of how to set up at least two GPIOs of nRF51822 to interrupt the CPU still remains an issue for us.&lt;/p&gt;
&lt;p&gt;When using Zephyr GPIO drivers, I was able to set up two GPIOs (but not more) to interrupt CPU as you can see in t&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/84298/nrf51822-and-zephyr-gpio-interrupt-on-multiple-gpios" rel="noopener noreferrer" target="_blank"&gt;his thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If the transaction manual says that there are four GPIOTE channels, how can I properly benefit from them and specify GPIOs connected/used in the channel?&lt;/p&gt;
&lt;p&gt;Thanks once again.&lt;/p&gt;
&lt;p&gt;Sincerely,&lt;/p&gt;
&lt;p&gt;Bojan.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 and Zephyr: Use nrfx gpiote for GPIO interrupts</title><link>https://devzone.nordicsemi.com/thread/360267?ContentTypeID=1</link><pubDate>Mon, 28 Mar 2022 11:36:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d824b94e-5bc6-4087-9990-da9aed7f8360</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I suggest to check out:&lt;br /&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/boards/nrf/nrfx/README.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/boards/nrf/nrfx/README.html&lt;/a&gt;&amp;nbsp;and&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.1.pdf"&gt;https://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.1.pdf&lt;/a&gt;&amp;nbsp;(chapter 15 GPIOTE).&lt;/p&gt;
&lt;p&gt;The reference manual will describe the difference between port events (low power wakeup) and IN event (higher current, but can be connected by PPI to tasks).&lt;/p&gt;
&lt;p&gt;All that said, are you sure you want to use NCS with nRF51-series? I do not believe there is proper production support there, for instance I can not find NCS listed in the compatibility matrix for the nRF51822 vs nRF52832 for instance:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/comp_matrix_nrf51/COMP/nrf51/nRF51422_nRF51822_ic_rev_sdk_sd_comp_matrix.html"&gt;https://infocenter.nordicsemi.com/topic/comp_matrix_nrf51/COMP/nrf51/nRF51422_nRF51822_ic_rev_sdk_sd_comp_matrix.html&lt;/a&gt;&amp;nbsp;vs.&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/comp_matrix_nrf52832/COMP/nrf52832/ic_rev_sdk_sd_comp_matrix.html"&gt;https://infocenter.nordicsemi.com/topic/comp_matrix_nrf52832/COMP/nrf52832/ic_rev_sdk_sd_comp_matrix.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you are making an BLE application for the nRF51-series you would need to use the zephyr BLE controller with the additional cost and time that requires for qualification (since it&amp;#39;s not qualified by Nordic). For new development I highly recommend to transition to the nRF52-series.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 and Zephyr: Use nrfx gpiote for GPIO interrupts</title><link>https://devzone.nordicsemi.com/thread/360187?ContentTypeID=1</link><pubDate>Mon, 28 Mar 2022 08:26:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:524fafbb-cd5e-450b-bc5b-622279b8cc06</guid><dc:creator>bojan</dc:creator><description>&lt;p&gt;For the second GPIO, I tried to allocate GPIOTE channel before initializing it with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t channel;
    err_code = nrfx_gpiote_channel_alloc(&amp;amp;channel);
    err_code = nrfx_gpiote_in_prealloc_init(PIN_ACCEL_INT2, &amp;amp;in_config_2, channel, gpiote_event_handler_2);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="background-color:#ccffcc;"&gt;&lt;em&gt;nrfx_gpiote_channel_alloc()&lt;/em&gt;&lt;/span&gt;&lt;/strong&gt; function properly allocates GPIOTE channel but the &lt;span style="background-color:#ccffcc;"&gt;&lt;strong&gt;&lt;em&gt;nrfx_gpiote_in_prealloc_init()&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt; returns &lt;span style="background-color:#ff99cc;"&gt;&lt;strong&gt;0xBAD0004&lt;/strong&gt;&lt;/span&gt; (&lt;span style="background-color:#ff99cc;"&gt;&lt;strong&gt;&lt;em&gt;NRFX_ERROR_INVALID_PARAM&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;According to the &lt;span style="background-color:#ccffcc;"&gt;&lt;strong&gt;&lt;em&gt;nrfx_gpiote_in_prealloc_init()&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt; brief description, this return code means that the pin is configured to not be controlled by the GPIOTE task and cannot be used with preallocated channel. It is also advised to use &lt;span style="background-color:#ccffcc;"&gt;&lt;strong&gt;&lt;em&gt;nrfx_gpiote_in_init()&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt; instead which, as I reported previously, returns &lt;span style="background-color:rgba(255, 153, 204, 1);"&gt;&lt;strong&gt;0xBAD0002&lt;/strong&gt; &lt;/span&gt;(&lt;span style="background-color:rgba(255, 153, 204, 1);"&gt;&lt;strong&gt;NRFX_ERROR_NO_MEM&lt;/strong&gt;&lt;/span&gt;).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>