/AUTOSAR-MCAL-Embedded-Upskilling-Bootcamp

AUTOSAR MCAL Embedded Upskilling Bootcamp by Modular MX.

Primary LanguageC

AUTOSAR MCAL Embedded Upskilling Bootcamp

This repo contains the projects, codes, examples, exercises and results for the "AUTOSAR MCAL Embedded Upskilling Bootcamp" by Modular MX.

AUTOSAR_MCAL_Upskilling.png

Date: July, 2024.

Autosar_MCAL_Certificate_Badge.png

Table of Contents

  1. Description
  2. Hardware Requirements
  3. Software Requirements
  4. Notes
  5. Documentation
  6. Examples and Exercises
  7. Final Project
  8. Sample Evidences

1. Description

<-- Back to Table of Contents

This AUTOSAR Upskilling Bootcamp, focused on MCAL layer, shows how to configure multiple peripherals that can be found in the microcontroller hardware by making use of Automotive industry tools. This Upskilling consists on 6 weeks, where 10% is theory and the 90% remaining is practice and hands-on.

By working through examples and exercises that use the NXP S32K144 board, the Modular MX Modular-S1 board and tools like Elektrobit Tresos, SEGGER Ozone debugger, and SavvyCAN, you'll gain an understanding on configuring, generating, and developing highly efficient low-level drivers and analyze their utilization in Classic AUTOSAR.

The Upskilling Bootcamp covers:

  1. Introduction to AUTOSAR MCAL and EB Tresos.
  2. PORT driver.
  3. DIO driver.
  4. MCU driver.
  5. GPT Driver.
  6. Platform Driver.
  7. ADC driver.
  8. PWM driver.
  9. SPI driver.
  10. I/O Hardware Abstraction.
  11. CAN driver.
  12. CANIF driver.
  13. Final Project.

What it's covered from the Classic AUTOSAR layers perspective:

AUTOSAR_layered_view.jpeg

2. Hardware Requirements

<-- Back to Table of Contents

NXP S32K144-Q100 Evaluation Board for Automotive General Purpose - Based on the 32-bit Arm® Cortex®-M4F S32K14 MCU, this is the base board used in this bootcamp.

S32K144_pinout.png

Modular-S1 Board - Board developed by Modular MX, comes with a whole new layer of additional peripherals customized specifically for NXP S32K144. Contains 2 potentiometers, 1 buzzer, 3 push buttons, 8 leds, general purpose inputs-outputs, USB Hub, CAN analyzer, 24 MHz logic analyzer, SPI display, 2 SPI Eeproms, and external CAN & LIN analyzer connectors.

Modular-S1_Board.png

NXP S32K144 Board + Modular-S1 Board:

NXP-S32K144_Modular-S1.png

3. Software Requirements

<-- Back to Table of Contents

EB Tresos Studio - Tool environment for electronic control unit (ECU) development with AUTOSAR. EB tresos Studio lets you configure, validate, and generate your ECU basic software (BSW). EB tresos Studio is the industry-standard tool for microcontroller abstraction layer (MCAL) development by semiconductor suppliers such as NXP, STM, and Infineon. Works on Windows and is free.

SEGGER Ozone - Full-featured graphical debugger for embedded applications. It is possible to debug any embedded application on C/C++ source and assembly level, as well as loading applications built with any tool chain / IDE or debug the target's resident application without any source. Ozone includes all well-known debug controls and information windows and makes use of the best performance of J-Link and J-Trace debug probes. Works on Windows/Linux/Mac and is free.

SavvyCAN - It is a CAN bus reverse engineering and capture tool. SavvyCAN can use any CAN interface supported by QT's SerialBus system (PeakCAN, Vector, SocketCAN, J2534, etc). It can capture and send to multiple buses and CAN capture devices at once. Works on Windows/Linux/Mac and is free.

4. Notes

<-- Back to Table of Contents

  • 4.1 Tools Installation and Configuration Guide:

You can find here Setup AUTOSAR Tools the section where Modular MX explains the right procedure to download, install and configure all needed tools, including its dependencies, how to import the template project file and flash it to the device.

  • 4.2 Ozone .jdebug files made portable for running debugger correctly:

