This document shows the step-by-step process to create a simple blinking LED application for the S32M2xx family using the S32 RTD AUTOSAR drivers. This example used for the S32M244 EVB, connected to a PC through P&E Debugger.
Preparation
- Setup the software tools
- Install S32 Design Studio for S32 Platform
- Install the S32M2xx development package and the S32M24 RTD AUTOSAR 1.9.0 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_With_AUTOSAR'. The name must be entered with no space characters.
- Expand Family S32M2xx, Select S32M244
- Click Next
- Click '…' button next to SDKs
- Check box next to PlatformSDK_S32K1_S32M24_2_0_0_S32M244_M4F (or whichever latest SDK for the S32M2xxx is installed). 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.
- Select the overview tab and disable Pins tool. Make sure to overview tab windows shows settings shown as below. Here, we are disabling pin tools and using MCAL driver from peripheral tools for using AUTOSAR drivers.
- Now from Overview menu, select peripheral tools and double click to open it.
- In the driver sections, “Port_Ip_1 driver” is the non-AUTOSAR version driver and so it must be replaced. Right click on ‘Port_Ip_1’ and remove it. Keep the BaseNXP driver as it is.
- Click on the ‘+’ next to the MCAL box.
- Locate and then select the ‘MCU’ component from the list and click OK.
- Click on the ‘+’ next to the MCAL box again, and Locate and then select the ‘Dio’ component from the list and click OK.
- Click on the ‘+’ next to the MCAL box again, and Locate and then select the ‘Port’ component from the list and click OK.
Now components tab should show like below :
Ignore the error for Port component for now.
- Now we required to configure the different MCAL drivers that we added. Starting with Dio configuration, open the Dio configuration.
- Now, open the ”DioConfig” tab. From that change Dio Port Id to 4 instead of 0
- In that, select “+” sign adjacent to Dio Channel.
- Then edit Name to “DioChannel_0”and “Dio Channel Id” to ‘6’ instead of ‘0’.
From the schematic for S32M244 EVB, we can select signal line for user LED from the schematic, channel 6 is connected to user LED signal, so we use channel 6 signal line to the chip on the user LED.
- Now Select Port tab for Port configuration.
- And select and open Port Configuration tab, and from that open “PortConfigSet” tab.
- Edit PortPin Pcr to “134” instead of “0”.
- Also, change Portpin Direction to “PORT_PIN_OUT” And PortPin Level Value to
“PORT_PIN_LEVEL_LOW”. After change it should be as below.
- At the bottom you will find the “UnTouchedPortPin ’’ . Click on “+’’ and add PortPins.
- Now add 6 port pins as per below configuration. Pins 0, 1,2,3, 4,5, and 6 should be setup.
- 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 clock tree and apply PLL as system clock, Apply a mode configuration, Initialize all pins using the Port driver by adding – editing code before write code here comment in main function.
/* Initialize the Mcu driver */
Mcu_Init(&Mcu_Config_BOARD_InitPeripherals);
/* Initialize the clock tree and apply PLL as system clock */
Mcu_InitClock(McuClockSettingConfig_0);
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{
/* Busy wait until the System PLL is locked */
}
Mcu_DistributePllClock();
Mcu_SetMode(McuModeSettingConf_0);
/* Initialize all pins using the Port driver */
Port_Init(NULL_PTR);
- Now replace the logic of for loop as shown below code section, which will enable the LED blinking for 10 times:
You also need to declare and initialize the loop variable uint8 count = 0U Then replace the code as below:
/* Logic for blinking LED 10 times */ while (count++ < 10)
{
/* Get input level of channels */
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:
void TestDelay(uint32 delay); void
TestDelay(uint32 delay)
{
static volatile 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:
Add
#include "Mcu.h"
#include "Port.h"
#include "Dio.h"
- Now, select and open max file again. Then, select and open peripheral tools.
Now, from the toolbar selection menu at the top, select and double click on the symbol as shown as below:
Now, from the global settings, for ComponentGenerationMethod from that select
“FunctionalGroups” from the drop down menu as shown below:
Now. click ‘Update Code’ from the menu bar.
- 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_with_AUTOSAR_Debug_RAM'. 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.
- Now, you need configuration for P&E MULTILINK Debug Probe.
- Connect PE Micro debugger to EVB using USB, and to make sure that debugger is connected via USB interface, then the COM port will be detected automatically (in the rare event where 2 or more debug Probes are connected via USB to the host PC, then it may be necessary to select which COM port is correct for the probe which is connected to the EVB).
- Now, Select PEMicro Multilink debugger, select “Run”, and select debug configuration tab, then select GDB PE Micro Interface Debugging, and from the option available under it, select option with Debug_FLASH_PNE.
- Now, in the debug configuration window, select the tab PEmicro Debugger, and in the PEMicro Interface settings, select the interface USB Multilink.
- Clink apply and debug
- Click Debug
- To see the LED blink, click ‘Resume'
- This code as it is will blink the LED 10 times, you can make changes in for loop condition to blink it infinitely.