HOWTO: Create a Blinking LED Project (MPC5748G)

Document created by Mike Doidge Employee on Oct 25, 2017Last modified by Mike Doidge Employee on Oct 31, 2017
Version 4Show Document
  • View in full screen mode

Perhaps you are just using the S32DS for Power for the first time, and maybe you've seen the provided examples and want to learn a bit more about how they were created. Here are the steps to create a simple application for the MCP5748G MCU which toggles a pin causing one of the user LEDs to blink. This example includes use of the S32 SDK for Power Architecture.

 

Please note: There are options in the steps below to cover the case of either the DEV-KIT(DEVKIT-MPC5748G) or Motherboard(X-MPC574XG-MB) with Daughtercard(X-MPC574XG-324DS) hardware EVBs.

 

1) Launch S32DS for Power

2) Select File -> New -> New S32DS Project

3) Enter a name for the project, such as 'BlinkingLED'

4) Locate, from the list of processors, Family MPC574xG -> MPC5748G, and select it.

5) Click Next

6) Uncheck the boxes for cores Z4 and Z2, leaving just Boot Z4 checked. This is because the application will run on the boot core and will not use either of the other two cores.

7) Click on the '…' button next to SDKs, in the column for BlinkingLED_Z4_0.

8) Check the box next to MPC5748G_SDK_Z4_0_GCC to include support for the SDK within the new project and for the core we have selected.

9) Click OK

10) Click Finish to close the New Project wizard window and start the project generation.

11) Wait a minute or two for the project generation script to complete.

12) Go to the 'Components Library' view then locate and double-click on 'pit' component to add it to the project. 

Alternatively, right-click and select Add to project.

You can verify it was added by inspecting the 'Components - <project_name>' view.

13) With 'pit' selected in the 'Components - BlinkingLED_Z4_0' view, go to the 'Component Inspector' view to see the configurations for the PIT component. Locate the section for 'Configuration 0'. You may have to scroll down to see it. Change the 'Time period' setting to 500000 microsec(0.5 sec).

14) Back in the 'Components' view, select 'pin_mux' component and return to the 'Component Inspector' view

15) From the 'Routing' tab, select the 'SIUL2' sub-tab and scroll down the Signals list until 'GPIO_0' (DEV-KIT) or 'GPIO_99' (Motherboard) is shown.

16) Change to the following settings:

a. Pin/Signal Selection: PA[0] (DEV-KIT) / PG[3] (Motherboard)

b. Direction: Output

Pin PA0/PG3 is connected to user LED 2 on the evaluation board.

17) Still within 'pin_mux' component, switch to the 'Settings' tab

18) Change the setting for 'Utilize After Reset Values' to yes. This option will enable code generation only for the modified pins. Generating one configuration structure for each pin will result in a very large array residing in target memory.

19) All configuration settings are now complete. Click Generate Processor Expert code button in the 'Components' view or use the menu bar Project-> Generate Processor Expert Code.

20) From the 'Project Explorer' view, the generated code is visible in the folder 'Generated_Code' of the project 'BlinkingLED_Z4_0'.

21) If not already open, in 'Project Explorer' open the file 'BlinkngLED_Z4_0\Sources\main.c' by double-click. This will open the file in the editor view.

22) Scroll down until the following comments are shown:

/* Write your code here */

/* For example: for(;;) { } */

23) First we need to initialize the clocks. From the 'Components' view, expand 'clock_manager' and then drag & drop CLOCK_SYS_Init and CLOCK_SYS_UpdateConfiguration functions into main() of main.c, just after the comments identified in the previous step within the text editor view.

24) Add to the function CLOCK_SYS_UpdateConfiguration(), the parameters 0U, CLOCK_MANAGER_POLICY_FORCIBLE. You will notice the second parameter will turn blue and a hover-over with the mouse pointer reveals the value, indicating that it was recognized as a defined macro.

25) Next we need to initialize the pins. Back in the 'Components' view, expand the 'pin_mux' then drag and drop the function PINS_DRV_Init.

26) Again from the 'Components' view, expand 'interrupt_manager', then drag & drop INT_SYS_InstallHandler in 'main()'. This installs the PIT channel 0 interrupt handler.

27) Enter the parameters: PIT_Ch0_IRQn, &pitCh0Handler, NULL

28) Add the implementation of the handler

a. Create a function called pitCh0Handler

b. In the function body: clear the interrupt flag and toggle LED

  /* IRQ handler for PIT ch0 interrupt */

  void pitCh0Handler(void)

  {

/* Clear PIT channel 0 interrupt flag */

PIT_DRV_ClearStatusFlags(INST_PIT1, 0U);

/* Toggle LED (GPIO 0 connected to user LED 2) */

SIUL2->GPDO[0] ^= SIUL2_GPDO_PDO_4n_MASK; // DEV-KIT

/* SIUL2->GPDO[99/4] ^=SIUL2_GPDO_PDO_4n3_MASK;*/ // Motherboard

  }

Note: Get PIT_DRV_ClearStatusFlags by drag & drop from the 'pit' component.

 

29) In 'Components' view, expand 'pit' component and then drag & drop PIT_DRV_Init, PIT_DRV_InitChannel & PID_DRV_StartChannel in main() after INT_SYS_InstallHandler().

30) Fill in the second parameter of the last function(channel number): 0U

31) Build the code. Click the down arrow next to the 'Build' button and select Debug_RAM. Check that there are no build errors.

32) Enter the 'Debug Configurations' menu:

a. From the menu bar, Run -> Debug Configurations...

b. From the toolbar, down arrow next to Debug button -> Debug Configurations...

33) The Debug Configurations window appears. Select the configuration BlinkingLED_Z4_0_Debug_RAM from within the GDB PEMicro Interface Debugging group.

34) Select the 'Debugger' tab to setup the connection to the debugger hardware device.

35) Select the PEMicro Interface which corresponds to your setup:

a. If using the motherboard, you will likely use the USB Multilink, which is connected to your PC via USB cable (type A on one end, type B on the other) and is connected to the motherboard via the 14-pin JTAG cable.

b. If using the DEV-KIT board, you will likely choose the OpenSDA, which is integrated into the DEV-KIT board and is connected with just a USB cable (type A on one end, type micro on the other).

36) Click Debug To launch the debugging session. This will also open the Debug perspective.

37) In the Debug perspective, once the debugging session has fully launched, the code will be executed to the start of main(), where a breakpoint was automatically set for you. Press Resume button in the toolbar, Run -> Resume in the menu bar, or F8 on your keyboard to run the application.

38) You should now see the User LED2 on the board blink every 0.5 seconds.

39) To see the value of the output register bit for the output pin connected to the LED:

a. Set a breakpoint on a line within pitCh0Handler()

b. Go to the EmbSys Registers view, expand the SIUL2 module and scroll down to the GPDO register index which is accessed in the code. Double-click it to read the value. Expand it to see the individual bits.

c. Press Resume a few times to see the register value change

Attachments

    Outcomes