TWR-K60N512 and KSDK Demo Apps

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

TWR-K60N512 and KSDK Demo Apps

Jump to solution
2,587 Views
weblar
Contributor V

I'm trying to get some KSDK demo apps up and running on my TWR-K60N512 tower stack (together with TWR-SER). Used the online configurator tool to generate the basic KSDK framework for the TWR-K60D100M (which I assume is the correct choice as the TWR-K60N512 option was not available to me).

When debugging any demo application, a hard fault occurs when calling the BOARD_BootClockRUN function, more specifically in the CLOCK_SetExternalRefClkConfig call within the CLOCK_BootToPeeMode function. 

As far as I know, the tower stack is configured correctly (50MHz EXTAL connected to CLKIN0 on elevator for ethernet) and all other jumpers set to their defaults.

Could anyone suggest what I'm missing?

Thanks.

Tags (2)
0 Kudos
1 Solution
1,342 Views
weblar
Contributor V

Ok, so I've managed to work around the issue - I've modified the following function and everything seems to work as expected.

status_t CLOCK_SetExternalRefClkConfig(mcg_oscsel_t oscsel)
{
bool needDelay;
uint32_t i;

#if (defined(MCG_CONFIG_CHECK_PARAM) && MCG_CONFIG_CHECK_PARAM)
/* If change MCG_C7[OSCSEL] and external reference clock is system clock source, return error. */
if ((MCG_C7_OSCSEL_VAL != oscsel) && (!(MCG->S & MCG_S_IREFST_MASK)))
{
return kStatus_MCG_SourceUsed;
}
#endif /* MCG_CONFIG_CHECK_PARAM */

// #######

// FIX - RETURN EARLY AS THE FOLLOWING CAUSES A HARD FAULT

// #######

return kStatus_Success;

if (MCG_C7_OSCSEL_VAL != oscsel)
{
// If change OSCSEL, need to delay, ERR009878.
needDelay = true;
}
else
{
needDelay = false;
}

MCG->C7 = (MCG->C7 & ~MCG_C7_OSCSEL_MASK) | MCG_C7_OSCSEL(oscsel);
if (kMCG_OscselOsc == oscsel)
{
if (MCG->C2 & MCG_C2_EREFS_MASK)
{
while (!(MCG->S & MCG_S_OSCINIT0_MASK))
{
}
}
}

if (needDelay)
{
/* ERR009878 Delay at least 50 micro-seconds for external clock change valid. */
i = 1500U;
while (i--)
{
__NOP();
}
}

return kStatus_Success;
}

View solution in original post

2 Replies
1,343 Views
weblar
Contributor V

Ok, so I've managed to work around the issue - I've modified the following function and everything seems to work as expected.

status_t CLOCK_SetExternalRefClkConfig(mcg_oscsel_t oscsel)
{
bool needDelay;
uint32_t i;

#if (defined(MCG_CONFIG_CHECK_PARAM) && MCG_CONFIG_CHECK_PARAM)
/* If change MCG_C7[OSCSEL] and external reference clock is system clock source, return error. */
if ((MCG_C7_OSCSEL_VAL != oscsel) && (!(MCG->S & MCG_S_IREFST_MASK)))
{
return kStatus_MCG_SourceUsed;
}
#endif /* MCG_CONFIG_CHECK_PARAM */

// #######

// FIX - RETURN EARLY AS THE FOLLOWING CAUSES A HARD FAULT

// #######

return kStatus_Success;

if (MCG_C7_OSCSEL_VAL != oscsel)
{
// If change OSCSEL, need to delay, ERR009878.
needDelay = true;
}
else
{
needDelay = false;
}

MCG->C7 = (MCG->C7 & ~MCG_C7_OSCSEL_MASK) | MCG_C7_OSCSEL(oscsel);
if (kMCG_OscselOsc == oscsel)
{
if (MCG->C2 & MCG_C2_EREFS_MASK)
{
while (!(MCG->S & MCG_S_OSCINIT0_MASK))
{
}
}
}

if (needDelay)
{
/* ERR009878 Delay at least 50 micro-seconds for external clock change valid. */
i = 1500U;
while (i--)
{
__NOP();
}
}

return kStatus_Success;
}

1,046 Views
stnslv
Contributor I

Hello, I don't know how stable is this solution but it helped me to get my code running. The problem is that MCG_C7_OSCSEL_VAL appears in the code not only one time. After fixing the clock initialization I got a problem with the UART initialization.

The TWR-K60N512, as I know, has some old Kinetis MCU. My board has revision D and uses the PK60N512VMD100 (Mask set 0M33Z). This MCU just doesn't have register MCG_C7. I expect that you use the same MCU. The best solution is maybe to switch to the TWR-K60D100M with newer MCU.

This Application Note explains the problem (https://www.nxp.com/docs/en/application-note/AN4526.pdf)

stnslv_0-1645196922348.png

stnslv_1-1645196982013.png

Best regards!

 

0 Kudos