This document shows the step-by-step process to create a simple 'Blinking_LED' application using the S32K1xx RTD and the S32 Configuration Tools. This example is for the S32K144EVB-Q100 EVB, connected to a PC through USB (OpenSDA) connection.
Preparation
- Setup the software tools
- Install S32 Design Studio for S32 Platform
- Install the S32K1xx development package and the S32K1 RTD AUTOSAR 4.4. Both of these are required for the S32 Configuration Tools.
- Launch S32 Design Studio for S32 Platform
Procedure
- New S32DS Project
OR
- Provide a name for the project, for example 'Blinking_LED_RTD_AUTOSAR'. The name must be entered with no space characters.
- Expand Family S32K1xx, Select S32K144
- Under Toolchain, select NXP GCC 9.2
- Click Next
- Click '…' button next to SDKs
- Check box next to PlatformSDK_S32K1_2022_02_S32K144_M4F. Click OK
- Click Finish. Wait for project generation wizard to complete, then expand the project within the Project Explorer view to show the contents.
- To control the LED on the board, some configuration needs to be performed within the Pins Tool. There are several ways to do this. One simple way by double-click on the MEX file.
- By default, the Pins tool is then presented. Since the AUTOSAR drivers will be used, click the switch to disable this tool from the Overview tab.
- Once the Pins tool is disabled, the Config Tools Overview menu appears. Select the Peripherals tool.
- After the Peripherals tool opens, look to the Components tab. By default, new projects are created with the osif and Port_Ip drivers. Leave the osif driver, but remove the Port_Ip driver. This will be replaced by AUTOSAR version. Right-click on the Port_Ip box and select Remove.
- Add the AUTOSAR version of the Port driver. Click on the ‘+’ next to the MCAL box. This will bring up a list of AUTOSAR components.
- Locate then select ‘Port’ and click OK. Do not worry about the warning message. It is only indicating that the driver is not already part of the current project. The associated driver package will be added automatically.
- There are a couple of other drivers needed. Click the ‘+’ next to MCAL again and this time select ‘Dio’. Once more, click the ‘+’ and select ‘Mcu’.
- Select the ‘Dio’ component. Now select the DioConfig tab. Under DioPort_0, change the Dio Port Id to 3. Click ‘+’ next to DioChannel to add a channel.
- Select the ‘Port’ component. Now select the PortConfigSet tabl.
- Under PortPin, change the setting for PortPin_0, PortPin Pcr from 0 to 96.
- Then change the setting PortPin Direction from PORT_PIN_IN to PORT_PIN_OUT.
- Change the setting PortPin Level Value from PORT_PIN_LEVEL_HIGH to PORT_PIN_LEVEL_LOW.
- Under UnTouchedPortPin, click ‘+’ and add the following 5 PortPin Pcr numbers: 4, 5, 10, 68, 69
- Now select the PortGeneral tab, uncheck ‘Port Ci Port Ip Development Error Detect’.
- Now the device configurations are complete and the RTD configuration code can be generated. Click ‘Update Code’ from the menu bar.
- To control the output pin which was just configured, some application code will need to be written. Return to the ‘C/C++’ perspective.
- If not already open, in the project window click the ‘>’ next to the ‘src’ folder to show the contents, then double click ‘main.c’ file to open it. This is where the application code will be added.
- Before anything else is done, initialize the mcu driver, the clock tree, and apply PLL as system clock. Insert the following line into main, after the comment 'Write your code here':
Mcu_Init(&Mcu_Config_BOARD_InitPeripherals);
Mcu_InitClock(McuClockSettingConfig_0);
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{
/* Busy wait until the System PLL is locked */
}
Mcu_DistributePllClock();
Mcu_SetMode(McuModeSettingConf_0);
- Before the pin can be controlled, it needs to be initialized using the configuration information that was generated from the S32 Configuration tools. Initialize all pins using the Port driver by adding the following line:
Port_Init(NULL_PTR);
- Turn the pin on and off with some delays in-between to cause the LED to blink. Make the delays long enough to be perceptible. Within the provided for loop, add the following lines:
Dio_WriteChannel(DioConf_DioChannel_DioChannel_0, STD_HIGH);
TestDelay(2000000);
Dio_WriteChannel(DioConf_DioChannel_DioChannel_0, STD_LOW);
TestDelay(2000000);
- Before the 'main' function, add a delay function as follows:
voidTestDelay(uint32 delay);
voidTestDelay(uint32 delay)
{
staticvolatile uint32 DelayTimer = 0;
while(DelayTimer<delay)
{
DelayTimer++;
}
DelayTimer=0;
}
- Update the includes lines at the top of the main.c file to include the headers for the drivers used in the application:
Remove
#include "Mcal.h"
Add
#include "Mcu.h"
#include "Port.h"
#include "Dio.h"
- Build 'Blinking_LED_RTD_AUTOSAR'. Select the project name in 'C/C++ Projects' view and then press 'Build'.
- After the build completes, check that there are no errors.
- Open Debug Configurations and select 'Blinking_LED_RTD_AUTOSAR_Debug_FLASH'. Make sure to select the configuration which matches the build type performed, otherwise it may report an error if the build output doesn’t exist.
- Confirm the EVB is connected to the PC via USB cable, then check the Debugger tab settings and ensure that 'OpenSDA Embedded Debug - USB Port' is selected for interface.
- Click Debug
- To see the LED blink, click ‘Resume'