<?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>MCU Stops Responding</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89178/mcu-stops-responding</link><description>Hi Everyone, 
 
 I am working on a project which involves reading data from an accelerometer ( MC3672 ) using NRF52832. 
 Currently sampling is done via the data ready pin, which is sensed by GPIOTE module and a flag is set which then 
 gets processed</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Jul 2022 13:29:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89178/mcu-stops-responding" /><item><title>RE: MCU Stops Responding</title><link>https://devzone.nordicsemi.com/thread/378118?ContentTypeID=1</link><pubDate>Thu, 21 Jul 2022 13:29:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40ac369c-55b9-409b-a119-bd7a1a33c786</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Sorry, I was out of office, and I will be next week as well. Unfortunately, due to limited staffing during the summer, I am not certain my colleagues will have the time to look into unhandled &amp;quot;old&amp;quot; cases like this one.&amp;nbsp;&lt;/p&gt;
[quote user="bryanhsieh"]Therefore the CPU is not stuck in a while loop, it crashes after the Serialize_SPI(CMD,1+size,NULL,0,true) function, which is what is confusing[/quote]
&lt;p&gt;This is not our function. What does it do? Did you try debugging it to see what&amp;#39;s going on? Are there places inside (or after, I didn&amp;#39;t understand where you meant) that the application can be stuck?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCU Stops Responding</title><link>https://devzone.nordicsemi.com/thread/377251?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2022 18:02:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea820334-0bbd-44c4-b82d-faa63260207c</guid><dc:creator>bryanhsieh</dc:creator><description>&lt;p&gt;Thanks. But unfortunately the problem is unrelated to it, as like you said the size is always +1. Also&amp;nbsp; _M_DRV_MC36XX_REG_WRITE function ( where the program would fail after ) is always writing 1 as the size however despite that the MCU would freeze randomly after a few minutes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCU Stops Responding</title><link>https://devzone.nordicsemi.com/thread/377031?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2022 17:01:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c427285a-b719-441f-9e47-623cd1aaee4c</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Using parameter&amp;nbsp;&lt;em&gt;size&lt;/em&gt; to define stack allocation and (worse) &lt;em&gt;memcpy()&lt;/em&gt; would be flagged as an error by MISRA; if &lt;em&gt;size&lt;/em&gt; is ever 0 there will be a crash or something horrible; fix by using predetermined max buffer size (not an issue here due to the +1) or do not perform stuff like &lt;em&gt;memcpy()&lt;/em&gt; if size == 0. Possibly not the issue, but worth addressing as often the errors are very random and hard to catch.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCU Stops Responding</title><link>https://devzone.nordicsemi.com/thread/377030?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2022 16:34:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a83ae60-4112-4961-935b-f5ff7d2f3de4</guid><dc:creator>bryanhsieh</dc:creator><description>&lt;p&gt;To Edvin,&lt;/p&gt;
&lt;p&gt;Hi sorry for the late reply.&lt;/p&gt;
&lt;p&gt;I thought the problem was resolved but upon testing the device recently, the same CPU locking behaviour occurred again.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The SPI is set up with an event handler and the mcube_write_regs is called from the main loop.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The issue is not interrupt related as the CPU locking occurs only after SPI transfer has finished ie the SPI_done flag has been set to true by the SPI interrupt handler. Therefore the CPU is not stuck in a while loop, it crashes after the Serialize_SPI(CMD,1+size,NULL,0,true) function, which is what is confusing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCU Stops Responding</title><link>https://devzone.nordicsemi.com/thread/373539?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2022 20:50:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:455c4a0d-b862-4b1e-b5c8-aac23ea004ff</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Ah, maybe I misunderstood then.&lt;/p&gt;
&lt;p&gt;So even if you remove the additional NRF_LOG_FLUSH() you are still stuck somewhere, right? Have you tried debugging and stepping through&amp;nbsp;mcube_write_regs()? Where does it stop?&lt;/p&gt;
&lt;p&gt;Is your SPI set up with an event handler or without? And in what context is&amp;nbsp;mcube_write_regs() called? Is it from inside an interrupt, or from main() (in the main()&amp;#39;s while loop?)&lt;/p&gt;
&lt;p&gt;I suspect that you are facing an interrupt priority blocking issue.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCU Stops Responding</title><link>https://devzone.nordicsemi.com/thread/373499?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2022 14:29:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efcfd1ef-3d75-4ecb-a936-e0574ed70c34</guid><dc:creator>bryanhsieh</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Thanks for the prompt response. I do not think the error is related to the log process as they were added&amp;nbsp;&lt;/p&gt;
&lt;p&gt;after I noticed the MCU would stop advertising randomly. But thanks for the best practice when it comes to logging.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCU Stops Responding</title><link>https://devzone.nordicsemi.com/thread/373479?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2022 13:51:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34fd6921-7d5b-4f22-9ccb-b1e8b5db0137</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I tried to figure out where it says that you shouldn&amp;#39;t call NRF_LOG_PROCESS() from elsewhere (NRF_LOG_FLUSH() is just a repeated call to NRF_LOG_PROCESS()), but I only found this in nrf_log_ctrl.h:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Macro for processing a single log entry from a queue of deferred logs.
 *
 * You can call this macro from the main context or from the error handler to process
 * log entries one by one.
 *
 * @note If logs are not deferred, this call has no use and is defined as &amp;#39;false&amp;#39;.
 *
 * @retval true    There are more logs to process in the buffer.
 * @retval false   No more logs in the buffer.
 */
#define NRF_LOG_PROCESS()    NRF_LOG_INTERNAL_PROCESS()&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCU Stops Responding</title><link>https://devzone.nordicsemi.com/thread/373478?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2022 13:49:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70fb012f-50eb-41be-a12a-686909a2d5fc</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Bryan,&lt;/p&gt;
&lt;p&gt;I see that you have added&amp;nbsp;NRF_LOG_FLUSH() inside&amp;nbsp;M_DRV_MC36XX_HandleINT().&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know where your first snippet is from (an interrupt or the main() loop), but you should never add NRF_LOG_FLUSH() or NRF_LOG_PROCESS() anywhere unless you mean to shut down immediately after. It should only be used in the main() loop and in error handlers. The reason for this is that this is not what we call a thread safe / thread aware function. What could happen (and is probably happening) in your case is that NRF_LOG_FLUSH() or NRF_LOG_PROCESS() is called regularly from your main loop (either directly, or indirectly from a function called something like &amp;quot;idle_state_handle()&amp;quot;. Then, if you get an interrupt, and this NRF_LOG_PROCESS() execution is interrupted half way through, and then you call NRF_LOG_PROCESS() again from that interrupt, then your nRF52832 will crash, which is probably what you are seeing.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you are having problems with too much log for the log module to handle (which I guess is the reason you added NRF_LOG_FLUSH() to another location), I suggest you either increase the log buffer size, or turn off deferred logging (both of these are done from sdk_config.h. Look for&amp;nbsp;NRF_LOG_BUFSIZE and NRF_LOG_DEFERRED).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>