Вы находитесь на странице: 1из 319

GETTING STARTED WITH

AUTOSAR MCAL
“HELLO WORLD” LEVEL EXAMPLES
STEVE MIHALIK
AND NXP AUTOSAR SUPPORT TEAM
REV JUNE 05 2019 – WORK IN PROGRESS

PUBLIC
Contents
Introduction
Installation
1. Get AUTOSAR installation SW to your NXP account
2. Download MCAL / OS installation SW from your NXP account
3. Download, install / renew Tresos license with (3A) activation code or (3B) license file
4. Download, install make utility
5. Install MCAL (and/or OS)
6. Sample application installation & configuration
7. Additional SW: Compiler, Java
8. Patches and Hot Fixes
Examples
1. Sample Ap – duplicate, import, generate, build MCAL sample application
2. Minimal Ap (Hello World) - Create subset project from Sample Ap project
3. Minimal Ap modified - changes to use different chip derivative
4. Port module – Add port pin configurations (as GPIO) to Minimal Ap project
5. Dio module - Add Digital I/O capability to control GPIO to Port project
6. Gpt module - Add General Purpose Timer capability using RTC to Minimal Ap project
7. Interrupt Ap - Add Interrupt capability to Gpt Ap
8. Standby Ap - Add low power capability to Gpt Ap project – incomplete write up
Appendix: Debugging, MPC574xG Memory Configurations
1 PUBLIC
INTRODUCTION

2 PUBLIC
You should Readme!
• This document is for those getting started with NXP AUTOSAR MCAL drivers. Although most
examples are based on MPC574xG devices, the process is the same for all devices. Users may be
able to use these instructions with other devices not documented here.

• Instructions are provided to obtain and install necessary software components for a few different
device families. Other devices will have a similar process.

• Exercises start with building the MCAL Sample Application included with MCAL releases. This is
then used as a basis for subsequent exercises.

• Some variations exist for different versions:


− Tresos: There are a few cases where an element may be located in a different location, so a little
searching may be needed. Newer MCAL versions may have new features that now appear in Tresos.
− Devices: Architecture among chip families, for example interrupts on S32K and MPC5xxx devices,
result in implementation variations as documented for current examples.
− Sample Applications: Early versions are called “Classic”; subsequent are called “Framework” as noted

3 PUBLIC
MCAL Exercise Sequence
Sample Application
Example 4: Port Example 5: Dio
(shipped with product)

Example 1: Sample Ap
Example 6: Gpt Example 7: IRQ
(copy, rename, build)
(with Mcu, Mcl)

Example 2: Minimal Ap Example 8: STANDBY


(reduced Sample Ap)

Select example 2 or 3 to use for


Example 3: Minimal Ap
examples 4 and 6 based on
with different derivative
intended target’s chip derivative
4 PUBLIC
Sample Application Versions
• Starting with MCAL 4.2 or MCAL 4.3, a different sample application is provided
that, although more complex, is closer to expected customer use cases.
• This document provides examples for both versions using names:
− Original sample application: “Classic Sample Ap”
− Newer sample application: “Framework Sample Ap”
Device (partial list) Classic Sample Ap Framework Sample Ap Tested compilers*
MPC574XG MCAL 4.2 and earlier MCAL 4.3 and later GHS, Diab
MPC5777C MCAL 4.0 GHS, Diab
S32K1xx MCAL 4.2 RTM 1.0.0 & earlier MCAL 4.2 RTM 1.0.1 & later IAR, GHS, GCC

* Tested compilers are those tested at NXP when developing MCALs.


Compilers used in examples are a subset.

5 PUBLIC
NXP AUTOSAR Licensing Summary rev. Sept 07 2018
Feature Eval- DISM Expired Produc-
uation tion4
MCAL, Latest updates1 for that version put in your NXP account Yes Yes No No
OS Installation license for your current or new PC Yes Yes No Yes
Generated code can be used by application code Yes Yes Yes Yes
Tresos Version used for testing is in your account Yes Yes Yes but2 Yes
A use license3 is put in your account (renewed quarterly) Yes Yes No Yes
Generated code’s configuration can be modified Yes Yes No Yes
Support On-line support No Yes No No

1 Updates include Hot Fixes & RTM releases for that version. New AUTOSAR versions, e.g., 4.2 to 4.3, require additional license
2 You can still download Tresos from your account but not use it due to expired license.

3 Notes: 1.) Tresos license only works with NXP products.


2.) Tresos license for versions 17.0 or later is an “activation code”; earlier versions is a “license file”.
3.) Tresos renewals are not done after evaluation licenses expire
4 Production licenses for licensed version do not expire

6 PUBLIC
Free of charge NXP AUTOSAR software rev. April 19 2019
• Free of charge AUTOSAR SW applies to all S12, MPC57xx & MPC56xx devices
except the new MPC5777C release for MCAL 4.3
• Software versions and download links are located at bottom on the webpage
www.nxp.com/autosar
• 4 year unrestricted license is granted:
− No restrictions for evaluation, development or production use
− No support and maintenance is provided including hotfixes
 Exception for a limited time: MPC574xG MCAL 4.3 (DISM available for this new release)
− After4 years a new 4 license may be available.
− Currently Tresos licenses still need to be updated from your account at end of each
quarter
• No new AUTOSAR versions or releases are planned for devices with free of
charge MCAL software on the NXP website.

7 PUBLIC
1. GET AUTOSAR
INSTALLATION SW
TO YOUR NXP
ACCOUNT
8 PUBLIC
1A. GET AUTOSAR
INSTALLATION SW
FROM WEB TO YOUR
NXP ACCOUNT
9 PUBLIC
Get AUTOSAR installation SW from web to your account 1

• Go to nxp.com Click on desired product*.


Example: MPC5748G:

1. Click on PRODUCTS

2. Click on POWER ARCH….

3. Click on MPC5xxx/55xx 32-bit MCUs

*Note The ISO26262 MCAL version is


developed according the SEooC requirements
of ISO26262. NXP supplies a FMEA and a
Safety Manual for this MCAL. The Safety
Manual will state the MCAL’s ASIL level.
10 PUBLIC
Get AUTOSAR installation SW from web to your account 2
• Click on MPC57xx

11 PUBLIC
Get AUTOSAR installation SW from web to your account 3
• Scroll down on next page

• Click MPC574xB-C-B

• Click on Software & Tools

12 PUBLIC
Get AUTOSAR installation SW from web to your account 4
1. Scroll down to AUTOSAR and
click on desired Download

2. Sign in with name and password


− If you do not have an account, register
 NXP & new employees use NXP ID and NXP password
 (Legacy Freescale employees use core ID and oneIT password)
3. Select desired product. Depending on product age, a
registration code may be needed to add installation software
to your account. Contact local sales office if needed.

13 PUBLIC
1B. GET AUTOSAR
INSTALLATION SW
FROM NXP SW
MARKETING TO
14
YOUR NXP ACCOUNT
PUBLIC
Get AUTOSAR installation SW from marketing to your account
• Some new version of MCAL, OS are not on the NXP public web site
• Customers can request these newer versions by:
− Create an account a nxp.com if they do not have one:
 Go to www.nxp.com
 Click on ACCOUNT in upper right corner
 Click on REGISTER and fill in the fields
− Provide their name(s), project, requested software (version and chip) to the local sales
office
− The sales representative will forward the request to NXP software marketing.
− Whenapproved, a registration code will be provided to customer(s). A code is good for
one PC.

15 PUBLIC
2. DOWNLOAD MCAL
/ OS INSTALLATION
FROM YOUR NXP
ACCOUNT
16 PUBLIC
Download installation SW from your NXP account 1

• Sign in to your account at nxp.com


• Click on drop-down arrow next to
your name, then click on “MY
ACCOUNT”

• Click “Software Licensing and


Support”
• NOTE: customers usually need a
unique registration code to
download a software product

17 PUBLIC
Download installation SW from your NXP account 2

• Click on desired category (the first


time you will have only one category)
− Example:
Automotive SW – Autosar MCAL

18 PUBLIC
Download installation SW from your NXP account 3

• Click in software you want to download


− Example:
Automotive SW – Autosar MCAL

• Note: Register button is for customers


to enter registration code

19 PUBLIC
Download installation SW from your NXP account 4
• Click on desired version. Examples – MCAL 4.0, MCAL 4.3:

20 PUBLIC
Download installation SW from your NXP account 5

• Click on I Agree to SW terms and


conditions

21 PUBLIC
Download installation SW from your NXP account 6
• Check boxes for
software to download
− Examples: MCAL4.0,
MCAL 4.3
• Click Download
Selected Files
• Note: some versions
have “hot fixes” to
enhance a version.
Hot fixes are
cumulative – only
need to install the last
one after installing the
released SW. See
hotfix’s release notes
to see if there is any
impact to your
application.
22 PUBLIC
Download installation SW from your NXP account 7
• Select folder (create if needed) to download
installation software and click OK.
This folder can be anywhere, e.g., when you
later run the install software, you can choose
a path for the actual software package.

• Download progress is shown

• Close window when download completes.

23 PUBLIC
Download AUTOSAR OS if needed
• If you also received a license code for the OS, follow the same steps to download
the OS

• NOTE: You must install TRESOS before MCAL or OS!!

• You must find the Tresos version needed for your MCAL or OS. See release
notes for MCAL or OS. Search for Tresos.

24 PUBLIC
3. DOWNLOAD,
INSTALL / RENEW
TRESOS

25 PUBLIC
Tresos Versions
• The Tresos version used for testing an MCAL version is put in your NXP
Account with your requested MCAL version.
• To determine or verify what Tresos version an MCAL used, search for
“Tresos” in MCAL’s or OS’s Release notes. (Normally higher number versions
will work fine.)
− Example from MCAL 4.0 release notes:

• INSTALLATION TIP: When installing Tresos,


include the version number in the Tresos folder name.
This prevents confusion when another Tresos version
is installed for a different MCAL version. Example:

26 PUBLIC
Tresos Licensing: License File vs Activation Code
• Tresos version requirements:
− Tresos versions before 17.0.0 require Tresos license files –for older MCALs
− Tresos versions 17.0.0 & after require Tresos activation codes –for newer MCALs
− Examples: Tresos Version Requirement MCAL Version
14.2.1 License File MPC574xG MCAL 4.0
20.1.0 Activation Code MPC5777C MCAL 4.0
21.0 Activation Code MPC574xG MCAL 4.2
23.0 Activation Code S32K14x MCAL 4.2
24.0 Activation Code MPC574xG MCAL 4.3
S32K14x MCAL 4.3

• Tresos license & activation codes are good for one calendar quarter (3 months)
• If you have a valid license in your account, a new license file or activation code is
automatically added to your account by the end of the quarter
27 PUBLIC
3A. DOWNLOAD,
INSTALL / RENEW
TRESOS WITH
ACTIVATION CODE
(VERSIONS 17 & AFTER)
28 PUBLIC
Install Tresos – Versions 17.0.0 and after (1 of 5)
• Go to Product Download for Tresos (example v21.0.0):
− Sign in to your account at nxp.com
− Click the following: Software Licensing and Support
 Autosar SW – Autosar MCAL
 Autosar SW – Elektrobit Tresos Studio / Autosar
Configuration Tool
 AUTOSAR Tresos Studio 21.0.0
 I agree
• Select all files and download to any folder.
Be sure to use “Download Selected Files” which uses the
Download Manager or else files will be compressed in the
wrong format.
− Note:A “host error” may appear with some firewalls when using
the Download Manager. If that happens:
 Download files just with browser to a folder
 Unzip all .uip files
 Add .uip extension to the unzipped .uip files
 Run setup.exe
29 PUBLIC
Install Tresos – Versions 17.0.0 and after (2 of 5)
• Note the activation code will be
needed in subsequent steps
− Codes are updated every 3 months.
− See “Files” tab of Product Download in
your account.
− Copy and paste Tresos activation code
to some temporary location for use
later.

30 PUBLIC
Install Tresos – Versions 17.0.0 and after (3 of 5)

• Run setup.exe from the


downloaded folder

• Choose unique folder


