<?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>Reading a register right after writing to it. Why?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42437/reading-a-register-right-after-writing-to-it-why</link><description>Hi! 
 
 I have found the following piece of code on an example from a Nordic employee. I&amp;#39;m curious as to its purpose. 
 
 
 Why is the register set, and then read just after? 
 
 Thanks</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Jan 2019 20:10:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42437/reading-a-register-right-after-writing-to-it-why" /><item><title>RE: Reading a register right after writing to it. Why?</title><link>https://devzone.nordicsemi.com/thread/165597?ContentTypeID=1</link><pubDate>Mon, 14 Jan 2019 20:10:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70bc21da-210b-45e6-b496-25f4092fab81</guid><dc:creator>wpaul</dc:creator><description>&lt;p&gt;I don&amp;#39;t think it&amp;#39;s really a question of &amp;quot;Nordic&amp;#39;s registers.&amp;quot; The way ARM SoC designs usually work, ARM Ltd. licenses the ARM CPU core and some related peripheral blocks (like the NVIC, GIC and L2 cache controllers, depending on exactly which CPU you&amp;#39;re talking about), while the SoC vendors connect their own custom peripheral blocks. However there are two ways to license the ARM core IP: 1) you get a pre-generated &amp;quot;binary-only&amp;quot; logic block with predefined peripheral interconnect logic (which is cheaper) or 2) you get the IP block &amp;quot;source code&amp;quot; which you can fully customize right down to the instruction level (which is much more expensive). Most SoC companies do the former. Apple is one example of a company that&amp;#39;s done the latter.&lt;/p&gt;
&lt;p&gt;So unless Nordic pays a lot more money, their peripheral blocks have to use the same bus interconnects as everyone else. In the nRF52832 product spec you mention above, if you look at the block diagram in section 3 (Figure 1), you&amp;#39;ll see that peripheral blocks are all connected to the CPU (and NVIC) through an AHB to APB bridge, which is exactly what the link above describes. The ARM SysTick timer is the one device that generates interrupts which is directly attached to the CPU core, and is likely the only one which doesn&amp;#39;t require the dummy read.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading a register right after writing to it. Why?</title><link>https://devzone.nordicsemi.com/thread/165318?ContentTypeID=1</link><pubDate>Sun, 13 Jan 2019 15:31:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf455d92-8786-45dd-95f9-9dfffeeb2972</guid><dc:creator>natersoz</dc:creator><description>&lt;p&gt;From the nRF52832 Product Specification v1.4&lt;br /&gt;Section 15.8.1 Peripheral Interface, Interrupt clearing&lt;/p&gt;
&lt;div class="page" title="Page 70"&gt;
&lt;div class="layoutArea"&gt;
&lt;div class="column"&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;Helvetica&amp;#39;;font-size:10.000000pt;"&gt;When clearing an interrupt by writing &amp;quot;0&amp;quot; to an event register, or disabling an interrupt using the INTENCLR register, it can take up to four CPU clock cycles to take effect. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;Helvetica&amp;#39;;font-size:10.000000pt;"&gt;So, while I like your answer, and am still thinking about whether your answer is in fact the underlying reason for requiring clearing, I think the answer is not a pipeline flush but merely a implementation of how Nordic&amp;#39;s registers work.&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading a register right after writing to it. Why?</title><link>https://devzone.nordicsemi.com/thread/165272?ContentTypeID=1</link><pubDate>Sat, 12 Jan 2019 00:25:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbeab141-dd78-4078-8f2b-6a42ffdd7eaa</guid><dc:creator>awneil</dc:creator><description>[quote userid="12368" url="~/f/nordic-q-a/42437/reading-a-register-right-after-writing-to-it-why"]Why is the register set, and then read just after?[/quote]
&lt;p&gt;Have you checked the register description in the &lt;strong&gt;Product Specification&lt;/strong&gt; for any clues?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading a register right after writing to it. Why?</title><link>https://devzone.nordicsemi.com/thread/165270?ContentTypeID=1</link><pubDate>Fri, 11 Jan 2019 23:31:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce74f7a7-b0e0-4665-b276-cdae9efbbf2f</guid><dc:creator>wpaul</dc:creator><description>&lt;p&gt;I think a good answer can be found here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0321a/BIHEADII.html"&gt;http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0321a/BIHEADII.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;quot;The memory barrier instructions, &lt;code class="code"&gt;DMB&lt;/code&gt; and &lt;code class="code"&gt;DSB&lt;/code&gt;, can be used to ensure that the write buffer on the processor has completed its operation before subsequent operations can be started. However, it does not check the status of the bus level write buffers. In such cases, if the system is based on AHB or AHB Lite, you might need to perform a dummy read through the bus bridge to ensure that the bus bridge has completed its operation. Alternatively, a SoC design might have a device specific status register to indicate whether the bus system write buffer is idle.&amp;quot;&lt;/p&gt;
&lt;p&gt;In short, register accesses take place over a peripheral bus, and sometimes the writes are buffered (the idea being to batch a bunch of writes into a burst if you can). But sometimes you need to be sure a register write actually completes before you proceed further through your program, and forcing a read access does this.&lt;/p&gt;
&lt;p&gt;You&amp;#39;re basically defeating a performance optimization in order to achieve correct program behavior. This is a common pastime in embedded and systems programming. :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>