AnsweredAssumed Answered

LPSPI_Reset causes HardFault (KE18F)

Question asked by John Adamson on Mar 8, 2018
Latest reply on Mar 9, 2018 by John Adamson

Sorry, this is probably a stupid newbie error for the KE18F or the fsl drivers, but I'm not seeing it.  

I'm trying to bring up the LPSPI.  I installed 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.  Code that follows is an attempt to trim it down to minimum.  Building for MKE18F256VLH16.   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.   If I comment out the LPSPI_Reset call, it runs fine, so it seems to not be an inadvertent side effect of earlier code.  

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?

 

int main(void) {
/* Init board hardware. */

//====================================================
// BOARD_InitBootPins();

/* Clock Control: 0x01u */
CLOCK_EnableClock(kCLOCK_PortA);
/* Clock Control: 0x01u */
CLOCK_EnableClock(kCLOCK_PortB);
/* Clock Control: 0x01u */
CLOCK_EnableClock(kCLOCK_PortC);
/* Clock Control: 0x01u */
CLOCK_EnableClock(kCLOCK_PortD);
/* Clock Control: 0x01u */
CLOCK_EnableClock(kCLOCK_PortE);

/* PORTB1 (pin 33) is configured as LPSPI0_SOUT */
PORT_SetPinMux(PORTB, 1U, kPORT_MuxAlt3);

/* PORTB2 (pin 32) is configured as LPSPI0_SCK */
PORT_SetPinMux(PORTB, 2U, kPORT_MuxAlt3);

/* PORTB3 (pin 31) is configured as LPSPI0_SIN */
PORT_SetPinMux(PORTB, 3U, kPORT_MuxAlt3);


//=============================================================
// BOARD_InitBootClocks();
scg_sys_clk_config_t curConfig;

/* Init FIRC. */
CLOCK_CONFIG_FircSafeConfig(&g_scgFircConfig_BOARD_BootClockRUN);
/* Set HSRUN power mode. */
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
SMC_SetPowerModeHsrun(SMC);
while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateHsrun)
{
}

/* Init SIRC. */
CLOCK_InitSirc(&g_scgSircConfig_BOARD_BootClockRUN);
/* Init SysPll. */
CLOCK_InitSysPll(&g_scgSysPllConfig_BOARD_BootClockRUN);
/* Set SCG to SPLL mode. */
CLOCK_SetHsrunModeSysClkConfig(&g_sysClkConfig_BOARD_BootClockRUN);
/* Wait for clock source switch finished. */
do
{
   CLOCK_GetCurSysClkConfig(&curConfig);
} while (curConfig.src != g_sysClkConfig_BOARD_BootClockRUN.src);

/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
/* Set PCC LPSPI0 selection */
CLOCK_SetIpSrc(kCLOCK_Lpspi0, kCLOCK_IpSrcFircAsync);

 

printf("Hello World\n");

LPSPI_Reset(LPSPI0);

/* Force the counter to be placed into memory. */
volatile static int i = 0 ;
/* Enter an infinite loop, just incrementing a counter. */
while(1) {
   i++ ;
}
return 0 ;
}

Outcomes