Overview

So hello guys, welcome back to another series of Microcontroller tutorials. As Microcontrollers are new big thing happening across the globe, but to learn about microcontrollers becomes quite challenging as most of the content on web is theoretical based and quite unorganized. Or the content is only roaming around 2-3 microcontrollers (Arduino, ESP or PIC), even though there are number of Microcontrollers of different vendors. Also, framework of Arduino and Arduino IDE hides most of the things that are going inside the microcontrollers.

Here at Gettobyte, you will get content on microcontroller tutorials for different vendors and much more via practical way. Which will help you to learn important skills to build you Carrer on Semiconductor Industry and also help you in product development/DIY projects for different Industries, so as to make embedded devices with Industry standard Microcontroller.

Would recommend viewers to read below blogs, if you are newbie, who is just coming from Arduino environment and wanna explore microcontrollers and wanna build Carrer into semiconductor industry, then this blog will give you overview of what all things are there to be needed for making projects and to play along with the different microcontrollers.

Table of Contents

This Time we are going to start with NXP Semiconductors S32K144 automotive MCU. Objective of this blog, will be to:

  • –> Learn About NXP Semiconductors.
  • –> Get to know about S32, S32K & S32K144 Platform of NXP Semiconductor.
  • –> Hardware Development Kit of S32K144 MCU.
  • –> Software Development Kit of S32K144

After this Introduction blog on s32K144 MCU, we will be doing hands on different peripherals of this MCU starting with GPIO, UART, I2C, SPI and…

About NXP Semiconductor

NXP Semiconductors is a global semiconductor company that designs and produces a broad range of semiconductor solutions providing hardware and software for them. It is a fabless company that designs the Microcontrollers, Microprocessor, ASICS’s and other discrete electronic components, targeting the industries like but not only limited to automotive, industrial automation, communication infrastructure, IoT, Robotics, Medical, Consumer Electronics, drones and Security Chips.

Apart from these chips and IC’s, NXP semiconductors also provide software to run these chips and demonstrating different applications where its products can be used. NXP semiconductor also works in AI/ML and edge computing.Making it not only giant hardware-based semiconductor company but software company too.

History of NXP Semiconductors roots back to 1950’s. It was founded in 1953 as part of the electronics giant Philips, at that time the company name is Philips Semiconductors. In 2006 it become independent company and its name changed to present name: NXP Semiconductors. After that it had acquired several companies and had done partnership deals with companies like Silicon labs, STMicroelectronics, Trident Microsystems, Conexant Systems and to expand its product lines and business revenue. In March 2015, merger agreement was announced through which NXP semiconductors acquired The Freescale semiconductors. After this merger NXP semiconductor become one of the largest semiconductor companies in the world. Both NXP and Freescale had deep roots stretching back to when they were part of Philips (NXP), and Motorola (Freescale). NXP primarily focusing on near field communication (NFC) and high-performance mixed signal (HPMS) hardware, and Freescale focusing on its microprocessor and microcontroller businesses. NXP semiconductor chips are used in almost every electronic gadget we see around us. To know more about NXP semiconductors, one can navigate to NXP website and Wiki page.

In this blog we are going to start with Automotive Industry. NXP semiconductors has a S32 Platform of microcontrollers and microprocessors specially targeting the Automotive industry. S32 platform has all the kind of MCU’s and MPU’s targeting different Domains of Automotive. There are broadly five domains in automotivePower Train, Chassis, Body & Comfort, HMI, and
Telematics. These 5 domains cover all the devices embedded in Automotive.

About NXP S32 Platform

S32 is a series of Microcontroller which are designed and manufactures by NXP Semiconductors, specially targeting for automotive applications but not only limited to them. Then with in S32, there are further categories as S32K, S32G, S32R, S32V.

NXP S32 Product Platform

Each of the category, can be used in one of the domains of automotive. Like say in powertrain one can use S32K for motor control applications and for telematics one can use S32R for radar processing, to get information about nearby objects. This is what something ADAS system is. Like when some car come nearby to a car, some sensor senses that distance (That is telematics zone) and after a certain threshold car speed automatically changes by controlling its motor RPM (that is part of powertrain).

NXP S32 Platform is being designed, providing end to end solutions for Automotive Industry. Not only MCU’s and MPU’s but NXP also provides large number of tools and software to build the applications for Automotive from S32 Platform. Dedicated IDE, Debugging tools and drivers, Real-time Drivers (RTD), RTOSes(FreeRTOS, Zephyr, NXP RTOS) and Autosar complaint SDK.

Almost every MCU of S32 family has support of Automotive protocols: CAN, LIN, FlexIO and etc. Ranging from ARM CortexM3(single core) to ARM Cortex A9(triple core). Having advance features to support automotive needs like : Hardware security modules(HSM) for safety and security, High Bandwidth Ethernet and USB support for connectivity and etc.

We are going to start with S32K312 MCU, which is part of S32K family. It is based on ARM Cortex M7 and has dedicated HSM-H that too upto EVITA specs and also ASIB/D complaint. Making it a perfect MCU to start for building general purpose Automotive applications.

Would get to know more about S32 platform along with tutorial series on S32K312 MCU. 

