<?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>Using runtime started LFCLK external oscillator with nRF5340 and Bluetooth enabled</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/109688/using-runtime-started-lfclk-external-oscillator-with-nrf5340-and-bluetooth-enabled</link><description>Using SDK 2.5.1 at time of writing. 
 This is less a &amp;quot;request for help&amp;quot; and more of a &amp;quot;here&amp;#39;s how I managed to do this and I&amp;#39;m documenting it here in case others want to do the same thing&amp;quot;. 
 The existing available configuration settings and APIs aren</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Apr 2024 06:36:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/109688/using-runtime-started-lfclk-external-oscillator-with-nrf5340-and-bluetooth-enabled" /><item><title>RE: Using runtime started LFCLK external oscillator with nRF5340 and Bluetooth enabled</title><link>https://devzone.nordicsemi.com/thread/476433?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2024 06:36:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7a938ed-1ed1-45fc-9d64-17693c07742a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;You are right, there is a static build assert that will be triggered if you build the network firmware without clock calibration enabled. From a HW perspective, it does not matter whether the calibration is performed on the application core or the network core. However, in the SDK, we have decided that clock calibration should be performed by the network core when BT is enabled. I thought&amp;nbsp;the calibration was done by the application core (this was true in&amp;nbsp;earlier SDK versions), and therefore, it would be possible to trick the BT controller into using the RC source uncalibrated.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using runtime started LFCLK external oscillator with nRF5340 and Bluetooth enabled</title><link>https://devzone.nordicsemi.com/thread/476192?ContentTypeID=1</link><pubDate>Wed, 27 Mar 2024 15:04:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52390411-1cc1-4057-b018-0a03c98f3994</guid><dc:creator>Nathan</dc:creator><description>&lt;p&gt;Using your register definitions in soc.h would probably be cleaner and I might switch to that later, it winds up being the same idea in the end though.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Earlier I tried&amp;nbsp;setting that CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION=n value, but it gave me a build error in&amp;nbsp;a zephyr driver.&amp;nbsp;I&amp;#39;ve re-tested it now and it worked fine when setting only application and bootloader, until I stopped lying to the network core and told it to use RC clock with no calibration. Then the build error shows up in /subsys/mpsl/init/mpsl_init.c in the mpsl_calibration_work_handler function. That function only cares about the CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC definition and always tries to grab CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_PERIOD, disrespecting the CALIBRATION=n setting.&amp;nbsp;So network core needs to be lied to and reset after runtime clock config right now, but maybe starting on RC would work fine if only the application and bootloader were told to use it with the calibration disabled. I&amp;#39;ll try testing that later when I get some time. In the meantime I don&amp;#39;t think there would be any issues of just falling back to startup with SYNTH instead as long as you can stomach the extra power draw of leaving HFCLK on (in my case the bootloader is USB based so I don&amp;#39;t care about power draw there, and init is short, so it&amp;#39;s no issue).&lt;/p&gt;
&lt;p&gt;In any case starting the network core on RC to prevent having to reset it is untenable due to the build error. And additionally that might be behavior that the SDK shouldn&amp;#39;t change, because in literally any other situation the SDK should produce a build error if the user is trying to use Bluetooth with an uncalibrated RC clock. It just happens that in this unique case I need to start up on an alternate clock source and have no intentions of leaving the network core&amp;nbsp;in a state where it&amp;#39;s running on an uncalibrated RC by the time I go to start initializing the Bluetooth services over hci_rpmsg.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using runtime started LFCLK external oscillator with nRF5340 and Bluetooth enabled</title><link>https://devzone.nordicsemi.com/thread/476184?ContentTypeID=1</link><pubDate>Wed, 27 Mar 2024 14:26:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87b9ec21-0507-4d2e-ad6d-a86b41f4ed0d</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I see. Generally, hardware specific initializations can be placed in your board files. However,&amp;nbsp;getting a clean solution in this case might be&amp;nbsp;difficult since configuration involves using the I2C bus. Technically, you could use the nRFx drivers directly for this, as they do not depend on the sysclock or other Zephyr resources. But I guess it&amp;nbsp;might conflict with the actual&amp;nbsp;initialization of the RTC later in the startup process.&lt;/p&gt;
[quote user="nproux"]For bypass, yes I had to resort to setting the bypass register directly while taking into account the base pointer difference between secure and non-secure application modes. I do this just before modifying the LFCLK source and kicking the start trigger. My code for that part looks basically like this:[/quote]
&lt;p&gt;Thanks. I just wanted to make sure. You can also include soc.h an use&amp;nbsp;our register&amp;nbsp;defintitions.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;E.g.,&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_OSCILLATORS_S-&amp;gt;XOSC32KI.BYPASS = 
    (OSCILLATORS_XOSC32KI_BYPASS_BYPASS_Enabled &amp;lt;&amp;lt; OSCILLATORS_XOSC32KI_BYPASS_BYPASS_Pos);&lt;/pre&gt;&lt;/p&gt;
