<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>i.MX Processorsのトピックi.MX8MM M4 core - Is it safe to use GPIO_PinSetInterruptConfig() inside ISR to change Rising/Falling</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8MM-M4-core-Is-it-safe-to-use-GPIO-PinSetInterruptConfig/m-p/1425438#M188021</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Is it safe to use GPIO_PinSetInterruptConfig() inside GPIO4_Combined_0_15_IRQHandler()&amp;nbsp; to change Rising/Falling state of GPIO's already configured for interrupts ?&lt;/P&gt;&lt;P&gt;The idea is that a GPIO pin is initially configured to trigger an interrupt on a rising edge, then inside the ISR it is reconfigured to trigger an interrupt on a falling edge.&lt;/P&gt;&lt;P&gt;The following (incomplete) code snippet illustrates the intent, the GPIO pins are configured elsewhere.&lt;/P&gt;&lt;P&gt;Is there a better and/or more complete way to do this ?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;static volatile bool gpio_one_FallingEdge = true;
static volatile bool gpio_two_FallingEdge = true;

void GPIO4_Combined_0_15_IRQHandler(void){
    uint32_t interruptFlags;
    interruptFlags = GPIO_PortGetInterruptFlags(GPIO4);

	if (interruptFlags &amp;amp; GPIO4_IO01_GPIO_PIN_MASK)
	{
		invertFallingRisingEdge(1);
		GPIO_PortClearInterruptFlags(GPIO4, 1U &amp;lt;&amp;lt; 1U);
	}

	if (interruptFlags &amp;amp; GPIO4_IO02_GPIO_PIN_MASK)
	{
		invertFallingRisingEdge(2);
		GPIO_PortClearInterruptFlags(GPIO4, 1U &amp;lt;&amp;lt; 2U);
	}

/*
 * Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
 * exception return operation might vector to incorrect interrupt.
 *
 * defined in core_cm4.h:71
 */
#if defined __CORTEX_M &amp;amp;&amp;amp; (__CORTEX_M == 4U || __CORTEX_M == 7U)
    __DSB();
#endif
}


void invertFallingRisingEdge(uint32_t gpio_pin)
{
     /*
      * Invert the direction of signal required to generate an interrupt
      * gpio_pin is the GPIO pin that caused the interrupt.
      */
     if (gpio_pin == 1)
     {
    	 if (gpio_one_FallingEdge)
    	 {
    		 GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntRisingEdge);
    		 gpio_one_FallingEdge = false;
    	 }
    	 else
		 {
    		 GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntFallingEdge);

    		 gpio_one_FallingEdge = true;
		 }
     }

     if (gpio_pin == 2)
     {
    	 if (gpio_two_FallingEdge)
    	 {
			GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntRisingEdge);
			gpio_two_FallingEdge = false;
    	 }
    	 else
		 {
			GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntFallingEdge);
			gpio_two_FallingEdge = true;
		 }
     }

}&lt;/LI-CODE&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2022 16:45:14 GMT</pubDate>
    <dc:creator>paulw2</dc:creator>
    <dc:date>2022-03-09T16:45:14Z</dc:date>
    <item>
      <title>i.MX8MM M4 core - Is it safe to use GPIO_PinSetInterruptConfig() inside ISR to change Rising/Falling</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8MM-M4-core-Is-it-safe-to-use-GPIO-PinSetInterruptConfig/m-p/1425438#M188021</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Is it safe to use GPIO_PinSetInterruptConfig() inside GPIO4_Combined_0_15_IRQHandler()&amp;nbsp; to change Rising/Falling state of GPIO's already configured for interrupts ?&lt;/P&gt;&lt;P&gt;The idea is that a GPIO pin is initially configured to trigger an interrupt on a rising edge, then inside the ISR it is reconfigured to trigger an interrupt on a falling edge.&lt;/P&gt;&lt;P&gt;The following (incomplete) code snippet illustrates the intent, the GPIO pins are configured elsewhere.&lt;/P&gt;&lt;P&gt;Is there a better and/or more complete way to do this ?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;static volatile bool gpio_one_FallingEdge = true;
static volatile bool gpio_two_FallingEdge = true;

void GPIO4_Combined_0_15_IRQHandler(void){
    uint32_t interruptFlags;
    interruptFlags = GPIO_PortGetInterruptFlags(GPIO4);

	if (interruptFlags &amp;amp; GPIO4_IO01_GPIO_PIN_MASK)
	{
		invertFallingRisingEdge(1);
		GPIO_PortClearInterruptFlags(GPIO4, 1U &amp;lt;&amp;lt; 1U);
	}

	if (interruptFlags &amp;amp; GPIO4_IO02_GPIO_PIN_MASK)
	{
		invertFallingRisingEdge(2);
		GPIO_PortClearInterruptFlags(GPIO4, 1U &amp;lt;&amp;lt; 2U);
	}

/*
 * Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
 * exception return operation might vector to incorrect interrupt.
 *
 * defined in core_cm4.h:71
 */
#if defined __CORTEX_M &amp;amp;&amp;amp; (__CORTEX_M == 4U || __CORTEX_M == 7U)
    __DSB();
#endif
}


void invertFallingRisingEdge(uint32_t gpio_pin)
{
     /*
      * Invert the direction of signal required to generate an interrupt
      * gpio_pin is the GPIO pin that caused the interrupt.
      */
     if (gpio_pin == 1)
     {
    	 if (gpio_one_FallingEdge)
    	 {
    		 GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntRisingEdge);
    		 gpio_one_FallingEdge = false;
    	 }
    	 else
		 {
    		 GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntFallingEdge);

    		 gpio_one_FallingEdge = true;
		 }
     }

     if (gpio_pin == 2)
     {
    	 if (gpio_two_FallingEdge)
    	 {
			GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntRisingEdge);
			gpio_two_FallingEdge = false;
    	 }
    	 else
		 {
			GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntFallingEdge);
			gpio_two_FallingEdge = true;
		 }
     }

}&lt;/LI-CODE&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 16:45:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX8MM-M4-core-Is-it-safe-to-use-GPIO-PinSetInterruptConfig/m-p/1425438#M188021</guid>
      <dc:creator>paulw2</dc:creator>
      <dc:date>2022-03-09T16:45:14Z</dc:date>
    </item>
  </channel>
</rss>

