<?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>compiler optimization level nrf api going wrong</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76518/compiler-optimization-level-nrf-api-going-wrong</link><description>sdk 17.0.2 
 IDE - segger embedded studio 
 For the below given code, &amp;quot; pin &amp;quot; is not updating when GPIO goes high when optimization level is kept &amp;quot;Level 3 for more speed&amp;quot;. upto &amp;quot;level 2&amp;quot; , &amp;quot; pin&amp;quot; is updating properly. 
 Could you please let me know why</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 22 Jun 2021 11:12:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76518/compiler-optimization-level-nrf-api-going-wrong" /><item><title>RE: compiler optimization level nrf api going wrong</title><link>https://devzone.nordicsemi.com/thread/316442?ContentTypeID=1</link><pubDate>Tue, 22 Jun 2021 11:12:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d1bd5aa-cdfb-4bc4-a4da-9e2ee623dde5</guid><dc:creator>kizhimon</dc:creator><description>&lt;p&gt;thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiler optimization level nrf api going wrong</title><link>https://devzone.nordicsemi.com/thread/316431?ContentTypeID=1</link><pubDate>Tue, 22 Jun 2021 10:08:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5254f3da-e23a-469e-bf3b-2d798b695ed6</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="kizhimon"]1) But why this problem is not happening when optimization level is low (the peripheral still runs at 16M).[/quote]
&lt;p&gt;its because no optimization uses more cycles in between configuring and reading the gpio input.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="kizhimon"]2) don&amp;#39;t you think these corrections should be included in the SDK driver files?[/quote]
&lt;p&gt;There are not many cases where this&amp;nbsp;issue of synchronization occurs, as a wait state is introduced whenever you read a event register. Adding a wait-state on all calls will not be efficient.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiler optimization level nrf api going wrong</title><link>https://devzone.nordicsemi.com/thread/316423?ContentTypeID=1</link><pubDate>Tue, 22 Jun 2021 09:32:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:894af539-a945-4089-9816-f78c22fd4352</guid><dc:creator>kizhimon</dc:creator><description>&lt;p&gt;Thank you for your reply. I understand it.&lt;/p&gt;
&lt;p&gt;1) But why this problem is not happening when optimization level is low (the peripheral still runs at 16M).&lt;/p&gt;
&lt;p&gt;2) don&amp;#39;t you think these corrections should be included in the SDK driver files?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiler optimization level nrf api going wrong</title><link>https://devzone.nordicsemi.com/thread/316387?ContentTypeID=1</link><pubDate>Tue, 22 Jun 2021 07:22:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0788dcc-1a53-4a97-b804-da5e863f6ac4</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;The CPU always runs on 64 MHz, but the peripherals are clocked from a 16 MHz clock source:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/clock.html?cp=4_2_0_18_0#concept_rp5_fgp_bs"&gt;https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/clock.html?cp=4_2_0_18_0#concept_rp5_fgp_bs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Whenever the cpu interacts with a peripheral register, its always updated on a 16M clock basis. Whenever you read an event, that will cause a wait-state.&lt;/p&gt;
&lt;p&gt;The different clock speeds considerations are also mentioned in the migration document from nrf51-&amp;gt;nrf52:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/migration_nrf52/MIG/nrf52_migration/functional.html?cp=4_8_0"&gt;https://infocenter.nordicsemi.com/topic/migration_nrf52/MIG/nrf52_migration/functional.html?cp=4_8_0&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiler optimization level nrf api going wrong</title><link>https://devzone.nordicsemi.com/thread/316310?ContentTypeID=1</link><pubDate>Mon, 21 Jun 2021 14:40:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14149a48-54dd-43cd-be58-c9551c5b5a4b</guid><dc:creator>kizhimon</dc:creator><description>&lt;p&gt;Thank you&amp;nbsp;&lt;span&gt;H&amp;aring;kon for your reply.&amp;nbsp;&lt;/span&gt;&lt;span&gt;It&amp;#39;s working when I added that line of code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Does&amp;nbsp;modifying compiler optimization flag changes CPU frequency ? My understanding is that CPU will be always running in 64 Mhz. Could you please clarify this&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiler optimization level nrf api going wrong</title><link>https://devzone.nordicsemi.com/thread/316179?ContentTypeID=1</link><pubDate>Mon, 21 Jun 2021 08:24:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f0231ac-fb4e-478e-99db-8748d7c66512</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I believe the problem is that you are writing and reading the register within a few cpu cycles, where the peripheral clock has not been able to execute in between. This is due to CPU running on 64M and the peripheral clock tree running on 16M.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Try adding a dummy &amp;quot;peripheral clock wait&amp;quot; and see if this helps:&lt;/p&gt;
&lt;p&gt;(void)NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0];&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This will generate a 1 cycle (on the 16M PCLK) between the two calls.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind 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>