<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to safely disable oscillator on K24 in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-safely-disable-oscillator-on-K24/m-p/1642742#M64994</link>
    <description>&lt;P&gt;Thanks for your response.&amp;nbsp; The post does make things a bit clearer, but I don't see that it addresses switching from external crystal to external clock.&lt;/P&gt;&lt;P&gt;For now I am switching back to the FEI state and then switching to FBE, then BLPE with the EREFS bit of MCG_C2 set to 0.&amp;nbsp; So far I have not had any issues with this method.&lt;/P&gt;</description>
    <pubDate>Mon, 01 May 2023 18:25:56 GMT</pubDate>
    <dc:creator>joee</dc:creator>
    <dc:date>2023-05-01T18:25:56Z</dc:date>
    <item>
      <title>How to safely disable oscillator on K24</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-safely-disable-oscillator-on-K24/m-p/1635666#M64966</link>
      <description>&lt;P&gt;My board is running with an external clock at 50MHz.&amp;nbsp; &amp;nbsp;The MCG and OSC are setup in the bootloader with the following code (from Keil Uvision startup file):&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#elif (CLOCK_SETUP == 2)
  /* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=1,OUTDIV4=1,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */
  SIM-&amp;gt;CLKDIV1 = (uint32_t)0x00110000u; /* Update system prescalers */
  /* Switch to FBE Mode */
  /* OSC-&amp;gt;CR: ERCLKEN=0,??=0,EREFSTEN=0,??=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
  OSC-&amp;gt;CR = (uint8_t)0x00u;
  /* MCG-&amp;gt;C7: OSCSEL=0 */
  MCG-&amp;gt;C7 = (uint8_t)0x00u;
  /* MCG-&amp;gt;C2: ??=0,??=0,RANGE0=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
  MCG-&amp;gt;C2 = (uint8_t)0x24u;
  /* MCG-&amp;gt;C1: CLKS=2,FRDIV=5,IREFS=0,IRCLKEN=0,IREFSTEN=0 */
  MCG-&amp;gt;C1 = (uint8_t)0xA8u;
  /* MCG-&amp;gt;C4: DMX32=0,DRST_DRS=0 */
  MCG-&amp;gt;C4 &amp;amp;= (uint8_t)~(uint8_t)0xE0u;
  /* MCG-&amp;gt;C5: ??=0,PLLCLKEN=0,PLLSTEN=0,PRDIV0=0 */
  MCG-&amp;gt;C5 = (uint8_t)0x00u;
  /* MCG-&amp;gt;C6: LOLIE=0,PLLS=0,CME=0,VDIV0=0 */
  MCG-&amp;gt;C6 = (uint8_t)0x00u;
  while((MCG-&amp;gt;S &amp;amp; MCG_S_OSCINIT0_MASK) == 0u) { /* Check that the oscillator is running */
  }
  while((MCG-&amp;gt;S &amp;amp; MCG_S_IREFST_MASK) != 0u) { /* Check that the source of the FLL reference clock is the external reference clock. */
  }
  while((MCG-&amp;gt;S &amp;amp; 0x0Cu) != 0x08u) {    /* Wait until external reference clock is selected as MCG output */
  }
  /* Switch to BLPE Mode */
  /* MCG-&amp;gt;C2: ??=0,??=0,RANGE0=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
  MCG-&amp;gt;C2 = (uint8_t)0x24u;
#endif&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to disable the oscillator in the main code so that I can use the XTAL pin as GPIO. I am trying to do this by setting the EREFS bit of MCG_C2 as seen in the following code, but occasionally I get a bus fault afterwards.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;MCG-&amp;gt;C2 &amp;amp;= ~MCG_C2_EREFS0_MASK; //set for external clock
while((MCG-&amp;gt;S &amp;amp; MCG_S_OSCINIT0_MASK ) != 0x00u);   /* Wait until external reference clock is selected as MCG output */&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there some other sequence I need to perform to do this or some other status to wait for?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 21:33:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-safely-disable-oscillator-on-K24/m-p/1635666#M64966</guid>
      <dc:creator>joee</dc:creator>
      <dc:date>2023-04-18T21:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to safely disable oscillator on K24</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-safely-disable-oscillator-on-K24/m-p/1639083#M64975</link>
      <description>&lt;P&gt;maybe this post can help you&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-System-Clocks/ta-p/1149854" target="_blank"&gt;https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-System-Clocks/ta-p/1149854&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 16:06:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-safely-disable-oscillator-on-K24/m-p/1639083#M64975</guid>
      <dc:creator>vicentegomez</dc:creator>
      <dc:date>2023-04-24T16:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to safely disable oscillator on K24</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-safely-disable-oscillator-on-K24/m-p/1642742#M64994</link>
      <description>&lt;P&gt;Thanks for your response.&amp;nbsp; The post does make things a bit clearer, but I don't see that it addresses switching from external crystal to external clock.&lt;/P&gt;&lt;P&gt;For now I am switching back to the FEI state and then switching to FBE, then BLPE with the EREFS bit of MCG_C2 set to 0.&amp;nbsp; So far I have not had any issues with this method.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 18:25:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-safely-disable-oscillator-on-K24/m-p/1642742#M64994</guid>
      <dc:creator>joee</dc:creator>
      <dc:date>2023-05-01T18:25:56Z</dc:date>
    </item>
  </channel>
</rss>