S32K MCU family series

We are going to start with S32K platform which are general purpose Microcontrollers designed to make different ECU in zonal and body control modules for automotive applications.

NXP S32K1 MCU series

S32K is further categorized into S32K1 and S32K3 series. S32K144 is part of S32K1 series.

About S32K144 MCU

S32K144 MCU is part of the S32K series of MCU of NXP, which are General purpose Microcontrollers for developing body & control, powertrain related applications automotive Industry. S32K144 is single core ARM cortex M4F processor based MCU with rich set of peripherals for Automotive Industry.

  • It has upto 89 General Purpose Input/Output (GPIO) pins for connecting large number of I/O sensors and modules to act as HMI, thus perfect choice for acting as ECU node in domain or zonal Architecture of E/E automotive.
  • It has 512 KB of on chip flash memory and 256KB of SRAM with ECC feature to have secure memory regions.
  • It operates at Voltage range (Vdd) of 2.7V to 5.5V, with temperature range of -40 to 150 degree Celsius.

Means if Voltage of 2.7V is supplied to IC then it will recognize input signal of 1.89V(0.7* Vdd) to 3V (Vdd+ 0.3) as High signal and input signal of -0.3V(Vss-0.3) to 0.81V(0.3*Vdd) as Low Signal. If Voltage of 5.5V(Vdd) is supplied to IC, then it will recognize input signal of 3.5V(0.65*Vdd) to 5.8V(Vdd+0.3) as High Signal and input signal of -0.3V(Vss-0.3) to 1.9V(0.35*Vdd) as Low Signal.            (Analyzed from DC electrical specification of S32K1-DS)

Thus, IC can be used to measure Input signals for low voltage sensors like accelerometers, Capacitive and Inductive sensors.

  • S32K144 IC has Arm Cortex M4 core, with Integrated DSP, Configured NVIC, Single Precision FPU and Debug CoreSite architecture. ARM Cortex M4 Core supports ARMv7 Architecture and Thumb2-ISA.
  •  IC can run up to at 112MHZ frequency when running at System Phase Locked Loop (SPLL). It has Fast Internal RC Oscillator (FIRC), Slow Internal RC Oscillator (SIRC), Low Power Oscillator (LPO), Real Time Counter External clock (RTC_CLK).
  • ADC peripheral is essential for applications involving Electrification. Thus, IC has two 12-bit SAR ADC modules of 16 channels. IC also has 8-bit internal DAC module for integrating power IC\’s in the case of electrification.
  •  IC also has onchip Debug facilities of Serial Wire Debug (SWD), Serial Wire Output (SWO) and JTAG combined. And IC inherits the CoreSight Debug Architecture of ARM processors.
  • In terms of On-board Communication peripherals. IC has 3 Low Power SPI, Low Power UART and FlexCAN peripheral, 1 Low Power I2C, one FlexIO module for emulation of on board communication protocols. Various and Different types of Automotive Sensors and modules can be connected along with this IC with rich support of Communication peripherals.
  • Automotive involves high secure and safety ECU nodes. Thus, IC has Cryptographic Service Engine (CSEc) implemented. It includes AES-128,CBC,ECB and CMAC. Pseudo and True Random Number Generators(PRNG,TRNG) with sequential, parallel and strict Boot Mode.
  • In addition TO CSEc, IC has Error Correction Code(ECC) and Cyclic Redundancy Check module, system memory protection units with Internal(WDOG) and external(EWM) Watchdog monitor.
  • For offloading the load on CPU while transferring data from memory regions of chip, IC has 16 channel DMA with 63 requests sources using DMAMUX.
  • IC also has Timing and Control module for capturing and outputting digital signals. It has 4 16 bit FlexTimers Module(FTM), 1 16 bit Low Power Timer Module(LPTMR),  1 32 bit Low Power Interrupt Timer(LPIT) and 1 32 bit Real time Clock(RTC).
  • IC comes only in LQFP packaging of 48,64 and 100 pins.

S32K144 MCU Block Diagram

 

Above is the high-level architectural view of S32K144 MCU. As told in my previous blogs, one can consider Microcontrollers as human body, in which there is one human brain and all other body parts are connected to it, to interact with outside world. In the case of Microcontrollers brain is processor and peripherals connected to processor are body parts. 

  • The first block in above diagram is ARM cortex M4F Processor, which is most important unit of MCU. It has additional features integrated in it like that of NVIC,DSP, Debug and etc. as one can see in the block diagram.
  • Second block is clock generation. As digital systems need to run at some frequency that is provided by clock peripheral. So this block takes care of generating clocks for various sub-units of MCU by having different clocks as shown in block diagram.
  • Third block is the analogous to body parts of human body that interact with outside world. Here 3rd part comprises of wide number of on chip peripherals, which are connected to external sensors or modules to have interaction with external world.
  • Fourth block is the memory block, which comprises of flash memory, SRAM and memory protection features.
  • These are the main 4 blocks which covers majority of IC features, but in addition to it there are also small blocks like DMA, CSEc and etc. which would be further discussed in upcoming blogs.

S32K144 Hardware Development Kit(HDK)

ElecronicsV Series: Arduino of Automotive World

