S32K144 Boards
NXP S32K144 MCU Tutorials
S32K144 Peripherals

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!

Table of Contents

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. 

In the blogs we will be exploring the LPUART Peripheral Abstraction Layer files (PAL) in more details, as that would be directly used in our application project development(main.c) and driver creation of UART modules (GPS, GSM, IoT Modules and etc)

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.
				
					status_t LPUART_DRV_Init(uint32_t instance, lpuart_state_t * lpuartStatePtr,
                         const lpuart_user_config_t * lpuartUserConfig);

				
			

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)
				
					#define INST_LPUART_LPUART_1  1

extern lpuart_state_t lpUartState1;

/* External declaration of LPUART configuration structure */
extern const lpuart_user_config_t lpUartInitConfig1;

lpuart_state_t lpUartState1;

const lpuart_user_config_t lpUartInitConfig1 = {
  .transferType = LPUART_USING_INTERRUPTS,
  .baudRate = 9600UL,
  .parityMode = LPUART_PARITY_DISABLED,
  .stopBitCount = LPUART_ONE_STOP_BIT,
  .bitCountPerChar = LPUART_8_BITS_PER_CHAR,
  .rxDMAChannel = 0UL,
  .txDMAChannel = 0UL
};

 /* Initialize LPUART instance */
  LPUART_DRV_Init(INST_LPUART_LPUART_1, &lpUartState1, &lpUartInitConfig1);
 
				
			

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
				
					status_t LPUART_DRV_SendDataPolling(uint32_t instance, const uint8_t *txBuff, uint32_t txSize);

				
			

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.
				
					  /* Welcome message displayed at the console */
#define welcomeMsg "This example is an simple echo using LPUART\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"

  
  /* Send a welcome message */
  LPUART_DRV_SendDataPolling(INST_LPUART_LPUART_1, (uint8_t *)welcomeMsg, strlen(welcomeMsg));

				
			
  • LPUART_DRV_ReceiveDataPolling
				
					status_t LPUART_DRV_ReceiveDataPolling(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize);

				
			

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.
				
					  /* Receive buffer size */
#define BUFFER_SIZE 256U

/* Buffer used to receive data from the console */
uint8_t buffer[BUFFER_SIZE];

LPUART_DRV_ReceiveDataPolling(INST_LPUART_LPUART_1, buffer, 1U);
    
				
			
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.
				
					/*! @brief LPUART configuration structure
 *
 * Implements : lpuart_user_config_t_Class
 */
typedef struct
{
    uint32_t baudRate;                           /*!< LPUART baud rate */
    lpuart_parity_mode_t parityMode;             /*!< parity mode, disabled (default), even, odd */
    lpuart_stop_bit_count_t stopBitCount;        /*!< number of stop bits, 1 stop bit (default) or 2 stop bits */
    lpuart_bit_count_per_char_t bitCountPerChar; /*!< number of bits in a character (8-default, 9 or 10);
                                                      for 9/10 bits chars, users must provide appropriate buffers
                                                      to the send/receive functions (bits 8/9 in subsequent bytes);
                                                      for DMA transmission only 8-bit char is supported. */
    lpuart_transfer_type_t transferType;         /*!< Type of LPUART transfer (interrupt/dma based) */
    uint8_t rxDMAChannel;                        /*!< Channel number for DMA rx channel.
                                                      If DMA mode isn't used this field will be ignored. */
    uint8_t txDMAChannel;                        /*!< Channel number for DMA tx channel.
                                                      If DMA mode isn't used this field will be ignored. */
} lpuart_user_config_t;


				
			
				
					/* External declaration of LPUART configuration structure */
extern const lpuart_user_config_t lpUartInitConfig1;

const lpuart_user_config_t lpUartInitConfig1 = {
  .transferType = LPUART_USING_INTERRUPTS,
  .baudRate = 9600UL,
  .parityMode = LPUART_PARITY_DISABLED,
  .stopBitCount = LPUART_ONE_STOP_BIT,
  .bitCountPerChar = LPUART_8_BITS_PER_CHAR,
  .rxDMAChannel = 0UL,
  .txDMAChannel = 0UL
};
				
			
  • lpuart_state_t: This structure has data members, which keep track of the on-going transfers . 
				
					/*!
 * @brief Runtime state of the LPUART driver.
 *
 * Note that the caller provides memory for the driver state structures during
 * initialization because the driver does not statically allocate memory.
 *
 * Implements : lpuart_state_t_Class
 */
