Get-To-Byte

UART Peripheral in S32K144 MCU

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

  • familiarity with UART peripheral for S32K144 MCU.
  • Would be understanding UART peripheral from Hardware point of view in S32K144 MCU.
  • Going to understand then how to use UART peripheral via S32K SDK/uart driver.
  • Would also be demonstrating the uart_echo_pall sketch.

So read along the blog and do tell me its reviews!

UART Peripheral Theory

UART is a serial communication protocol which is used to interface external sensor & IoT modules to the Host MCU. IoT modules like: GSM Module, GPS Module, BLE Modules, WiFi Modules are connected to Host MCU via UART protocol. Thus, understanding of UART communication protocol and its driver implementation, plays a crucial role.

To know about UART peripheral in theory, viewers can refer to this blog.

LPUART Peripheral in S32K144 MCU

In S32K144 MCU, UART can be used via 2 peripherals: LPUART & FlexIO.

UART in S32K144 MCU

LPUART is referred as Low Power Universal Asynchronous Receiver/Transmitter. LPUART is onchip peripheral only to do UART communication protocol. UART is a serial communication protocol which is done via UART peripheral in the Microcontrollers.

Also, in S32K144, there is FlexIO peripheral through which on-board serial communication protocols like UART, I2C & SPI can be emulated. So, through FlexIO peripheral, also UART peripheral can be implemented. To know about FlexIO peripheral in S32K144, refer to this blog.