(Tip: include Tresos
version # in the name)

• Click Install

31 PUBLIC
Install Tresos – Versions 17.0.0 and after (4 of 5)
• If EB Client License Administrator is
not already on your PC, install it.
− Look for the program in the Windows
program menu.
− To install, start the EB Client
Administrator setup program from your
downloaded folder.

• Start EB Client Administrator program


from Start menu

• If necessary, click Next to get thru


dialog boxes until you get to FlexLM
License information
− Click Use License Activation Codes
− Click Next

32 PUBLIC
Install Tresos – Versions 17.0.0 and after (5 of 5)

• You will be prompted for one


of the following dialog boxes:
− Click Install
or
− EnterTresos activation code
(stored earlier; see slide 2 of 5)
− Click Activate (You must be on
line to activate

Tresos is now activated

33 PUBLIC
Tresos Activation Code Renewal 1 (For versions 17.0.0 and after)
• Every 3 months the Tresos activation codes expire
• Customers with an active MCAL license (such as DISM or
evaluation), will automatically get a new activation code in
their account.
• Obtaining new Tresos activation code (for Tresos 17.0.0 or
later):
1. Go to Tresos in your nxp account:
− Sign in to your account at nxp.com
− Click the following: Software Licensing and Support
 Autosar SW – Autosar MCAL
 Autosar SW – Elektrobit Tresos Studio / Autosar
Configuration Tool

2. Select the Tresos version for your MCAL or OS. Example:

34 PUBLIC
Tresos Activation Code Renewal 2 (For versions 17.0.0 and after)
3. Agree to SW terms and conditions.

4. Copy activation code

35 PUBLIC
Tresos Activation Code Renewal 3 (For versions 17.0.0 and after)
5. From the Windows start menu, start EB Client
License Administrator

36 PUBLIC
Tresos Activation Code Renewal 4 (For versions 17.0.0 and after)

6. In the dialog box:


− (For
expired licenses, select
and click Return)
− Enter(paste) the new Tresos
activation code.
(Note: you must be on line to
activate.)
− Click Activate

Tresos is now activated

37 PUBLIC
3B. DOWNLOAD,
INSTALL / RENEW
TRESOS WITH
LICENSE FILE
(VERSIONS BEFORE 17)
38 PUBLIC
Install Tresos – Versions before 17.0.0 (1 of 4)
• Go to Product Download for Tresos:
− Sign in to your account at nxp.com
− Click the following: Software Licensing and Support
 Autosar SW – Autosar MCAL
 Autosar SW – Elektrobit Tresos Studio / Autosar Configuration Tool
 AUTOSAR Tresos Studio 14.2.1
 I agree
• Select all files and download to any folder.
Be sure to use “Download Selected Files” which uses the Download
Manager or else files will be compressed in the wrong format.
− Note: A “host error” may appear with some firewalls when using the
Download Manager. If that happens:
 Download files just with browser to a folder
 Unzip all .uip files
 Add .uip extension to the unzipped .uip files
 Run setup.exe
− Versions before 17.0.0: also download license
(versions 17.0.0 and later use activation codes)

39 PUBLIC
Install Tresos – Versions before 17.0.0 (2 of 4)
• Unzip the downloaded Tresos file

• Run setup.exe

• Choose unique folder

• Click Install
40 PUBLIC
Install Tresos – Versions before 17.0.0 (3 of 4)
• Start Tresos
• First time: a workspace needs
to be created.
− Click Yes.
• Close Welcome screen
• After several seconds, the
License Information window
appears
− Click Licenses..

• Click “+”
41 PUBLIC
Install Tresos – Versions before 17.0.0 (4 of 4)
• Navigate to where you downloaded the
Tresos license file (probably with other
Tresos installation files from your
account
• Select license file
• Click Open
• Click OK

42 PUBLIC
License File Renewal 1 – Tresos versions before 17.0.0
• Every 3 months the Tresos license file expires
• Customers with an active MCAL license (such as
DISM or evaluation), will automatically get a new
license file in their account.
• Obtaining new Tresos license:
− Sign in to your account at nxp.com
− Click the following: Software Licensing and Support
 Autosar SW – Autosar MCAL
 Autosar SW – Elektrobit Tresos Studio / Autosar
Configuration Tool

− Download the most recent license to a file

43 PUBLIC
License File Renewal 2 – Tresos versions before 17.0.0

• Start Tresos
• Go to Help – Licenses
• Click on green “+” to add a licnes
• Navigate to downloaded license
• Click OK

44 PUBLIC
4. DOWNLOAD,
INSTALL MAKE
UTILITY
45 PUBLIC
Make from GnuWin32 1
• Go to https://sourceforge.net/projects/getgnuwin32/files/

• Note – screenshots are done with


Windows 7. Windows 10 may differ.

• Click on getgnuwin32

46 PUBLIC
Make from GnuWin32 2
• Click on the recent version

47 PUBLIC
Make from GnuWin32 3

• Click on version to download


• Wait for download to complete

48 PUBLIC
Make from GnuWin32 4
• Go to your download file and double click
on it to start installation

• Click Accept

49 PUBLIC
Make from GnuWin32 5

• If desired, change GetGnuWin subfolder location. (Steve’s default folder is shown)

• Click Install
• A subfolder is
created called
GetGnuWin32

50 PUBLIC
Make from GnuWin32 6

• Follow instructions to complete installation as shown on the following


slides

51 PUBLIC
Make from GnuWin32 7

• Change directory to the subfolder created in your download folder

52 PUBLIC
Make from GnuWin32 8

• Run “download”

53 PUBLIC
Make from GnuWin32 9

• Run install command with proper path (default shown is fine)

54 PUBLIC
Make from GnuWin32 10
• During installation you may get a message that utilities are outdated, and given the
opportunity to update.
− IMPORTANT: Hit return for every prompt --
anything else may cancel installation

• The make utilities by default will be in:


C:\gnuwin32\bin

55 PUBLIC
5. INSTALL MCAL
(AND/OR) OS

56 PUBLIC
Install MCAL or OS Software 1
• If you plan to use MCAL, just install MCAL.
− If you also plan to use OS, then install OS also.
• Double click on the installation SW that you downloaded.
− Example organization of download
folders

• Note: some versions have an


installation for MCAL and an
installation for the MCAL sample
application. Both need to be
installed.

57 PUBLIC
Install MCAL (or OS Software) 2

• Click Next

• Agree to License
Agreement and
click Next

58 PUBLIC
Install MCAL or OS Software 3
• A license file is needed.
Go back to Product
Download Page and click
on License Keys tab.
(If logged off, go to nxp.com & sign
in ACCOUNT, then click, e.g.:
Software Support and Licensing 
Automotive SW – Autosar MCAL
Automotive SW – Autosar MCAL
SW574xG-MCAL401-RTMC_SR
1.0.4  I agree)
• Click on License Keys tab

59 PUBLIC
Install MCAL or OS Software 4
• If more than one license is shown,
find the one that shows an expiration
date that is in the future by checking
the displayed Expiration Date after
generating. Example:
− Click on one license check box
− Click on Generate
− Viewexpiration date (licenses cannot
be generated after expiration date!)

60 PUBLIC
Install MCAL or OS Software 5
• Click “Save All”

• Save generated license to a file. Suggestions:


− Providea common license folder. Example
C:/NXP/AUTOSAR/licenses
− Choose a name with identification and .dat extension.
Example:
license_MPC574xG_MCAL4_3.dat

61 PUBLIC
Install MCAL or OS Software 5

• Go back to the MCAL installation


program and click on the navigate
button to locate your license file

• Select your license file

• Click on “Open”

62 PUBLIC
Install MCAL or OS Software 6
• Click Next

• Click Next to install


selected
components

• Chose destination
folder (default
shown) and click
Next

63 PUBLIC
MCAL Installation only – specify path 7a
• EB Tresos install
directory: Click to
location where Tresos is
installed
• Select proper Tresos
directory (If you have
multiple“Tresos”
folders, select the
right one!)
• Click OK
• Click Install
• When done, click Finish

64 PUBLIC
OS Installation only – specify paths 7b

• Browse to and specify


required paths. Example:
• GHS 201416 is
recommended (it was
validated with this version)
• Cygwin is required if using
OS Sample Application
from OS installation
• Tresos path is mandatory

• Click Install
• Click Finish when done

65 PUBLIC
AUTOSAR OS
• If the OS is to be installed, repeat prior installation steps for OS

66 PUBLIC
6. SAMPLE
APPLICATION
INSTALLATION &
CONFIGURATION
67 PUBLIC
Installation (Framework Sample Application step only)
• The downloaded software has a separate sample application installation;
repeat prior installation steps for it
− Example of separate installation:

• Example of completed
installation of MCAL and
sample application.
− Note Tresos workspaces
for different chip versions

68 PUBLIC
Copy sample application plugins (Framework Sample Application step only)

• Copy IntegrationFramework plugin folder


from the sample application’s eclipse/plugins
folder

to NXP MCAL’s eclipse/plugins folder

69 PUBLIC
launch.bat 1 - Introduction
The sample application includes a batch file to build the application that must be
modified for your paths.
• Locate launch.bat (see next slide slide)
• Make a backup copy of the original launch.bat
• Open launch.bat with an editor.
• Modify path names for your PC (see examples)

70 PUBLIC
launch.bat 2 – locate it for your sample application
“Framework Sample Application”
“Classic Sample Application”

Compiled output
Documentation
Chip header files
launch.bat
Application code Compiled output

launch.bat
Chip header files
Application code
Documentation

71 PUBLIC
launch.bat 3A – Classic Sample Application launch.bat example
::TRESOS
SET TRESOS_DIR=C:\EB\tresos14_2_1
::GHS (recommend comp_201416 since MCAL and OS ver 4.0 were tested with it)
SET GHS_DIR=C:\ghs\comp_201714 Tip: if copying path names from a
::DIAB Different application, like PowerPoint,
Be sure there are not any extra spaces
::SET DIAB_DIR=C:/Tools/WindRiver/diab/5.9.4.8 At the end of the paths!
::Path to the plugins folder
SET PLUGINS_DIR=C:\NXP\AUTOSAR\MPC574XG_MCAL4_0_RTM_1_0_4\eclipse\plugins
SET MAKE_DIR=C:\gnuwin32
::SSC is required when OS is used
::SSC can still be defined if OS is not installed or not defined at all
SET SSC_ROOT=C:\NXP\AUTOSAR\MPC574xG_AUTOSAR_OS_4_0_92_RTM_1_0_3

72 PUBLIC
launch.bat 3B – Framework Sample Application launch.bat example
• Example launch.bat with modified path names and using Green Hills compiler:
::TRESOS
Tip: if copying path names from a
SET TRESOS_DIR=C:\EB\tresos24_0_0
Different application, like PowerPoint,
::GHS Be sure there are not any extra spaces
SET GHS_DIR=C:\ghs\comp_201754 At the end of the paths!
::DIAB
::SET DIAB_DIR=C:/Tools/WindRiver/diab/5.9.4.8
::SET LINARO_DIR
SET PLUGINS_DIR=C:\NXP\AUTOSAR\MPC574XG_MCAL4_3_RTM_1_0_0\eclipse\plugins
SET MAKE_DIR=C:\gnuwin32
::SSC is required when OS is used
::SSC can still be defined if OS is not installed or not defined at all
SET SSC_ROOT=C:\NXP\AUTOSAR\MPC574xG_AUTOSAR_OS_4_0_92_RTM_1_0_3
SET TRESOS_WORKSPACE_DIR= C:\EB\tresos24_0_0\workspace\MPC574XG_MCAL4_3_RTM_1_0_0_Sample_Ap\output

Note: this folder name will change for each Tresos project which started.
73
With Framework sample aps. For initial path name , include your chip, MCAL version
PUBLIC
Launch.bat 4 – Add “pause” command to end of file
• TIP: Add a pause command at the very end of the launch.bat file:

− Now when you can use launch.bat by double clicking on it from a Windows browser. The
batch file executes but after completion it does not automatically immediately exit back to
windows. The pause command allows you to see if the make file worked or had errors.

74 PUBLIC
Changes if using NXP S32 Design Studio
launch.bat changes:
• Change MAKE_DIR path:
SET MAKE_DIR=c:\NXP\S32DS_ARM_v2018.R1\utils\msys32\usr
• Change compiler path:
SET LINARO_DIR=C:\NXP\S32DS_ARM_v2018.R1\Cross_Tools\gcc-6.3-arm32-eabi
make\linaro\build_cfg.mak changes:
• Make a backup copy of build_cfg.mak
• Modify make\linaro\build_cfg.mak file by adding the last LDOPT line (in red):
LDOPT := -mcpu=cortex-m4 \
-msoft-float \
-mthumb \
-e _start \
-nostartfiles -static -lc -lm -lgcc -lnosys \
--sysroot=$(LINARO_DIR)/arm-none-eabi/newlib

75 PUBLIC
7. ADDITIONAL SW:
COMPILER, JAVA

76 PUBLIC
Compiler for MCAL, OS
• NXP’s MCAL and OS products are tested using multiple compilers.
− See the release notes for versions.

• Examples in this presentation are based on MPC574xG MCAL & OS version 4.0.3
using Green Hills Software compiler version 201416.
− Later versions have not been known to be a problem.

• Obtain and install the compiler if you have not done so.

77 PUBLIC
OS installation only: Java
• If using Autosar OS, a Java version 1.6 or higher is required for the Autosar OS system
generator
− Usually it is already installed in windows
• To determine if Java is installed and the version, go to the DOS command prompt and
enter: java –version
− Example:

• If you do not have version 1.6 or higher, it can be obtained at


https://java.com/en/download/
− Caution:sometimes installing a new Java version can affect other programs!
Suggest not installing it if AUTOSAR OS is not needed.

78 PUBLIC
8. PATCHES AND HOT
FIXES

79 PUBLIC
Patches
• A patch contains one or more full MCAL Modules, having implemented bug fixes or new
features requested by customer, when the customer needs the updates sooner than the next
official release (EAR, Beta or RTM) is planned.
• Patch Releases are not fully qualified and are not intended for production, they must be
replaced by the next qualified standard release.
• The reported problems are not blocking issues for customers (these are in scope for hot-fix
process.)
• Patch changed items are identified by a specific ticket number as listed in the Release Notes
included with the software. Example:
Ticket numbers

• Patches are cumulative; that is, new ones include all earlier patches
• Recommendation: CHECK RELEASE NOTES. Prior patches and even original installation
may need to be removed before using patch in Tresos.
− This
minimizes risk of Tresos using an older MCAL version due to old link in Tresos links folder
which could cause build errors.

80 PUBLIC
Hot Fixes
• The intention of a Hot Fix Release is immediate fix of a critical and blocking issue at the
customer.
• Hot Fix releases are not fully qualified and are not intended for production; they must be
replaced by the next qualified standard release.
• Hot Fix releases are delivered at customer request and do not undergo full testing, but
changed functionalities are tested.
• Hot Fix changed items are identified by a specific ticket number as listed in the Release
Notes included with the software. Example:

Ticket number
• Hot fixes are cumulative; that is, new ones include all earlier hot fixes
• Hot Fix vs Patch: Hot fixes are to be applied to prior released version, not to patches
EXCEPT if identified in the Hot Fix. Example: HF1_P4_1_0_1 would apply to Patch 4.
• Recommendation: install hot fixes if your application requires them. If installing hot
fixes, prior hot fix and even original release can be removed, or just renamed (renaming
for archival purpose.)

81 PUBLIC
EXAMPLE 1:
SAMPLE AP -
DUPLICATE, IMPORT,
GENERATE, BUILD
82 PUBLIC
Sample Application introduction
• Summary: Go through the common project workflow steps using a copy provided
sample application.
− Slightworkflow differences exist as documented in the examples for the Classic Sample
Application and newer Framework Sample application.
− Project build steps vary by compiler.
• Example overview:
− Duplicate the Sample Application provided with NXP MCAL drivers
− Tresos: Import and rename project. Generate
− Application code: Build using Tresos output and provided project code
• Architectures tested and differences are noted for:
− MPC574xG (with GHS compiler)
− S32K14x (with gcc compiler)

83 PUBLIC
Workflow: Example 1 Sample Ap
This workflow is suggested for starting with MCAL projects and shown in following slides.
1. Tresos:
1. Close any previous projects (reduces risk of configuring module of wrong project)
2. Import the existing Tresos project to be used to start project*
3. Rename Tresos project *
4. Load project’s configuration
5. Sanity check: Generate and ensure no errors
6. Modify as desired (not done in this first example)
7. Generate
* First time only
2. Windows:
1. Duplicate & rename application folder to be used to start example*
2. Tresos output files (.c and .h):
1. Classic Sample Ap: Copy Tresos output files to application’s folder used for build
2. Framework Sample Ap: Update launch.bat’s Tresos workspace path *
3. Modify application code as desired (not done in this first example)
4. Build

84 PUBLIC
TRESOS
EXAMPLE 1 – SAMPLE AP

85 PUBLIC
Import Sample Application into Tresos - 1
1. Start Tresos. Use 64 bit if there is an option and you have Windows 64 bit. (First time: click yes to
create workspace directory). Click:
File - Import - General - Existing Projects into Workspace -> Click Next
2. First time: Check “Copy” box to copy workspace from NXP folder to EB folder.)
3. Browse to root directory for each Classic or Framework’s Sample Application:
3A. Classic Sample Application: Go to sample application’s Tresos folder. Example:
C:\NXP\AUTOSAR\MPC574XG_MCAL4_2_RTM_1_0_0\ MPC5746C_RTM_1_0_0_Sample_Ap\Tresos

MM

86 PUBLIC
Import Sample Application into Tresos - 2

3B. Framework Sample Application: go to sample ap Tresos Workspace folder’s project. Example:
C:\NXP\AUTOSAR\MPC574XG_MCAL4_3_RTM_1_0_0\MPC5748G_MCAL4_3_RTM_1_0_0_sample_ap
\Tresos\Workspace\lighting_MPC5748G_4.3
4. Click on project then click OK

87 PUBLIC
Import Sample Application into Tresos - 3

6. First time: Check “Copy” to EB folder if


not checked already.

7. Click OK -> Click Finish

Note: If project is greyed out, there is


already a project with that name in the EB
workspace folder! Names must be unique!

88 PUBLIC
Rename Tresos Project
• Right click on project – Rename

• Enter new name. Examples:


− Classic Sample Application-
MPC5746C_MCAL4_2_RTM_1_0_0_Sample_Ap
− Framework Sample Application-
Note- this must match the name in your launch.bat file:

MPC5746C_MCAL4_3_RTM_1_0_0_Sample_Ap

• Click OK

89 PUBLIC
Load Sample Application Project Configuration

Right click
on project

-> select Load Configuration


(there should not be errors)

-> click OK

-> click to expand project to see its modules

90 PUBLIC
Framework Sample Ap only – potential error on initial version
• If code generation gives a message of an invalid license even
though there is a valid license, this is a bug.

• License workaround
− Right click ECUC
− Select Module configurations..
− Uncheck generate for IntegrationFramework
− Click OK

• New Crypto files are required for building. Contact


NXP to get these files.
− Files are to be unzipped and copied into folder:
c:\NXP\AUTOSAR\MPC574XG_MCAL4_3_RTM_1_0_0\
eclipse\plugins\IntegrationFramework_TS_T2D35M10I0R0\
META-INF
− After copying files, be sure to re check the Generate box

• Restart Tresos after doing above


91 PUBLIC
Generate project
Right Click on configuration (under project name) and select Generate
Project

Click OK when done


92 PUBLIC
Locate generated Tresos output files (Used with drivers, code in build)

1. Right click on project

2. Select properties

3. Select Resource,
& note Location

93 PUBLIC
WINDOWS
EXAMPLE 1 – SAMPLE AP

94 PUBLIC
Duplicate & Rename Sample Application
• Copy the sample application folder.
• Paste
• Rename.
 include part number in projects
to avoid confusion, or include the
memory size such as “3M”
to indicate 3MB flash.
 Examples:
MPC5746C_MCAL4_2_RTM_1_0_0_Sample_Ap
- or -

95 PUBLIC
Update application with Tresos generated files
• Classic Sample Ap only:
− Copyinclude & src folders from the EB Tresos
generated folder location:

− Deleteprior folders then paste copied folders


into application’s cfg folder (not tresos folder)
(May need to create cfg folder in application folder)

• Framework Sample Ap – first time only:


− Update launch.bat’s TRESOS_WORKSPACE_DIR
with Tresos project’s output path

96 PUBLIC
Build MCAL project - using default tools
• Build: Double click on launch.bat file in your
application folder from Windows explorer:

Classic Sample Application: example path:


C:\NXP\AUTOSAR\MPC574XG_MCAL4_2_RTM_
1_0_0\MPC5746C_MCAL4_2_RTM_1_0_0_Samp
le_Ap
Framework Sample Application example path:

• Note: If build aborts at adc.c (1st module in list), then the


compiler path may be the problem. Verify the path in
launch.bat. Make sure your compiler license is valid too.

97 PUBLIC
Build MCAL project - using gcc-like tools
• If building with gcc like tools such as NXP’s S32 Design Studio, build options must
be specified either:
− fromthe command prompt or
− making a new batch file containing the build command and options
• Note: order options like MODE, TOOLCHAIN is important!
• Command prompt build example:
− From prompt enter
launch.bat MODE=USER TOOLCHAIN=linaro
• Batch file build example:
− Createnew batch file with name like launch_linaro.bat that contains
launch.bat MODE=USER TOOLCHAIN=linaro
− From Windows Explorer, double lick on launch_linaro.bat

98 PUBLIC
Build MCAL project - inside S32 Design Studio (S32K14x example)
• MCAL sample application is a makefile project. To build it inside S32 Design Studio perform the following steps:
1. Open S32 Design Studio
2. In Menu, select File->New->Makefile project with Existing code
3. Fill in “Project Name” as S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application
4. Set “Existing Code Location” to point to the MCAL sample application folder
5. Click Finish -> now the MCAL sample application can be seen in Project Explorer in S32 Design Studio
6. Right click on the project “S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application” and select “Properties”
7. Select C/C++ Build
1. On “Builder Settings” tab, uncheck checkbox “Use default build command” and write this text:
launch.bat or launch.bat TOOLS=LINARO etc???
into the “Build command” edit box (use launch.bat OS if you want to build with OS)
2. On “Builder Settings” tab, modify the Build location to be as follows (pointing to the build folder):
${ProjDirPath}/eclipse/plugins/IntegrationFramework_TS_T40D2M10I1R0/auxiliary/build
What is the folder to be used for the classic sample application (non Framework)?
3. On “Behavior “ tab, in “Build (Incremental build)” edit box, write this text:
TOOLCHAIN=linaro MODE=SUPR DERIV=144 (or TOOLCHAIN=ghs/iar if you use GHS/IAR compiler)
8. Click ok
9. Now you can build the project inside design studio by right clicking on the MCAL sample project and selecting
“Build Project”

99 PUBLIC
Downloading sample ap – using S32 Design Studio

• To debug MCAL sample application from S32 Design Studio update the project created as per
the previous slide as follows:
1. Right click on the project “S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application”
2. Click on Debug As->Debug Configurations…
3. Double click on “GDB PEMicro Interface Debugging” – this will create the launch
configuration with name “S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application Default”
4. In the “Main” tab, in the “C/C++ Application” write the text: bin/sample_app_mcal.elf to select
the executable file to be loaded to the evaluation board
5. In the “Debugger” tab select:
Interface: USB Multilink, USB Multilink FX, Embedded OSBDM/OSJTAG – USB Port
Select Device: Vendor: NXP, Family: S32K1xx Target:S32K144F512M15
Core: M4
Executable:
${S32DS_ARM32_TOOLCHAIN_DIR}/bin/${arm32_cross_prefix}gdb${arm32_cross_suffix}
6. Click Apply and Debug to start debugging

100 PUBLIC
Method to clean project
• In the project’s bin directory, select all files except if there are debugger files
like run.cmm or any other .cmm file and then delete those selected files.
Example:

• If you do a clean of the project, be sure to rebuild by executing launch.bat to


prepare for the next exercise, download and debug.
101 PUBLIC
EXAMPLE 2:
HELLO WORLD
MINIMAL
APPLICATION
102 PUBLIC
Hello World minimal application introduction
• Summary: create a minimal application from the prior sample ap project.
− This will be be a “hello world” project base for subsequent project(s)

• Example Overview:
− Duplicate the sample project
− Tresos: Import project workspace, rename it, remove unneeded elements
− Application code: Replace main function with minimal code, remove unneeded elements

• Architectures tested and differences are noted for:


− MPC574xG (with GHS compiler)
− S32K14x (with gcc compiler)

103 PUBLIC
Workflow: Example 2 Minimal Ap
This workflow is suggested for starting with MCAL projects and shown in following slides.
1. Tresos:
1. Close any previous projects (reduces risk of configuring module of wrong project)
2. Import prior Tresos project to be used to start example*
3. Rename Tresos project to same name as application’s folder*
4. Load project’s configuration
5. Sanity check: Generate and ensure no errors
6. Modify configurations (disable generation of unneeded modules)
7. Generate
* First time only
2. Windows:
1. Duplicate & rename an application folder to be used to start example*
2. Tresos output files (.c and .h):
1. Classic Sample Ap: Copy Tresos output files to application’s folder used for build
2. Framework Sample Ap: Update launch.bat’s Tresos workspace path *
3. Modify application code as desired (simplify main & removed unused elements)
4. Clean & Build

104 PUBLIC
TRESOS
EXAMPLE 2 – MINIMAL AP

105 PUBLIC
Copy and rename prior Tresos project
1. Start Tresos – be sure to use the right version for your MCAL.
Use 64 bit if there is an option and you have Windows 64 bit.
2. Tip: Close any prior projects that are open to minimize confusion.
3. Double click on prior project, Sample Ap, to ensure it is open.
4. Right click on project – Copy

5. Right click in Project Explorer window – Paste

6. Rename project to minimal_ap. Example:


MPC574xG_MCAL4_2_RTM_1_0_0_minimal_ap_3M

106 PUBLIC
Load project
• Double click on project

• Project is loaded, and there should not


be errors

• Click OK

107 PUBLIC
Disable generating unneeded Tresos configurations – Classic Sample Ap

Modules not used in the minimal project


must be disabled.
• Right click on project
• Select Module Configurations…
• In Module configurations window,
disable Enable & Generation except for:
− Base
− Det(MCAL 4.0)
− Dem
− EcuM
− Mcu
− Resource
• Click OK
108 PUBLIC
Tresos - Generate code to verify no errors
• Make sure project is selected and
click on Generate code button

• Code generates:

• Click OK when done

109 PUBLIC
WINDOWS
EXAMPLE 2 – MINIMAL AP

110 PUBLIC
Duplicate & Rename Application
• In Windows, make a copy of desired
application folder

• Give it a new name, such as


MPC574xG_MCAL4_2_RTM_1_0_0_minimal_ap_3M

111 PUBLIC
Update application with Tresos generated files
• Classic Sample Ap only:
− Copy include & src folders from the EB Tresos
generated folder location:

− Delete prior folders then paste copied folders


into application’s cfg folder (not tresos folder)
(May need to create cfg folder in application folder)

• Framework Sample Ap – first time only:


− Update launch.bat’s TRESOS_WORKSPACE_DIR
with Tresos project’s output path

112 PUBLIC
Verify application src, include folders from Tresos
• Folders should only have files shown below

113 PUBLIC
Get container names from Tresos to use in application code
• Main code for this example performs initializations that require the following
containers that are named in Tresos:
− McuModuleConfiguration container (used for Mcu_Init)
 Tresos location: Mcu – Generatl tab – McuModuleConfiguration
− McuClockSettingConfig container (used for Mcu_InitClock)
 Tresos location: Mcu – McuClockSettingConfig tab – McuClockSettingConfig (index 0)
• See examples below.
Device MCAL / Tresos versions McuModuleConfiguration name McuClockSettingConfig name
MPC574xG MCAL 4.0 / Tresos 14.2 McuConfigPB_0 McuClockSettingConfig
MCAL 4.2 / Tresos 21.0 McuConfigPB McuClockSettingConfig
MCAL 4.3 / Tresos 24.0 McuConfigPB McuClockSettingConfig
S32K14x MCAL 4.2 RTM 1.0.0 / Tresos 23.0 McuModuleConfiguration McuClockSettingConfig_0

114 PUBLIC
Simplify main function - Classic Sample Ap
• Edit src/main.c - Replace main.c’s main function with simpler one below
− IMPORTANT: Get container names (in red) from Tresos per prior slide. Names will vary.
int main( )
{
volatile uint32_t counter = 0; /* “Volatile” prevents being optimized out */
Std_ReturnType ret = E_OK;
Mcu_Init(&McuConfigPB);
ret = Mcu_InitClock(McuConf_McuClockSettingConfig_McuClockSettingConfig);
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{ /* wait until all enabled PLLs are locked */
}
Mcu_DistributePllClock(); /* switch system clock tree to PLL */
while (1)
{
counter++; /* increment a variable */
}
return 0;
}
115 PUBLIC
Simplify main function – Framework Sample Ap - DRAFT
• Edit src/main.c - Replace main.c’s main function with simpler one below
int main( )
{
volatile uint32 dummy_ctr=0; /* “Volatile” prevents being optimized out */
/* OS/stand-alone initialization - prepare the tasks(for OS), or the threads when no OS is used(uses Timers) */
#ifdef D_CACHE_ENABLE
/*init Data caches*/
m4_cache_init(SYS_CACHE);
#endif
#ifdef I_CACHE_ENABLE
/*init Code caches*/
m4_cache_init(CODE_CACHE);
#endif
SysDal_Init();
while (1){
dummy_ctr++;
}
#if defined(AUTOSAR_OS_NOT_USED)
/* SysDal_IntSch_TaskScheduler(); */
#endif
return 0;
}
116 PUBLIC
Remove unused elements: main.c - Classic Sample Ap
• Edit src/main.c
− Remove highlighted include statements

− Add include for Mcu.h

• Remove highlighted globals

117 PUBLIC
Remove unused elements : build_cfg.mak - Classic Sample Ap – GHS tools

For debug visibility, reduce compiler


optimization to prevent code being optimized out
• Open build_cfg.mak for editing
• Search for “ignore” to find LDOPT line
• Remove ignore_debug_references line

118 PUBLIC
Remove unused elements: files.mak - Classic Sample Ap
• Edit make/files.mak

− Remove highlighted files


(not main.c)

119 PUBLIC
Remove unused elements: include files - Classic Sample Ap
• Edit application’s “include” folder
− Remove any highlighted application configuration
files present from prior application

− Remaining files
do not have any
_cfg headers:

120 PUBLIC
Remove unused elements: Vector_vle_mcal.s file – 1 - Classic Sample Ap – Power Architecture

• Edit toolchains/Vector_vle_mcal.s file

− Remove or delete highlighted global


symbols of unneeded ISRs

121 PUBLIC
Remove unused elements: Vector_vle_mcal.s file – 2 - Classic Sample Ap – Power Architecture

− Uninstall the 10 existing interrupt handler routines from vector table with a period (.)
 Example: replace

 With period “.”

 (Tip: search for “Isr” to quickly locate lines)


− Also replace ADC’s function in vector table (which does not have Isr name) with a
period

122 PUBLIC
Remove unused elements: Modules file
• Replace line in Modules (S32K14x MCAL called Modules.mak) file with
− MCAL 4.0:
MODULE_LIST := Base Dem Det EcuM Mcu Rte
− MCAL 4.2:
MODULE_LIST := Base Dem Det EcuM Mcu Rte

123 PUBLIC
Remove unused elements: Tresos workspace include, src files
• Go to the application’s Tresos folder
− Navigate to the generated folder.
• Delete blue highlighted folders below in the MCAL minimal application’s
Tresos folder (contain prior application’s files)
− Tresos will make new folders with only the needed files which will be used later in
this tutorial but in a different location

124 PUBLIC
Clean then build project
• Clean: In the project’s bin directory, select all files except if there are debugger
files like run.cmm or any other .cmm file. Delete non-debugger files. Example:

• Build: Click on launch.bat


− If building with gcc like tools such as NXP’s S32 Design Studio, build with command:
launch.bat TOOLCHAIN=linaro
125 PUBLIC
Build MCAL project - inside S32 Design Studio (S32K14x example)
Review
• MCAL sample application is a makefile project. To build MCAL sample application from S32 Design Studio perform the following steps:
1. Open S32 Design Studio
2. In Menu, select File->New->Makefile project with Existing code
3. Fill in “Project Name” as S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application
4. Set “Existing Code Location” to point to the MCAL sample application folder
5. Click Finish -> now the MCAL sample application can be seen in Project Explorer in S32 Design Studio
6. Right click on the project “S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application” and select “Properties”
7. Select C/C++ Build
8. On “Builder Settings” tab, uncheck checkbox “Use default build command” and write this text:
launch.bat
into the “Build command” edit box (use launch.bat OS if you want to build with OS)
On “Builder Settings” tab, modify the Build location to be as follows (pointing to the build folder):
${ProjDirPath}/eclipse/plugins/IntegrationFramework_TS_T40D2M10I1R0/auxiliary/build
On “Behaviour “ tab, in “Build (Incremental build)” edit box, write this text:
TOOLCHAIN=linaro MODE=SUPR DERIV=144 (or TOOLCHAIN=ghs/iar if you use GHS/IAR compiler)
9. Click ok
10. Now you can build the project inside design studio by right clicking on the MCAL sample project and selecting “Build Project”

126 PUBLIC
Downloading project using S32 Design Studio
Review

• Example:
1. Right click on the project “S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application”
2. Click on Debug As->Debug Configurations…
3. Double click on “GDB PEMicro Interface Debugging” – this will create the launch
configuration with name “S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application Default”
4. In the “Main” tab, in the “C/C++ Application” write the text: bin/sample_app_mcal.elf to select
the executable file to be loaded to the evaluation board
5. In the “Debugger” tab select:
Interface: USB Multilink, USB Multilink FX, Embedded OSBDM/OSJTAG – USB Port
Select Device: Vendor: NXP, Family: S32K1xx Target:S32K144F512M15
Core: M4
Executable:
${S32DS_ARM32_TOOLCHAIN_DIR}/bin/${arm32_cross_prefix}gdb${arm32_cross_suffix}
6. Click Apply and Debug to start debugging

127 PUBLIC
Backup: SysDal (System Driver abstraction layer - no OS) – Framework only
File location: C:\NXP\AUTOSAR\MPC574XG_MCAL4_3_RTM_1_0_0\
Calypso6M_MCAL4_3_RTM_1_0_0_minimal_ap\
eclipse\plugins\IntegrationFramework_TS_T2D35M10I0R0\src\bsw\SysDal
• Mcu_Init
• Mcu_InitClock Green: used in Minimal_Ap
• Mcu_DistributatePllClock Black: not used in this example
• UserId (work in progress for future low power demo code) Grey: future demo use
• SysDal_Config.SetProgrammableInterruptsCallout();
− Used for easily configuring interrupts
• SysDal_IntSch_StopScheduler
• SysDal_ValidateWakeupReason, etc (work in progress for future low power demo)
• Mcu_SetMode (performs mode transition)
• SysDal_IntSch_StopScheduler
• SysDal_Config.InitDriversCallout (initialization for all configured drivers)
• SysDal_Config.ClearProgrammableInterruptsCallout() (work in progress)
• SysDal_IntSch_StartScheduler (starts scheduler; uses PIT0)
• Mcu_SetMode (transition to full power coming from sleep mode)
128 PUBLIC
Backup: Common build problems - 1
• “error #20: identifier ……. is undefined”

− Issue: undefined reference


− Navigate
to error. E.g. line 72. ADC should not be in project!
Remove per subsequent statements

129 PUBLIC
Backup: Common build problems – 2
• “EMIOS_0_CH_0_CH_1_ISR from Vector_vle_mcal.o
… (error) errors during processing
make.exe ….

− Issue: undeclared
− Open Vector_vle_mcal.s file and remove references

130 PUBLIC
Backup: Common build problems – unresolved symbols
• … (error #412) unresolved symbols…”

− Issue: undeclared
− Open Vector_vle_mcal.s file and remove references

131 PUBLIC
Backup: JTAG connection on MPC5748G DEVKIT EVB

• Pin 1 is top right pin in photo


− Ifusing notched JTAG connector,
the connector tab/nipple is on the
top side (as shown in photo) going
to the pins
• Note power supply: external 12V
supply is used, so the power
selection jumper must connect
pins 1-2 on right as shown in
photo.

132 PUBLIC
EXAMPLE 3:
CHANGE MINIMAL AP
TO USE A DIFFERENT
CHIP DERIVATIVE
133 PUBLIC
Minimal Ap - new derivative introduction
• Summary: Change the minimal ap project to use a different derivative in the same family
with different memory size and peripherals.
− Note: Only minimal changes are made here. Other changes will be made in subsequent
exercises as required. (Example: new derivative has more timer channels so Tresos
configurations will need to be modified as instructed in the timer exercise.)

• Example Overview:
− Duplicate the minimal ap project
− Tresos: Import project workspace, rename it, modify for new derivative
− Application code: Modify for new derivative

• Architectures tested:
− MPC574xG (with GHS compiler): Ported from MPC5746C to MPC5748G

134 PUBLIC
Workflow: Example 3 Minimal Ap with different derivative
1. Tresos:
1. Close any previous projects (reduces risk of configuring module of wrong project)
2. Copy prior Tresos project to be used to start example*
3. Rename Tresos project to same name as application’s folder*
4. Load project’s configuration
5. Sanity check: Generate and ensure no errors
6. Modify as desired (configure for new derivative and fix errors)
* First time only
7. Generate
2. Windows:
1. Duplicate & rename an application folder to be used to start example*
2. Tresos output files (.c and .h):
1. Classic Sample Ap: Copy Tresos output files to application’s folder used for build
2. Framework Sample Ap: Update launch.bat’s Tresos workspace path *
3. Modify application code as desired (change for new derivative: header &application files)
4. Clean & Build
135 PUBLIC
TRESOS
EXAMPLE 3 – DIFFERENT DERIVATIVE

136 PUBLIC
Duplicate & rename prior Tresos minimal ap project
1. Start Tresos. Use 64 bit if there is an option and you have Windows 64 bit. (First
time: click yes to create workspace directory)
2. Tip: Close any prior projects that are open to minimize confusion.
3. Copy prior minimal ap 3M project
4. Paste then rename project by deleting “Copy of “ at start of name and changing
“3M” to “6M”
MPC574XG_MCAL4_2_RTM_1_0_0_minimal_ap_6M and click OK

137 PUBLIC
137
Load project
• Load project by either
− Double click on project, or,
− Right click on project – Load Configuration

• Project is loaded, and there


should not be errors

• Click OK

138 PUBLIC
Verify Modules configuration
• Right click on project.. - Module configurations…
• Double check to ensure only needed modules are checked for enable & generate
• Click OK

139 PUBLIC
Tresos - Generate code to verify no errors
• Make sure project is selected and
click on Generate code button

• Code generates:

• Click OK when done

140 PUBLIC
Configure project different derivative - 1

• For this example, select derivative from different family (MPC584xG family, not
MPC574xC family)
− Double click on Resource module then change ResourceSubderivative to desired derivative

141 PUBLIC
Configure project different derivative - 2

• MCAL sample application (OS only)


− In Tresos OS configuration modified OsTargetMCU parameter to
MPC5748G and configure OsSysTimer (the same way as on
MPC5746C)

142 PUBLIC
Fix problems from missing peripherals - Introduction
• The MPC5748G has additional peripherals not found in MPC5746C, causing
problems:

• These peripherals need to be added to the project configuration.


• Click on the Path of the problems view to get to the container to add them.

• The peripherals to add can be found by comparing the reference manual memory
map for Mode Entry module for both derivatives (see next slide)

143 PUBLIC
143
Fix problems from missing peripherals – Identifying additional modules

MPC5746C MPC5748G
(original (new
derivative) derivative)

Mode Entry
module
memory map
comparison
used to find
additional
peripherals.

(Partial list
shown.)
144 PUBLIC
144
Fix problems from missing peripherals – peripherals to be added
• List of additional peripherals to be added to McuPeripheral for this example:

eMIOS_2 Peripheral Control Register (MC_ME_PCTL3)


USB OTG Peripheral Control register (MC_ME_PCTL4)
USB_SPH Peripheral Control Register (MC_ME_PCTL5)
MLB Peripheral Control Register (MC_ME_PCTL6)
SDHC Peripheral Control Register (MC_ME_PCTL7)

LIN_16 Peripheral Control Register (MC_ME_PCTL66)


LIN_17 Peripheral Control Register (MC_ME_PCTL67)
SPI4 Control Register (MC_ME_PCTL100)
SPI5 Control Register (MC_ME_PCTL101)

145 PUBLIC
145
Fix problems from missing peripherals – McuPeripheral list
• The current Mcu module, McuPeripheral list starts with:

Click on the “+” nine times to add to add the nine new peripherals (“elements”)

146 PUBLIC
146
Fix problems from missing peripherals – add new peripherals
• Items 57- 65 were added by the nine clicks on the “+”

• Double click on the index of the first one (57) to configure the first added
peripheral

147 PUBLIC
147
Fix problems from missing peripherals – configure new peripherals
eMIOS_2 Peripheral Control Register (MC_ME_PCTL3)
• Select the first peripheral to be added: USB OTG Peripheral Control register (MC_ME_PCTL4)
USB_SPH Peripheral Control Register (MC_ME_PCTL5)
MLB Peripheral Control Register (MC_ME_PCTL6)
SDHC Peripheral Control Register (MC_ME_PCTL7)
LIN_16 Peripheral Control Register (MC_ME_PCTL66)
LIN_17 Peripheral Control Register (MC_ME_PCTL67)
SPI4 Control Register (MC_ME_PCTL100)
SPI5 Control Register (MC_ME_PCTL101)

• Select configurations 0 (default)


for the run and non-run modes
• Navigate up (up arrow)
• Repeat for remaining new peripherals

148 PUBLIC
148
Fix problems from missing peripherals – added peripherals
• McuPeripheral container after adding MPC5848G peripherals (highlighted):

149 PUBLIC
149
Generate code
• Click on Generate code

• There should be no errors

150 PUBLIC
150
WINDOWS
EXAMPLE 3 – DIFFERENT DERIVATIVE

151 PUBLIC
Copy and rename prior Tresos project
1. Start Tresos – be sure to use the right version for your MCAL.
Use 64 bit if there is an option and you have Windows 64 bit.
2. Tip: Close any prior projects that are open to minimize confusion.
3. Double click on prior project, Sample Ap, to ensure it is open.
4. Right click on project – Copy

5. Right click in Project Explorer window – Paste

6. Rename project to minimal_ap. Example:


MPC574xG_MCAL4_2_RTM_1_0_0_minimal_ap_6M

152 PUBLIC
Update application with Tresos generated files
• Classic Sample Ap only:
− Copy include & src folders from the EB Tresos
generated folder location:

− Delete prior folders then paste copied folders


into application’s cfg folder (not tresos folder)
(May need to create cfg folder in application folder)

• Framework Sample Ap – first time only:


− Update launch.bat’s TRESOS_WORKSPACE_DIR
with Tresos project’s output path

153 PUBLIC
Get header file for new derivative (MPC5748G.h)
• Go to MPC574xG product page on web by clicking links:
− www.nxp.com – PRODUCTS – POWER ARCHITECTURE® PROCESSORS –
MPC5xxx/55xx 32-bit MCUs – MPC57xx – MPC574xB-C-G

• Click on SOFTWARE & TOOLS

• Click on header files download


• Unzip files
• Rename MPC5748G (Union based).h file to MPC5748G.h and place it in folder:
MPC574XG_MCAL4_2_RTM_1_0_0_minimal_ap_6M\include
154 PUBLIC
Getting S32K14x Header Files From S32 Design Studio
• S32 Design Studio includes an SDK which has device header files
• Example: S32K146 path:
c:\NXP\S32DS_ARM_v2018.R1\S32DS\S32SDK_S32K14x_RTM_2.0.0\platform\devices\S32K146\include\S32K146.h

or if you have an early version such as:

C:\NXP\S32DS_ARM_v2018.R1\S32DS\S32SDK_S32K14x_EAR_0.8.6\platform\devices\S32K146\include

then get the latest update for S32DS:


https://www.nxp.com/support/developer-resources/run-time-software/s32-design-studio-ide/s32-design-
studio-ide-for-arm-based-mcus:S32DS-ARM?tab=Design_Tools_Tab

155 PUBLIC
155
Getting S32K14x Header Files From S32 Design Studio
• S32 Design Studio includes an SDK which has device header files
• Example: S32K146 path:
c:\NXP\S32DS_ARM_v2018.R1\S32DS\S32SDK_S32K14x_RTM_2.0.0\platform\devices\S32K146\include\S32K146.h

or if you have an early version such as:


C:\NXP\S32DS_ARM_v2018.R1\S32DS\S32SDK_S32K14x_EAR_0.8.6\platform\d
evices\S32K146\include
then get the latest update for S32DS:
https://www.nxp.com/support/developer-resources/run-time-software/s32-design-studio-ide/s32-design-studio-ide-for-arm-based-mcus:S32DS-ARM?tab=Design_Tools_Tab

156 PUBLIC
156
Update application files for derivative MPC5748G - 1

• MCAL sample application (add lines in red)


− Add two variables at the beginning of launch.bat:
 SET DERIVATIVE=5748G
 SET mcu=5748G

− Update common.mak to support mcu 5748G:


 ifneq ($(mcu),5748G)
 …..
 $(error Undefined mcu type: '$(mcu)', expected one of following: 5607B, 5604P or 5606S)
 ……
 endif

157 PUBLIC
Update application files for derivative MPC5748G - 2
− Update files.mak to support DERIVATIVE 5748G:
 ifeq ($(DERIVATIVE), 5748G)
 #take linker command files
 LINKER_DEFS_GHS_FLASH := $(DEV_DIR)/toolchains/autosar_flash.ld
 LINKER_DEFS_CW_FLASH := $(DEV_DIR)/toolchains/autosar_flash.lcf
 LINKER_DEFS_DIAB_FLASH := $(DEV_DIR)/toolchains/autosar_flash.dld After
 else
.
.
.
 endif
Before

158 PUBLIC
Update application files for derivative MPC5748G - 3

• Update MCAL sample application. • MCAL sample application (OS only)


− Updated Startup_vle_os.c to correctly boot after power on
Add text in red. by updating the RCHW (OS sample app works only if
started from debugger)
− Added include of mpc5748G.h in  extern uint32 _start[];
toolchains/Startup_vle.c and if present, in  #define RCW 0x005A0002UL /* 0x2 start core0 */
Startup_vle_os.c:
 #ifdef MPC5748G  #if defined(DIAB)
 #pragma section CONST ".rcw"
 #include "MPC5748G.h"
 #elif defined(GHS)
 #else  #pragma ghs section const=".rcw"
#include "mpc5746c.h"

After  #else
 #endif  #error Unknown compiler
 #endif /* DIAB */

Before  const uint32 RCHW1=RCW;


 const uint32 RCHW2=(uint32)_start;
 const uint32 RCHW3=(uint32) 0;
 const uint32 RCHW4=(uint32) 0;
 const uint32 RCHW5=(uint32)_start;
 const uint32 RCHW6=(uint32)_start;
 const uint32 RCHW7=(uint32) 0;
159 PUBLIC
Clean then build project
• Clean: In the project’s bin directory, select all files except if there are debugger
files like run.cmm or any other .cmm file. Delete non-debugger files. Example:

• Build: Click on launch.bat


− If building with gcc like tools such as NXP’s S32 Design Studio, build with command:
launch.bat TOOLCHAIN=linaro
160 PUBLIC
Downloading project using S32 Design Studio
Review

• Example:
1. Right click on the project “S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application”
2. Click on Debug As->Debug Configurations…
3. Double click on “GDB PEMicro Interface Debugging” – this will create the launch
configuration with name “S32K14X_MCAL4_2_RTM_1_0_1_Sample_Application Default”
4. In the “Main” tab, in the “C/C++ Application” write the text: bin/sample_app_mcal.elf to select
the executable file to be loaded to the evaluation board
5. In the “Debugger” tab select:
Interface: USB Multilink, USB Multilink FX, Embedded OSBDM/OSJTAG – USB Port
Select Device: Vendor: NXP, Family: S32K1xx Target:S32K144F512M15
Core: M4
Executable:
${S32DS_ARM32_TOOLCHAIN_DIR}/bin/${arm32_cross_prefix}gdb${arm32_cross_suffix}
6. Click Apply and Debug to start debugging

161 PUBLIC
Backup: JTAG connection on MPC5748G DEVKIT EVB

• Pin 1 is top right pin in photo


− Ifusing notched JTAG connector,
the connector tab/nipple is on the
top side (as shown in photo) going
to the pins
• Note power supply: external 12V
supply is used, so the power
selection jumper must connect
pins 1-2 on right as shown in
photo.

162 PUBLIC
EXAMPLE 4:
PORT MODULE

163 PUBLIC
Port Module Introduction
• Summary: The Port module configures pins for a particular function.
− Port module initializes MCU pad control registers such as:
 MPC574xG: SIUL2_MCSR., SIUL2_IMSR
− Port Pin identification is done with:
 MPC574xG: Pin Configuration Register numbers (SIUL_MSCRx)
• Example Overview:
− Duplicate the minimal ap project for your derivative
− Tresos: Port module - remove prior port pins except JTAG and add 2 for GPIO
− Application code: Ensure Port_Init is called.
• Architectures tested:
− MPC574xG (with GHS compiler)

164 PUBLIC
Background: MPC574xG EVB Port I/O Compatibility
NXP’s MCAL Sample Ap I/O Mother–Daughter EVB DEVKIT-MPC5748G MPC5748G-LCEVB
(MCU in socket) (MPC5748G soldered) (MPC4748G soldered)
$495 $39 $179
Push buttons (GPIO inputs) PA1, PA2, PF9, PF11 PE12, PG1 (non wakeup) PA1 (also NMI), PA2
LED1, LED2, LED3, LED4 PG2, PG3, PG4, PG5 PA10, PA7, PF15, PC4, PG2, PG3, PG4, PG5
(GPIO outputs) PH5, PJ4, PA0, PA4
ADC Pot PB4 (PCR 20) PB4 PB4
eMIOS icu measurement eMIOS channel pins are eMIOS channel pins are
eMIOS 1 11 PG2 on connectors on connectors
CAN0_TX/RX, PB0/PB1, (PCR 16/17) PB0/PB1, PB0/PB1,
CAN1_TX/RX PC10/PC11 (PCR 42/43) -- PC10/PC11
CAN Transceiver / Termination TJA1051 / none MC33901 / none MC33901 / none
LIN0_TX/RX PB2/PB3 PB2/PB3 PB2/PB3
LIN1_TX/RX PC6/PC7 (PCR38/39) - PC6/PC7
LIN2_Tx/Rx (UART) PC8/PC9 (PCR 40/41) PC8/PC9 PC8/PC9
DSPI_0 SOUT/SIN PA12/13 (PCR 13/12) Pins are on connectors Pins are on connectors
165 PUBLIC
Port API Functions
void Port_Init( const Port_ConfigType* ConfigPtr )
void Port_SetPinDirection( Port_PinType Pin, Port_PinDirectionType
Direction )
void Port_RefreshPortDirection( void )
void Port_GetVersionInfo( Std_VersionInfoType* versioninfo )
void Port_SetPinMode( Port_PinType Pin, Port_PinModeType Mode )

 The user must call Port_Init function which contains all the port
configurations.
 For MCAL Port specification, web search “Autosar MCAL Port”
 (Bold function is used in example)

166 PUBLIC
Workflow: Example 4 Port module
1. Windows:
1. Duplicate & rename an application folder to be used to start example*
2. Tresos:
1. Close any previous projects (reduces risk of configuring module of wrong project)
2. Copy prior Tresos project to be used to start example*
3. Rename Tresos project to same name as application’s folder*
4. Load project’s configuration
5. Sanity check: Generate and ensure no errors * First time only
6. Modify as desired (Remove unneeded port pins and add/configure two new ones)
7. Generate
3. Windows:
1. Tresos output files (.c and .h):
1. Classic Sample Ap: Copy Tresos output files to application’s folder used for build
2. Framework Sample Ap: Update launch.bat’s Tresos workspace path *
2. Modify application code as desired (Add port header, init function; update Modules.List )
3. Clean & Build

167 PUBLIC
TRESOS
EXAMPLE 4 – PORT MODULE

168 PUBLIC
Duplicate & rename prior Tresos minimal ap project
1. Start Tresos. Use 64 bit if there is an option and you have Windows 64 bit. (First
time: click yes to create workspace directory)
2. Tip: Close any prior projects that are open except one to be copied.
3. Copy prior minimal ap 3M project
4. Paste then rename project by deleting “Copy of “ at start of name and changing
“minimal_ap” to “port”.
MPC574XG_MCAL4_2_RTM_1_0_0_port_6M & click OK

169 PUBLIC
169
Load project
• Load project by either
− Double click on project, or,
− Right click on project – Load Configuration

• Project is loaded, and there


should not be errors

• Click OK

170 PUBLIC
Tresos - Generate code to verify no errors
• Make sure project is selected and
click on Generate code button

• Code generates:

• Click OK when done

171 PUBLIC
Port configurations - Remove PortPins except JTAG; add 2 GPIO
Port module
Tab: PortConfigSet
Index 0: PortConfigSet_0
Tab: PortContainer
Index 0: PortContainer_0
Tab: PortPin
Index n: PortPin names (remove all port pins
except JTAG (DCI) pins, add 2 PortPins)
Index of 1st added PortPin
Tab: General (name LED4, PCR x,
output, GPIO mode, portpin high level)
Index of 2nd added PortPin
Tab: General (name Switch2, PCR y,
input, GPIO mode)

172 PUBLIC
Port (1): Enable Port module & code generation
• Right click on
project &
select Module
Configurations…

• Check both Enable and Generate for Port


module, then click OK

173 PUBLIC
Port (2): Select PortConfigSet 0 1
• Double click on Port
module’s configuration
(“Port”)
• Click on PortConfigSet tab

174 PUBLIC
Port (3): Select PortConfigSet 0 2
• Double click on
PortConfigSet’s Index 0

• Click on PowerConfigSet_0’s
PortContainer tab

175 PUBLIC
Port (4): In PortConfigSet 0 select PortContainer 0

• Double click PortConfigSet_0’s Index 0

• Click on the PortPin tab

176 PUBLIC
Port (5): Delete all current PortPins in PortContainer
• Select all Indices (in Index column) EXCEPT JTAG:
− Click on Index number, e.g. “0” in the Index column, then CTRL-A, then CTRL on DCI’s
• Click X to remove all existing pins

JTAG
Port
Pins

177 PUBLIC
Port (6): Add two PortPins
• Click + twice to add two new port
pins
− PortPin_0 and PortPin_1 are added

• Double click on Index of the first


added PortPin to configure it

178 PUBLIC
Port (7): Configure PortPin output – 1
• Configure fields starting with PortPinPcr:
− Portpins are listed in evaluation board
documentation.
− Using the spreadsheet in the Reference Manual,
the Pad Control Register # can be found for each
pin.
− Use the PortPinPcr for your EVB
 Example on right: MPC574xG Mother-Daughter EVB
Device Evaluation Board (EVB) Switch (Input) LED (Output)
Switch# Port Pin Pad Ctrl Reg* LED# Port Pin Pad Ctrl Reg*
MPC574xG Mother–Daughter EVB & MPC5748G-LCB Switch2 PA2 MSCR2 LED4 PG5 MSCR101
MPC5748G DEVKIT – MPC5748G Switch2 PE12 MSCR76 LED4 PA10 MSCR10

179 PUBLIC
Port (8): Configure PortPin output - 2
• Name: LED4
• PortPin ID: PortPin Ids are a unique
number used to identify the port
configuration
− Clickon the “Calculate Value” icon to
automatically ensure a unique number.
• PortPin Direction: PORT_PIN_OUT
− _OUT sets MSCR bits IBE=0,OBE=1
_IN sets MSCR bits IBE =1, OBE =0
_Disabled sets MSCR both IBE,OBE=0
• PortPin Mode: GPIO
• PortPin Level Value:
PORT_PIN_LEVEL_HIGH
180 PUBLIC
Reference: S32K14x Port Mapping Example - 1
• From the Sample Application User Manual: Use highlighted port, with PCR ID 96

• Tresos Sample Application project: Open


Port Module – Port Container tab – Double click on Index 0 (PortContainer_0)
- click on PortPin tab –
• Find PCR ID 96

181 PUBLIC
Reference: S32K14x Port Mapping Example - 2
• Double click on that port pin’s index, 17

• Port pin parameters can be configured

182 PUBLIC
Port (9): Go back to prior container & select other port pin
• Navigate back a
container by clicking on
up arrow

• Double click on other


added PortPin’s index to
configure it

183 PUBLIC
Port (11): Configure PortPin input – 1
• Configure fields starting with PortPinPcr:
− Portpins are listed in evaluation board
documentation.
− Using the spreadsheet in the Reference
Manual, the Pad Control Register # can be
found for each pin.
− Use the PortPinPcr for your EVB
 Example on right: MPC574xG Mother-Daughter
EVB
Device Evaluation Board (EVB) Switch (Input) LED (Output)
Switch# Port Pin Pad Ctrl Reg* LED# Port Pin Pad Ctrl Reg*
MPC574xG Mother–Daughter EVB & MPC5748G-LCB Switch2 PA2 MSCR2 LED4 PG5 MSCR101
MPC5748G DEVKIT – MPC5748G Switch2 PE12 MSCR76 LED4 PA10 MSCR10

184 PUBLIC
Port (12): Configure PortPin input - 2
• Name: Switch2

• PortPin Id: Click on Calculate Value


icon to ensure a unique ID

• PortPin Direction: PORT_PIN_IN

• PortPin Mode: GPIO

185 PUBLIC
Need help?
• Need help? Click on a configuration and see help box in workspace bottom right.

186 PUBLIC
Port (13): There will be an error, like below……
• Click in problems view window to expand Tresos errors (these are before generation)

• Note 2nd error has message port number


of pins is out of range
• Click on 2nd error
• This brings up the Port Container window
− Clickthe pencil then calculate icon for
PortNumberOfPortPins
− Double click to automatically get the proper #
• Double click on each remaining error, then double click on “Calculate Value”
187 PUBLIC
Port (14): Navigate back
• Go back to prior container

• Note PortPins at a glance (D by the box means default value) :

188 PUBLIC
Port (15): Generate
• As a check, Generate project (right click
on PPC, select Generate Project) to
ensure no errors occurred.

• Click Save icon (disk icon in upper left)

189 PUBLIC
WINDOWS
EXAMPLE 4 – PORT MODULE

190 PUBLIC
Duplicate & Rename Application
• Duplicate a minimal ap project

• Give it a new name, such as


MPC574xG_MCAL4_2_RTM_1_0_0_port_6M

191 PUBLIC
Update application with Tresos generated files
• Classic Sample Ap only:
− Copy include & src folders from the EB Tresos
generated folder location:

− Delete prior folders then paste copied folders


into application’s cfg folder (not tresos folder)
(May need to create cfg folder in application folder)

• Framework Sample Ap – first time only:


− Update launch.bat’s TRESOS_WORKSPACE_DIR
with Tresos project’s output path

192 PUBLIC
Edit src/main.c: add include file, Port_Init
Add to header files:
#include “Port.h”
Add Port_Init function to code (in red) using Name from Port module:
int main( )
{
volatile uint32_t counter = 0;
Std_ReturnType ret = E_OK;
Mcu_Init(&McuConfigPB);
ret = Mcu_InitClock(McuConf_McuClockSettingConfig_McuClockSettingConfig);
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{
/* wait until all enabled PLLs are locked */
}
Mcu_DistributePllClock(); /* switch system clock tree to PLL */
Port_Init(&PortConfigSet); /* initialize configured pins */
while (1)
{
counter++; /* increment a variable */
}
return 0;
}
193 PUBLIC
Edit Modules file: add newly enabled module
• In project’s root directory (which has launch.bat):
− Edittext file “Modules” to add Port.
(TIP: Add in alphabetical order – a good habit because it makes it easier to check)

# specify modules which will be compiled and linked


MODULE_LIST := Base Det Dem EcuM Mcu Port Rte

194 PUBLIC
Clean then build project
• Clean: In the project’s bin directory, select all files except if there are debugger
files like run.cmm or any other .cmm file. Delete non-debugger files. Example:

• Build: Click on launch.bat


− If building with gcc like tools such as NXP’s S32 Design Studio, build with command:
launch.bat TOOLCHAIN=linaro
195 PUBLIC
EXAMPLE 5:
DIO MODULE

196 PUBLIC
Dio Module Introduction
• Summary: The Dio module is used for reading and writing GPIO pins
− Port pin identification with Dio module is done with:
 MPC574xG: Port number and channel in that port. E.g., port PA[5]

• Example Overview:
− Duplicate the prior Port project
− Tresos: Enable Dio module & add names to the two GPIO ports. Generate.
− Application code: Update main.c with code and include file. Add Dio to module list

• Architectures tested:
− MPC574xG (with GHS compiler)

197 PUBLIC
Dio API Functions
Dio_ReadChannel
Dio_WriteChannel
Dio_ReadPort
Dio_WritePort
Dio_ReadChannelGroup
Dio_WriteChannelGroup
Dio_GetVersionInfo
Dio_FlipChannel

 Bold functions are used in example.


 For MCAL Dio specification, web search “Autosar MCAL Dio”

198 PUBLIC
Workflow: Example 5 Dio module
1. Windows:
1. Duplicate & rename an application folder to be used to start example*
2. Tresos:
1. Close any previous projects (reduces risk of configuring module of wrong project)
2. Copy prior Tresos project to be used to start example*
3. Rename Tresos project to same name as application’s folder*
4. Load project’s configuration
5. Sanity check: Generate and ensure no errors * First time only
6. Modify as desired (Remove existing ports, channels & add 2 for GPIO)
7. Generate
3. Windows:
1. Tresos output files (.c and .h):
1. Classic Sample Ap: Copy Tresos output files to application’s folder used for build
2. Framework Sample Ap: Update launch.bat’s Tresos workspace path *
2. Modify application code (Add dio header, add code loop: read/write GPIO, update Modules.List )
3. Clean & Build

199 PUBLIC
TRESOS
EXAMPLE 5 – DIO MODULE

200 PUBLIC
Duplicate & rename prior Tresos project
1. Start Tresos. Use 64 bit if there is an option and you have Windows 64 bit. (First
time: click yes to create workspace directory)
2. Tip: Close any prior projects that are open except one to be copied.
3. Copy prior minimal ap project
4. Paste then rename project by deleting “Copy of “ at start of name and changing
“minimal_ap” to “dio.”
MPC574XG_MCAL4_2_RTM_1_0_0_dio_6M & click OK

201 PUBLIC
201
Load project
• Load project by either
− Double click on project, or,
− Right click on project – Load Configuration

• Project is loaded, and there


should not be errors

• Click OK

202 PUBLIC
Tresos - Generate code to verify no errors
• Make sure project is selected and
click on Generate code button

• Code generates:

• Click OK when done

203 PUBLIC
Add Dio module to configurations
• Right click on
project &
select Module
Configurations…

• Check both Enable and Generate for Dio


module, then click OK

204 PUBLIC
Dio configurations - Remove Dio Ports; add 2 ports/channels
Dio module (DioPorts and DioChannels shown for Mother-Daugher EVB)
Tab: DioConfig
Index 0: DioConfig_0
Tab: DioPort (remove all DioPorts; add 2 DioPorts)
Index of 1st added DioPort: DioPort_0
Tab: General (Name Diox, Dio Port Id = y)
Tab: DioChannel (Add channel)
Index 0: DioChannel_0
Tab: General (Name Switch2, Chan Id x)
Index of 2nd added DioPort: DioPort_1
Tab: General (Name Diox, Dio Port Id = y)
Tab: DioChannel (Add channel)
Index 0: DioChannel_0 (Name LED4, Chan Id y)
205 PUBLIC
Dio (1): Enable code generation
• Enable modules that will be configured to
generate code:
− Right click on PPC
− Select Module Configurations….
− In Generate column, check box
for:
 Dio
− Click OK

206 PUBLIC
Dio (2): Open Dio configuration
• Double click on Dio’s configuration. Dio module’s General settings appear.

207 PUBLIC
Dio (3): Remove all Dio ports
• Click on DioConfig tab

• Double click on Index 0 of DioConfig

• Select all indices (index 0 and 1)


• Click the red X to remove those ports

208 PUBLIC
Dio (4): Add first DioPort
• Click on the green + to add a port

• Double click on the new port’s index

209 PUBLIC
Dio (5): Configure first DioPort - 1
• Click on
Dio Port Id (0 -> 16)*
• Note description for the
Dio Port Id. The value
corresponds to Port A,
B, C, etc.

210 PUBLIC
Dio (6): Configure first DioPort - 2
• Select the first port for your evaluation board.
− Example: MPC574xG Mother-Daughter EVB -
 Name: DioPA
 Dio Port Id: 0 (for Port A)

Device Evaluation Board (EVB) Switch (Input) LED (Output)


Switch# Port Pin Pad Ctrl Reg* LED# Port Pin Pad Ctrl Reg*
MPC574xG Mother–Daughter EVB & MPC5748G-LCB Switch2 PA2 MSCR2 LED4 PG5 MSCR101
MPC5748G DEVKIT – MPC5748G Switch2 PE12 MSCR76 LED4 PA10 MSCR10

211 PUBLIC
Dio (7) Add channel to DioPort - 1
• Click on DioChannel tab
• Click on green + to add new DioChannel

• Double click on index 0 to configure the


first channel

212 PUBLIC
Dio (8) Add channel to DioPort - 2
• Name and select the port’s channel for your
evaluation board.
− Example: MPC574xG Mother-Daughter EVB -
 Name: Switch2
 Dio Channel Id: 2
• Click the up arrow to navigate one container
upward
Device Evaluation Board (EVB) Switch (Input) LED (Output)
Switch# Port Pin Pad Ctrl Reg* LED# Port Pin Pad Ctrl Reg*
MPC574xG Mother–Daughter EVB & MPC5748G-LCB Switch2 PA2 MSCR2 LED4 PG5 MSCR101
MPC5748G DEVKIT – MPC5748G Switch2 PE12 MSCR76 LED4 PA10 MSCR10

213 PUBLIC
Dio (9) Add second port
We are done configuring the first port and its
channel. Now the second one must be
configured.
NOTE: If the second Dio port is on the same
port, adding this a port is not needed.
• Click on the up arrow to navigate upward a
container

• Click on the green + to add a new port.


• A new port with Index 1 is created
• Double click on Index 1 to configure the
new port

214 PUBLIC
Dio (10) Configure second port
(NOTE: If the second Dio port is on the same
port, adding a new port is not needed).
• Select the first port for your evaluation board.
− Example: MPC574xG Mother-Daughter EVB -
 Name: DioPG
 Dio Port Id: 6 (for port G)

Device Evaluation Board (EVB) Switch (Input) LED (Output)


Switch# Port Pin Pad Ctrl Reg* LED# Port Pin Pad Ctrl Reg*
MPC574xG Mother–Daughter EVB & MPC5748G-LCB Switch2 PA2 MSCR2 LED4 PG5 MSCR101
MPC5748G DEVKIT – MPC5748G Switch2 PE12 MSCR76 LED4 PA10 MSCR10

215 PUBLIC
Dio (11) Add second channel - 1
• Add Channel:
− Click on DioChannel tab

− Click on + to add channel


− Double click on the
channel’s index to bring up
its configuration

216 PUBLIC
Dio (12) Add second channel - 2
• Name and select the port’s channel for
your evaluation board.
− Example: MPC574xG Mother-Daughter
EVB -
 Name: LED4
 Dio Channel Id: 5
• Generate and save project to ensure
no errors.
Device Evaluation Board (EVB) Switch (Input) LED (Output)
Switch# Port Pin Pad Ctrl Reg* LED# Port Pin Pad Ctrl Reg*
MPC574xG Mother–Daughter EVB & MPC5748G-LCB Switch2 PA2 MSCR2 LED4 PG5 MSCR101
MPC5748G DEVKIT – MPC5748G Switch2 PE12 MSCR76 LED4 PA10 MSCR10

217 PUBLIC
Generate
• Generate project, and fix any errors

218 PUBLIC
WINDOWS
EXAMPLE 5 – DIO MODULE

219 PUBLIC
Duplicate & Rename Application
• Duplicate a minimal ap project

• Give it a new name, such as


MPC574xG_MCAL4_2_RTM_1_0_0_dio_6M

220 PUBLIC
Update application with Tresos generated files
• Classic Sample Ap only:
− Copy include & src folders from the EB Tresos
generated folder location:

− Delete prior folders then paste copied folders


into application’s cfg folder (not tresos folder)
(May need to create cfg folder in application folder)

• Framework Sample Ap – first time only:


− Update launch.bat’s TRESOS_WORKSPACE_DIR
with Tresos project’s output path

221 PUBLIC
Edit Modules file to add newly enabled modules
• In project’s root directory (which has launch.bat):
− Edittext file “Modules” to add Dio and Port.
(TIP: Add in alphabetical order – a good habit because it makes it easier to check)

# specify modules which will be compiled and linked


MODULE_LIST := Base Det Dem Dio EcuM Mcu Port Rte

222 PUBLIC
Add Dio code to main function in main.c application’s src folder:
Add include file:
#include “Dio.h”
Add global variable:
VAR(uint8, AUTOMATIC) Level_Switch2 =0;
Add code inside forever loop:
/* Turn off (1) LED4 if Switch 2 is pressed (reads 1 if pressed)*/
Level_Switch2 = Dio_ReadChannel((Dio_ChannelType)DioConf_DioChannel_Switch2 );
if (Level_Switch2 == 1)
{
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED4, 1); /* Off */
}
else
{
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED4, 0); /* On */
}

223 PUBLIC
Clean, build, download and test project
• In the project’s bin directory, select all files except if there are debugger files
like run.cmm or any other .cmm file and then delete those selected files.
Example:

• Click on launch.bat to build


• Download to board and test: Press Switch2 and see LED4 change state
224 PUBLIC
EXAMPLE 6:
GPT MODULE

225 PUBLIC
Gpt Module Introduction
• Summary: The Gpt (General Purpose Timers) module configures timers using the different HW timers on a chip.
• This example creates a free running timer. The flag will set but no action is taken and the timer keeps counting.
− Clock sources for timers are configured in the Mcu module
− The steps illustrated have an intentional error to demonstrate how to easily fix errors
− If the minimal ap used for this example was for a derivative, then additional steps are required as noted

• Example Overview:
− Duplicate a minimal ap project for your target
− Tresos:
 Mcu module – configure 32 KHz SXOSC clock
 Gpt module – configure timer RTC using SXOSC clock divided by 32
− Application code:
 Enable SXOSC clock (and any other clocks)
 Start Gpt timer with timeout of ½ sec

• Architectures tested:
− MPC574xG (with GHS compiler)

226 PUBLIC
Background: Mcu module “owns” clocks
• Clocks are enabled and configured in the MCU module. Example:
− MPC574xG: Enable SXOSC for 32KHz crystal and divider of 1
• Mcu module clock reference points (McuClockReferencePoint) are a mechanism
to provide clock information to other modules like Gpt.
− Example reference clock flow: Mcu SXOSC clock ref. point  Gpt  a Gpt channel:

Mcu module Gpt module


McuClockSettingConfig: GptClockReferencePoint: GptChannelConfiguration:
- Enable SXOSC - Create Gpt clk. ref. point - Create Gpt channel config.
- Configure SXOSC (dividers) GptClkRefPnt_0_SXOSC named RtcTimer that uses
- Create SXOSC reference point using clk. ref. point named GptChannelSrcRef =
named ClkRefPnt_SXOSC ClkRefPnt_SXOSC GptClkRefPnt_0_SXOSC
-Etc. for other Gpt clock - Etc. for other Gpt channel
config configurations

227 PUBLIC
Gpt API Functions

Gpt_GetVersionInfo Gpt_EnableNotification
Gpt_Init Gpt_DisableNotification
Gpt_DeInit Gpt_SetMode
Gpt_GetTimeElapsed Gpt_DisableWakeup
Gpt_GetTimeRemaining Gpt_EnableWakeup
Gpt_StartTimer Gpt_CheckWakeup
Gpt_StopTimer Gpt_GetPredefTimerValue

• Bold functions are used in example.


• For MCAL Gpt specification, web search “Autosar MCAL Gpt”
228 PUBLIC
Workflow: Example 6 Gpt module
1. Tresos:
1. Close any previous projects (reduces risk of configuring module of wrong project)
2. Copy prior Tresos project to be used to start example*
3. Rename Tresos project to same name as application’s folder*
* First time only
4. Load project’s configuration
5. Sanity check: Generate and ensure no errors
6. Modify as desired (Configure clock source in Mcu module and timer channel in Gpt module)
7. Generate
2. Windows:
1. Duplicate & rename an application folder to be used to start example*
2. Tresos output files (.c and .h):
1. Classic Sample Ap: Copy Tresos output files to application’s folder used for build
2. Framework Sample Ap: Update launch.bat’s Tresos workspace path *
3. Modify application code (Add headers, add code to enable/start timer, update Modules.List )
4. Clean & Build
229 PUBLIC
TRESOS
EXAMPLE 6 – GPT MODULE

230 PUBLIC
Duplicate & rename prior Tresos minimal ap project
1. Start Tresos. Use 64 bit if there is an option and you have Windows 64 bit. (First
time: click yes to create workspace directory)
2. Tip: Close any prior projects that are open except one to be copied.
3. Copy again the prior minimal ap project for your target
4. Paste then rename project by deleting “Copy of “ at start of name and changing
“minimal_ap” to “gpt”
5. Click OK

231 PUBLIC
231
Load & generate project; verify no errors
• Load project by either
− Double click on project, or,
− Right click on project – Load Configuration
• Project is loaded, and there
should not be errors
• Click OK

• Right click on Project configuration (Ecuc here)


• Click on Generate Project
• Project is generated and there
should not be errors
• Click OK

232 PUBLIC
Enable Gpt, Mcl configuration and generation
• Right click on PPC
• Click on Module Configurations…

• Click both Enable and Generate


to enable Gpt and Mcl (Micro
Controller Library) module
configurations and code generation.

233 PUBLIC
Gpt configurations - Mcu module: create clock configuration for SXOSC
– Tresos 21.0
Mcu module
Tab: General
Section: McuModuleConfiguration (Verify Slow Crystal Frequency = 32KHz)
Tab: McuClockSettingConfig
Index 0: McuClockSettingConfig
Tab: General (Enable SXOSC)
Tab: McuSXOSC (Configure SXOSC divider, etc.)
Tab (far right): McuClockReferencePoint (add SXOSC reference point)
Index (new one): (Name: ClkRefPnt_SXOSC,
freq. select = SXOSC,
automatically calc ref pt value)

234 PUBLIC
Gpt configurations - Mcu module: create clock configuration for SXOSC –
Tresos 14.2.1
Mcu module
Tab: McuModuleConfiguation
Index 0: McuConfigPB_0
Tab: General (Verify Slow Crystal Frequency = 32KHz)
Tab: McuClockSettingConfig
Index 0: McuClockSettingConfig
Tab: General (Enable SXOSC)
Tab: McuSXOSC (Configure SXOSC divider, etc.)
Tab (far right): McuClockReferencePoint
(Add reference point for SXOSC)
Index (new one):
(Name: ClkRefPnt_SXOSC,
freq. select: SXOSC,
GptPrescaler: divide by 32,
automatically calc ref pt value)

235 PUBLIC
Mcu (1): SXOSC - verify crystal frequency
• Go to the Slow Crystal Frequency field
− (Tresos 21.0 shown): Mcu module click on:
 General tab
 Scroll down to McuModuleConfiguration section
− Tresos 14.2.1: Mcu module click on:
 McuModuleConfiguration tab
 Double click on Index 0 (McuConfigPB_0)
 General tab

• Verify the value 32767 (default).


− This is the SXOSC crystal.

236 PUBLIC
Mcu (2): SXOSC - Enable

• Click on McuClockSettingConfig tab


• Double click on index 0 to open
McuClockSettingConfig

• In the General tab,


scroll down to bottom right,
click to enable SXOSC
(if not enabled already)

237 PUBLIC
Mcu (3): SXOSC - Set frequency, other parameters
• Click on McuSXOSC tab
− Configureparameters as
needed. (Tresos 21.0 shown)
− For this example, the default
values are used so no changes
are needed
− Note other parameters
− Note: You can configure the
Mcu driver to not touch SXOSC
at all using parameter
SXOSC under MCU control
 Similar capability exists for other
Mcu resources

238 PUBLIC
Mcu (4) - Configure clock reference point with SXOSC - 1
• Click on box with number N which display names of other N tabs:

• Select McuClockReferencePoint

239 PUBLIC
Mcu (5) - Configure clock reference point with SXOSC - 2
• Click green + to add new clock
reference point for SXOSC
− This will be needed for Gpt driver

• Double click on added reference


point’s index to configure it

240 PUBLIC
Mcu (6) - Configure clock reference point with SXOSC - 3
• Name: ClkRefPnt_SXOSC

• Mcu Clock Frequency Select:


choose SXOSC

• Mcu Clock Reference Point


Frequency: Double click on
calculate value

• Remember -
− Mcu module configures all clocks.
− Clock reference points are a
mechanism to provide clock
information from Mcu module to
other modules.

241 PUBLIC
Gpt configurations - Gpt module: RTC / SXOSC channel & clk ref pt
Gpt module
Tab: GptClockReferencePoint
Index 0: GptClockReferencePoint_0 (rename to GptClkRefPnt__0_SXOSC)
Tab: General (select GptClockReference = ClkRefPnt_SXOSC)
Tab: GptChannelConfigSet
Index 0: GptChannelConfigSet_0
Tab: GptChannelConfiguration (delete current configurations,
then add new one)
Index 0: GptChannel_0
Tab: General (rename channel to RtcTimer,
GptHwCh = RTC, continuous mode,
RTC clock source = SXOSC,
GptChannelSrcRef = GptClkRefPnt_0_SXOSC

242 PUBLIC
Gpt (1) – Gpt clock reference points – delete prior ones
• Go to Gpt configuration
• Delete prior ref. points:
− Selecttab
GptClockReferencePoint
− Click
the GptClockReference
shown for Index 0 to select it
− Click red “X” to delete index 0
− (Repeat if any other reference
points are present)

243 PUBLIC
Gpt (2) – Gpt clock reference points – add one for SXOSC
• Add new ref. point:
− Click green ”+” to add index
− Edit Name:
 Select index 0 Name cell
 Change name to
GptClkRefPnt_0_SXOSC
− Edit GptClockReference
 Click on cell to highlight it,
 Click on down arrow on right
for options and select
ClkRefPnt_SXOSC

244 PUBLIC
Gpt (3) : Delete existing channels
• Click GptChannelConfigSet tab

• Select all existing channels


(select indices)

• Click X to delete those unneeded


channels

245 PUBLIC
Gpt (4) - Add Gpt channel
• Add Channel: Click on Green +

• Double click on new channel’s index to


configure it

246 PUBLIC
Gpt (5) – Configure Gpt channel - 1

• Name: RtcTimer

• GptHwChannel: Scroll down


selections to enable and select
RTC_0_CH_0

• Note some parameters have red


boxes in front of them. This means
the parameter is disabled.
• Those boxes will have to be
checked to enable the parameter
for configuration

247 PUBLIC
Gpt (6) - Configure Gpt channel - 2

• GptChannelMode: choices are one


shot or continuous. Select
GPT_CH_MODE_CONTINUOUS
• GptChannelTickFrequency: this can
be configured automatically later
GptRtcChannelClkSrc:
− Click red box to enable configuration
− Select RTC_GPT_CLKSRC_SXOSC
• GptChannelPrescaler: See
Description for prescaler value to
divisor. Enter “2” for divide the
32KHz SXOSC by 32.

248 PUBLIC
Check for problems
• Either Generate or look at the Problems tab at the bottom of the Tresos workspace.
• The following slides show expected errors and how to fix them.
− Error correction is efficient for most problems.

249 PUBLIC
New Derivative Possible Error – Not enough children 1

• The Error description says there are not enough “children” in the container
GptHwConfiguration_0 (i.e. not enough Gpt channels)
− MPC5748G has more channels than
MPC5748C
• Clicking on the error message brings up
the module’s window that needs fixing,
GptHwConfiguration

250 PUBLIC
New Derivative Possible Error – Not enough children 2
• Select all elements
(indices) in
container
• Remove all
elements in
container

• Click on “Add
required elements”

251 PUBLIC
New Derivative Possible Error – Not enough children 3
• Now we have all
required 55 elements
(0 to 54)

252 PUBLIC
Possible Error –Mcu Number of Mcu Modes value

• Expand error and click on


“Invalid value for node”
• The Mcu – General Tab
appears and the cell is
highlighted for Mcu Number
of Mode Settings
• Click on down arrow to
“Calculate value”
• The proper value is
calculated

253 PUBLIC
Possible Error – Gpt channel not configured
• Select the error message
• Hover mouse over error to
see detail
• Click on message and the
Gpt – GptHwConfiguration
window appears with the
index highlighted that has
the problem
• Check both boxes for
RTC_0_CH_0:
− GptIsrEnable
− GptChannelsUsed

254 PUBLIC
Possible Error – Gpt channel tick value max
• Note: Some MCALs are
16 bit, but this is 32 bit
so the timer counter
must be changed to
2**32 (4294967295)

• Enter 4294967295 in the


GptChannelTickValueMax field

255 PUBLIC
Possible Error – Value out of range
• Clicking on this error
message brings up the
GptChannelConfiguration
window

• Click on the field’s down arrow to


automatically calculate the
proper value

• The field is loaded with the


calculated value

256 PUBLIC
Still have error indication? – Try a classic fix
• If the errors/problems have been corrected but an error is still displayed,
try a classic fix: Exit and restart Tresos!

257 PUBLIC
Gpt configurations - Mcu module: Complete configuration - Tresos 21.0
(Added configurations in bold print)
Mcu module
Tab: General
Section: McuModuleConfiguration (Verify Slow Crystal Frequency = 32KHz)
??Mcu Number of Mode Settings (Auto calculate value)
Tab: McuClockSettingConfig
Index 0: McuClockSettingConfig
Tab: General (Enable SXOSC)
Tab: McuSXOSC (Configure SXOSC divider, etc.)
Tab (far right): McuClockReferencePoint (add SXOSC reference point)
Index (new one): (Name: ClkRefPnt_SXOSC,
freq. select = SXOSC,
automatically calc ref pt value)

258 PUBLIC
Gpt configurations - Gpt module: Complete configuration - Tresos 21.0
(Added configurations in bold print)
Gpt module
Tab: GptClockReferencePoint
Index 0: GptClockReferencePoint_0 (rename to GptClkRefPnt__0_SXOSC)
Tab: General (select GptClockReference = ClkRefPnt_SXOSC)
Tab: GptChannelConfigSet
Index 0: GptChannelConfigSet_0
Tab: GptChannelConfiguration (delete current configurations,
then add new one)
Index 0: GptChannel_0
Tab: General (rename channel to RtcTimer,
GptHwCh = RTC, continuous mode,
RTC clock source = SXOSC,
GptChannelSrcRef = GptClkRefPnt_0_SXOSC
Gpt Channel Tick Frequency: auto calculate
Gpt Channel Tick Value: correct value)
Tab: GptHwConfiguration (If new derivative, update number of children in container)
Index x: RTC_0_CH_0: (Enable ISR and channel)

259 PUBLIC
WINDOWS
EXAMPLE 6 – GPT MODULE

260 PUBLIC
Duplicate & Rename Application
• Make another copy of the minimal
ap project

• Rename the project to replace


“minimal_ap” with “gpt”

261 PUBLIC
Update application with Tresos generated files
• Classic Sample Ap only:
− Copy include & src folders from the EB Tresos
generated folder location:

− Delete prior folders then paste copied folders


into application’s cfg folder (not tresos folder)
(May need to create cfg folder in application folder)

• Framework Sample Ap – first time only:


− Update launch.bat’s TRESOS_WORKSPACE_DIR
with Tresos project’s output path

262 PUBLIC
Modules– Add new modules to be built to the application’s list
• If present, remove Dio and Port modules (used in prior project)
• Add Gpt and Mcl (GPT requires Mcl to build) modules which will be compiled and
linked. In Modules file of application’s root folder:

MODULE_LIST := Base Det Dem EcuM Gpt Mcl Mcu Rte

263 PUBLIC
Add Gpt code to main function in main.c application’s src folder:

Add include file:


#include “Gpt.h”

Add code* to get timers to run before forever loop:


Gpt_Init(&GptChannelConfigSet);
Gpt_StartTimer(GptConf_GptChannelConfiguration_RtcTimer, 512 - 1);

• The 512-1 value is the timeout value until the flag is set. (512 clks @ 1K Hz)
• SXOSC and other clocks are already enabled by function Mcu_InitClock

* Note: in MPC574xG MCAL 4.0 the name of the GptChannelConfigSet was


GptChannelConfigSet_0 but is
GptChannelConfigSet for MPC574xG MCAL 4.2.

264 PUBLIC
Clean, build, download, debug
• Run program and verify RTC increments using the debugger

265 PUBLIC
Misc note

266 PUBLIC
EXAMPLE 7:
INTERRUPT

267 PUBLIC
Interrupt Introduction
• Summary: This example expands the prior Gpt project to have the timer’s flag
generate an interrupt. The interrupt service routine calls a notification function
which performs a simple task.

• Example Overview:
− Tresos: create a notification function for Gpt (RTC), enable channel/ISR
− Code: install ISR, enable IRQ and its notification, write notification function

• Architectures tested:
− MPC574xG (with GHS compiler)

268 PUBLIC
Background: Additional steps to Gpt example for interrupt
Step Where Notes
Tresos 1 Name notification Module container. Example: Notification function is user
function Gpt-GptChannelConfiguration code
-Channel’s Index
Prologue
2 Install provided ISR MPC574xG Classic Ap file: Get ISR name and vector
name at IRQ vector toolchains/vector_vle_mcal.s from module’s integration
manual Notification
ISR
3 Create enable Example’s main.c file Code will vary per chip Function
interrupt function family called
Code
4 Create Gpt channel Example’s main.c file MCAL driver will clear flag
notification function Epilogue
5 Enable Gpt channel Example’s main.c file MCAL driver will clear flag
notification
6 Enable Gpt channel Example’s main.c file (MPC5748G) Write IRQ
interrupt vector’s priority & core # to
INTC_PSRx
7 Enable all interrupts Example’s main.c file

269 PUBLIC
Workflow: Example 7 Interrupt
1. Tresos:
1. Close any previous projects (reduces risk of configuring module of wrong project)
2. Copy prior Tresos project to be used to start example*
3. Rename Tresos project to same name as application’s folder*
4. Load project’s configuration
* First time only
5. Sanity check: Generate and ensure no errors
6. Modify as desired (Name notification)
7. Generate
2. Windows:
1. Duplicate prior gpt application folder and rename to MPC574XG_MCAL4_2_RTM_1_0_0_gpt_irq_6M*
2. Tresos output files (.c and .h):
1. Classic Sample Ap: Copy Tresos output files to application’s folder used for build
2. Framework Sample Ap: Update launch.bat’s Tresos workspace path *
3. Modify application code (Install ISR, enable IRQ & notification add notification function)
4. Clean & Build
270 PUBLIC
TRESOS
EXAMPLE 7 - INTERRUPTS

271 PUBLIC
Tresos: Duplicate prior project
• Start Tresos
• Copy prior Gpt Project
• Rename project to MPC574XG_MCAL4_2_RTM_1_0_0_gpt_irq_6M
• Close unrelated projects
• Load project
• Generate to verify no errors

272 PUBLIC
Interrupt configurations - Gpt module: Name timer’s notification
Gpt module
Tab: GptChannelConfiguration
Index 0: RtcTimer
Tab: General (Enable & name RtcTimeoutNotification)

Prologue

Notification
ISR
Function
called

Epilogue

273 PUBLIC
Name Gpt notification

• Click on red box before


GptNotification to enable
naming notification

• Enter name for notification


function (name will be
used in your code):
RtcTimeoutNotification
− Notification function will be
called from the ISR.
− Notification function is for
user code in ISR

274 PUBLIC
Finish
• Ensure boxes checked: Required
for MPC574xG MCAL4.2 and
later-
GptHwConfiguration tab: Check
the RTC timer’s boxes for:
− GptIsrEnable
− GptChannelsUsed

• Save
• Generate
− Note: screenshot is from MCAL4.2.
It is not present in MCAL4.0 since
this is done automatically with that
version.
275 PUBLIC
WINDOWS
EXAMPLE 7 – INTERRUPTS

276 PUBLIC
Duplicate & Rename Application
• Make another copy of the gpt
project

• Rename the project to replace “gpt”


with “gpt_irq”

277 PUBLIC
Update application with Tresos generated files
• Classic Sample Ap only:
− Copy include & src folders from the EB Tresos
generated folder location:

− Delete prior folders then paste copied folders


into application’s cfg folder (not tresos folder)
(May need to create cfg folder in application folder)

• Framework Sample Ap – first time only:


− Update launch.bat’s TRESOS_WORKSPACE_DIR
with Tresos project’s output path

278 PUBLIC
Get ISR name & HW interrupt vector number

• See Integration Manual in MCAL’s eclipse/plugins/module/doc folder.


• Example from MPC574xG MCAL integration manual:
C:\NXP\AUTOSAR\MPC574XG_MCAL4_2_RTM_1_0_0\eclipse\plugins\Gpt_TS_T2D35M10I0R0\doc

279 PUBLIC
Vector_vle_mcal.s file (MPC574xG) - Install ISR to vector table
• Edit Vector_vle_mcal.s file in the application’s “toolchains” folder using integration
manual’s name and interrupt number. Add global and branch target as shown in
red below.
--------------------------------------
.globl Gpt_RTC_0_Ch_0_ISR
--------------------------------------
IRQ225:
e_b Gpt_RTC_0_Ch_0_ISR #interrupt 225
.align ALIGN_SIZE

280 PUBLIC
main.c file (MPC574xG) – Add enable IRQ & notification functions
• Remember - notification name(s) were created in Tresos.
• Use two underscores in front of “asm”: __asm
/*====================================================================
GLOBAL VARIABLES
======================================================================*/
VAR(uint8, AUTOMATIC) GptRtcCounter = 0;
/*====================================================================
LOCAL FUNCTION PROTOTYPES
======================================================================*/
void sys_enableAllInterrupts(void);
void RtcTimeoutNotification(void);
/*====================================================================
LOCAL FUNCTIONS
======================================================================*/
void sys_enableAllInterrupts(void)
{
__asm(" wrteei 1"); /* MPC5xxx: sets MSR[EE] = 1 */
}
void RtcTimeoutNotification(void)
{
GptRtcCounter++;
}

281 PUBLIC
main.c file (MPC574xG) – Add enable IRQ & notification code
• Add device header file for writing to chip’s registers (used here for enabling a
peripheral interrupt and priority.)
#include “MPC5748G.h”
• Add the three code lines just befo re starting the Gpt timer:
Gpt_Init(&GptChannelConfigSet_0);
Gpt_EnableNotification(GptConf_GptChannelConfiguration_RtcTimer);
REG_WRITE16(INTC_PSR(225), 0x8006); /* Gpt_RTC_0_CH_0_ISR: Core 0, priority 6 */
sys_enableAllInterrupts();
Gpt_StartTimer(GptConf_GptChannelConfiguration_RtcTimer, 512-1);

• Note:
− RTC clock rate is 32KHz divided by 32 here = 1KHz.
− RTC timeout is 512 clocks @ 1KHz, about every half second.

282 PUBLIC
Complete project
• If not done, save Tresos and code changes
• Clean
• Run launch.bat
• If no errors, download and run.
• Verify GptRtcCounter increments

283 PUBLIC
Review: Timer Interrupt Example Steps
Configuration:
• Add GPT channel (done)
− Configure GPT channel for RTC_0_CH_0 and set other parameters for this channel (done)
 MCAL supports RTC-API wakeup only, not just RTC wakeup
• Name notification function (to be called in ISR between prologue and epilogue)
• Enable the GPT channel in GptHwConfiguration (Required for MCAL 4.2 and later)
Code:
• Install interrupt service routine Gpt_RTC_0_Ch_0_ISR on vector 225 (MPC574xG)
− Vector_vle_mcal.s file: use name from GPT Integration Manual
• Enable interrupt and notification in initialization task (if OS used then ISR needs to be
configured in OS configuration)
• Call Gpt_StartTimer() using either the timer’s ID number or symbolic name (done)
• Write notification function (called by driver ISR) for interrupt [see main.c]

284 PUBLIC
Review: Interrupt sequence (shown with RTC)
• RTC interrupt is recognized in hardware
• Execution starts at peripheral’s vector (#225 for MPC574xG RTC)
• Vector’s ISR, Gpt_RTC_0_Ch_0_ISR, is executed
− Executes generated prologue
− If notification is configured, then ISR will call notification function.
 In this example RtcTimeoutNotification is has been configured
 Notification function includes user application code, such as incrementing counter, writing
outputs, etc.
− Executes generated epilogue

285 PUBLIC
EXAMPLE 8:
STANDBY MODE

286 PUBLIC
STANDBY Introduction
• Summary: This example expands the prior Gpt project. The Gpt (RTCAPI) and a pin transition are configured to be
wakeup events. STANDBY mode is entered then exits by a reset or wakeup events of Gpt timeout or pin transition
caused by pushbutton. LEDs indicate reset or wakeup event occurred.
− Not covered in example: wakeup to SRAM, maintaining variable values during STANDBY, pad keeper function

• Example Overview:
− Tresos: Configure Icu for wakeup events, Mcu STANDBY mode, Port & Dio for an input with wakeup capability and two outputs.
− Code:
 Perform first initializations including Port configurations for LEDs
 Test and show if reset or wakeup event occurred:
• If a STANDBY exit from RTCAPI timeout occurred: clear wakeup source flag and turn on LED1
• If a STANDBY exit from a pin transition occurred: clear wakeup source flag and turn on LED2
• If a reset occurred: clear all reset flags and turn on both LED1 and LED2
• Delay (for observing which LEDs are on)
 Perform additional initializations including those to prepare for STANDBY
 Enter STANDBY. If STANDBY mode is not entered, service any wakeup events and try again.

• Architectures tested:
− MPC574xG (with GHS compiler)

287 PUBLIC
Background: RTC API timer Gpt timer is started
& configured (APIVAL
• The chip hardware has value) by user code.
This example uses
capability for low power APIVAL=1000, for
timer exit when the RTC 1 second timeouts
counter value matches
− The RTCVAL value, or
− The sum of a prior RTC GptChannelPrescaler:
counter value plus APIVAL divide by 32
RTC counter input:
offset. 1 KHz clock
• API, Autonomous Periodic
Interrupt, is used by MCAL.
• This example’s
configuration is shown in
red CLKSEL:
32 KHz SXOSC

288 PUBLIC
Background: Wakeup sources (MPC5748G)
• RTC API timeout:
− Wakeup source ID: 0
− WKPU registers bit: 31

• Pin PA2 pin transition:


− Wakeup source ID: 3
− WKPU registers bit: 28

Wakeup source ID: 31 30 29 ... 0


• Reference: MPC5748G WKPU registers bit: 0 1 2 … 31

reference manual’s WKPU


chapter and attached I/O
spreadsheet
289 PUBLIC
Background: Handling blocked STANDBY Mode entry
• STANDBY mode entry, Mcu_SetMode(McuConf_McuModeSettingConf_STANDBY), is prevented if there is a:
− Pending wakeup: Function returns but hardware prevents STANDBY entry, and invalid & illegal mode transition status bits set.
− Pending interrupt: Function returns after timeout configured in MCU driver by parameter McuTimeout.
(Note: Mode Entry unit recognizes external interrupts even if disabled at core, i.e., MSR[EE] = 0.)
− RESET: Code starts at reset vector
Note: Users can poll above bits to check status, but this MCAL example does not use them nor clear them.
To examine MCAL driver code for standby, see source files. Example:
C:\NXP\AUTOSAR\MPC574XG_MCAL4_2_RTM_1_0_0\eclipse\plugins\Mcu_TS_T2D35M10I0R0\src
Issue blocking ME_IS[I_IMODE] ME_GS[S_MTRANS] User Action
STANDBY entry (invalid mode transition) & (mode transition in
ME_IMTS[S_MRIG] progress)
(Illegal mode transition request)

Pending 1 0 - Service wakeup event,


Wakeup - then clear ME_IS[I_IMODE] & ME_IMTS[S_MRIG] flags,
Event - then re-attempt entering STANDBY.
Pending 0 0 (if using MCAL Application error. The Mode Entry module assumes all
Interrupt Mcu_SetMode) interrupts are disabled and serviced (other than wakeups)
before attempting to enter STANDBY mode. Recommend:
1 (if using bare - Development phase: trap condition to allow resolution
metal code) - Production phase: Provide error handler to recover condition

290 PUBLIC
Workflow: Example 8 STANDBY
1. Tresos:
1. Close any previous projects (reduces risk of configuring module of wrong project)
2. Copy prior Tresos project to be used to start example*
3. Rename Tresos project to same name as application’s folder*
4. Load project’s configuration
* First time only
5. Sanity check: Generate and ensure no errors
6. Modify as desired (Configure Mcu, EcuM, Icu, Gpt, Port & Dio)
7. Generate
2. Windows:
1. Duplicate prior gpt application folder and rename to MPC574XG_MCAL4_2_RTM_1_0_0_gpt_irq_6M*
2. Tresos output files (.c and .h):
1. Classic Sample Ap: Copy Tresos output files to application’s folder used for build
2. Framework Sample Ap: Update launch.bat’s Tresos workspace path *
3. Modify application code (Enter STANDBY; use LEDs to indicate reset or STANDBY exit)
4. Clean & Build
291 PUBLIC
TRESOS
EXAMPLE 8 – STANDBY

292 PUBLIC
Tresos: Duplicate prior project
• Start Tresos
• Copy prior Gpt Project
• Rename project to MPC574XG_MCAL4_2_RTM_1_0_0_standby_6M
• Close unrelated projects
• Load project
• Generate to verify no errors
• Module Configurations: check Enable and Generate boxes for modules:
− Icu
− Port
− Dio

293 PUBLIC
If using a new derivative: update IcuHwInterruptConfigList
Example: Using MC5748G and original ap was
for MPC5746C, which has a subset of
MPC5748G peripherals

• Select all elements in list

• Click red X to delete all elements

• Click on Add required elements


-> the peripherals for that derivative are
automatically added.

If above is not done, there will be a Tresos Error


Log Entry. Right clicking on entry shows the
details.

294 PUBLIC
STANDBY configurations - Mcu: add STANDBY mode & enable it for RTCAPI

Mcu module
Tab: McuModeSettingConf (Click + to add element)
Index of new element: McuModeSettingConf_1 (Double click)
Tab: General (Configure per below:)
Name: STANDBY,
Operating Mode: STANDBY0,
System Clock Switch: DISABLE,
Uncheck (disable) clock boxes except: SXOSC enabled,
Flash Power-Down Control: PowerDown,
Output Power Down Control: check box
McuModeSettingConfAfterWkp – OPTIONAL if Mcu Fast Transition enabled
System Clock Switch: SIRC (becomes sysclk)
SXOSC Control: Checked
Tab: General
McuModuleConfiguration (Name: McuConfigPB)
McuEnableMode (Name: McuEnableMode)
(check STANDBY0 Mode box to enable it)
Mcu Number of Mode Settings
(Click on “Calculate Value” to update number for new mode)
Tab: McuPeripheral (If PCTL102_RTC_API is not listed, click + to add element. Configure per below)
McuPeripheral_##:
Name: PCTL102_RTC_API
Run Modes Configuration: Select McuRunConfig_0
Non-Run Modes Configuration: Select McuLowPowerConfig_0
Tab: McuRunConfig
Index McuRunConfig_0: Ensure at least DRUN is selected
Tab: McuLowPowerConfig
Index McuLowPowerConfig_0: Ensure at least STANDBY is selected
295 PUBLIC
STANDBY configurations - EcuM: Add wakeup sources
EcuM module
Tab: EcuMWakeupSource (Add 2 wakeup sources)
Index 0:
Tab: General (Add, wakeup source RTC_API, ID 0)
EcuMWakeupSourceId: 0
EcuM WakeupSourcePolling: check box
Index 1:
Tab: General (Add, wakeup source pin PA2, ID 3)
EcuMWakeupSourceId: 0
EcuM WakeupSourcePolling: check box

296 PUBLIC
STANDBY configurations - Gpt: Enable wakeup for RTC-API
Gpt module
Tab: General
GptConfigurationOfOptApiServices (Enable wakeup API)
GptWakeupFunctionalityApi: Check box
Tab: GptChannelConfiguration
Index 0: RtcTimer
Tab: General
GptEnableWakeup: Enable by checking it’s box
GptWakeupConfiguration
Name: Enable by checking its box
GptWakeupSourceRef: select EcuMWakeupSource_0

297 PUBLIC
STANDBY configurations – Icu 1: Configure Icu & Wakeup channels
Icu module [note: create IcuWkpu channels first as shown here!]
Tab: IcuWkpu
Index 0: IcuWkpu_0 (Click green “+” twice to add 2 elements)
Tab: IcuWkpuChannels
Index 0:
Tab: WkpuChannels
Name: RTC_timer_wakeup,
Wkpu Channel: select WKPU_CH_0
Index 1:
Tab: WkpuChannels
Name: Pushbutton_wakeup,
Wkpu Channel: select WKPU_CH_3
Tab: IcuChannel (Click green “+” twice to add 2 elements)
Index of 1st added element
Tab: General IcuChannel_RTCwakeup used
Name: IcuChannel_RTCwakeup for API IcuInit
IcuHwIP: WKPU
IcuWkpuChannelRef: check to enable & select RTC_timer_wakeup
IcuMeasurement mode: Select edge detect (only option for STANDBY)
IcuWakeupCapability: Check box to enable
IcuSignalEdgeDetection
Name: Check box (turns green) to enable
IcuSignalEdgeDetection: check box (turns green) to enable
IcuWakeup:
Name: Check box to enable & use name IcuWakeup
IcuChannelWakeupInfo: Check box to enable and select EcuMWakeupSource_0

298 PUBLIC
STANDBY configurations – Icu 2: Configure Icu & Wakeup channels
Icu module - continued
Tab: IcuChannel - continued
Index of 2nd added element
Tab: General
Name: IcuChannel_PushbuttonWakeup
IcuHwIP: WKPU
IcuWkpuChannelRef: check to enable & select Pushbutton_wakeup
IcuMeasurement mode: Select edge detect (only option for STANDBY)
IcuWakeupCapability: Check box to enable
IcuSignalEdgeDetection
Name: Check box (turns green) to enable
IcuSignalEdgeDetection: check box (turns green) to enable
IcuWakeup:
Name: Check box to enable & use name IcuWakeup
IcuChannelWakeupInfo: Check box to enable and select
EcuMWakeupSource_1
Tab: General
IcuConfigSet IcuConfigSet used for APIs Icu_EnableEdgeDetection
Name: IcuConfigSet & Icu_EnableWakeup
IcuMaxChannel: (Click to automatically update value)
Tab: IcuHwInterruptConfigList – update if using different derivative than original Sampe App

299 PUBLIC
STANDBY configurations - Port module: Add 3 GPIO pins -NEW
Port module
Tab: General
Name used for API PortInit
PortConfigSet: Name: PortConfigSet
Tab: PortContainer
Index 0: Name: PortContainer_0
Tab: PortPin (remove all existing port pins except JTAG (DCI) pins & add 3 PortPins)
Index of 1st added PortPin
Name: LED1
Tab: General
Device Evaluation Board LED (Output) PortPinId (click on calculate value)
PortPinPcr: 98, PortPinDirection: output
GPIO Port Pad Ctrl
PortPin Mode: GPIO
Pin Reg
Index of 2nd added PortPin
MPC574xG Mother–Daughter EVB LED1 PG2 MSCR98 Name: LED2
& MPC5748G-LCB Tab: General
LED2 PG3 MSCR99 PortPinId (click on calculate value)
Switch2 PA2 MSCR2 PortPinPcr: 99, PortPinDirection: output
PortPin Mode: GPIO
MPC5748G DEVKIT – MPC5748G LED1 PA10 MSCR10
Index of 3rd added PortPin
LED2 PA7 MSCR7 Name: Switch2
Tab: General
Switch pins lack wakeup PortPinId (click on calculate value)
PortPinPcr: 2, PortPinDirection: input
PortPin Mode: GPIO
Index of 4 remaining DCI (JTAG) PortPins
PortPinId (click on calculate value)
300 PUBLIC Tab: General: PortNumberOf PortPins: Click calculate value to update number
STANDBY configurations - Dio module: add 2 ports/channels
Dio module (DioPorts and DioChannels shown for Mother-Daugher EVB)
Name: Dio
Tab: General
DioConfig: Name: DioConfig
Index 0: DioConfig_0
Tab: DioPort (remove all DioPorts; add 1 DioPort)
Index 0:
Name: Dio_PG
Tab: General
Dio Port Id: 6 (for Port G) Device Evaluation Board LED (Output)
Tab: DioChannel (Add 2 channels) LED# Port Pad Ctrl
Index 0: Pin Reg
Name: LED1 MPC574xG Mother–Daughter EVB LED1 PG2 MSCR98
& MPC5748G-LCB
Dio Channel Id: 2 LED2 PG3 MSCR99
Index 1: MPC5748G DEVKIT – MPC5748G LED1 PA10 MSCR10
Name: LED2 LED2 PA7 MSCR7
Dio Channel Id: 3

301 PUBLIC
STANDBY configurations - Dio module: add ports, 3 channel NEW
Dio module (DioPorts and DioChannels shown for Mother-Daugher EVB)
Name: Dio
Tab: General
DioConfig: Name: DioConfig
Index 0: DioConfig_0
Tab: DioPort (remove all DioPorts; add 2 DioPorts)
Index 0:
Name: Dio_PG
Tab: General
Dio Port Id: 6 (for Port G) Device Evaluation Board LED (Output)
Tab: DioChannel (Add 2 channels) GPIO Port Pad Ctrl
Index 0:
Name: LED1 Pin Reg
Dio Channel Id: 2 MPC574xG Mother–Daughter EVB LED1 PG2 MSCR98
Index 1: & MPC5748G-LCB
Name: LED2 LED2 PG3 MSCR99
Dio Channel Id: 3
Index 1: Switch2 PA2 MSCR2
Name: Dio_PA MPC5748G DEVKIT – MPC5748G LED1 PA10 MSCR10
Tab: General LED2 PA7 MSCR7
Dio Port Id: 0 (for Port A)
Tab: DioChannel (Add 1 channel) Switch pins are not wakeup
Index 0:
Name: Switch2
Dio Channel Id: 2

302 PUBLIC
Generate
• Generate project, and fix any errors

303 PUBLIC
WINDOWS
EXAMPLE 8 – STANDBY –

304 PUBLIC
Duplicate & Rename Application
• Make another copy of the gpt
project

• Rename the project to replace “gpt”


with “standby”

305 PUBLIC
Update application with Tresos generated files
• Classic Sample Ap only:
− Copy include & src folders from the EB Tresos
generated folder location:

− Delete prior folders then paste copied folders


into application’s cfg folder (not tresos folder)
(May need to create cfg folder in application folder)

• Framework Sample Ap – first time only:


− Update launch.bat’s TRESOS_WORKSPACE_DIR
with Tresos project’s output path

306 PUBLIC
Modules– Add new modules to be built to the application’s list
• Add Port & Dio module (used for output to LEDs) and Icu to list in Modules file of
application’s root folder:

MODULE_LIST := Base Det Dem Dio EcuM Gpt Icu Mcl Mcu Rte Port

307 PUBLIC
main.c (1): Include files
#include "typedefs.h“
#include "Mcal.h“
#include "Mcu.h“
#include "Gpt.h“
#include "Icu.h“
#include "Mcl.h“
#include "Port.h“
#include "Dio.h“
#include "MPC5748G.h"

308 PUBLIC
main.c (2): First initializations
int main( )
{
volatile uint32_t ret = 0;
volatile uint32_t delay_counter = 0;

/*********** First initializations *******************************/

Mcu_Init(&McuConfigPB);
ret = Mcu_InitClock(McuConf_McuClockSettingConfig_McuClockSettingConfig);
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{ /* wait until all enabled PLLs are locked */
}
Mcu_DistributePllClock(); /* switch system clock tree to PLL */
Port_Init(&PortConfigSet); /* Initialize configured pins */

309 PUBLIC
main.c (3): Test if wakeup or reset
/************** Test if wakeup or reset occured and show status *************/
/* If RTC-API wakeup: clear flag, turn LED1 on */
if (WKPU.WISR.R == 0x00000001)
{
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED1, 0); /* LED 1 on */
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED2, 1); /* LED 2 off */
WKPU.WISR.R = 0x00000001; /* Clear RTC flag */
}
/* If Pushbutton wakeup: clear flag, turn LED2 on */
if (WKPU.WISR.R == 0x00000008)
{
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED1, 1); /* LED 1 off */
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED2, 0); /* LED 2 on */
WKPU.WISR.R = 0x00000008; /* Clear WKPU[3] flag */
}
/* If any reset: clear all reset flag(s), turn both LEDs on */
if (MC_RGM.DES.R || MC_RGM.FES.R) /* if reset */
{
MC_RGM.DES.R = 0xFFFFFFF; /* clear flags */
MC_RGM.FES.R = 0xFFFFFFF;
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED1, 0); /* LED 1 on */
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED2, 0); /* LED 2 on */
}
/* Delay to observe LED status */
for (delay_counter = 0; delay_counter < 400000; delay_counter++) {}