After generating MCAL source files with EB Tresos Studio IDE and building the project, we need to make use of the .jdebug files that I'm providing in order to be capable or flashing the board with Ozone as well as for debugging. These files after generated were modified to be portable (using $(ProjectDir)), hence no need to be modified again and are ready to be executed.

Below you can see an example of the snippet for the .jdebug configuration file for any given project.

/*********************************************************************
*                                                                     
*       OnProjectLoad                                                 
*                                                                     
* Function description                                                
*   Project load routine. Required.                                   
*                                                                     
**********************************************************************
*/                                                                    
void OnProjectLoad (void) {
  //
  // Dialog-generated settings
  //
  Project.AddPathSubstitute ("C:/EB/tresos/workspace/DIO_Example4_Reading_channel", "$(ProjectDir)");
  Project.AddPathSubstitute ("c:/eb/tresos/workspace/dio_example4_reading_channel", "$(ProjectDir)");
  Project.SetDevice ("S32K144");
  Project.SetHostIF ("USB", "");
  Project.SetTargetIF ("JTAG");
  Project.SetTIFSpeed ("4 MHz");
  Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M4F.svd");
  //Project.AddSvdFile ("C:/EB/tresos/workspace/DIO_Example4_Reading_channel/S32K144.svd");
  Project.AddSvdFile ("$(ProjectDir)/S32K144.svd");
  //
  // User settings
  //
  File.Open ("$(ProjectDir)/Build/temp.elf");
}

5. Documentation

<-- Back to Table of Contents

You can find here Documentation all reference documents regarding:

  • AUTOSAR MCAL drivers.
  • Compiler Manuals.
  • NXP S32K144 Board.
  • Modular S-1 Board.
  • SEGGER Tools.

6. Examples and Exercises

<-- Back to Table of Contents

You can find here Tresos Workspace the base template file as well as all the examples and exercises created for this Upskilling Bootcamp. It is divided in folders for each of the MCAL drivers worked, and inside you will find 2 folders, Examples and Exercises.

  1. Templates: Tresos Project and Ozone Semihosting RTT.
  2. DIO and PORT driver.
  3. MCU driver.
  4. GPT Driver.
  5. Platform Driver.
  6. ADC driver.
  7. PWM driver.
  8. SPI driver.
  9. I/O Hardware Abstraction.
  10. CAN driver.
  11. CANIF driver.

7. Final Project

<-- Back to Table of Contents

You can find here the Final Project created for this Upskilling Bootcamp. It consists on an AUTOSAR I/O Hardware Abstraction for the on board Buttons and LEDs (PORT and DIO Drivers), Potentiometers (MCU and ADC Drivers), and Buzzer (PWM Driver), all together with the Scheduler and a state machine with specific application tasks requirements and the following events, each with particular peripheral behaviors:

Button 1 Events:

Button 2 Events:

Button 3 Events:

Button 1 Single Click:

Back to Final Project

  • Shall toggle ON/OFF RGB_LED_BLUE (D0) and C10_LED2 (as SINGLE_CLICK visual indicator).

Button_1_Single_click.GIF

Button_1_Single_click.mp4

Button_1_Single_click_Terminal.png

Button 1 Double Click:

Back to Final Project

  • Shall display (SEGGER_RTT_printf) Pot 1 ADC0 value in ohms, toggle C13_LED5 (as DOUBLE_CLICK visual indicator), and toggle C14_LED6 (as Pot 1 visual indicator).

Button_1_Double_click.GIF

Button_1_Double_click.mp4

Button_1_Double_click_Terminal.png

Button 1 Hold and Release:

Back to Final Project

  • Buzzer shall start to beep and play Tone 1, then stop.

Button_1_Hold_Release.GIF

Button_1_Hold_Release.mp4

Button_1_Hold_Release_Terminal.png

Button 2 Single Click:

Back to Final Project

  • Shall toggle ON/OFF RGB_LED_RED (D15) and C9_LED1 (as SINGLE_CLICK visual indicator).

Button_2_Single_click.GIF

Button_2_Single_click.mp4

Button_2_Single_click_Terminal.png

Button 2 Double Click:

Back to Final Project

  • Shall display (SEGGER_RTT_printf) Pot 2 ADC0 value in ohms, toggle C12_LED4 (as DOUBLE_CLICK visual indicator), and toggle C15_LED7 (as Pot 2 visual indicator).

Button_2_Double_click.GIF

