HOWTO: Create a Blinking LED example project using S32K1xx RTD with AUTOSAR

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HOWTO: Create a Blinking LED example project using S32K1xx RTD with AUTOSAR

HOWTO: Create a Blinking LED example project using S32K1xx RTD with AUTOSAR

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

  1. Setup the software tools
    1. Install S32 Design Studio for S32 Platform
    2. Install the S32K1xx development package and the S32K1 RTD AUTOSAR 4.4. Both of these are required for the S32 Configuration Tools.
      image.png
  2. Launch S32 Design Studio for S32 Platform

Procedure

  1. New S32DS Project
    image.png
    OR
    image.png
  2. Provide a name for the project, for example 'Blinking_LED_RTD_AUTOSAR'. The name must be entered with no space characters.
  3. Expand Family S32K1xx, Select S32K144
  4. Under Toolchain, select NXP GCC 9.2
  5. Click Next
    image.png
  6. Click '…' button next to SDKs
    image.png
  7. Check box next to PlatformSDK_S32K1_2022_02_S32K144_M4F. Click OK
    image.png
  8. Click Finish. Wait for project generation wizard to complete, then expand the project within the Project Explorer view to show the contents.
    image.png
  9. 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.
    mikedoidge_0-1654712888960.png
  10. 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.
    image.png
  11. Once the Pins tool is disabled, the Config Tools Overview menu appears. Select the Peripherals tool.
    image.png
  12. 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.
    image.png
  13. 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.
    image.png
  14. 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.
    image.png
  15. 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’.
  16. 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.
    image.png
  17. Select the ‘Port’ component. Now select the PortConfigSet tabl.
    1. Under PortPin, change the setting for PortPin_0, PortPin Pcr from 0 to 96.
    2. Then change the setting PortPin Direction from PORT_PIN_IN to PORT_PIN_OUT.
    3. Change the setting PortPin Level Value from PORT_PIN_LEVEL_HIGH to PORT_PIN_LEVEL_LOW.
    4. Under UnTouchedPortPin, click ‘+’ and add the following 5 PortPin Pcr numbers: 4, 5, 10, 68, 69
      image.png
  18. Now select the PortGeneral tab, uncheck ‘Port Ci Port Ip Development Error Detect’.
    image.png
  19. Now the device configurations are complete and the RTD configuration code can be generated. Click ‘Update Code’ from the menu bar.
    image.png
  20. To control the output pin which was just configured, some application code will need to be written. Return to the ‘C/C++’ perspective.
    image.png
  21. 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.
    image.png
  22. 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);
    image.png
  23. 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);
    image.png
  24. 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);
    image.png
  25. 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;
    }
    image.png
  26. 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"
    image.png
  27. Build 'Blinking_LED_RTD_AUTOSAR'. Select the project name in 'C/C++ Projects' view and then press 'Build'.
    image.png
  28. After the build completes, check that there are no errors.
    image.png
  29. 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.
    image.pngimage.png
  30. 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.
    image.png
  31. Click Debug
  32. To see the LED blink, click ‘Resume'
    image.png
Comments

I would like to use PWM  (FlexPWM0 submoudle3  A3 & X3 2channel )function to control 2 LEDs via TI Dual-Channel Smart High-Side Power Switch.    

 

Use the internal clock.

Can switch the duty cycle. (25% / 50%)

How to config / init / start PWM on S32R372 ?  Could anyone provide the sample code ?

 

 

This is an insane way to toggle a port pin !!!

In your steps above you say "change the Dio Port Id to 3." Why 3? What does 3 mean ?!

What is the significance of 96? in "PortPin Pcr from 0 to 96".

Why do this "and add the following 5 PortPin Pcr numbers: 4, 5, 10, 68, 69" ?

This seems much more complicated than the just setting the pins in the pins page and using the SDK!

Andy

No ratings
Version history
Last update:
‎06-09-2022 01:41 PM
Updated by: