Get-To-Byte

Clock Peripheral in S32K144 MCU

Objective

So hello guys, welcome back to NXP Semiconductors S32K144 MCU Tutorial series. In the last blog we just started with S32K144 MCU. In this blog we are going to explore the clock peripheral of this MCU. Going to Start with Clock peripheral. Objective would be to get

  • familiarity with clock peripheral for S32K144 MCU.
  • How to do clock configuration in S32K144 MCU using S32 Design Studio Config tools.
  • Going to understand the how to use GPIO peripheral via S32K SDK/pins driver.
  • Would also be demonstrating the blink LED sketch for GPIO in the end.

Clock Peripheral in S32K144

The clock peripherals of S32k1xx have 3 modules that configure the clocks of the S32K1xx MCU’s.

The clock peripherals are basically divided into three modules 

  • System clock generator
  • Low power oscillator
  • Peripheral clock control

System clock generator: – This Module generates the Core system clock which is the most important and crucial part. Via this Core system clock, all the peripherals get the clock frequency. So, for generating core system clocks there are 4 sources that can be done. The SCG supports four clock sources, as below:

  1. System Oscillator(SOSC):– the system oscillator in conjunction with an external crystal or resonator. That generates a reference clock for the MCU. The frequency of SOSC lies in between XTAL & EXTAL…
  2. Fast internal reference clock (FIRC_CLK):- an internally generated 48MHZ clock, which can be used as a clock source for other on-chip peripherals.
  3. Slow internal reference clock (SIRC_CLK):– an internally generated 8MHZ clock, which can be used as a clock source for other on-chip peripherals.
  4. System phase-locked loop (SPLL):– phase-locked loop that has a VCO(voltage-controlled oscillator) that generates an output signal whose frequency can be adjusted by an input voltage.

Peripheral clock control (PCC):- This module basically configures, controls, and generates the clock for all the peripherals of the MCU via system clock frequency. To conserve the power most modules’ clocks can be turned off by configuring the CGC field of the peripheral control register in the PCC module. These fields are cleared after any reset, which disables the peripheral clock of the corresponding module.

Note: We will be mainly focusing on the above two clock modules only for our initial development. Understanding and learning.

Low power oscillator (LPO):- an internally generated low power oscillator clock with a typical frequency of 128 kHz which can be used as the clock source for modules operational in low power modes.

How to configure clock peripheral in S32K144 using S32 Design Studio IDE

Clock peripheral of S32K144 MCU can be configured using the Clock Configuration tools of S32 Design Studio. These tools provide us with the GUI interface to configure the clock of the MCU. To know in detail about the clock configuration of S32 Design Studio refer to these.

For Demonstration purpose on how to do the Clock Configuration in S32 Design Studio, using the hello world demo example from GPIO Peripheral of S32K144 and configuring its core clock with 16 MHZ external crystal oscillator using SPLL.

Clock Configuration Header and Source Files

So, as if now we have configured the clock peripheral of the S32K144 MCU, without actually writing any code and just by using S32 Clock Configuration Tool, by just having understanding of the theory of Clock peripheral of our corresponding S32K Microcontroller!!. Isn’t that interesting.

Lets now just see what code is generated and how is generated code gonna configure our controller.

  • clock_config.h: contains the macros and variable declaration that will store the input values for clock peripheral.

Their are 2 important variables, clockMan1_InitConfig0 and peripheralClockConfig0, which are objects of the structures clock_manager_user_config_t and peripheral_clock_config_t.

Both of these structure conatins the various data fields for configuring the clock. To see the defination of these structure, see file clock_S32K1xx.h

  • clock_config.c: contains the defination and initialization values for the variables that are declared in .h file. 

Both of these variables clockMan1_InitConfig0 and peripheralClockConfig0  are initialized in this file.

Now, in this file all the initializations of the variables are done. As you change the configuration in S32 Clock Config tool, you can see change in values over here. 

Now the variables that are configured in  above .c/.h files are send to the functions of the Peripheral Abstraction Layer(Also called as Hardware Abstraction Layer). 

Peripheral Abstraction Layer Functions are directly used in main.c or application specific files. And internally Peripheral Abstraction Layer functions calls the low level functions which do the register level hardware changes on the corresponding S32K1 MCU.

Clock Peripheral Header and Source Files

S32 SDK driver provides an easy to use and quick way to use the Clock Peripheral in S32K144, using its Clock Manager driver Module.

Clock Manager Module SDK files for S32K144 MCU

Each S32 SDK driver can be configured and enabled to use in the project via S32 Configuration Tool. Will be digging into that part, in next section. For now, let’s understand the Clock Manager SDK in some detail, so as to use Clock  peripheral.

In the SDK of Clock Manager there are header and source files for Clock PAL( Peripheral Abstraction Layer) and Clock Low-Level Files:

  • Clock Low-Level Files: contains functions that configures the Clock Peripheral registers for initializing the peripheral, configuring the Peripheral and processing the data of peripheral at hardware level. These are the only ones which actually interacts with the hardware and make it configurable to our needs.
  • Clock Application/Peripheral Abstraction Layer(PAL): contains functions and variables that are directly used in main.c or application code. And internally these functions use the Clock Low-level Driver files.

So if hardware is changed out of any S32K1xx family of MCU’s, Clock peripheral would remain same and only internal low-level driver files needs to be changed or modified. By this way, we don’t have to make many changes on application level.

In the blogs we will be exploring the Clock Manager Peripheral Abstraction Layer files (PAL) in more details, as that would be directly used in our application project development(main.c) and doing custom Clock Configuration.

Clock Manager PAL

In CLOCK_CONFIG PAL there are 2 files CLOCK_S32K144.c and CLOCK_S32K144.h files.

Lets get into these files:

  1. CLOCK_S32K144.h: contains the enums, structures and function declarations that would be used in application code. Only functions which are declared in this header file can be used in main.c or application project.

  2. CLOCK_S32K144.c: contains the function definations of the declared functions(uses the low-level driver functions) along with some static functions also that are restricted to use in this file only.

Functions

  • CLOCK_DRV_Init: This function is the first function that has to be used in CLOCK_S32K144.h to initialize the clock in the MCU. 

  • CLOCK_SYS_GetScgClockFreq :- this function is used to get the system clock frequency that is bydefault by the MCU.

Demo Code for Clock Peripheral

Demo Code Description

Next Blogs to read

Leave a Comment

Scroll to Top