<?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>Processor Expert SoftwareのトピックEnabling usage_fault exception with division_by_zero fault</title>
    <link>https://community.nxp.com/t5/Processor-Expert-Software/Enabling-usage-fault-exception-with-division-by-zero-fault/m-p/1289940#M4728</link>
    <description>&lt;P&gt;Hi, I am developing on a FRDM-K66F and I am trying to trap floating point exception by generating an interrupt.&lt;/P&gt;&lt;P&gt;I understand that it should be a usage fault interrupt that will be triggered.&lt;/P&gt;&lt;P&gt;The sample code below show that I am enabling the usage_fault interrupt, I set a priority then I enable all possible floating point exceptions in the Interrupt Status Register (MCM_ISCR) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I run this part of code, after the div/0 I see that the MCM detect it because if I read MCM_ISCR back I see 0x9F120200, FDZC is now set as well as the FPSCR[DZC].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question: What am I missing to generate the interrupt&lt;/SPAN&gt;&lt;SPAN&gt;?&amp;nbsp; Code goes through, never calling the ISR (which is a while(1) for now.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;float toto=1.0;&lt;/P&gt;&lt;P&gt;SCB-&amp;gt;SHCSR|=SCB_SHCSR_USGFAULTENA_Msk |SCB_SHCSR_BUSFAULTENA_Msk |SCB_SHCSR_MEMFAULTENA_Msk;&lt;/P&gt;&lt;P&gt;NVIC_SetPriority (UsageFault_IRQn,0x08);&lt;/P&gt;&lt;P&gt;*(uint8_t *)0xe0080010=(uint8_t)0x9F;&lt;/P&gt;&lt;P&gt;toto=toto/0.0F;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 09 Jun 2021 13:54:45 GMT</pubDate>
    <dc:creator>amigneault</dc:creator>
    <dc:date>2021-06-09T13:54:45Z</dc:date>
    <item>
      <title>Enabling usage_fault exception with division_by_zero fault</title>
      <link>https://community.nxp.com/t5/Processor-Expert-Software/Enabling-usage-fault-exception-with-division-by-zero-fault/m-p/1289940#M4728</link>
      <description>&lt;P&gt;Hi, I am developing on a FRDM-K66F and I am trying to trap floating point exception by generating an interrupt.&lt;/P&gt;&lt;P&gt;I understand that it should be a usage fault interrupt that will be triggered.&lt;/P&gt;&lt;P&gt;The sample code below show that I am enabling the usage_fault interrupt, I set a priority then I enable all possible floating point exceptions in the Interrupt Status Register (MCM_ISCR) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I run this part of code, after the div/0 I see that the MCM detect it because if I read MCM_ISCR back I see 0x9F120200, FDZC is now set as well as the FPSCR[DZC].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question: What am I missing to generate the interrupt&lt;/SPAN&gt;&lt;SPAN&gt;?&amp;nbsp; Code goes through, never calling the ISR (which is a while(1) for now.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;float toto=1.0;&lt;/P&gt;&lt;P&gt;SCB-&amp;gt;SHCSR|=SCB_SHCSR_USGFAULTENA_Msk |SCB_SHCSR_BUSFAULTENA_Msk |SCB_SHCSR_MEMFAULTENA_Msk;&lt;/P&gt;&lt;P&gt;NVIC_SetPriority (UsageFault_IRQn,0x08);&lt;/P&gt;&lt;P&gt;*(uint8_t *)0xe0080010=(uint8_t)0x9F;&lt;/P&gt;&lt;P&gt;toto=toto/0.0F;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 13:54:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Processor-Expert-Software/Enabling-usage-fault-exception-with-division-by-zero-fault/m-p/1289940#M4728</guid>
      <dc:creator>amigneault</dc:creator>
      <dc:date>2021-06-09T13:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Enabling usage_fault exception with division_by_zero fault</title>
      <link>https://community.nxp.com/t5/Processor-Expert-Software/Enabling-usage-fault-exception-with-division-by-zero-fault/m-p/1291553#M4732</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Please add these lines to enable the registers:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;NVIC_EnableIRQ(UsageFault_IRQn);
SCB-&amp;gt;CCR |= (SCB_CCR_DIV_0_TRP_Msk);
SCB-&amp;gt;SHCSR|= SCB_SHCSR_USGFAULTENA_Msk |SCB_SHCSR_BUSFAULTENA_Msk |SCB_SHCSR_MEMFAULTENA_Msk;&lt;/LI-CODE&gt;
&lt;P&gt;The reason why the interruption is not detected is the line "toto=toto/0.0F;"&lt;BR /&gt;If you add this function to your code we can see that the Usage fault is called:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;static int _DivideByZero(void) {
  int r;
  volatile unsigned int a;
  volatile unsigned int b;

  a = 1.0;
  //          movs r3, #1       &amp;lt;- Load dividend
  b = 0.0;
  //          movs r3, #0       &amp;lt;- Load divisor
  r = a / b;
  //      udiv r3, r2, r3   &amp;lt;- divide by 0 raises fault exception
  return r;
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Omar_Anguiano_0-1623442993442.png" style="width: 578px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/146957i47822F22CF89895E/image-dimensions/578x270?v=v2" width="578" height="270" role="button" title="Omar_Anguiano_0-1623442993442.png" alt="Omar_Anguiano_0-1623442993442.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you have more questions do not hesitate to ask me.&lt;BR /&gt;Best regards,&lt;BR /&gt;Omar&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 20:23:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Processor-Expert-Software/Enabling-usage-fault-exception-with-division-by-zero-fault/m-p/1291553#M4732</guid>
      <dc:creator>Omar_Anguiano</dc:creator>
      <dc:date>2021-06-11T20:23:40Z</dc:date>
    </item>
  </channel>
</rss>

