<?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>FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/12433/fpu-divide-by-0-and-high-current-consumption</link><description>I was trying to track down high, approx. 6mA, processor current consumption and I have found high current consumption if the FPU executes a divide by 0. If I comment out the line the current consumption goes down to tens of micro amps. If the line is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Nov 2016 16:42:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/12433/fpu-divide-by-0-and-high-current-consumption" /><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47046?ContentTypeID=1</link><pubDate>Fri, 18 Nov 2016 16:42:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:698e462e-220d-4130-8f39-d44ec133d367</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;Good question for low power application&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47061?ContentTypeID=1</link><pubDate>Mon, 05 Sep 2016 11:06:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44cd08c4-c721-4d0d-9b2c-8f9d37d1168d</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;solution to this is to clear &lt;a href="https://devzone.nordicsemi.com/question/87838/fpu-exception-trigged-when-convertting-float-type-to-uint32_t-type/"&gt;pending FPU interrupt&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47063?ContentTypeID=1</link><pubDate>Fri, 02 Sep 2016 12:07:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2ee70fb-ca3c-4d27-9da1-4850d9c4f099</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;OK, I spent some time in it. This is a bug for implementation of sd_app_evt_wait, it polls for the pending bit in NVIC to see if has to sleep or not and I think it has also check for the interrupt being enabled or not. I will create a ticket and track this thing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47062?ContentTypeID=1</link><pubDate>Fri, 02 Sep 2016 10:57:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bad5c9de-2252-4c77-9c55-a1cfbdf37ddd</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;i am not sure if i understood it correctly, but yousay that sd_app_evt_wait is behaving differently on an unhandled FPU exception.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47060?ContentTypeID=1</link><pubDate>Thu, 31 Mar 2016 11:15:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09f50775-e0ea-4f48-98f0-2763dc0734c5</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;Answer is edited to be more inline with the release notes of SDK. It seemed like only the interrupt solution works with FreeRTOS, could you confirm this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47059?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2016 12:46:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e79ad10-3275-42a0-9779-ec186bfd9170</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;seems like FPU Automatic state preservation bit needs to be set. Can you guys try to enable ASPEN b it when you enable FPU and see if the context is stored and restored correctly?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;FPU-&amp;gt;FPCCR  |= (FPU_FPCCR_ASPEN_Msk);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47064?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2016 08:28:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:455a0f0d-5f94-40b6-bab7-413ac69d7e13</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Ok - that sounds more likely than a hardfault on write. The only thing which comes to mind there is as issue with stacking, or lazy stacking, of the FPU registers when the SVC call is executed or later in the Softdevice handling of them. I suppose that writing the FPCSR register will set the CONTROL.FPCA bit which means the next SVC call (or any interrupt) will stack (or lazy stack) the FP registers.&lt;/p&gt;
&lt;p&gt;That said I can&amp;#39;t reproduce this, not in a trivial example anyway, I called an sd_ function inside the loop and it was fine, no hardfault.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47058?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2016 07:36:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d776ed3-6093-487e-a59f-e1e2e66ed07b</guid><dc:creator>Michael Dierks</dc:creator><description>&lt;p&gt;Above I commented on the FPSCR clearing, I stepped thru the register manipulation, that was OK.  The hardfault occurs for me when I execute a soft device SVC call.  I thought it might be a response to the sd_app_evt_wait, but I replaced that with some others, checking status of event set flags, and it always occured at the SVC call following the FPSCR manipulation.  We have gotten the sleep pattern we expect, but there are some loose ends on this cleanup.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47057?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2016 07:03:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38f71cae-d3dc-4f41-85ff-a8c6b70854f8</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Really? The only thing I thought caused a hardfault writing to the FPU unit was if it wasn&amp;#39;t enabled, but if it&amp;#39;s not enabled then you wouldn&amp;#39;t be getting FPU exceptions set. You could check at the point you&amp;#39;re doing the write that it&amp;#39;s not been disabled by something. You can check the SCB-&amp;gt;CPACR register and make sure bits 20, 21, 22 and 23 are set when you&amp;#39;re doing the write.&lt;/p&gt;
&lt;p&gt;Sure that&amp;#39;s where the hardfault is happening, at the write to the FPSCR?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47056?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2016 06:47:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a64e827-533f-4071-81e4-f9c8ed3c63a2</guid><dc:creator>WestCoastDaz</dc:creator><description>&lt;p&gt;RK,&lt;/p&gt;
&lt;p&gt;Haha..I plan on not dividing by zero in the production release!  Ole&amp;#39;s answer isn&amp;#39;t 100% correct since the writes to the FPU status register he suggests causes a hardfault.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47055?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2016 06:42:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:524b2382-07d1-49d2-be1a-be6a00e57840</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;why don&amp;#39;t you just enable the FPU interrupt and clear the divide by zero condition when it fires.&lt;/p&gt;
&lt;p&gt;.. or stop dividing things by zero&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47054?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2016 06:37:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0accac1f-fcc2-4fb0-a51e-8caf0f20e870</guid><dc:creator>WestCoastDaz</dc:creator><description>&lt;p&gt;Ole,&lt;/p&gt;
&lt;p&gt;Can you show how to apply you code with Tickless sleep?  Right now the only way I can get the power down is to use a combination of tickless sleep and the idle task which is clearing the FPU interrupt.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47053?ContentTypeID=1</link><pubDate>Thu, 10 Mar 2016 01:31:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa6c5d8c-363c-46e3-9c18-f715d9359a54</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;You made me actually test it! It appears to be an effect of sd_app_evt_wait(). It&amp;#39;s quite hard to get it to do it all just using __wfe() directly if the FPU exception is disabled (which it is). You need SEVONPEND set to make the exception raise cause an event, else the pending exception is ignored, then you need to arrange for the exception to re-trigger in order to cause another event, just ignoring it entirely and leaving it pending doesn&amp;#39;t raise another event and __wfe() doesn&amp;#39;t return again. So for instance clearing the exception but leaving the FPU flags will re-raise it and then you&amp;#39;ll get another event, but that&amp;#39;s what it takes.&lt;/p&gt;
&lt;p&gt;Replacing __wfe() with sd_app_event_wait() makes the code busy loop constantly if the FPU exception is pending, even with SEVONPEND cleared and even if it were only raised the one time. sd_app_evt_wait() is clearly more conservative than __wfe().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47052?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 23:25:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02197a47-4a58-4bad-9638-1eca0ef4c3eb</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;And what if you don&amp;#39;t use sd_app_evt_wait() but just __wfe(), since you&amp;#39;re testing it it would be handy to know if the pending, disabled interrupt does keep the processor from sleeping at all, ie WFE continues to return instantly, in which case I get to read the manual again to work out why, or it&amp;#39;s something that sd_app_evt_wait() does. I stopped using the latter a while ago because I never quite got comfortable that I knew exactly what it did.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47051?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 18:00:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:975dab8f-c54e-485f-a02a-b957e94a6857</guid><dc:creator>Michael Dierks</dc:creator><description>&lt;p&gt;Learning is good.&lt;/p&gt;
&lt;p&gt;Learning now is understanding the link between WFE on events, and how pending levels in the NVIC relate to events that cause wakeup.  I clearly see the condition occur, the FPU flag is set, and the exception condition in the NVIC is raised (NVIC_IPR1, bit 6) and never cleared.  When I run the code without clearing, the sd_app_evt_wait() call never stalls, returns immediately.    As Darren said, if I comment out the math instruction, the NVIC pending is not set, and then the instrumented idle wait performs a very nice 1ms sleep wait, as I expect.&lt;/p&gt;
&lt;p&gt;When I leave the math instruction, and add the code that Ole suggested, I have partial success.  The sd_nvic_ClearPendingIRQ() works, and I get expected results.  If I leave the __set_FPSCR() and __DMB();    __DSB();    _&lt;em&gt;ISB(); calls in, then ANY subsequent sd&lt;/em&gt; function calls hardfault.&lt;/p&gt;
&lt;p&gt;Still some testing to finish.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47050?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 17:05:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa752575-be0c-4f28-bddd-ddf88772a233</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;or I could just be wrong in my understanding of how disabled interrupts wake up the CPU. I thought they basically didn&amp;#39;t, and if they did it was only once, only in WFE and only in certain circumstances. But I&amp;#39;ve been wrong before and usually end up learning something.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47049?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 16:36:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4851193c-6bd4-414e-9818-d7c549888c1f</guid><dc:creator>Michael Dierks</dc:creator><description>&lt;p&gt;So is the SD not entering the sleep state when it &amp;quot;sees&amp;quot; the event condition?  This seems like another posting that RK had commented on, where the source of the sleep-exit-trigger was not apparent&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/question/50892/wakeup-immediately-from-sd_app_evt_wait-with-external-lfclk/"&gt;wakeup-immediately-from-sd_app_evt_wait-with-external-lfclk&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47048?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 15:17:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbbbfacc-848b-4852-9d9b-538e2546061e</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Hmm that&amp;#39;s confusing. If the interrupt is disabled then it shouldn&amp;#39;t wake the processor from WFI, nor WFE, unless SEVONPEND is also set in which case even if disabled it should trigger WFE to wake, but only once, not continuously. Don&amp;#39;t see why it continues to wake the processor.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47047?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 14:58:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58f0054c-1cb8-4bcd-9a39-9a9a3b5ac22c</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;&lt;strong&gt;EDIT 2016-03-31:&lt;/strong&gt; To be more inline with the release notes of the SDK the example code has been changed slightly. The two solutions are also presented equally, although it seems that only the interrupt solution works with FreeRTOS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EDIT 2016-03-11:&lt;/strong&gt; Added explanation of why sd_app_evt_wait() does not allow the chip to sleep if pending FPU interrupt is not cleared. Solution with FPU interrupt implementation added as best solution. Previous solution kept as reference.&lt;/p&gt;
&lt;p&gt;The FPU will generate an exception when dividing by 0 due to overflow/underflow. This exception will trigger the FPU interrupt, see &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.0/cpu.html?cp=1_2_0_5_0#fpu"&gt;here&lt;/a&gt;. If the interrupt is not cleared/handled the CPU will not be able to go to sleep.&lt;/p&gt;
&lt;p&gt;The CPU will not be able to go to sleep if you are using sd_app_evt_wait(). It will return if there are any pending interrupts, even if the interrupts are not enabled through NVIC_EnableIRQ(..). You could use __WFE() instead, but then the application will wake up a lot more from events that are only handled by the SoftDevice. With SoftDevice S132 v2.0.0 sd_app_evt_wait() will also turn off MWU before calling WFE(), so using __WFE() from the application instead will lead to an increase in sleep power consumption of about 800uA.&lt;/p&gt;
&lt;p&gt;One way to fix this is to implement the FPU_IRQHandler. First make sure to have the latest Device Family Pack (8.5.0 at the time) such that the IRQ is included in the vector table. Set priority and enable IRQ in main:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NVIC_SetPriority(FPU_IRQn, APP_IRQ_PRIORITY_LOW);
NVIC_EnableIRQ(FPU_IRQn);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Implement the FPU_IRQHandler and clear the FPSCR. The FPSCR state is pushed on the stack when we enter the interrupt and popped when we exit the the interrupt. Therefore we cannot use __set_FPSCR() since the value will be overwritten when we exit the interrupt. We have to change the stack value instead:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define FPU_EXCEPTION_MASK 0x0000009F