typedef struct
{
    const uint8_t * txBuff;              /*!< The buffer of data being sent.*/
    uint8_t * rxBuff;                    /*!< The buffer of received data.*/
    volatile uint32_t txSize;            /*!< The remaining number of bytes to be transmitted. */
    volatile uint32_t rxSize;            /*!< The remaining number of bytes to be received. */
    volatile bool isTxBusy;              /*!< True if there is an active transmit.*/
    volatile bool isRxBusy;              /*!< True if there is an active receive.*/
    volatile bool isTxBlocking;          /*!< True if transmit is blocking transaction. */
    volatile bool isRxBlocking;          /*!< True if receive is blocking transaction. */
    lpuart_bit_count_per_char_t bitCountPerChar; /*!< number of bits in a char (8/9/10) */
    uart_callback_t rxCallback;          /*!< Callback to invoke for data receive
                                              Note: when the transmission is interrupt based, the callback
                                              is being called upon receiving a byte; when DMA transmission
                                              is used, the bytes are copied to the rx buffer by the DMA engine
                                              and the callback is called when all the bytes have been transferred. */
    void * rxCallbackParam;              /*!< Receive callback parameter pointer.*/
    uart_callback_t txCallback;          /*!< Callback to invoke for data send
                                              Note: when the transmission is interrupt based, the callback
                                              is being called upon sending a byte; when DMA transmission
                                              is used, the bytes are copied to the tx buffer by the DMA engine
                                              and the callback is called when all the bytes have been transferred. */
    void * txCallbackParam;              /*!< Transmit callback parameter pointer.*/
    lpuart_transfer_type_t transferType; /*!< Type of LPUART transfer (interrupt/dma based) */
#if FEATURE_LPUART_HAS_DMA_ENABLE
    uint8_t rxDMAChannel;                /*!< DMA channel number for DMA-based rx. */
    uint8_t txDMAChannel;                /*!< DMA channel number for DMA-based tx. */
#endif
    semaphore_t rxComplete;              /*!< Synchronization object for blocking Rx timeout condition */
    semaphore_t txComplete;              /*!< Synchronization object for blocking Tx timeout condition */
    volatile status_t transmitStatus;    /*!< Status of last driver transmit operation */
    volatile status_t receiveStatus;     /*!< Status of last driver receive operation */
} lpuart_state_t;

				
			
				
					extern lpuart_state_t lpUartState1;

lpuart_state_t lpUartState1;

				
			

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

				
					/*
 * Copyright 2020 NXP
 * All rights reserved.
 *
 * NXP Confidential. This software is owned or controlled by NXP and may only be
 * used strictly in accordance with the applicable license terms. By expressly
 * accepting such terms or by downloading, installing, activating and/or otherwise
 * using the software, you are agreeing that you have read, and that you agree to
 * comply with and are bound by, such license terms. If you do not agree to be
 * bound by the applicable license terms, then you may not retain, install,
 * activate or otherwise use the software. The production use license in
 * Section 2.3 is expressly granted for this software.
 */
/* ###################################################################
**     Filename    : main.c
**     Project     : lpuart_echo_s32k144
**     Processor   : S32K144
**     Version     : Driver 01.00
**     Compiler    : GNU C Compiler
**     Date/Time   : 2020-02-20, 12:27, # CodeGen: 1
**     Abstract    :
**         Main module.
**         This module contains user's application code.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.00
** @brief
**         Main module.
**         This module contains user's application code.
*/
/*!
**  @addtogroup main_module main module documentation
**  @{
*/
/* MODULE main */

/* Including needed modules to compile this module/procedure */
#include "sdk_project_config.h"
#include <stdio.h>
#include <string.h>

volatile int exit_code = 0;

/* Welcome message displayed at the console */
#define welcomeMsg "This example is an simple echo using LPUART\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"

/* Error message displayed at the console, in case data is received erroneously */
#define errorMsg "An error occurred! The application will stop!\r\n"

/* Timeout in ms for blocking operations */
#define TIMEOUT     500U

/* Receive buffer size */
#define BUFFER_SIZE 256U

/* Buffer used to receive data from the console */
uint8_t buffer[BUFFER_SIZE];
uint8_t bufferIdx;

/* UART rx callback for continuous reception, byte by byte */
void rxCallback(void *driverState, uart_event_t event, void *userData)
{
    /* Unused parameters */
    (void)driverState;
    (void)userData;

    /* Check the event type */
    if (event == UART_EVENT_RX_FULL)
    {
        /* The reception stops when newline is received or the buffer is full */
        if ((buffer[bufferIdx] != '\n') && (bufferIdx != (BUFFER_SIZE - 2U)))
        {
            /* Update the buffer index and the rx buffer */
            bufferIdx++;
            LPUART_DRV_SetRxBuffer(INST_LPUART_LPUART_1, &buffer[bufferIdx], 1U);
        }
    }
}

/*!
 \brief The main function for the project.
 \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
 */
int main(void)
{
  /* Write your local variable definition here */
  status_t status;
  /* Declare a buffer used to store the received data */
  uint32_t bytesRemaining;

  /* Write your code here */
  /* For example: for(;;) { } */

  /* Initialize and configure clocks
   *     -    see clock manager component for details
   */
  CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
                 g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
  CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

  /* Initialize pins
   *    -    See PinSettings component for more info
   */
  PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);

  /* Initialize LPUART instance */
  LPUART_DRV_Init(INST_LPUART_LPUART_1, &lpUartState1, &lpUartInitConfig1);
  /* Install the callback for rx events */
  LPUART_DRV_InstallRxCallback(INST_LPUART_LPUART_1, rxCallback, NULL);
  /* Send a welcome message */
  LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, (uint8_t *)welcomeMsg, strlen(welcomeMsg), TIMEOUT);

  /* Infinite loop:
   *     - Receive data from user
   *     - Echo the received data back
   */
  while (1)
  {
      /* Receive and store data byte by byte until new line character is received,
       * or the buffer becomes full (256 characters received)
       */
      LPUART_DRV_ReceiveData(INST_LPUART_LPUART_1, buffer, 1U);
      /* Wait for transfer to be completed */
      while(LPUART_DRV_GetReceiveStatus(INST_LPUART_LPUART_1, &bytesRemaining) == STATUS_BUSY);

      /* Check the status */
      status = LPUART_DRV_GetReceiveStatus(INST_LPUART_LPUART_1, &bytesRemaining);

      if (status != STATUS_SUCCESS)
      {
          /* If an error occurred, send the error message and exit the loop */
          LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, (uint8_t *)errorMsg, strlen(errorMsg), TIMEOUT);
          break;
      }

      /* Append string terminator to the received data */
      bufferIdx++;
      buffer[bufferIdx] = 0U;

      /* If the received string is "Hello Board", send back "Hello World" */
      if(strcmp((char *)buffer, "Hello Board\n") == 0)
      {
          strcpy((char *)buffer, "Hello World\n");
      }

      /* Send the received data back */
      LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, buffer, bufferIdx, TIMEOUT);
      /* Reset the buffer index to start a new reception */
      bufferIdx = 0U;
  }

  for(;;) {
    if(exit_code != 0) {
      break;
    }
  }
  return exit_code;
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
 ** @}
 */

				
			
lpuart_echo_s32k144 demo code explanation:

Next blogs to read

Peripheral Drivers(Non Autosar)
Kunal Gupta

FlexCAN Peripheral Software Stack Explanation using NXP S32K144 MCU

Overview and motive Objective is to: To get to know what is FlexCAN driver and its features. To Understand How to use FlexCAN Driver(software environment setup and chronology in software configuration)). FlexCAN Driver GUI explanation for configuring FlexCAN Peripheral. Relation of functions of FlexCAN Driver functions via FlexCAN peripheral features. In Depth Understanding of FlexCAN driver functions/data types, with questions like What and why? Chronology of APIs for using basic features of FlexCAN Peripheral for doing CAN communication(How and When?) By basic features we mean the CAN transmission and reception via Mailbox and FiFo mechanism using polling&Interrupt method. What is FlexCAN Driver FlexCAN Driver are set of libraries which are used for using FlexCAN peripheral to do CAN communication via NXP S32K1xx Microcontrollers. Here by library, we mean a set of .h and .c files written in c language. These set of FlexCAN libraries are: Library of FlexCAN Peripheral Hardware registers. Library for FlexCAN Peripheral Interrupt Handlers. Library for FlexCAN peripheral API’s. Miscellaneous files for FlexCAN. Now in FlexCAN Driver there are 3 sets: FlexCAN_Ip.h/.c FlexCAN_Ip_Hw_Access.h/.c FlexCAN IP_Irq.h/.c 3 extra header files: FlexCAN_Ip_DeviceReg.h/FlexCAN_Ip_Types.h/FlexCAN_Ip_Wrapper.h: The first one contains the function and data types through which different features of FlexCAN peripheral are used. Features like of sending data, receiving data, configuring message id filter table and etc. It contains functions like: FlexCAN_IP_Send(). FlexCAN_IP_receive, FlexCAN_IP_RXFIFO and etc. The Second one also contains the functions and data types through which FlexCAN Peripheral registers. Are accessed. Kind of like Bare Metal codes of FlexCAN peripheral are written in this files. And the Functions of this file are used by FlexCAN_Ip.h/.c files. Third one contains the function definition and data types for for IRQ handler of FlexCAN Peripheral And the last one contains the misceeleneours Data types and macros for using flexCAN peripheral. In our application code, we are just going to add FlexCAN_Ip.h header file to access the FlexCAN Driver in our code. And these files are located in the root directory of S32 DS where software installtion of RTD package takes place. FlexCAN Driver and Code Configuration tool relation. Now for using the FlexCAN peripheral, there is a feature of code configuration tool in S32DS via which we can configure the FlexCAN Driver in Gui base. That is instead of writing code, we can confiure how to use FlexCAN Module by GUI presentation. The code configuration tool in S32 Design Studio, generates the set of .c/.h files for FlexCAN peripheral. These are different from library files which I have explained above.  In these generated files it defines and initializes some of the variables. These variables are then used by FlexCAN APIs in the application code. This support of code configuration tool makes it easy for configuring FlexCAN module in easy way via GUI presentation and variables which are generated by code configuration tool are used as parameters in FlexCAN APIs to use them in application code. So, in short to say, code configuration tool generates the values of some of the parameters that has to be send in FlexCAN Driver API. Closure of FlexCAN Driver: There are number of files, functions and data types but for now we are going to concentrate on those which will be required for using FlexCAN in Standard CAN, in normal mode for transmitting and receiving via mailbox and FiFo mechanism. In FlexCAN library there are number of functions and data types through which all the features of FlexCAN peripheral can be used. But we are not going to dwell into all functions and data types. We are just going to cover the functions and data types through which we can send and transmit can data via mailbox/rxfifo mechanisms. As this is the scope of this course and module, for other functions and features you can explore our Advance CAN Courses or can reach out to us privately, Software to install to use FlexCAN Peripheral Driver To use FlexCAN Peripheral Driver, we need to install following things in your Host Desktop/PC: S32 Design Studio IDE 3.4 or 3.5 (any will work though here, we are going to use S32 Design Studio 3.4) S32K1 Real Time Drivers Version 1.0.0 S32 Design Studio 3.4 S32K1 Real Time Drivers Version 1.0.0 S32K1 RTD V1.0.0 is Software Stack for using NXP S32K1xx microcontrollers. It Contains Peripheral Driver library files for using the S32K1xx microcontroller peripherals. It supports all peripherals of S32K1xx MCU’s.  This Software Stack contains 2 packages: Autosaur MCAL layer complaint and standard based peripheral driver files for S32K1xx MCU’s. It is Autosar 4.4.0 complaint. Non-Autosar based peripheral driver files for S32K1xx MCU’s.  It is a collection of peripheral drivers designed to simplify and accelerate application development on NXP microcontrollers. From Learning point of view and long-term skill development, having handson with Autosaur MCAL layer based peripheral driver file would be a good starting point. But as a fresher it might be more challenging to start with autosar standard. So In this blog, we are going to explore Non-Autosar based peripheral driver for FlexCAN module.  Further once having basic Handson with Non-Autosar, will explore Autosar MCAL layer based peripheral driver. Refer to this blog/video to get to know how to install S32 Design Studio 3.4 and Install S32K1 Real Time Drivers v1.0.0. Also it is recommended to explore Code Configuration Tool and Project Creation Modules of S32 Design Studio IDE, so as to get understanding how to use S32 Design Studio throughout the learning cycle. How to use FlexCAN Peripheral Driver FlexCAN Driver can be used via S32 Design Studio Code Configuration tool which provides Graphical User Interface manner in S32 Design Studio IDE, through which we can generate the FlexCAN driver libraries and code automatically in our project. This thing makes it easy to develop applications fast and easy way. The Code Configuration tool generates 2 things: Library Files to use FlexCAN Peripheral. Configured parameters in the form of Data Types (structures, macros, arrays and etc.), which are used as input parameters in different functions of library files. Chronology to follow

Read More »
Peripheral Drivers(Autosar)
Kunal Gupta

Port Driver of Autosaur MCAL layer (S32K1xx MCU)

Motive: To get understanding of what Port Driver in Autosaur MCAL Layer stack do: Done: What is Port Driver in Autosaur? To get understanding of Different Functions and Data Types in Port Driver Module: Their description, their description with respect to parameters that are send to them, and how are those paramters configured via tool. How to configure different pins in autosar, using Port Driver Module. To get familiarity with Usecases and how to use different Port Driver Module APIs in what chronology. Autosar Documentation blogs: Understanding AUTOSAR and its Applications in the Automotive Industry (einfochips.com) AUTOSAR_SWS_BSWGeneral.pdf : This document explains the BSW layer configurtaion What is Port Driver in Autosar? Port Driver is Part of MCAL Layer in BSW layer of Autosar Stack. Port Driver is responsible for initializing and configuration of microcontroller pins and corresponding ports of those pins. Only Initilization part and configuration part. It initializes and configures pins and ports for various functionalities like: ADC, SPI, I2C, Ethernet, PWM and etc. According to alternate function pin mapping configurations of microcontroller. The Pins and ports which are configured by Port Driver Module, are used by the DIO (Digital Input/Output) Driver module. Only the pins and ports which are configured by Port Driver will be used by DIO Driver Module. Port Driver Module Provide following important functional specifications: Direction setting of Microcontroller pins (Input/Output). Initial value setting of microcontroller pin. Activation of Internal Pull-ups for microcontroller pin. Slew Rate control for microcontroller pins. Microcontroller Alternate function/GPIO registers are used by this layer. Important Data Types in Port Driver: Port_ConfigType: Port_PinType: Port_PinDirectionType: Port_PinModeType: Important Functions in Port Driver: Port_Init : Port_SetPinDirection: Port_RefreshPortDirection: Port_SetPinMode Documents to refer for Port Driver. AUTOSAR_SWS_PortDriver.pdf : This specification specifies the functionality, API and the configuration of the AUTOSAR Basic Software module PORT Driver. Important points of Port Driver? This PORT driver module completes the overall configuration and initialization of the port structure which is used in the DIO driver module. Therefore, the DIO driver works on pins and ports which are configured by the PORT driver. Important Data Types in Port Driver: Port_ConfigType: Port_PinType: Port_PinDirectionType: Port_PinModeType: Port_PinConfigType: Port_UnUsedPinConfigType: Port_Ci_Port_Ip_DigitalFilterConfigType: Port_Ci_Port_Ip_PinSettingsConfig: Port_ConfigType: Port_PinType: Port_PinDirectionType: Port_PinModeType: Port_ConfigType: It is a structure, which contains different contents to initialize the pin of the microcontroller as per user configuration. This Structure is used only in Port_Init() API. And the contents of this structure are changed automatically as we change the configurations in PORT Driver in .ebtresos. //This part has to be written more( Explain use configuration examples) Here by user configuration we mean: Input/Out direction, pull up enable or disable and etc. This structure contains the contents which are used for initialization of microcontroller pin. As the initialization of microcontroller pin is different in SoC’s. So, this structure has different contents from SoC to SoC and its content dependent on GPIO/DIO peripheral registers of corresponding microcontroller. S32K3xx typedef struct { uint16 u16NumPins; /**< @brief Number of used pads (to be configured) */ uint16 u16NumUnusedPins; /**< @brief Number of unused pads */ uint16 au16NumImcrs[PORT_NUM_SIUL2_INSTANCES_U8]; /**< @brief Used pads IMCRs number */ const Port_Siul2_UnUsedPinType *pUnusedPads; /**< @brief Unused pad id’s array and SIUL2 instance */ const Port_Siul2_UnUsedPinConfigType *pUnusedPadConfig; /**< @brief Unused pad configuration */ const Port_Siul2_PinConfigType *pUsedPadConfig; /**< @brief Used pads data configuration */ const Port_Siul2_ImcrConfigType *pImcrConfig[PORT_NUM_SIUL2_INSTANCES_U8]; /**< @brief Used pads IMCR configuration */ const uint32 *pau32Port_PinToPartitionMap; /**< @brief Pointer to pin partition mapping */ const uint8 *pau8Port_PartitionList; /**< @brief Pointer to used partitions */ const Siul2_Port_Ip_PinSettingsConfig *IpConfigPtr; /**< @brief Ip configuration */ const Tspc_Port_Ip_ObeGroupConfig *TspcIpConfigPtr; /**< @brief tspc configuration */ } Port_ConfigType; S32K1xx typedef struct { uint16 u16NumPins; /**< @brief Number of used pads (to be configured) */ uint16 u16NumUnusedPins; /**< @brief Number of unused pads */ const uint16 * pUnusedPads; /**< @brief Unused pad id’s array */ const Port_UnUsedPinConfigType * pUnusedPadConfig; /**< @brief Unused pad configuration */ const Port_PinConfigType * pUsedPadConfig; /**< @brief Used pads data configuration */ uint8 u8NumDigitalFilterPorts; /**< @brief Number of configured digital filter ports */ const Port_Ci_Port_Ip_DigitalFilterConfigType * pDigitalFilterConfig; /**< @brief Digital filter ports configuration */ const uint32 *pau32Port_PinToPartitionMap; /**< @brief Pointer to pin partition mapping */ const uint8 *pau8Port_PartitionList; /**< @brief Pointer to used partitions */ const Port_Ci_Port_Ip_PinSettingsConfig *IpConfigPtr; /**< @brief Ip configuration */ } Port_ConfigType; For now, we will focus on data structure elements of S32K1xx. u16NumPins : Number of pins which are configured u16NumUnusedPins : Number of unsused pins left( uint16 * pUnusedPads: const Port_UnUsedPinConfigType * pUnusedPadConfig: Port_PinConfigType * pUsedPadConfig: u8NumDigitalFilterPorts: Port_Ci_Port_Ip_DigitalFilterConfigType * pDigitalFilterConfig uint32 *pau32Port_PinToPartitionMap: uint8 *pau8Port_PartitionList: Port_Ci_Port_Ip_PinSettingsConfig *IpConfigPtr: Port_PinType: Use for symbolic name of a Port Pin. Sybolic name is the pin count of that pin. Port_PinDirectionType: Tab Content Port_PinModeType: Tab Content Author: Kunal Gupta

Read More »
Getting Started
Kunal Gupta

FreeMaster with S32 Design Studio(NXP Semiconductor)

https://youtu.be/N6w_xWoOH-Q Overview In this blog, we will get to know how to use FreeMaster Desktop Application Via S32 Design Studio. for NXP Semiconductors S32 automotive Microcontrollers. We Will be using ElecronicsV2 Development Board which has ARM Coretx M4 Processor based Automotive Microcontroller: S32K144 The objective of this blog series is to teach people on how to use FreeMaster Desktop application: which is a great tool for run time debugging, as it provides run time debug monitor(Oscilloscope, Watch Grid, sending 2-way commands) and data visualization (Creating animated GUI pages). The best part about this is that real time debugging and tracing can be done without any expensive or heavy debuggers (SWO/Jlink/JTAG/Lauterbach/PEMicro or etc) and that too on interesting GUI pages. One can Interface FreeMaster with our Target Development Board (ElecronicsV2/AutoboardV1), via UART, CAN, ProBug Jlink Debugger or even over TCP/IP network. To know more about FreeMaster: what is it, why it should be used and its features. Checkout This Blog: FreeMaster Debugging Tool – Get To Byte This is getting started blog to learn and teach how to use FreeMaster Desktop Application. Initially we will be using it via UART and ProBug Debugger. In later blogs and stages, we will be interfacing it via CAN, TCP/IP and exploiting many other features of FreeMaster. Subscribe yourself to get notified Blog will be out on 20th of June 2024. Right Now, blog is under development, so subscribe yourself from below button and tell us about your use-cases so that we can customise blogs according to your needs. Subscribe Author: Kunal Gupta

Read More »
Kunal Gupta
Author: Kunal Gupta

Author

Kunal Gupta

Leave a comment

Stay Updated With Us

Error: Contact form not found.

      Blog