Features of UART via LPUART peripheral in S32K144 MCU:

  • LPUART peripheral of S32K144 supports full duplex mode and has NRZ data encoding (That is Logic 1 bit represents High value and Logic 0 bit represents Low value).
  • It has programmable Baud rates(
  • LPUART peripheral supports Interrupts mode, DMA mode or pooled operation mode for transmitting/receiving the data using LPUART protocol or for detecting below listed errors while LPUART communication session is happening:
  1. Transmit data register empty and transmission complete.
  2. Receive data register full.
  3. Receive overrun, parity error, framing error, and noise error.
  4. Idle receivers detect.
  5. Active edge on receive pin.
  6. Break detect supporting LIN.
  7. Receive data match.
  • S32K144 also supports hardware parity generation and checking to ensure the integrity of the data while LPUART communication is happening.
  • It has Programmable LPUART data length of 7-10 bits and LPUART stop bits of 1-2 bits.
  • S32K144 MCU has feature to use the LPUART peripheral to wake up the MCU (if it is programmed in sleep modes), it can be waked up in either of the 3 below mentioned events:
  1. Idle line wakeup
  2. Address mark wakeup
  3. Receive data match.
  • Support of request to send (RTS) and clear to send (CTS) signals, for hardware flow control,  example of hardware flow control is a half-duplex radio modem to computer interface.
  • Support of IrDA 1.4 format with programmable pulse width for IR communication.
  • LPUART peripheral of S32K144 supports independent FIFO buffer for transmission and receiving of Data.
  • Also, LPUART peripheral FIFO of S32K144 has additional features like:
  1. configurable watermark (lowest number of bytes) for transmit and receive buffer, when watermark is achieved corresponding status is changed of LPUART peripheral.
  2. Option for receiver to assert request after a configurable number of idle. 
    characters if receive FIFO is not empty.
  • Tx and Rx FIFO in S32K144 for all LPUART Instances both are of 4 words size. 1 Word is 1 byte(8 bits). So FiFo size is 4 byte long(32 bits).

LPUART Hardware Pinout in S32K144 MCU

LPUART Pinout and Hardware Instances

LPUART peripheral in S32K144 has 3 instances: LPUART0, LPUART1, LPUART2.

All the LPUART Instances has 4 pins: 

  • RX: Receiving of data
  • TX: Transmission of data
  • CTS: Clear to Send pin for hardware flow control.
  • RTS: Request to Send for hardware flow control.
    S32K144 UART Pins

Each LPUART instance supports all the 4 pins, with below mentioned pin details.

How to use LPUART Pins in S32K144 MCU for doing UART Communication?

Now for doing UART communication, we need to connect hardware UART pins of the MCU, for doing so follow the steps:

  1. At first select which instance of LPUART wanna use, once selected. As told above their are 3 instances of LPUART in S32K144 MCU.
  2. Once selected, then use above excel to short select which pin of corresponding LPUART has to be used. 
  3. Lets say we use LPUART1 and use PTC7 and PTC6 as Tx & Rx pins of LPUART.
  4. So connect these pins of MCU with external UART Module.
  5. Remember Tx pin of MCU is connected to Rx pin of external UART Module and Rx pin of MCU is connected to Tx pin of external UART Module.
  6. Here i am going to use USB to serial FTDI connector with Original S32K144 evaluation2 board.
  7. With ElecronicsV2 board, it has on-board UART driver IC at LPUART1 PTC7 and PTC6 pins.

How to configure UART Peripheral in S32K144 using S32 Design Studio IDE

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

BLE Module interfacing with S32K144 MCU
GPS Module interfacing with S32K144 MCU
WiFi Module interfacing with S32K144
GSM Module interfacing with S32K144

LPUART SDK for S32K144 MCU

LPUART SDK

S32K SDK/drivers provide an easy to use and quick way to use LPUART peripheral in S32K144, which is known as LPUART SDK.

LPUART SDK for S32K MCU’s

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 LPUART SDK in some detail, so as to use UART peripheral via LPUART.

LPUART SDK files

In the SDK of LPUART there are header files and source files for LPUART Driver and LPUART Interrupt.

  • LPUART interrupt files contains functions for using &configuring of LPUART interrupts and IRQ handler in S32K144 MCU.
  • LPUART driver files contains functions for using/configuration of LPUART Peripheral.

LPUART Driver 

LPUART driver files are further divided into LPUART Peripheral Abstraction Layer (PAL) & LPUART Low-level drivers., as shown below:

LPUART Driver Files
  • LPUART Peripheral Abstraction Layer(PAL): contains functions and variables that are directly used in main.c or application code. And internally these functions use the LPUART Low-level drivers & LPUART IRQ . So if hardware is changed LPUART PAL would remain same and only internal low-level driver files need to be changed or modified. By this way we don’t have make many changes on application level.
  • LPUART Low-level driver: contains functions that configures the LPUART peripheral registers for initializing the peripheral, using the peripheral and processing the data of peripheral at hardware level. These files are the ones which actually interacts with the hardware and make it configurable to our needs. 

LPUART PAL

In LPUART PAL there are 2 files lpuart_driver.c and lpuart_driver.h files.

Lets get into these files:

  1. lpuart_driver.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. lpuart_driver.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

How to use LPUART PAL for doing UART Communication in S32K144 MCU.

  1. Features of LPUART PAL.
  2. Initialization and configuration API’s of UART peripheral using LPUART PAL.
  • LPUART_DRV_Init: This function is the first function that has to be used in main.c to initialize the LPUART peripheral. This function is just like Serial.begin(9600) of Arduino IDE environment.

This function has 3 function parametrs as follows:

  1. instance: integer number indicating which instance of LPUART we are going to use.
  2. lpuart_user_config and lpuart_state_t: structure pointers have to be sent in this function as parameters. (For the info on these structures refers next section)

In LPUART PAL their are 3 ways by which we can send and receive data.

  1. Interrupt based
  2. DMA Based 
  3. Pooling Based.

In this blog, we are going to explore and understand pooling based method and it’s API. As to use by interrupt and DMA based, we have to know about Interrupt and DMA. So we are going to cover Interrupt and DMA based LPUART communication under topics: Interrupts in S32K144 and DMA in S32K144 MCU.

What is pooling method in Embedded?

LPUART PAL API’s for doing pooling based communication

  • LPUART_DRV_SendDataPolling

This function has 3 parametrs:

  1. instance: integer number indicating which instance of LPUART we are going to use.
  2. txBuff: buffer pointer, pointing to the data which needs to be send out.
  3. txSize: size of data that has to be sent.
  • LPUART_DRV_ReceiveDataPolling

This function has 3 function parameters:

  1. instance: integer number indicating which instance of LPUART we are going to use.
  2. rxBuff: buffer pointer, would be containing the received data.
  3. rxSize: size of data that has to be received.
Data Types

There are 2 structures that are important and will be used often

  • lpuart_user_config_t: This structure has members to configure the LPUART according to user defined settings.
  • lpuart_state_t: This structure has data members, which keep track of the on-going transfers . 

UART Demo Code for S32K144 MCU

 S32 SDK/provides as example demo on LPUART driver to demonstarate how to use the LPUART driver for UART communicatio protocol. Demo Example is named as: lpuart_echo_s32k144

lpuart_echo_s32k144 demo code explanation:

Next blogs to read

Leave a Comment

Scroll to Top