310 PUBLIC
main.c (4): Additional initializations and STANDBY preparation
/******* Additional initializations and to prepare for STANDBY ***********/

Gpt_Init(&GptChannelConfigSet);
Gpt_EnableWakeup(GptConf_GptChannelConfiguration_RtcTimer);
Gpt_StartTimer(GptConf_GptChannelConfiguration_RtcTimer, 1000); /* Timeout ~1000 msec */
GPR.CTL.B.RTC_SXOSC_FREE_RUNNING = 1; /* Run SXOSC during resets, STANDBY */

Icu_Init(&IcuConfigSet); /* Any wakeup flags are cleared here */


Icu_EnableEdgeDetection(IcuConf_IcuChannel_IcuChannel_RTCwakeup);
Icu_EnableWakeup(IcuConf_IcuChannel_IcuChannel_RTCwakeup);
Icu_EnableEdgeDetection(IcuConf_IcuChannel_IcuChannel_PushbuttonWakeup);
Icu_EnableWakeup(IcuConf_IcuChannel_IcuChannel_PushbuttonWakeup);

Icu_SetMode(ICU_MODE_SLEEP); /* Put non-wakeup channels to sleep */


Gpt_SetMode(GPT_MODE_SLEEP); /* Put non-wakeup channels to sleep */