ElecronicsV is a Automotive Development Board Series, supporting various automotive technologies like: Autosar MCAL layer, Matlab Model Base Designing, Vehicle communication protocols like” CAN, LIN, JN5189, Hardware Security Module based on SHE standard for providing safety/security support and advance motor control application for mobility applications.

These Development boards are built on automotive microcontroller S32K144 which are based on ARM Cortex M4 Processor and has various on-board features to enable the hassle-free development and learning of automotive technologies.

There are in total 3 versions in ElecronicsV series:

  1. ElecronicsV1: Breadboard Compatible Development board based on S32K144 MCU with basic on-board features of RGB LED’s, Switches,  Potentiometer and UART. This Board is obsoleted now. It was launched in July 2023.
  2. ElecronicsV2: Breadboard Compatible Development board based on S32K144 MCU with on-board features of RGB LEDs, Switches, Potentiometer, UART over Type C Cable and CAN transceiver IC making ElecronicsV2 self-sufficient CAN Node. This Board is also obsoleted now. It was launched in September 2023.
  3. ElecronicsV3: Breadboard Compatible Development Board based on S32K144 MCU with on-board features of: RGB LEDs, Switches, Potentiometer, BNO055 IMU Sensor, On-Board Jlink Debugger via Type C cable, CAN FD transceiver IC making ElecronicsV3 self-sufficient CAN Node and Virtual UART COM Port. This board is latest product and available in stock. It was launched in June 2024.

For buying the ElecronicsV3 board: S32K144 Elecronics V3 with onboard J-Link, BNO055 and CAN – Electronics Infra

ElecronicsV3 board is great amount of value of money at 6,000 INR. At just 6,000 INR, one can learn and get exposure to automotive technologies which are highly valued in the industry and great in demand. As usually other automotive hardware kits supporting all these technologies comes at heavy and heft prices of about more then 15-20K. Also, For ElecronicsV3, a full getting started and in-depth resources are they’re at: ElecronicsV(S32K144 MCU) – Get To Byte

Elecronicsv3 Board Pin Out

 
PINOUT of NXP S32K144 Evaluation Board

Above is the pinout of Evaluation board. We can easily connect sensor and modules via Jumper wires. Also the board has Arduino uno compatible expansion shield support.

  1. The board has on-board Mini High speed CAN Transceiver and System Basis Chip: UJA1169TK.( CAN_TX –> PTE5&CAN_RX –> PTE4).
  2. Single and multichannel LIN transceivers: TJA1027( LIN_TX–> PTD7 & LIN_RX -> PTD6).
  3. 2x touchpads(PTC3&PTC0), 1x Potientiometer(PTC14), 1x RGB LEDS( RED: PTD15, Blue: PTD0 and Green: PTD16) and 2x push buttons.

Debuggers

For Programming ElecronicsV series of Board, one can debug via Segger Jlink Debuggers or Even PEMicro Debugger via SWD protocol which is accessed via on-board 10 pin Debug connector pins.

ElecronicsV1 and ElecronicsV2 doesn’t have on-board Jlink Debuggers, for those board we will be needing external Jlink Debuggers for programming and debugging the S32K144 Microcontroller. Those who are interested in getting Jlink Debuggers for NXP S32 Family of MCU, can have a look at our ProBug Debugger. Which is Jlink debugger indigenously developed by Gettobyte.

ElecronicsV3 has onboard Jlink debugger and that too with virtual UART COM part, which makes it very easy and cost-effective enablement on automotive technologies. User just need to connect USB Type C cable from the ElecronicsV3 board to Host PC/Desktop. And now you are good to go. Doesn’t need anything else.

S32K144 Software Development Kit

IDE(Integrated Development Environment)

NXP provides the Integrated Development Environment especially for S32 platform products, S32 Design Studio which is built on Eclipse IDE.  S32 Design studio is based on open-source GNU Compiler collection (GCC) and also has GNU debugger (GDB).

S32 Design Studio Home page

One can easily download the S32 design studio from NXP website after logging in from here.

S32 Design Studio also provides various features for debugging and flashing the firmware. In addition to that we can add various extensions and install SDK packages of S32 platform directly from S32 design Studio.

S32 Design Studio is the Integrated Development Environment (IDE) which is used for writing, building and debugging the code to run on S32K144 MCU. S32 DS has many inbuilt features for debugging and analyzing the code, for efficient and fast implementation. Steps to install S32 Design studio are pretty straight forward and can be referred from here. Am skipping that part as that is pretty well documented on NXP Website and directly moving to GPIO Peripheral specific API’s and Files.

SDK(Software Development Packages)

NXP also provides built-in Software packages for fast development of applications: S32 Software Development Kit for S32K1. The SDK includes: Real Time Drivers, FreeRTOS support, Ethernet Stack, NXP motor control Libraries and etc. The SDK support 5 compilers for compilation: GCC, GreenHills(GHS), ARM Compiler, IAR and WindRiver DIAB.

Now there are 2 SDK’s, which are provided for S32K144 MCU by NXP Semiconductors.

