Observations:
hardware_init.c -> hardware_init function
BOARD_ClockInit()
{
/* Set allowed power mode, allow all. */
SMC_HAL_SetProtection(SMC, kAllowPowerModeAll);
/* Setup board clock source. */
// Setup OSC0 if used.
// Configure OSC0 pin mux.
PORT_HAL_SetMuxMode(EXTAL0_PORT, EXTAL0_PIN, EXTAL0_PINMUX);
PORT_HAL_SetMuxMode(XTAL0_PORT, XTAL0_PIN, XTAL0_PINMUX);
BOARD_InitOsc0();
BOARD_InitRtcOsc();
The SetMuxMode functions seems to set the RTC pins PTB16 (EXTAL32K) and PTB17 (XTAL32K) not osc0
Strange defined in board.h
/* EXTAL0 PTA18 */
#define EXTAL0_PORT PORTB
#define EXTAL0_PIN 17
#define EXTAL0_PINMUX kPortPinDisabled
/* XTAL0 PTA19 */
#define XTAL0_PORT PORTB
#define XTAL0_PIN 16
#define XTAL0_PINMUX kPortPinDisabled
Should be:
48QFN,32QFN,PinName,DEFAULT ,ALT0 ,ALT1 ,ALT2 ,ALT3 ,ALT4 ,ALT5 ,ALT6 ,ALT7
21,15,PTB16 ,EXTAL32K ,EXTAL32K ,PTB16 ,— ,I2C1_SCL,— ,TPM2_CH0,— ,—
22,16,PTB17 ,XTAL32K ,XTAL32K ,PTB17 ,— ,I2C1_SDA,— ,TPM2_CH1,— ,—
-----
/* Function to initialize OSC0 base on board configuration. */
void BOARD_InitOsc0(void)
{
// OSC0 has not configuration register, only set frequency
MCG_WR_C2_RANGE(MCG,kOscRangeHigh);
g_xtal0ClkFreq = 32000000U;
}
pag 102
MKW40Z/30Z/20Z Reference Manual, Rev. 1.2, 10/2015

pag 156
6.2.2.5 Multipurpose clock generator loss-of-clock (LOC)
The MCG module supports external reference clocks.
If MCG_C6[CME] is set, the clock monitor associated with the RF reference oscillator is
enabled. If the external reference falls below floc_low or floc_high, as controlled by
MCG_C2[RANGE], the MCU resets. MCG_SC[LOCS0] and [RCM_SRS0[LOC] are set
to indicate this reset source.
If MCG_C8[CME1] is set, the clock monitor associated with the RTC oscillator is
enabled. If the external reference falls below floc_low, the MCU resets. MCG_C8[LOCS1]
and RCM_SRS0[LOC] are set to indicate this reset source.
page 407
Chapter 24 Multipurpose Clock Generator (MCG)