void FPU_IRQHandler(void)
{
    uint32_t *fpscr = (uint32_t *)(FPU-&amp;gt;FPCAR+0x40);
    (void)__get_FPSCR();

    *fpscr = *fpscr &amp;amp; ~(FPU_EXCEPTION_MASK);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The other solution is to clear the interrupt every time the CPU wakes up from sleep. For example change the power_manage() function to:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define FPU_EXCEPTION_MASK 0x0000009F

static void power_manage(void)
{
    __set_FPSCR(__get_FPSCR()  &amp;amp; ~(FPU_EXCEPTION_MASK));      
    (void) __get_FPSCR();
    NVIC_ClearPendingIRQ(FPU_IRQn);
    
    uint32_t err_code = sd_app_evt_wait();
    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: FPU divide by 0 and High Current Consumption</title><link>https://devzone.nordicsemi.com/thread/47045?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 12:28:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6b4bf6d-43c7-411f-90ac-33a620e2d1f8</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;By default an FPU divide by zero doesn&amp;#39;t do anything, you can set flags in the System Control Block to make it execute a Usage fault (which escalates to a hardfault if you don&amp;#39;t have a handler); in this way it&amp;#39;s much like the unaligned access on the M3/M4, it only faults if you ask it to.&lt;/p&gt;
&lt;p&gt;I see nothing in the startup file which enables those flags, so it most likely just sets the divide by zero flag in the FPU (which is sticky) and returns zero.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>