getting started with mcal - nxp...manual, chapter 4 lin j13 j12 spi a12 - a13 uart j16 adc j17 pwm...
TRANSCRIPT
NXP and the NXP logo are trademarks of NXP B.V. All other product or service names are the property
of their respective owners. © 2017 NXP B.V.
PUBLIC
STEVE MIHALIK
GETTING STARTED WITH
MCAL
AMF-AUT-T2787 | AUGUST 2017
PUBLIC 1
AGENDAWhat is AUTOSAR, MCAL?
Sample Application
Example 1: Duplicate, Import, Generate, Build
Sample Application
Example 2: Download
Example 3: Port Module
Example 4: Dio Module
PUBLIC 2
What is AUTOSAR, MCAL?
PUBLIC 3
What is it AUTOSAR and why do we need it?
• AUTOSAR (AUTomotive Open System ARchitecture) is a partnership of automotive
manufacturers and suppliers working together to develop and establish an open industry standard
for automotive ECUs architectures.
• From a technical point of view, we can summarize the driving forces for the intended standardization
as follows:
− Manage increasing ECUs complexity associated with growth in functional scope
− Improve flexibility for product modification, upgrade and update
− Improve scalability of solutions within and across product lines
− Improve quality and reliability of E/E systems
− Enable detection of errors in early design phases
PUBLIC 4efficient qualified SW layer abstracting microcontroller complexity
MCAL =
MicroController Abstraction Layer• Production qualified software abstraction of
complex hardware features
− Easy to port from one platform to another
− Developed using SPICE Level 3 and ISO26262 standard compliant process.
15 standard drivers (MCU, PORT, DIO, ADC, GPT, PWM, ICU, WDG, FLS, FEE, SPI, LIN, CAN, FlexRay, Ethernet)
4 complex drivers extending AutoSAR on various platforms:
− MCL – centralized DMA & DMAMuxconfiguration and functionality, common timer code – all platforms
− I2C – Inter-Integrated Circuit driver – S32K
− MCEM – MicroController Error Management covering FCCU, MEMU – safety extension
− CRCU – CRC hardware acceleration – safety extension
PUBLIC 5
Sample Application
PUBLIC 6
Sample Application
• To get started, use the sample application included with released NXP MCAL product
• See the PDF document in the sample application’s doc folder for instructions
• AUTOSAR software specs can be downloaded from the autosar.org web site
− Click on Documents
− Click on Specifications
PUBLIC 7
MPC5748G EVB
connections• Important: EVB
connections
must be made or
Sample
Application code
may trap
• See Sample
Application User
Manual, chapter 4
LIN
J13
J12
SPI
A12 - A13
UART
J16
ADC
J17
PWM – LED52
A14 - A15 - P19-1
PUBLIC 8
Sample Application code summary (assumes no AUTOSAR OS)
• Main:
− Initialize MCU, clocks, peripherals, tasks, etc
− Loop while no errors:
Switch between 3 tasks
• Task 1: Read switches, set LEDs, configure timers and states
• Task 2: Serial operations: SPI, LIN, FlexRay, CAN, UART
• Task 3: ADC, PWM, IC
E2 emulation
− Write error message to console
PUBLIC 9
Sample application source code (shown in default install folder)
C:\NXP\AUTOSAR\MPC574XG_MCAL4_2_RTM_1_0_0\MPC574XG_MCAL4_2_RTM_1_0_0_Sample_Application\src
PUBLIC 10
Example 1: Duplicate, import,
generate, build sample project
PUBLIC 11
Suggested Sample Application Workflow
1. Windows:
1. Duplicate & rename sample application’s folder*
2. Tresos:
1. Import (copy) sample application’s Tresos project*
2. Rename project if desired*
3. Load project’s configuration
4. Sanity check: Generate and ensure no errors
5. Modify as desired
6. Generate
3. Windows:
1. Copy output (.c and .h files) from Tresos project’s output folder to sample application’s folder
2. Modify application code as desired
3. Build
* First time only
PUBLIC 12
Duplicate & Rename Sample Application
• Copy folder
• Paste
• Rename
PUBLIC 13
Importing Sample Application into Tresos
1. File - Import - General - Existing Projects into Workspace -> Click Next
2. Browse to root directory (Tresos folder). Example:
c:\NXP\ AUTOSAR\MPC574XG_MCAL4_2_RTM_1_0_0\ Sample1\Tresos
3. First time: Check “Copy” box to copy workspace from NXP folder to EB folder.)
4. Click OK -> Click Finish
PUBLIC 14
Optional: Rename Tresos Project
• Right click on project – Rename
• Enter new name - OK
PUBLIC 15
Opening a Sample Application Project
Right click on Sample1 -> select Load configuration
Now the project can be opened.
PUBLIC 16
Code Generation
Right Click on Sample1 and select Generate Project
PUBLIC 17
Tip: How to locate generated Tresos output files
1. Right click on project
2. Select properties
3. Select Resource,
& note Location
PUBLIC 18
After generation, copy new generated files to application
• Copy include & src folders from the EB Tresos generated folder location:
− Delete prior folders & paste new into application cfg folder (not tresos cfg folder)
PUBLIC 19
Build project
• Build: From a DOS prompt, go to the application’s folder. Example:
C:\NXP\AUTOSAR\MPC574XG_MCAL4_2_RTM_1_0_0\Sample1
• Enter launch.bat
PUBLIC 20
Example 2: Download
PUBLIC 21
Lesson Learned Tip (1 of 3): BAF records - Background
• The MPC57xx devices contain “BAF” code that executes before user code.
• One key task of BAF code is to identify a boot header, used to start core(s)
• BAF code does this task by:
− Searching defined locations in flash for an identifier value, starting with the lowest
address first
MPC5748G:
− Once found, the starting core(s) is identified and the subsequent start address(es) sent to
that core
PUBLIC 22
Lesson Learned Tip (2 of 3): BAF records – Case study
• 0xF8_C000: boot header often used for demo programs, such as in application note AN4830, Qorivva Recipes forMPC574xG. This is the 1st boot header location.
• 0xF9_8000: boot header used for MPC574xG MCAL sample application. This is the 7th boot header location, so 6 other boot header locations are searched first for the boot ID.
• When debuggers flash a program, they typically do not erase the entire code area, but just erase the code flash blocks required by that .elf file.
• Lesson learned sequence:
1. Loaded a demo program to flash, with boot header in the first location
2. Debugger stepped through source code and displayed symbols
3. Loaded MCAL sample application to flash, with boot header in 7th location. Erasure only erased flash blocks used in program!
4. MCU booted using demo code’s boot header, with demo code’s start vector
5. Debugger only displayed assembly code, and no symbols!
• Solution: erase entire code flash before loading above MCAL sample application
PUBLIC 23
Lesson Learned Tip (3 of 3): Erasing prior program flash
• GHS: Simple method - open prior project and follow steps to program the project,
but uncheck “Program”, keeping “Erase” and other boxes checked.
• Lauterbach: Use separate CMM file to erase all of code flash
• PEMicro: Use tool to erase code blocks ONLY.
PUBLIC 24
Download with Lauterbach
• A Lauterbach script file (.cmm) is included in the projects bin folder.
• Start Trace32
• Select File – Run
• Double click on run.cmm file in the project’s bin folder
− The .elf file will be used to program the flash.
− Enter in the bottom command window “go main” to get to the start of main
PUBLIC 25
Example 4: Port Module
PUBLIC 26
Background: MCAL Modules Used for GPIO
• PORT
− Configures port pins (SIUL2_MCSR and SIUL2_IMSR pad control register initializations)
− Pin identification: Done using Pin Configuration Register numbers (SIUL_MSCRx)s
− Generated code will be put in Port_Init function (name is an AUTOSAR standard). User must call Port_Init
• DIO (covered later)
− Used for reading and writing GPIO data
− Configures name to GPIO port pins (e.g. PA1, PA2, …, PB1, PB2, etc.)
− Pin identification: Dio Port Id number: Corresponds to port’s letter. (PortA=0, PortB=1, PortC=2, etc.)Dio Channel Id number: Corresponds to port Port pin’s number (0, 1, 2,…)
• References:
− User Manual for Sample MCAL Application
− AUTOSAR MCAL Integration and User Manuals for:
PORT Driver
DIO (Digital I/O) Driver
PUBLIC 27
Port and Dio APIs
• Port:
• 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 )
• Dio
• Dio_LevelType Dio_ReadChannel( Dio_ChannelType ChannelId )
• void Dio_WriteChannel( Dio_ChannelType ChannelId, Dio_LevelType Level )
• Dio_PortLevelType Dio_ReadPort( Dio_PortType PortId )
• void Dio_WritePort( Dio_PortType PortId, Dio_PortLevelType Level )
• Dio_PortLevelType Dio_ReadChannelGroup( const Dio_ChannelGroupType* ChannelGroupIdPtr )
• void Dio_WriteChannelGroup( const Dio_ChannelGroupType* ChannelGroupIdPtr, Dio_PortLevelTypeLevel )
• void Dio_GetVersionInfo( Std_VersionInfoType* VersionInfo )
• Dio_LevelType Dio_FlipChannel( Dio_ChannelType ChannelId )
PUBLIC 28
GPIO Configuration Example Summary
Using a copy of Sample Application:
• Remove two existing GPIO configurations:
• Add (back in) two GPIO pin configurations (use different name for LED 2 signal):
Name Function MCU Pin
Key1 Input from switch SW3 PA1
LED2 Output to LED 2, turned on by switch then timeout PG3
Name Function MCU Pin
KeySw4 Input from switch SW4 PA2
LED2Sw4 Output to LED 2, to be turned on/off by SW4 PG3
PUBLIC 29
MPC574xG EVB Information for desired GPIO
KeySw4
SIUL
MSCR#
1
28991
LED2Sw4
98
99
101
100
SIUL MSCR#
Used for DIO
pin identification
Used for PORT
pin identification
PUBLIC 30
Port: Delete two GPIO PortPins
• Navigate to
PortContainer_0:
− Select Port module
− Select PortContainer tab
− Double click on index 0
− Click PortPin tab
• Select Index 8 and
Index 12 (Ctrl-click)
• Click on the red
X to remove those
Port Pins
PUBLIC 31
Port: PortPin Id & # of Port Pins Adjustments
• PortPin Ids: must be contiguous & unique. Simple method -edit Ids manually:
− Click on PortPin Id column to sort column
− See PortPin Ids 6 and 9 are missing
− Edit last two PortPin Ids to be 6 and 9. PortPin Id’s automatically re-order.
• PortNumberOfPortPins: must be adjusted:
− Navigate up to PortContainer, General tab
− Click the “Calculate Value” and the number automatically re-adjusts
After
adjustmentBefore
adjustment
PUBLIC 32
Port: Example Task – add two port pins for GPIO
• Configure PORT (and DIO later) for two GPIO signals:
• From the signal description and input multiplexing tables in the spreadsheet attached to the MCU’s reference manual the Pin Configuration Register numbers are obtained in the SIUL MSCR# for these two ports.
• These values identify the port pin in the PortPinPcr field
Name Function MCU Pin
KeySw4 Input from switch SW4 PA2
LED2Sw4 Output to LED 2, to be turned on/off by SW4 PG3
PUBLIC 33
Port: Add 2 PortPins
• Add 2 ports (to be
configured for GPIO)
− Select a port (example:
Index 11)
− Click on “+” (or right-
click, “duplicate”)
− Add a second port by
clicking “+” again
• 2 unconfigured ports
are now added
PUBLIC 34
Port: Configure PortPin input (1 of 3)
• Double click on first port pin’s index (for
PortPin_0)
• See default port pin configuration
PUBLIC 35
Port: Configure PortPin input (2 of 3)
• Name: enter “KeySw4”
• PortPinPcr: (This is SIUL MSCR#. See ref.
manual’s signals spreadsheet):
− Be sure the field’s pencil icon is showing. If
not, click icon to “Set manually edited”.
− PortPinPcr: Set to 2
• PortPin Direction: PORT_PIN_IN
• PortPin Mode: GPIO
PUBLIC 36
Port: Configure PortPin input (3 of 3)
• PortPin Id:
− PortPin Ids are a unique number
used to identify the port configuration
− Click on the “Calculate Value” icon to
automatically get a unique number if
there is not one there already.
• Additional settings are not needed
here.
PUBLIC 37
Port: Configure PortPin output (1 of 2)
• Navigate back by up arrow at top right
of Window
• Double click on the other new
port pin’s index
PUBLIC 38
Port: Configure PortPin output (2 of 2)
• Name: LED2Sw4
• PortPin ID: Double click to ensurenumber is unique
• PortPinPcr: 99
• PortPin Direction: PORT_PIN_OUT
• PortPin Mode: GPIO
• PortPin Level Value (initial output level):
PORT_PIN_LEVEL_HIGH
PUBLIC 39
Port: There may be an error, like below……
• Click in problems view window to expand the error
− Click on the bottom line
• This brings up the Port Container window
− Click to get the calculate icon for PortNumberOfPortPins
− Double click to automatically get the proper number
• Now Problems View has no errors
PUBLIC 40
Example 4: DIO (for GPIO)
PUBLIC 41
Dio: driver mapping of ports (1 of 2)
• Project Explorer window:
− Click on Dio to expand
− Double click then in lower Dio
• Outline window:
− Expand DioConfig as shown
− Digital I/O symbols assigned to port pins can be seen
Example: Port Dio_PG: 1 channel (port pin led2)
with existing symbol names of Dio_LED2 & Dio_LED3
PUBLIC 42
Dio: driver mapping of ports (2 of 2)
• Digital I/O ports have numbers which
correspond to port letters in MPC5xxx
chips.
• Outline window: Click on Dio Port 0
• DIOPort window: Click on General tab
and see Dio Port ID of 0
• Properties window: describes port
mapping
PUBLIC 43
Dio: Remove channels(1 of 3)
Remove DioChannels which will be
replaced:
• Project Explorer: Click on Dio
• Dio window: Click on DioPort tab
• Dio tab: Double lock on Index 0
• DioChannel tab: select index 0
• Click red X “Remove selected elements”
PUBLIC 44
Dio: Remove channels(2 of 3)
• Click up arrow to navigate up to Dio
• Select Index 0
• Click red X to remove
the empty Dio_PA port
• Double click on the index for Dio_PG,
now 0
PUBLIC 45
Dio: Remove channels (3 of 3)
• Select DioChannel tab
• Select channel Dio_Led2
• Click red X to Remove selected element
PUBLIC 46
Dio: Add DioPort (1 of 2)
• Dio module config – double click
• Select DioPort tab. Port G is already there, but Port A is needed.
• Add new element for a port different from Port G (need Port A, pin PA1, for button)
Name Function MCU Pin
KeySw4 Input from switch SW4 PA2
Led2Sw4 Output to LED 2, to be turned on while SW4 is closed PG3
PUBLIC 47
Dio: Add DioPort (2 of 2)
• Double click on new index
• Change name to
to Dio_PA (to indicate
Port A in chip)
• Enter Port ID = 0 for
Port A
(See Properties
Description)
PUBLIC 48
Dio: Add channel to DioPort 0 (1 of 2)
• DioChannel tab: add new element by
clicking on “+”
• Double click on index 0
to configure new element
PUBLIC 49
Dio: Add channel to DioPort 0 (2 of 2)
• DioChannel Name: KeySw4
• Channel ID: 2 (for pin2 of port A; PA2)
PUBLIC 50
Dio: Add channel to Dio_PG (1 of 2)
• Navigate back twice (to Dio container)
• Double click on Index 0 for Port G channels
• Select DioChannel tab
• Add new element to get a new
channel for Dio_PG
PUBLIC 51
Dio: Add channel to Dio_PG (2 of 2)
• Double click in new channel ‘s index in DioPort DIO_PG (Index 1)
• Enter desired name: LED2Sw4
• Enter Dio Channel Id = 3(on MPC574xG, this is the port pin 3of port G, called pin PG3)
• Generate to check for errors
PUBLIC 52
Dio: channel symbolic names
• AUTOSAR convention requires using the following name format.
• Format: ModulenameConf_Containername_channel name
• Example (original names):DioConf_DioChannel_Dio_Led2
DioConf_DioChannel_Dio_Key1
• Symbolic names for coding are generated and placed in file Dio_Cfg.h in
folder c:\EB\tresos\workspace\sample_app….\output\include:#define DioConf_DioChannel_LED2Sw4 ((uint16)0x0063U)
#define DioConf_DioChannel_KeySw4 ((uint16)0x0002U)
PUBLIC 53
Dio: Place new Dio code in main.c:
Add global variable::
VAR(uint8, AUTOMATIC) LevelKey_4 =0;
Replace line of code in switch case 1:
ret = SampleAppTask1( p_stSampleAppData );
With code:
/* Turn off (1) LED2 if key 2 (SW4)is pressed (reads 1 if pressed)*/
LevelKey_4 = Dio_ReadChannel((Dio_ChannelType)DioConf_DioChannel_KeySw4 );
if (LevelKey_4 ==1)
{
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED2Sw4, 1);
}
else
{
Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED2Sw4, 0);
}
PUBLIC 54
Misc.
PUBLIC 55
MPC574xG EVB I/O Compatibility for MCAL Sample Application
MCAL Sample Ap Mother Board DEVKIT-MPC5748G Low Cost EVB
LED1, LED2, LED3, LED4 PG2, PG3, PG4, PG5 PA10, PA7, PF15, PC4,
PH5, PJ4, PA0, PA4
PG2, PG3, PG4, PG5
ADC Pot PB4 (PCR 20) PB4 PB4
eMIOS icu measurement:
eMIOS 1 11 PG2
eMIOS channel pins are
on connectors
eMIOS channel pins are
on connectors
CAN0_TX/RX,
CAN1_TX/RX
PB0/PB1, (PCR 16/17)
PC10/PC11 (PCR 42/43)
PB0/PB1,
--
PB0/PB1,
PC10/PC11
CAN Transceiver / Termination TJA1051 / none MC33901 / none MC33901 / none
LIN0_TX/RX
LIN1_TX/RX
LIN2_Tx/Rx (UART)
PB2/PB3
PC6/PC7 (PCR38/39)
PC8/PC9 (PCR 40/41)
PB2/PB3
-
PC8/PC9
PB2/PB3
PC6/PC7
PC8/PC9
DSPI_0 SOUT/SIN PA12/13 (PCR 13/12) Pins are on connectors Pins are on connectors
Push buttons (not used AN4830) PA1, PA2, PF9, PF11 PA3, PE12 PA1 (also NMI), PA2
NXP and the NXP logo are trademarks of NXP B.V. All other product or service names are the property of their respective owners. © 2017 NXP B.V.