Using : MBDToolbox 4.2.1,with hotfix for register access blocks.
Using: S32K144 LQFP-100, on proprietary hardware board
The dropdown box for XTAL Frequency does not display the option to use the onboard oscillator module; the "External 8" option misleadingly suggests it is for an external oscillator, but actually configures the onboard oscillator module.
When the block is configured as "External 8", the following code is generated in the s32k_clock_init.c file:
.soscConfig =
{
.initialize = true, /* Initialize */
.freq = XTAL_FREQ, /* Frequency */
/* SOSCCSR */
.monitorMode = SCG_SOSC_MONITOR_DISABLE,/* SOSCCM */
.locked = false, /* LK */
/* SOSCCFG */
.extRef = SCG_SOSC_REF_OSC, /* EREFS */
.gain = SCG_SOSC_GAIN_LOW, /* HGO */
.range = SCG_SOSC_RANGE_HIGH, /* RANGE */
/* SOSCDIV */
.div1 = MBDT_SOSCDIV,/* SOSCDIV1 */
.div2 = MBDT_SOSCDIV,/* SOSCDIV2 */
},
This configures the SOSC module with EREFS=1, which selects the internal oscillator amplifier module as the source of the clock (instead of the external reference clock on pin EXTAL).
Page 90 of the S32 reference manual (4.5.1) states
NOTE
If oscillator is enabled then enabling the GPIO or LPI2C
function for EXTAL/XTAL pins can lead to device damage.
This must be avoided by software.
I am using an external oscillator (square wave) to drive the EXTAL pin, and I dodged a bullet here as I did not connect XTAL on my board or configure any I/O on the pin.
The current options should be relabelled as "Internal crystal oscillator 8", and new options for "External Oscillator 8" should be added which set EREFS=0.
Additonally, it would be good to issue a warning when the internal oscillator is used with a link to seciton 4.5.1 of the manual and that the EXTAL/XTAL pins should not be configured for use by any peripherals other than the SOSC module.
Hello @glenndoiron,
The default configuration provided in the MBDT toolbox targets the Evaluation boards delivered by NXP.
Luckily, this default configuration could be easily adapted to generate code for your particular setup. In your case, you could change the s32k_clock_init.c file from the sources of our toolbox. This file is always copied when the code is generated from the toolbox sources. What you could do is to type the following command in MATLAB Command Window: cd(fullfile(mbd_find_s32k_root, 'mbdtbx_s32k14x\src\c_library'))
Here, you could modify the extRef clock, EREFS value from SCG_SOSC_REF_OSC into SCG_SOSC_REF_EXT
Hope this helps,
Marius
This is great information.
A bit more digging thru the datasheet reveals the source of my confusion; the SOSC module is referred to as the system oscillator in some sections, while in others it is referred to as the external reference clock.
Additionally in chapter 28, under the description of the EREFS bit, it says
External Reference Select
Selects the source for the external reference clock. This bit selects which clock is output from the System
OSC (SOSC) into the SCG, thus either the crystal oscillator or from an external clock input
0 External reference clock selected
1 Internal crystal oscillator of OSC selected.
The data sheet should probably be amended here (where italicized), and in the other parts which call it the "external reference clock" instead of the system oscillator (such as in the watchdog timer module section), to instead refer to it as the "System Oscillator Clock". This bit is switching between an external clock signal at valid digital input levels (external reference) or a buffer which is sampling the output of the internal amplifier (used for driving a crystal).