One is Autosar 4.4.0 complaint, in which all the peripheral drivers and RTD’s of the MCU peripherals are build based on Autosar classic standard. For the sake of refernce thorughout the series i will be naming this SDK as Autosar Complaint Drivers for S32K. Naming convention of these are like this: SW32K1_RTD_4_4_1_0_0_D2108

And other is generic one, based on MISRA C guidelines and Standards in which all the peripheral drivers, RTD’s and other software stacks (FreeRTOS and middleware: TCP/IP) are built on easy-to-use architecture, with less abstraction layers and complexities as compared to Autosar based for easy to use. Would be naming this as S32K Software Development Kit (S32 SDK). It boast an impressive array of features, including a comprehensive suite of robust hardware abstraction layers, peripheral drivers, RTOS, stacks, and middleware. These tools are specifically designed to simplify and accelerate the application development process, making it easier for developers to create high-quality applications with ease. Naming convention for these are like: S32_SDK_S32K1xx_RTM_4.02

 

S32K SDK

We will be using SDK based on MISRA C guidelines and standards, the S32K Software Development Kit at first: S32SDK_S32K1xx_RTM_4.0.2.

S32K Software Development Kit (S32 SDK) boasts an impressive array of features, including a comprehensive suite of robust hardware abstraction layers (HAL), peripheral drivers, RTOS, stacks, and middleware. These tools are specifically designed to simplify and accelerate the application development process, making it easier for developers to create high-quality applications with ease

As This SDK can also be downloaded easily from website. Am skipping the part of its installation part, in case of any Douts do reach out to me.

S32K Software Development Kit consists of several key components that can be used for Application development. When we download the package of S32K SDK, one will see following folder structure:

//just some overview on what each folder does!

We will be initially focusing on Hardware Abstraction Layer and peripheral drivers. For that folder platform is key component. Under the Platform, their are 3 folders as shown below:

  • devices folder: contains the controller specific register header files, core specific register header files, controller specific feature configuration file, linker scripts and startup codes for different S32K MCU’s.
  • drivers folder: this contains the low level drivers for the peripherals of the MCU. Depending on the configurations done, low level drivers would be implemented.
  • pal folder: this contains the Peripheral Abstraction Layer for providing the unified interface for families of peripheral, allowing for cross -platform compatibility of application code.

As we are using S32K144 MCU, so we will find 2 files in devices folder: S32K144.h & S32K144_features.h files.

These are kind of configuration files, peripheral register address files and enables/disables the features that are to be supported in S32K144 MCU. These 2 files are one of the key files and would be used time to time.

				
					/*
** ###################################################################
**     Processor:           S32K144
**     Reference manual:    S32K1XX RM Rev.13
**     Version:             rev. 4.4, 2021-04-26
**     Build:               b210426
**
**     Abstract:
**         Peripheral Access Layer for S32K144
**
**     Copyright 1997-2016 Freescale Semiconductor, Inc.
**     Copyright 2016-2021 NXP
**
**     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.
**
**     http:                 www.nxp.com
**     mail:                 support@nxp.com
**
** ###################################################################
*/
/*!
 * @file S32K144.h
 * @version 4.4
 * @date 2021-04-26
 * @brief Peripheral Access Layer for S32K144
 *
 * This file contains register definitions and macros for easy access to their
 * bit fields.
 *
 * This file assumes LITTLE endian system.
 */
				
			
				
					/*
 * Copyright (c) 2015 Freescale Semiconductor, Inc.
 * Copyright 2016-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.
 */

/*!
 * @file S32K144_features.h
 * @brief Chip specific module features
 *
 * @page misra_violations MISRA-C:2012 violations
 *
 */


				
			

Run Time Debugging Tool: FreeMaster

FreeMaster Run-Time debugging tool

 FreeMaster Run-Time debugging tool

NXP Also provides the FreeMaster tool for run-time debugging. We will get onto this in upcoming blog, for the time being we are going to start with S32 Design Studio and S32K1 SDK.

Getting Started

 Getting Started with S32K144 Evaluation Board

We will get started with NXP S32K144 EVB board by running the Hello world program. In Microcontroller world Hello World example is Blink LED project. But before that we need above mentioned IDE and SDK for setting up the environment of S32K144 to do cross compilation in our Desktop/Laptop.

Refer this link: Get Started with the S32K144EVB | NXP Semiconductors for IDE, SDK installation and building Hello World program on S32K144 Evaluation board. Starting from the next blog we are going to develop application projects by interfacing different sensors and modules.

Further blogs to read
Using a function in Embedded C.

