<?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>Kinetis Microcontrollers中的主题 Re: LPSPI_Reset causes HardFault (KE18F)</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740923#M45145</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLOCK_EnableClock(kCLOCK_Lpspi0); can be used to enable the clock gate of LPSPI0.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="CLOCK_EnableClock.PNG"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/12362i54D035F16BF08229/image-size/large?v=v2&amp;amp;px=999" role="button" title="CLOCK_EnableClock.PNG" alt="CLOCK_EnableClock.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="_clock_ip_name.PNG"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/14899i898638C0F6626B6D/image-size/large?v=v2&amp;amp;px=999" role="button" title="_clock_ip_name.PNG" alt="_clock_ip_name.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Robin&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Mar 2018 08:41:48 GMT</pubDate>
    <dc:creator>Robin_Shen</dc:creator>
    <dc:date>2018-03-09T08:41:48Z</dc:date>
    <item>
      <title>LPSPI_Reset causes HardFault (KE18F)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740921#M45143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, this is probably a stupid newbie error for the KE18F or the&amp;nbsp;fsl drivers, but I'm not seeing it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to bring up the LPSPI.&amp;nbsp; I installed&amp;nbsp;an example app and have been trying to follow it, but I can't use it directly, as I don't have the twrke18f board.&amp;nbsp; Code that follows is an attempt to trim it down to minimum.&amp;nbsp; Building for MKE18F256VLH16.&amp;nbsp; &amp;nbsp;I enable port clocks, set the pin mux, set the clock for LPSPI0, but when I try to reset the SPI, I end up in the HardFault_Handler.&amp;nbsp; &amp;nbsp;If I comment out the LPSPI_Reset call, it runs fine, so it seems to not be an inadvertent side effect of earlier code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So apparently there's something more that must be done for the LPSPI on the KE18F that didn't need to be done on the K60?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;int main(void) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Init board hardware. */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;//====================================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; // BOARD_InitBootPins();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* Clock Control: 0x01u */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_EnableClock(kCLOCK_PortA);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Clock Control: 0x01u */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_EnableClock(kCLOCK_PortB);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Clock Control: 0x01u */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_EnableClock(kCLOCK_PortC);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Clock Control: 0x01u */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_EnableClock(kCLOCK_PortD);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Clock Control: 0x01u */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_EnableClock(kCLOCK_PortE);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* PORTB1 (pin 33) is configured as LPSPI0_SOUT */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; PORT_SetPinMux(PORTB, 1U, kPORT_MuxAlt3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* PORTB2 (pin 32) is configured as LPSPI0_SCK */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; PORT_SetPinMux(PORTB, 2U, kPORT_MuxAlt3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* PORTB3 (pin 31) is configured as LPSPI0_SIN */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; PORT_SetPinMux(PORTB, 3U, kPORT_MuxAlt3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; //=============================================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; // BOARD_InitBootClocks();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; scg_sys_clk_config_t curConfig;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* Init FIRC. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_CONFIG_FircSafeConfig(&amp;amp;g_scgFircConfig_BOARD_BootClockRUN);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Set HSRUN power mode. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; SMC_SetPowerModeHsrun(SMC);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateHsrun)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* Init SIRC. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_InitSirc(&amp;amp;g_scgSircConfig_BOARD_BootClockRUN);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Init SysPll. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_InitSysPll(&amp;amp;g_scgSysPllConfig_BOARD_BootClockRUN);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Set SCG to SPLL mode. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_SetHsrunModeSysClkConfig(&amp;amp;g_sysClkConfig_BOARD_BootClockRUN);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Wait for clock source switch finished. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; do&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;CLOCK_GetCurSysClkConfig(&amp;amp;curConfig);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; } while (curConfig.src != g_sysClkConfig_BOARD_BootClockRUN.src);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* Set SystemCoreClock variable. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Set PCC LPSPI0 selection */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; CLOCK_SetIpSrc(kCLOCK_Lpspi0, kCLOCK_IpSrcFircAsync);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;printf("Hello World\n");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;LPSPI_Reset(LPSPI0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* Force the counter to be placed into memory. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; volatile static int i = 0 ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; /* Enter an infinite loop, just incrementing a counter. */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; while(1) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;i++ ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; return 0 ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Mar 2018 18:50:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740921#M45143</guid>
      <dc:creator>johnadamson</dc:creator>
      <dc:date>2018-03-08T18:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: LPSPI_Reset causes HardFault (KE18F)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740922#M45144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, I think I see what the problem is, but it only raises more questions.&amp;nbsp; The code for CLOCK_SetIpSrc in fsl_clock.h is:&lt;/P&gt;&lt;P&gt;static inline void CLOCK_SetIpSrc(clock_ip_name_t name, clock_ip_src_t src)&lt;BR /&gt;{&lt;BR /&gt; uint32_t reg = (*(volatile uint32_t *)name);&lt;/P&gt;&lt;P&gt;assert(reg &amp;amp; PCC_CLKCFG_PR_MASK);&lt;BR /&gt; assert(!(reg &amp;amp; PCC_CLKCFG_INUSE_MASK)); /* Should not change if clock has been enabled by other core. */&lt;/P&gt;&lt;P&gt;reg = (reg &amp;amp; ~PCC_CLKCFG_PCS_MASK) | PCC_CLKCFG_PCS(src);&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt; * If clock is already enabled, first disable it, then set the clock&lt;BR /&gt; * source and re-enable it.&lt;BR /&gt; */&lt;BR /&gt; (*(volatile uint32_t *)name) = reg &amp;amp; ~PCC_CLKCFG_CGC_MASK;&lt;BR /&gt; (*(volatile uint32_t *)name) = reg;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tracing through it, I realized that the next-to-last line does indeed "first disable it", but the&amp;nbsp;last line does NOT "then re-enable it".&amp;nbsp; If I change the last line to:&lt;/P&gt;&lt;P&gt;(*(volatile uint32_t *)name) = reg&lt;STRONG&gt; | PCC_CLKCFG_CGC_MASK&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;the later code doesn't hard fault.&amp;nbsp; Because, of course, the clock for LPSPI0 was never getting enabled before and now it is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So...am I missing a major step in my initialization, 'cause otherwise I don't get how anyone's code ever works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Mar 2018 19:30:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740922#M45144</guid>
      <dc:creator>johnadamson</dc:creator>
      <dc:date>2018-03-08T19:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: LPSPI_Reset causes HardFault (KE18F)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740923#M45145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLOCK_EnableClock(kCLOCK_Lpspi0); can be used to enable the clock gate of LPSPI0.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="CLOCK_EnableClock.PNG"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/12362i54D035F16BF08229/image-size/large?v=v2&amp;amp;px=999" role="button" title="CLOCK_EnableClock.PNG" alt="CLOCK_EnableClock.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="_clock_ip_name.PNG"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/14899i898638C0F6626B6D/image-size/large?v=v2&amp;amp;px=999" role="button" title="_clock_ip_name.PNG" alt="_clock_ip_name.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Robin&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Mar 2018 08:41:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740923#M45145</guid>
      <dc:creator>Robin_Shen</dc:creator>
      <dc:date>2018-03-09T08:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: LPSPI_Reset causes HardFault (KE18F)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740924#M45146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yup, that was it.&amp;nbsp; In trying to duplicate the functionality of&amp;nbsp;LPSPI_MasterInit, I missed that line.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Mar 2018 14:54:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/LPSPI-Reset-causes-HardFault-KE18F/m-p/740924#M45146</guid>
      <dc:creator>johnadamson</dc:creator>
      <dc:date>2018-03-09T14:54:54Z</dc:date>
    </item>
  </channel>
</rss>