Button_2_Double_click.mp4

Button_2_Double_click_Terminal.png

Button 2 Hold and Release:

Back to Final Project

  • Buzzer shall start to beep and play Tone 2, then stop.

Button_2_Hold_Release.GIF

Button_2_Hold_Release.mp4

Button_2_Hold_Release_Terminal.png

Button 3 Single Click:

Back to Final Project

  • Shall toggle ON/OFF RGB_LED_GREEN (D16) and C8_LED0 (as SINGLE_CLICK visual indicator).

Button_3_Single_click.GIF

Button_3_Single_click.mp4

Button_3_Single_click_Terminal.png

Button 3 Double Click:

Back to Final Project

  • Shall display (SEGGER_RTT_printf) Pot 1 and Pot 2 ADC1 alternate values in ohms, toggle C11_LED3 (as DOUBLE_CLICK visual indicator), toggle C14_LED6 (as Pot 1 visual indicator), and toggle C15_LED7 (as Pot 2 visual indicator).

Button_3_Double_click.GIF

Button_3_Double_click.mp4

Button_3_Double_click_Terminal.png

Button 3 Hold and Release:

Back to Final Project

  • Buzzer shall start to beep and play Tone 3, then stop.

Button_3_Hold_Release.GIF

Button_3_Hold_Release.mp4

Button_3_Hold_Release_Terminal.png

8. Sample Evidences

<-- Back to Table of Contents

You can find here captures and media, relevant to examples and exercises, visible output in communication (software) or physical world (board).

DIO-PORT Driver Evidences

Back to Sample Evidences

Pressing 1st button will rotate the LEDs from right to left, and pressing 2nd button will rotate them from left to right. 3rd button activates a different speed.

DIO_Exercise8_Rotate_LEDs_Left_Right_Buttons.GIF

DIO_Exercise8_Rotate_LEDs_Left_Right_Buttons.mp4

GPT Driver Evidences

Back to Sample Evidences

Using two different timers (FTM1 and FTM2) to toggle two pairs of leds (1st pair: normal led C8 and Blue RGB led, 2nd pair: normal led C9 and Green RGB led) at 100ms and 300ms, both timers use notifications in one shot mode, plus been feed by FIRC clock at 12MHz.

GPT_Exercise1_2Timers_OneShot_FIRC_2LEDs.GIF

GPT_Exercise1_2Timers_OneShot_FIRC_2LEDs.mp4

Using three FTM timers with one channel each, toggle the three RGB leds at different values (100ms, 400ms, and 800ms), the most important is that each FTM timer is feed by a different clock reference (12MHz, 4MHz, and 8MHz).

GPT_Exercise3_3Timers_FTM_RGB_DiffClkRef.GIF

GPT_Exercise3_3Timers_FTM_RGB_DiffClkRef.mp4

ADC Driver Evidences

Back to Sample Evidences

Vary the rotation speed of eight LEDs C8 to C15 using one of the potentiometers on the board.

ADC_Exercise1_Rotate_Speed_8LEDs_Potentiometer.GIF

ADC_Exercise1_Rotate_Speed_8LEDs_Potentiometer.mp4

ADC_Exercise1_Rotate_Speed_8LEDs_Potentiometer_Terminal.png

Display the values of the two potentiometers in Ohms and Volts.

ADC_Exercise2_2PotValues_Ohms_Volts_Terminal.png

Using a jumper wire to connect other channels available from ADC0 to have four channels to sample:

  • Pot 1: pin PTB1->CH5 connected to pin PTB0->CH4 (Blue jumper wire).
  • Pot 2: pin PTB13->CH8 (Interleaved, by default ADC0-CH8 is connected to PTC0 but changed to PTB13 using interleave function in code) connected to pin PTC1->CH9 (Purple jumper wire).

Also configure the hardware average sample with a value of 8, and calculate the total timing conversion for the entire group of channels.

ADC_Exercise6_4Channels_ADC0_2Pots.png

ADC_Exercise6_4Channels_ADC0_2Pots_Terminal.png

ADC0 and ADC1 Interleaved Channels diagram from NXP S32K1xx Reference Manual Rev. 13, page 1194 and 1195:

ADC_Exercise6_4Channels_ADC0_2Pots_Interleave.png

PWM Driver Evidences