In this example, we will make animations by turning off and on Leds with some delays. We could simply do it like this. We could simply do it like this. PORTB=0B10101010; _delay_ms(1000); PORTB=0B01010101; _delay_ms(1000); . . . PORTB=0B01000001; _delay_ms(1000); But instead of writing like this, we would use the function Led_pin( ). It will reduce the typing a bit but in the next blog, we will learn to make it very small by learning a concept called Bit Shifting. Let\’s go for an example. #define F_CPU 16000000UL //defining the clock speed of the processor #include <avr/io.h>  // library for using registers [PORTX,PORTD,PINX] #include <util/delay.h> // library for using delay void Led_pin(uint8_t byte) // Making a function with argument \”byte\” having data type unsigned int 8. { PORTB = byte;   // Whenever the function is called it will store the argument byte in PORTB with delay. _delay_ms(100); } int main(void) { DDRB = (0b00111110); while(1) { Led_pin(0b00101010); Led_pin(0b00010100); Led_pin(0b00101110); Led_pin(0b00010001); Led_pin(0b00101010); Led_pin(0b00011100); Led_pin(0b00101011); Led_pin(0b00010100); PORTB=0b00000000; _delay_ms(1000); } return(0); } In the above code we made a function  Led_pin( ). void Led_pin(uint8_t byte) { PORTB = byte;   _delay_ms(100); } Here Led_pin takes a single byte of data type unsigned int [uint8_t]. Whenever our code calls this function the arguments inside it directly go to the PORTB and blink for 100 microseconds asset in delay. OUTPUT If you are new and feeling confused about other libraries and functions then please refer to this blog. Author: Kunal Gupta

Read More »
SPI Peripheral In STM32F103

Overview So, in this blog we will be covering another alternate functionality of GPIO pins i.e SPI (Serial Peripheral Interface). Previously we hve covered following peripherals implementation in STM32F103 MCU’s. ADC(Analog To Digital Converter) in STM32F103 UART Peripheral in STM32F103 GPIO Peripheral in S32K144 MCU Clock Peripheral in STM32F103 PWM on STM32F103 SPI is a synchronous and full duplex communication between a master and several slave devices. It is used in devices or sensors in which speed is a priority . It operates at data transmission rate 8 Mbits or more. The protocol uses 3 or usually 4 wires for data transmission and receiver .It is used by various sensors and modules such as OLED Display, BMP280 , RC522 , DAC , Shift Registers etc. SPI Theory The SPI uses 2 pins for data transfer SDIN and SDO , SCLK clock for synchronization of data transfer between 2 chips, CE chip select that is used to initiate and terminate the data transfer. SDI  =  MOSI SDO  =  MISO SCLK  =  SCK CE  =  SS MOSI: MASTER OUT SLAVE IN This pin is used to send data from master to slave MISO: MASTER IN SLAVE OUT Lorem ipsum dolor sit amet, consectetur adipisi cing elit, sed do eiusmod tempor incididunt ut abore et dolore magna SCK: SERIAL CLOCK This is used to generate clock to synchronize data transfer between the master and slave device . This is generated by master SS:SLAVE SELECT Used to select the particular slave to send data . Besides SPI communication the SPI interface can switch between I2S communication protocol that is a synchronous serial communication interface. It supports 4 audio standards including the I2S Philips standard, the MSB- and LSB-justified standards, and the PCM standard. The operating modes can be full duplex(4 wires) and half duplex (6 wires) Multi Mode Configuration Multiple subnodes can be used with a single SPI main. The subnodes can be connected in regular mode or daisy-chain mode.   How Data is Transmitted in SPI Initially SCK is enabled that starts the transmission The master sets the SS line low of the slave Data is usually shifted out with most significant bit  first , shifting a new least significant bit into the same register Data in slave side is shifted into least significant bit of the register Hence after all the shifting is done the master and slave has transferred the data If more data is to be exchanged the registers are reloaded and the process is repeated When no more data transmission is there the master stops toggling the SCK and deselects the slave using SS   SPI Peripheral Bus Modes Before discussing about the various bus modes we will be discussing the clock phase and polarity i.e CPOL:Clock Polarity and CPHA:Clock Phase and it is the combination of CPOL and CPHA that is referred to as Bus Modes. CPOL = 0  Active state of clock = 1 Idle state of clock= 0 Means the sampling on the first edge      CPHA = 0 – Data is captured on the rising edge and output on falling edge      CPHA = 1 – Data is captured on the falling edge and output on the rising edge        CPOL = 1 Active state of clock = 0 Idle state of clock = 1 Means sampling is on the second edge          CPHA = 0 – Data is captured on the falling edge and output on rising edge        CPHA = 1 – Data is captured on the rising edge and output on the falling edge SPI Features in STM32F103 Full-duplex synchronous transfers on three lines   Simplex synchronous transfers on two lines with or without a bidirectional data line 8- or 16-bit transfer frame format selection  Multimaster mode capability   8 master mode baud rate prescalers (fPCLK/2 max.)  Slave mode frequency (fPCLK/2 max)   Faster communication for both master and slave   NSS management by hardware or software for both master and slave: dynamic change of master/slave operations   Programmable clock polarity and phase Programmable data order with MSB-first or LSB-first shifting  Dedicated transmission and reception flags with interrupt capability   SPI bus busy status flag   Hardware CRC feature for reliable communication:   – CRC value can be transmitted as last byte in Tx mode  – Automatic CRC error checking for last received byte  Master mode fault, overrun and CRC error flags with interrupt capability   1-byte transmission and reception buffer with DMA capability: Tx and Rx requests SPI Instances in STM32F103 SPI instances vary from microcontroller to microcontroller from 1 in stmf103c6t6a to 6 in stm32f7 each having different pins NSS pulse mode , TI mode and hardware crc calculations SPI1 features PA5 as SCK , PA6 as MOSI  and PA7 as MISO SPI2 features PB3 as SCK, PB4 as MISO and PB5 as MOSI.  NSS Management in SPI protocol for STM32F103 NSS line can to be driven via 2 modes Software Mode- SS is driven internally by firmware Hardware Mode – A dedicated GPIO pin is used to drive the SS line Also NSS features NSS output and output disabled mode. Output mode is used only when device operates in master mode and it is disabled allowing mutli master capability NSS hardware mode must be used in TI mode . CPHA and CPOL are forced to conform to Texas Instrument (TI) protocol requirements. In this NSS signal pulses at the end of every transmitted byte APPLICATIONS OF SPI PROTOCOL Application 1 Memory Devices- SD-Card, MMC, EEPROM and FLASH Application 2 Sensors- Temperature and pressure (BMP280) Application 3 Control Devices -ADC, DAC, Audio Codec Application 4 Others- Camera Lens , RTC, LCD , Touch Screen RFID Module interfacing with STM32F103 W25Q SPI Flash Memory ST77389 LCD Display with STM32F103 NRF24L01 RF Module with STM32F103 How to Configure SPI Peripheral for STM32F103 We would be using STM32 HAL and STM32CubeIDE for using the SPI peripheral in STM32F103 in this blog tutorial series. SPI BLOCK DIAGRAM SPI CONFIGURATION ALERNATE FUNCTION MAPPING CONFIGURATION IN STM32CUBEIDE FIG 1- Selecting MOSI, MISO , SS and SCK pins

