<?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>Disable interrupts to enter critical section on nRF5340</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/116275/disable-interrupts-to-enter-critical-section-on-nrf5340</link><description>Hi! I&amp;#39;m working on the firmware part that needs to perform operations on the same variables both inside GPIO IRQ and the software timer callback. So, there is a need for a critical section to make sure they operate properly. By looking through the documentation</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Nov 2024 16:27:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/116275/disable-interrupts-to-enter-critical-section-on-nrf5340" /><item><title>RE: Disable interrupts to enter critical section on nRF5340</title><link>https://devzone.nordicsemi.com/thread/510350?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2024 16:27:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1de5c552-ea1e-47e9-bcd8-856d94e09000</guid><dc:creator>AntonZ</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;br /&gt;&lt;br /&gt;Thanks for the quick response and an explanation.&lt;br /&gt;&lt;br /&gt;Yes, BASEPRI configuration is a bit confusing. I just missed the point with the bit shift.&lt;br /&gt;&lt;br /&gt;Just made a simpler test code and found that &amp;quot;irq_lock()&amp;quot; is enough to restrict GPIO IRQs.&lt;br /&gt;Looks like a context switch took place (that is why lock was released by the kernel as described here: &lt;a href="https://docs.nordicsemi.com/bundle/ncs-2.1.3/page/zephyr/kernel/services/interrupts.html#When%20the%20thread%20once%20again%20becomes%20the%20current%20thread,%20the%20kernel%20re-establishes%20its%20interrupt%20lock"&gt;Interrupt docs&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Anton&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disable interrupts to enter critical section on nRF5340</title><link>https://devzone.nordicsemi.com/thread/510113?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 13:36:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fea0bd45-932a-41a2-b3d0-84a342e8c395</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi &lt;span&gt;Anton&lt;/span&gt;,&lt;/p&gt;
&lt;p&gt;BASEPRI==0x20 should disable interrupts with priority 1-7 thus only leaving interrupts with priority 0 enabled (SVCs, zero latency interrupts).&amp;nbsp; This may&amp;nbsp;seem confusing at first, but the register is 8-bit wide, and&amp;nbsp;since this CPU only implements 3-bits,&amp;nbsp;we need to left-shift the priority bits&amp;nbsp;before writing to the basepri register.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1 &amp;lt;&amp;lt; 5 = 0x20 # disable interrupt priority 1-7&lt;/p&gt;
&lt;p&gt;2 &amp;lt;&amp;lt; 5&amp;nbsp; = 0x40 # disable interrupt priority 2-7&lt;/p&gt;
&lt;p&gt;3 &amp;lt;&amp;lt; 5&amp;nbsp; = 0x60 # disable interrupt priority 3-7&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;From ARM&amp;#39;s documentation at&amp;nbsp;&lt;a href="https://developer.arm.com/documentation/100235/0004/the-cortex-m33-processor/programmer-s-model/core-registers#vox1485885594532__CRHJEW"&gt;https://developer.arm.com/documentation/100235/0004/the-cortex-m33-processor/programmer-s-model/core-registers#vox1485885594532__CRHJEW&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1731417928065v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1731417893207v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I&amp;nbsp;tried to test this with the peripheral_lbs sample in SDK v2.7.0 (without TF-M) but was unable to reproduce the issue. I added the code below before bt_enable() in main() and confirmed that I could not trigger the button interrut while the program was running in this loop.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	unsigned int key;

	key = irq_lock();
	
	// Wait for GPIOTE IRQ
	while(1);

	irq_unlock(key);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Do you still read the BASEPRI value as 0x20 if you place a breakpoint in the GPIOTE ISR?&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1731418573034v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>