<?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>APP_PWM_INSTANCE does not initialize p_cb.state</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30149/app_pwm_instance-does-not-initialize-p_cb-state</link><description>Hello, 
 Considering nRF5_SDK_14.2.0_17b948a. 
 In SDK documentation I can read that the steps to use the app_pwm library is to: 
 
 instantiate a context with APP_PWM_INSTANCE 
 call app_pwm_init to initialize the context 
 
 OK, now in APP_PWM_INSTANCE</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Feb 2018 10:27:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30149/app_pwm_instance-does-not-initialize-p_cb-state" /><item><title>RE: APP_PWM_INSTANCE does not initialize p_cb.state</title><link>https://devzone.nordicsemi.com/thread/119900?ContentTypeID=1</link><pubDate>Tue, 06 Feb 2018 10:27:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2c645e8-b8e4-4047-bfba-b3e8ffe67faa</guid><dc:creator>Vincent Bela&amp;#239;che</dc:creator><description>&lt;p&gt;Dear&amp;nbsp;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for your answer. It would be good if these&amp;nbsp;subtleties were documented.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In the SDK there might also be other structures that could be allocated in the stack or heap rather than in the static memory (I am just speculating), and I suspect that freeRTOS, in some configurations, may initialize these RAM areas with some non zero patterns to make it easier detect stack overflow/heap corruption.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So, you should&amp;nbsp;check for that too : probably in the case of stack a different macro is needed to make the&amp;nbsp;initialization explicit, and in the case of heap, you would need a completely different&amp;nbsp;mechanism, so (an)other macro(s) too. As a minimal update, in any case, if you don&amp;#39;t want to support any stack/heap allocation for structures where in theory that would be feasible, you should just clearly document it.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp; Vincent.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: APP_PWM_INSTANCE does not initialize p_cb.state</title><link>https://devzone.nordicsemi.com/thread/119887?ContentTypeID=1</link><pubDate>Tue, 06 Feb 2018 09:21:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f09c300-3701-4064-980c-8c83035e66f0</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]do you rely on the compiler generating some start-up code setting all static memory to zero before entering the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;main&lt;/span&gt; function ?[/quote]
&lt;p&gt;Yes. All C compliant compilers shall zero initialize the BSS area. I see your point, which is that we rely on &amp;quot;NRF_DRV_STATE_UNINITIALIZED&amp;quot; is 0. A clearer way is to set .state=NRF_DRV_STATE_UNINITIALIZED in case this enum changes order or value in the future.&lt;/p&gt;
[quote user=""]does this mean that the&amp;nbsp;&lt;span&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;APP_PWM_INSTANCE&lt;/span&gt; macro cannot be called within a function, like in a thread --- as that would be allocated in the stack, not in the static memory ? If so, I just notice that this constraint is not documented.&lt;/span&gt;[/quote]
&lt;p&gt;That is correct. The structure holds a mix of flash and ram mapped structures for both state handling and callback registration, and is required to be in the static/global scope.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>