Read More »
Secure Hardware Extension: Cryptography peripheral for automotive chips

The more realistic you get, the more distinct you become in modern world Gettobyte What is SHE (Security Hardware Extension) Technology? Secure Hardware Extension, short form SHE: is a standard that specifies performing basic cryptography ciphers and managing cryptography keys via automotive Microcontrollers. SHE has been stated as standard in automotive microcontrollers to protect the cryptographic keys from software attacks by hardening them into the memory of the microcontroller and to perform basic symmetric cryptographic ciphers like AES & CMAC for encrypting and decrypting the data. SHE standard is implemented in microcontrollers by having an on-chip extension(peripheral) as a security subsystem which follows, the SHE standard. SHE standard is stated by hersteller-initiative-software (HIS) consortium in April 2009. This consortium was founded in 2004 and consists of members from Audi, BMW, Daimler, Porsche, and Volkswagen to address activities and develop common automotive manufacturing standards. SHE standard states that the peripheral in the Microcontroller should have the following 3 blocks, to implement SHE standard in MCU: Control Logic: Connecting the parts of the CPU to the microcontroller. Storage Area: To keep the cryptographic keys and additional corresponding information. Cryptographic cipher core: a hardware core or module to perform necessary calculations for performing cryptographic ciphers. Automotive Chips, which have SHE peripheral: MPC5646C Freescale MCU’s S32K144 NXP Semiconductor’s MCU Components of SHE Technology SHE Technology  Why SHE Technology? Working principal of SHE Technology? USE cases of SHE Technology? How to use SHE Technology? Add Your Heading Text Here Author: Kunal Gupta

Read More »
Tigger MUX Control(TRGMUX) Peripheral in S32K144 MCU

What is TRGMUX peripheral? TRGMUC provides an extremely flexible mechanism for connecting various trigger sources to multiple pins/peripherals. The trigger multiplexer (TRGMUX) module allows software to configure the trigger inputs for various peripherals.   The TRGMUX module allows software to select the trigger source for peripherals.   TRGMUX is a peripheral which provides mechanisms for connecting various trigger sources to multiple pins/peripherals. Each peripheral that accepts external triggers usually has one specific 32-bit trigger control register. Each control register supports upto 4 triggers and each trigger can be selected from available trigger sources.   Author: Kunal Gupta

Read More »
Starting with RTOS: FreeRTOS