/* NOTE: Before attempting STANDBY entry, all interrupts must be disabled by clearing
their interrupt enabled bit. Clearing MSR[EE] has no effect to Mode Entry module in this
case. After disabling interrupts, service any that were pending.
*/

311 PUBLIC
main.c (5): Enter STANDBY mode (end of main)
/************************* Enter STANDBY ***************************/
while (1)
{
/* Attempt to enter STANDBY */
Mcu_SetMode(McuConf_McuModeSettingConf_STANDBY);
/* If RTC-API wakeup exists: clear flags */
if (WKPU.WISR.R == 0x00000001)
{
WKPU.WISR.R = 0x00000001; /* Clear RTC-API wakeup flag */
RTC.RTCS.R = 0x00002000; /* Clear RTC-API interrupt flag */
}
/* If Pushbutton wakeup exists: clear flag */
if (WKPU.WISR.R == 0x00000008)
{
WKPU.WISR.R = 0x00000008; /* Clear pin transition wakeup flag */
}
}
} /* End of main */

312 PUBLIC
Complete project
• If not done, save Tresos and code changes
• Clean
• Run launch.bat
• If no errors, download and run.
• Verify LED behavior:
− LED1 and LET2 lit on reset
− LED1 lit on wakeup from RTC-API
− LED2 lit on wakeup from pin transition caused by pushbutton

