<?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>nRF52833 Resets when PWM_CONFIG_LOG_ENABLED is 0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87871/nrf52833-resets-when-pwm_config_log_enabled-is-0</link><description>I&amp;#39;m running into an odd problem with the PWM driver. We&amp;#39;re using SDK 17.0.2 and the S113 softdevice on an nRF52833. We&amp;#39;re using the PWM module to drive some LEDs. 
 The nRF52833 will consistently reset without hitting any of the error handlers or printing</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 May 2022 11:43:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87871/nrf52833-resets-when-pwm_config_log_enabled-is-0" /><item><title>RE: nRF52833 Resets when PWM_CONFIG_LOG_ENABLED is 0</title><link>https://devzone.nordicsemi.com/thread/368035?ContentTypeID=1</link><pubDate>Mon, 16 May 2022 11:43:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:140c3688-5442-4acf-8325-b02721ca9a21</guid><dc:creator>CurtisHx2</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Thanks for that sample application.&amp;nbsp; I think I see the problem now.&amp;nbsp; nrfx_pwm_init is sometimes returning NRF_ERROR_INVALID_STATE, and our code is ignoring that return value, so it calls straight into nrfx_pwm_simple_playback, which is causing the reboot.&amp;nbsp; It was hidden in the log output by a bunch of &amp;quot;nrfx_pwm_is_stopped returned 0&amp;quot; outputs while the code waited for the PWM to stop.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Edit with more information:&lt;/p&gt;
&lt;p&gt;We are using the PWM driver to run RGB LEDs that indicate the state of the system.&amp;nbsp; In order to change what the LEDs were showing, we would call nrfx_pwm_stop in the mainline code, and call nrfx_pwm_uninit in the nrfx_pwm_handler_t, that&amp;#39;s passed to nrfx_pwm_init.&lt;/p&gt;
&lt;p&gt;This was causing a concurrency problem, where sometimes nrfx_pwm_init and nrfx_pwm_simple_playback were getting called before nrfx_pwm_uninit was getting called.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s some really basic example code.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/******************************************************************************
* Unititializes the pwm driver on stop.
*******************************************************************************/
void PWM_Handler(nrf_drv_pwm_evt_type_t eventType)
{
  if (eventType == NRF_DRV_PWM_EVT_FINISHED || eventType == NRF_DRV_PWM_EVT_STOPPED)
  {
    nrfx_pwm_uninit(&amp;amp;pwm);
  }
}

/******************************************************************************
* Inits and starts the requested animation based on the state
*******************************************************************************/
void PWM_RunAnimation(LEDState_T *state)
{
    currentState = state;
    currentState-&amp;gt;isActive = true;
    nrfx_pwm_init(&amp;amp;pwm, &amp;amp;state-&amp;gt;config, PWM_Handler);
    nrfx_pwm_simple_playback(&amp;amp;pwm, &amp;amp;state-&amp;gt;sequence, state-&amp;gt;playbacks, NRFX_PWM_FLAG_STOP);
}

/******************************************************************************
* Stops the requested animation based on the state
*******************************************************************************/
void PWM_StopAnimation()
{
    nrfx_pwm_stop(&amp;amp;pwm, true);
}

/******************************************************************************
* Updates the LED state
*******************************************************************************/
void PWM_UpdateState()
{
   PWM_StopAnimation();
   PWM_RunAnimation(&amp;amp;animations[index]);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The entrance to this code is in PWM_UpdateState().&amp;nbsp; It stops the current animation and starts the next animation.&amp;nbsp; The first thing it does is call PWM_StopAnimation, which triggers the stop sequence.&amp;nbsp; BUT it takes time for the stop sequence to happen, meanwhile the running code is in PWM_RunAnimation.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The callback to PWM_Handler usually took more time than it took for the code to run through PWM_RunAnimation with the PWM logging disabled.&amp;nbsp; With PWM logging enabled, it would usually take longer for the logging code to run, giving maybe enough time for the callback to be called.&lt;/p&gt;
&lt;p&gt;I fixed this by calling nrfx_pwm_uninit in PWM_StopAnimation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52833 Resets when PWM_CONFIG_LOG_ENABLED is 0</title><link>https://devzone.nordicsemi.com/thread/367968?ContentTypeID=1</link><pubDate>Mon, 16 May 2022 07:00:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae9f3e0b-937d-4bc1-8a1e-6211086d7455</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I am sorry for the late reply.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tested the pwm_driver with the armgcc compiler and the nRF52833 DK from SDK17.0.2 with PWM_CONFIG_LOG_ENABLED set to 0, and I didn&amp;#39;t encounter any issues. I just used the unmodified pwm_driver example from SDK\examples\peripheral\pwm_driver, and I copied the pca10056 folder, renamed it pca10100, and then changed all occurrences of nrf52840 to nrf52833 and all&amp;nbsp;&lt;span&gt;occurrences&amp;nbsp;of pca10056 to pca10100 in the makefile, and I changed the RAM and FLASH sizes to half of the default values in the pwm_driver_gcc_nrf52.ld in pca10100\blank\armgcc.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I don&amp;#39;t know what project you started out with, since you are using the s113 softdevice, or what IDE you are using, but perhaps you can zip and send me the project folder, so that I can have a look?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In case you are interested in testing the project that I tested, you can find it here:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;NB: I only modified the armgcc compiler folder, and not the Keil, SES, or IAR projects.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/pwm_5F00_driver_5F00_10100.zip"&gt;devzone.nordicsemi.com/.../pwm_5F00_driver_5F00_10100.zip&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BR,&lt;br /&gt;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52833 Resets when PWM_CONFIG_LOG_ENABLED is 0</title><link>https://devzone.nordicsemi.com/thread/367886?ContentTypeID=1</link><pubDate>Fri, 13 May 2022 15:17:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf075f4b-8801-4bde-8943-cfea642fdfc6</guid><dc:creator>CurtisHx2</dc:creator><description>&lt;p&gt;Spent another 3 hours trying to track this down and my original conclusion is correct.&amp;nbsp; The nRF52 is rock stable with PWM_CONFIG_LOG_ENABLED set to 1, and reliably crashes with PWM_CONFIG_LOG_ENABLED set to 0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52833 Resets when PWM_CONFIG_LOG_ENABLED is 0</title><link>https://devzone.nordicsemi.com/thread/367823?ContentTypeID=1</link><pubDate>Fri, 13 May 2022 11:30:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3c61d50-8b37-4686-9065-edca67f86159</guid><dc:creator>CurtisHx2</dc:creator><description>&lt;p&gt;I did some more investigation and my original conclusion is incorrect.&amp;nbsp; The stability might come from having an active debug link, not having PWM_CONFIG_LOG_ENABLED turned on.&amp;nbsp; I need to do some more investigation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>