Table of Contents Intro From this blog, we will be starting with RTOS(FREERTOS). In RTOS there are many concepts & things related to kernel, tasks management, task scheduling, IPC, and many other terminologies. In the tutorial series, we are not going into a theoretical understanding of the RTOS topics, we would be mainly focusing on developing different applications in RTOS. Like how to use mutexes, and semaphores in different applications, we will get into the RTOS kernel and understand its different components like scheduler, task management and etc., compare different scheduling algorithms in terms of time and how to create multiple tasks and pass information between them, how to use Software timers, queues and etc. while writing firmware for industrial projects. As there are many resources & tutorials to understand these theoretical concepts and how to use RTOSes APIs to build different kinds of applications is not much there. So, we would be focusing on that thing. RTOS is used in applications like that AGV(Automated Guidance Vehicles), Automotive ECU, and industrial automation products (Like metering instruments, industrial smart sensors and etc.). I have a personal interest and passion for these, so I would be making projects using RTOS related to these by interfacing sensors and modules used in these applications. Ultimately making the different tasks run together to utilize the power of RTOS to make an efficient project. To Know about what RTOS is, refer to this blog What is Real Time Operating System (RTOS) | gettobyte Now to start with RTOS, there are many open source RTOSes available like FreeRTOS, embed OS, Zypher OS, ThreadX OS and etc. But starting with FreeRTOS would be my choice that too with STM32 because the integration of STM32CubeIDE with FREERTOS is pretty easy & gives an easy starting point for beginners. Subsequently, we will migrate to NXP controllers with FreeRTOS. Once getting hands-on with FreeRTOS via STM32. Requites: Bare metal coding On MCU’s (Register level programming, working of MCU’s, SoC/processor architecture, boot process: linker script, startup code, GNU GCC, Debugging and etc.). Knowledge of peripheral of UART, I2C, SPI, ADC, Interrupts, DMA and etcC/CPP programming, etc). Device driver development to integrate different sensors & Modules with MCU. (Datasheet reading, communication protocols, sensors and modules working/Cpp programming). Knowledge of C/CPP programming. Software Development Kit, IDE, HAL, RTD drivers and etc. FreeRTOS What is FreeRTOS? FreeRTOS is Real Time Operating System, which is highly used in industry. It is also best recommended for beginners to start with if one wants to learn RTOS, because of its wide number of resources available, documentation, and community support. FreeRTOS is a market-leading embedded System RTOS, which is available for many processor architectures, it supports more than 40 processor architectures including ARM cortex processors. Also portable to a wide number of compilers and hardware platforms. FreeRTOS is supported by a wide number of silicon vendor chips like NXP Semiconductors, STMicroelectronics, Texas Instruments, and many others. You can find a full list of that here: Microcontrollers and compiler toolchains supported by FreeRTOS. Features of RTOS Highly configurable kernel. FreeRTOS has Microkernel architecture. Pre-emptive or co-operative operation. Inter Processor Communication techniques like Mutex and Semaphore for synchronization. Support for message queues. Software Timers. Event groups. Memory management to maintain heap memory. Also, advanced features for debugging the tasks in Real Time. FreeRTOS Kernel The kernel is the most important thing and core of the RTOS. For the understanding you can have analogy that Human body is RTOS, and Human Brain is RTOS kernel. As without our brain we can’t do any work and loose our capabilities. Same without the kernel, RTOS can’t work. It is kernel which makes electronic devices, a multitasking system. It is kernelling whose responsibility is to run different tasks and have communication between them. Kernel act as the interface between system resources and user application. Kernel has different services for making multitasking system. Just like human brain has different biological parts to make us work. ( In the upcoming blogs and in this also, i would be using analogy of Human brain and Human body for understanding). The basic services of RTOS kernel are:  Task/Process Managment (Creation and deletion of tasks) Task/Process Scheduling (Scheduler) task/Process synchronization (Inter Process Communication) Memory Managment (heap & static) Interrupt Handling Error/Exception handling Coming to the FreeRTOS, it has highly configurable kernel. We can configure how to use the FreeRTOs kernel and which features/services of it. FreeRTOS is configured by FreeRTOSConfig.h header file. This file contains application specific definitions to configure FreeRTOS kernel. Every RTOS has one such configuration file which has macros, which can be enabled or disabled. Like we can configure which scheduling algorithm to use, how to create the tasks (static or dynamic), which IPCs to use for communication between tasks, enabling of run-time trace and debug features. When you will download the FreeRTOS kernel zip file, you will find many numbers of files. But core FreeRTOS is runned by just 2 files tasks.c and list.c. They are located in FreeRTOS/Source directory. In addition to these files, imp files whose Api’s we would be using are queue.c, timers.c, event_groups.c, croutines.c. Examples of RTOS Kernel: Mach QNX VXworks FreeRTOS Chibios ThreadX mbedOS FreeRTOS Libraries In addition to FreeRTOS kernel, there are add on libraries to extend the RTOS functionality. FreeRTOS+: To add support of TCP/IP stack and command line interpreter. FreeRTOS Core: To add support of cloud connectivity with HTTP, MQTT, JSON, Cellular interface. FreeRTOS AWS: To add support of AWS services. How To Start with RTOS? So, as of now, I have told you many things about RTOS and FreeRTOS. Most of you must have come up with that now how to start with FreeRTOS to learn RTOS. When we go to the FreeRTOS website for starting with RTOS, there are many things on the website, lots of documentation, articles, and resources on the website that might become overwhelming and confusing for beginners to start with it. At least for me, it does become like that, so I

Read More »
STM32F103 & ADC: Single Channel Conversion