313 PUBLIC
Low Power – misc. notes 1
1. You can use Mcu_SetMode(Mcu_ModeType McuMode) API to put MCU to any expected mode of
operation from the list. You would need to create an McuMode configuration in Tresos at:
McuModuleConfiguration -> McuModeSettingConf. Please refer to UM/IM documents delivered for
further detail.

2. In STOP and LPU_STOP (not STANDBY) you can operate CAN in Pretended Networking Mode
where the Can controller is put into that mode and MCU are under the low power. If the Can controller
receives one wake up message, one wake-up event will be generated to wake MCU up. Please take it
in your consideration that this feature is only available
on MPC574XG_MCAL_1_0_0_RTM_ASR_REL_4_2. In order to do that, you may consider this
testing context:

- Configure the Can controller by calling to Can_SetIcomConfiguration() (this new API is only
available in ASR4.2 release for MPC574XG).

- Put Micro-controller into Low Power Mode (STOP/STANDBY/LPU,...) by calling toMcu_SetMode().

- Wait wake-up Can driver by call Pretended Networking interrupt.

314 PUBLIC
Low Power – misc. notes 2
3. If Pad Keeper function is enabled, the debugger will lose communication in
STANDBY mode (see note in reference manual – this is the intended behavior)
4. A simple test for code behavior of attempting to enter STANDBY is:
- When reset is detected, set a variable like Reset_Case = 1
- Just before entering STANDBY, wait for one of the wakeup events like timeout
by adding code to wait for the any wakeup status bit like:
while (WKPU.WISR.R == 0) { }

315 PUBLIC
Low Power - Preserving RAM contents in STANDBY Mode
The only way to guarantee RAM contents are preserved in STANDBY it is to assign those
contents to an address range using sections from the link file.

The retained 256k SRAM corresponds to addresses 0x40000000-0x4003FFFF which shall


be allocated to linker section and put there the data to retain during STANDBY.

In the MCAL MCU driver to retain 256k SRAM this needs to be configured inside the
McuPmcRamDomain_Config container by parameters:
“RAM Domain 64K Retention”
“RAM Domain 128K Retention”
“RAM Domain 256K Retention”

All these parameters shall be configured to true (checkboxes checked).

316 PUBLIC
Low Power - Measuring STANDBY current

• On MPC574xG mother-daughter
evaluation board:
− Remove jumper 3V3S and place current
meter between pins
− Measured current on application with
16MHz FIRC system frequency:
 60 uA STANDBY mode
 20 mA normal running mode
• Note: Wakeup pins that have external
pull down resistors should disable weak
pullup resistors on those pins in the
wakeup module to get specified
wakeup current.

317 PUBLIC

Вам также может понравиться