Back to Sample Evidences

A program that generates two PWM channels but using two different timers, must see which pins are available with FTM functionality. Feed those timers with a SIRC clock.

  • Timer 1: FTM0, Channel: CH0, Pin: RED RGB LED.
  • Timer 2: FTM2, Channel: CH0, Pin: BLUE RGB LED.

Both RGB LEDs working, hence the purple color.

PWM_Exercise1_2CH_2Timers_FTM_SIRC_Clk.png

Generate two complement PWM signal with dead time insertion of around 1% of the period of the signal.

PWM_Exercise2_2CH_Complementary_DeadTime_Insertion.mp4

PWM_Exercise2_2CH_Complementary_DeadTime_Insertion_Tresos.png

'Paired channel enable' Tresos feature: The channels n and n+1 will be used as a channel pair. In this case the pair is Red RGB Led (FTM0-CH0) for 'channel n' and Green RGB Led (FTM0-CH1) for 'channel n+1'.

'Complementary channel enable' Tresos feature: Enable the complementary mode for Ftm channel. In Complementary mode, the channel (n+1) output (Green RGB Led) is the inverse of the channel (n) output (Red RGB Led).

'Complementary mode' Tresos feature: Selects complementary mode of the Ftm channel n+1. Here we confirm that the desired mode is 'Invert Output'. Hence when one RGB Led goes OFF the other goes ON and viceversa.

'Deadtime enable' Tresos feature: Enable the deadtime delay for Ftm channel. The deadtime delay insertion ensures that no two complementary signals (channels n and n+1) drive the active state at the same time.

'Phase Shift (Ticks)' Tresos feature: Define the offset value (in tick) from 1 that the leading edge of pulse signal will start. In this case it is wanted to be 1% of the period, so the 375 ticks value is the 1% of the 37500 period value configured for the channels.

Channel (n+1) output in Complementary mode diagram from NXP S32K1xx Reference Manual Rev. 13, page 1448:

PWM_Exercise2_2CH_Complementary_DeadTime_Insertion_ComplementaryMode.png

Used a potentiometer to variate the PWM duty cycle, connected to Blue RGB led, from 10% to 90% in steps of 10%. Two available methods, with and without steps, can be found in code with algorithm explained.

PWM_Exercise4_ADC_Pot_DutyCycle_RGB_LED.mp4

PWM_Exercise4_ADC_Pot_DutyCycle_RGB_LED_Terminal.png

SPI Driver Evidences

Back to Sample Evidences

Read and display the first 32 bytes of an Eeprom in different formats using Semihosting with RTT.

SPI_Exercise1_ReadPrint_32bytes_EEPROM_ASCII_Terminal.png

Wrote two functions that allow to write and read a byte to any valid memory address in the Eeprom memory, functions shall have the following prototypes:

  • void write_byte( uint16 addr, uint8 data );
  • uint8_t read_byte( uint16_t addr );

SPI_Exercise4_Function_Write_Read_Byte_Terminal.png

Wrote the following functions to allow to write a given array of n number of bytes starting at any address of the eeprom:

  • void write_data( uint16 addr, uint8 *data, uint8 size );
  • void read_data( uint16 addr, uint8 *data, uint8 size );

SPI_Exercise5_Function_Write_Read_ArrayData_Terminal.png

CAN Driver Evidences

Back to Sample Evidences

Hardware board transmits (Tx) an 8-byte single message with ID 0x123 and specified Data payload: 01 02 03 04 05 06 11 12. Savvy CAN receiving (Rx) the data, everytime having byte 1 and 8 increased by value of 0x1 as per the example intentional behavior.

CAN_Example3_Transmission_using_Interrupts.png

Hardware board receives (Rx) an 8-byte single message with ID 0x010 and specified Data payload: 32 01 01 01 01 01 01 01. Savvy CAN transmits (Tx) the data. Notice how in code we can establish a condition, in this case where the first byte must be 0x32 and once that is confirmed, can proceed and receive the rest of the data.

CAN_Example4_Reception_using_Interrupts_Dataset1.png

Similar as previous, hardware board receives (Rx) an 8-byte single message with ID 0x010 and specified Data payload: 32 08 07 06 05 04 03 02. Savvy CAN transmits (Tx) the data. Notice how in code we can establish a condition, in this case where the first byte must be 0x32 and once that is confirmed, can proceed and receive the rest of the data.