In the last post, we have gotten to know about the features of ADC Peripheral that we have in STM32 MCU. Now in this blog with the series of bare Metal Programming for Blue Pill, we will understand different register bytes and bits of ADC Peripheral to be used for using it in different features, configurations, and modes as we get to know about in the Previous Post. In this blog, we will be going through how to use  ADC Peripheral for converting a Single Channel of ADC (only one ADC pin) and see its bare metal code. Single  Channel Conversion  Mode: Only one ADC pin is used, this mode is like when we have say connected only one analog sensor to one of the ADC pins of MCU  like the Potentiometer is connected at PA0 pin. ADC Registers In depth for: Let\’s get into an in-depth understanding of which registers and their bits are used for configuring the ADC peripheral of Blue Pill in Single Channel Configuration. We will focus on bits and will give an explanation of why those bits are used for the 1.   ADC_SR(ADC status Register) –>This register tells the status of ADC channel  Conversion, as it name says. STM32F103 ADC Status Register: 11.12.1 Bit 1[EOC ]: This bit is set by hardware when a single channel of any group (Regular or Injected) is converted successfully. So this bit is used for monitoring when the ADC conversion is completed by using it inside the while loop if interrupts are disabled. 0: ADC Channel Conversion is not completed 1: ADC Channel Conversion is completed When hardware set this bit, we can clear this bit from the firmware end by setting the bit to 0 or by reading ADC_DR(ADC Data Register) Bit 4[STRT]: This bit is set by hardware when regular channel conversion has begun. So when we start the Regular Channel Conversion, we will use this bit inside the while loop to check that whether Regular Channel conversion has started or not. 0: No regular Channel Conversion has started 1: Regular Channel Conversion has started When hardware sets this bit, we can clear this bit from the firmware end by setting the bit to 0. Even if we don\’t clear this bit it will cause no effect during ADC Conversion. But its good practise to clear all bits of Status Register before starting the new conversion 2.            ADC_DR(ADC Data Register) –> This register stores the converted digital data at a 12-bit resolution of the converted ADC channel. STM32F103 ADC Data Register 11.12.14 Bit 15:0 [DATA 15:0]: The ADC_DR is divided into two 16 bits groups. The first 16 bits from 0-15 contain the Converted value of the configured ADC Regular Channel. As our ADC is of 12-bit resolution, so this is left aligned or right aligned to 4 bits so as to get the 12 ADC converted data . Left Aligned or Right alignment of ADC Data Depends on ALIGN bit of ADC_CR2 So we will have following code and algorithm for ADC_SR & ADC_DR register:while(!(ADC1->SR & ADC_SR_STRT)) while(!(ADC1->SR & ADC_SR_EOC)); // wait till a group channel converstion has completed adc_data = ADC1->DR; //clear the EOC bit by reading DR register ADC1->SR &= ~ADC_SR_STRT;      3.      ADC_CR1(ADC Configuration register 1) –> This register is used for the  Configuration of ADC peripheral for Analog Watchdog Discontinuous Mode Interrupt Enable/disable Dual Mode configuration Scan Mode  As we are not using any of these features, so all the bits for these registers will be set to zero, and to know about these features and their bit functions, u can navigate to corresponding blogs for those. STM32F103 ADC Configuration Register 1. 11.12.2 Bits 19:16 [DUALMODE 3:0]:  These bits are used to configure the type of operating mode. In the blue pill, we have two ADC peripherals: ADC1 & ADC2. We can use these  2 ADC peripherals simultaneously by configuring the respective ADC in different modes or in independent modes. We are going to use these ADC in independent mode as will be using only ADC1 peripheral, so DUALMODE[3:0] will be set to 0. Bit 8[SCAN]: This bit is used to enable/disable the SCAN Mode feature in the ADC peripheral of BLUEPILL. Scan Mode is used when we convert more than 1 channel to scan all the configured channels in a Regular Group. As we are using only a single channel, means only one ADC pin is used so SCAN mode is not used and this bit will be set to 0. 0: Scan Mode disabled. 1:Scan Mode Enabled. So we will have following code and algorith for ADC_CR1 register:ADC1->CR1 &= ~(ADC_CR1_SCAN); // SCAN DISABLED, if using scan mode then dma must be enabled ADC1->CR1 &= ~(ADC_CR1_JDISCEN | ADC_CR1_DISCEN); // Discontinous mode disabled for both injected and regular groups ADC1->CR1 &= ~(ADC_CR1_DISCNUM_2 | ADC_CR1_DISCNUM_1 | ADC_CR1_DISCNUM_2 ); // no channels are configured in discontinous way. // if discontinous mode is enabled then number of //conversions to be done by discontinous mode has to be configured // DISNUM bits ADC1->CR1 &= ~(ADC_CR1_DUALMOD_0 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_2); // INDEPENDENT MODE SELECTED ADC1->CR1 &= ~(ADC_CR1_AWDEN | ADC_CR1_JAWDEN); // Analog watchdog disabled for both groups: regular and ibnjected 4. ADC_CR2(ADC Configuration Register 2) –> This register is used for the configuration of  ADC Peripheral for:  ADC Conversion enables/disabled for regular and injected groups and ADC peripheral enable/disable. Trigger source configuration for regular and injected groups. ADC Data Alignment, DMA, Continous, temperature sensor setting. STM32F103 ADC Configuration Register 2 11.12.3 Bit 0 [ADON]: ADC Peripheral On/OFF. This bit will be set to 1 to enable the ADC peripheral.  All channel configurations and ADC Peripheral configurations have to be made before setting this bit to 1. 0: Disable ADC Peripheral 1: Enable ADC Peripheral Bit 1 [CONT]: This bit configures between Single Conversion mode and Continous Conversion mode. Continuous Conversion mode is selected when we have more than 1 ADC channel to be converted. As in this blog, we have

Read More »
Kunal Gupta
Author: Kunal Gupta

Stay Updated With Us

Error: Contact form not found.

      Blog