[quote user="nproux"] If there was a way to suppress periodic calibration of the RC clock then that would have been an option as well, given that you don&amp;#39;t actually need regular calibration in this situation, but that would definitely require some changes to the SDK to become available as an option[/quote]
&lt;p&gt;Did you try to build with&amp;nbsp;CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION=n in your appcore FW?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using runtime started LFCLK external oscillator with nRF5340 and Bluetooth enabled</title><link>https://devzone.nordicsemi.com/thread/476176?ContentTypeID=1</link><pubDate>Wed, 27 Mar 2024 13:56:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e2488c9-96af-4211-82f8-dd2479e8614f</guid><dc:creator>Nathan</dc:creator><description>&lt;p&gt;It is probably possible to start the external clock&amp;nbsp;pre-kernel in many cases. There&amp;#39;s just no &lt;em&gt;general&lt;/em&gt; way to do it&amp;nbsp;that could be added to the SDK files because what&amp;#39;s actually required to start up your external clock is heavily dependent on your exact hardware setup. Mine for example needs both a&amp;nbsp;GPIO write to bring up power to the oscillator, plus some extra I2C serial transactions to set it to the correct&amp;nbsp;speed. Others might just be started up automatically with board power and never need a manual kickoff. The limitation when doing it&amp;nbsp;pre-kernel&amp;nbsp;is that you can&amp;#39;t use any resources that rely on LFCLK to be running as part of your external oscillator startup procedure, and if you do need those resources then your only option is to start up on SYNTH and do a manual switchover later. If there was a way to suppress periodic calibration of the RC clock then that would have been an option as well, given that you don&amp;#39;t actually need regular calibration in this situation, but that would definitely require some changes to the SDK to become available as an option.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For bypass, yes I had to resort to setting the bypass register directly while taking into account the base pointer difference between secure and non-secure application modes. I do this just before modifying the LFCLK source and kicking the start trigger. My code for that part looks basically like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Set address of registers based on secure vs non-secure application mode
#if APP_NS
static const uint32_t oscillators_base_addr = 0x40004000;
static const uint32_t oscillators_bypass_offset_addr = 0x6C0;
static const uint32_t oscillators_bypass_enable = 0x1;
#else
static const uint32_t oscillators_base_addr = 0x50004000;
static const uint32_t oscillators_bypass_offset_addr = 0x6C0;
static const uint32_t oscillators_bypass_enable = 0x1;
#endif

// Set bypass to use &amp;quot;oscillator mode&amp;quot; instead of &amp;quot;crystal mode&amp;quot; on external pin
uint32_t volatile *p_osc_bypass_reg = (uint32_t volatile *)(oscillators_base_addr + oscillators_bypass_offset_addr);
*p_osc_bypass_reg = oscillators_bypass_enable;
__DMB();
__DSB();&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using runtime started LFCLK external oscillator with nRF5340 and Bluetooth enabled</title><link>https://devzone.nordicsemi.com/thread/476141?ContentTypeID=1</link><pubDate>Wed, 27 Mar 2024 12:53:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56a9e1b2-0ff2-4919-8b50-83944980b1e5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for the detailed write-up. I&amp;#39;m wondering if it would be possible to initiate the external clock source before the pre-kernel initialization here:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/272786b074227b4abcbe8f954d5bb8acf54f3dd3/drivers/timer/nrf_rtc_timer.c#L771"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/272786b074227b4abcbe8f954d5bb8acf54f3dd3/drivers/timer/nrf_rtc_timer.c#L771&lt;/a&gt;&amp;nbsp;which is requesting the LF clock.&lt;/p&gt;
[quote user=""]You&amp;#39;ll of course need to make sure that the low frequency external oscillator is connected to the XL1 pin as usual, and that XL2 is left floating.&amp;nbsp;[/quote]
&lt;p&gt;For the nRF52 series we had the following Kconfig symbols to enable support for external clock source in the clock driver:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/272786b074227b4abcbe8f954d5bb8acf54f3dd3/drivers/clock_control/Kconfig.nrf#L45"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/272786b074227b4abcbe8f954d5bb8acf54f3dd3/drivers/clock_control/Kconfig.nrf#L45&lt;/a&gt;. Support for the nRF53 does not appear to have been added yet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you set the bypass register directly?&amp;nbsp;&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/pastedimage1711542529712v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a title="Low-frequency (32.768 kHz) crystal oscillator (LFXO)" href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/oscillators/doc/oscillators.html?cp=4_0_0_3_11_1#concept_osc_lfxo"&gt;Low-frequency (32.768 kHz) crystal oscillator (LFXO)&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>