CAN_Example4_Reception_using_Interrupts_Dataset2.png

Hardware board transmits (Tx) three 8-byte messages with ID 0x123, 0x133 and 0x143, all having the same specified Data payload: 01 02 03 04 05 06 11 12. Savvy CAN receiving (Rx) the data, everytime having byte 1 and 8 increased by value of 0x1 as per the example intentional behavior.

CAN_Example5_Transmission_Mailboxes_Buffers.png

Hardware board receives (Rx) every second an 8-byte single message with ID 0x1EF and specified Data payload: 32 00 00 00 01 02 03 04. Savvy CAN transmits (Tx) the data. Notice how in code we can establish a condition, in this case where the first byte must be 0x32 and once that is confirmed, can proceed and receive the rest of the data.

CAN_Example6_Reception_with_Filters_ID_0x1EF.png

Hardware board receives (Rx) every second an 8-byte single message with ID 0x022 and specified Data payload: 32 00 00 00 05 06 07 08. Savvy CAN transmits (Tx) the data. Notice how in code we can establish a condition, in this case where the first byte must be 0x32 and once that is confirmed, can proceed and receive the rest of the data.

CAN_Example6_Reception_with_Filters_ID_0x022.png

Program that, upon pressing the button on the board, transmits a message with identifier 0x001 to the CAN bus, and upon releasing it, transmits a message with an identifier of 0x002. Hardware board transmits (Tx) two 8-byte messages with ID 0x001 and 0x002, all having the same specified Data payload: 01 02 03 04 05 06 11 12. Savvy CAN receiving (Rx) the data, everytime having byte 1 and 8 increased by value of 0x1 as per the exercise intentional behavior.

CAN_Exercise3_Button_Tx_MsgID_01_02.png

A program that senses three buttons and, upon pressing each one, sends a message indicating which button was pressed. Interrupts used in this program. Hardware board transmits (Tx) an 8-byte message with ID 0x154, having the default Data payload: 00 00 00 00 00 00 00 00 that then will have the last byte changed to 01, 02 or 03 depending on which button is pressed. Savvy CAN receiving (Rx) the data.

CAN_Exercise4_3Buttons_Tx_1Msg_3Data.png

CAN Interface (CANIF) Driver Evidences

Back to Sample Evidences

Hardware board transmits (Tx) an 8-byte single message with ID 0x123 and specified Data payload: 01 02 03 04 05 06 11 12. Savvy CAN receiving (Rx) the data, everytime having byte 1 and 8 increased by value of 0x1 as per the example intentional behavior.

CANIF_Example1_Transmission_single_PDU.png

Hardware board transmits (Tx) two 8-byte messages with ID 0x123 and 0x124, all having the same specified Data payload: 01 02 03 04 05 06 11 12. Savvy CAN receiving (Rx) the data, everytime having byte 1 and 8 increased by value of 0x1 as per the example intentional behavior.

CANIF_Example2_Two_PDU_Tx_one_single_HOH.png

Hardware board transmits (Tx) two 8-byte messages with ID 0x123 and 0x124, all having the same specified Data payload: 01 02 03 04 05 06 11 12. Each message has its own interrupt callback function to indicate that the message was transmitted. Savvy CAN receiving (Rx) the data, everytime having byte 1 and 8 increased by value of 0x1 as per the example intentional behavior.

CANIF_Example3_2_PDU_Tx_2_HOH_2_Notif.png

Hardware board receives (Rx) every second an 8-byte single message with ID 0x1EF and specified Data payload: 32 00 00 00 01 02 03 04. Savvy CAN transmits (Tx) the data. Notice how in code we can establish a condition, in this case where the first byte must be 0x32 and once that is confirmed, can proceed and receive the rest of the data.

CANIF_Example4_Reception_single_PDU_single_Hrh_ID_0x1EF.png

Hardware board receives (Rx) every second an 8-byte single message with ID 0x010 and specified Data payload: 32 08 07 06 05 04 03 02. Savvy CAN transmits (Tx) the data. Notice how in code we can establish a condition, in this case where the first byte must be 0x32 and once that is confirmed, can proceed and receive the rest of the data.

CANIF_Example4_Reception_single_PDU_single_Hrh_ID_0x010.png