HOWTO: Create a Blinking LED Project (MPC5748G)

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

HOWTO: Create a Blinking LED Project (MPC5748G)

No ratings

HOWTO: Create a Blinking LED Project (MPC5748G)

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

pastedImage_1.png

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

pastedImage_3.png

6) Uncheck the boxes for cores e200z4 and e200z2, leaving just e200z4 (boot) 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.

pastedImage_4.png

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

pastedImage_1.png

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.

pastedImage_8.png

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

pastedImage_9.pngpastedImage_10.png

Alternatively, right-click and select Add to project.

pastedImage_11.png

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

pastedImage_13.pngpastedImage_14.png

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). Note that we are editing the settings for Clock configuration 'clockMan_InitConfig0', you will need the name of this configuration later.

pastedImage_15.png

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

pastedImage_16.png

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.

pastedImage_17.png

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.

pastedImage_18.png

17) 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.

pastedImage_2.pngpastedImage_3.png

18) Wait for the code generation to complete.

pastedImage_4.png

19) Now, from the 'Project Explorer' view, the generated code is visible in the folder 'Generated_Code' of the project 'BlinkingLED_Z4_0'.

pastedImage_5.png

20) 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.

pastedImage_11.png

21) Scroll down until the following comments are shown:

/* Write your code here */

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

pastedImage_9.png

We need to add some code here to initialize the clocks, timers and pins. Then we will setup a timer interrupt handler to toggle the pin.

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

pastedImage_12.png

pastedImage_13.png

23) Add to the function CLOCK_DRV_Init(), the parameter &clockMan1_InitConfig0 to give it the address of the user configuration structure generated by ProcessorExpert in '.../Generated_Code/clockMan1.c'. This is the clock configuration for which we edited the timer period in an earlier step.

pastedImage_15.png

24) 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 after the clock initialization.

pastedImage_16.png

pastedImage_17.png

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

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

pastedImage_18.png

pastedImage_19.png

27) In the User includes section at the start of main.c, 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.

pastedImage_21.png

pastedImage_22.png

28) 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().

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

pastedImage_23.png

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

pastedImage_24.png

31) Enter the 'Debug Configurations' menu:

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

pastedImage_25.png

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

pastedImage_26.png

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

pastedImage_2.png

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

34) 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.

pastedImage_3.png

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).

pastedImage_4.png

pastedImage_5.png

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

36) 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.

pastedImage_30.png

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

38) 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()

pastedImage_31.png

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

pastedImage_32.png

Comments

First of all. Great introductory. I wish I would have found this earlier. 

Second, all the example projects and this one gives me the error "No source available for "0x1000000" when I try to debug. 

Sometimes it will say "No source available for "(gdb[2].proc[42000].threadGroup[i1],gdb[2].proc[42000].OSthread[1]).thread[1].frame[0]" "

I am using the X - MPC574XG - MB with the MPC574XG-176DS with the USB Multilink interface debugger.

/*** The following is the Console output ***/

Connection from "127.0.0.1" via 127.0.0.1
Copyright 2017 P&E Microcomputer Systems,Inc.
Command Line :C:\NXP\S32DS_Power_v2017.R1\eclipse\plugins\com.pemicro.debug.gdbjtag.ppc_1.7.2.201709281658\win32\pegdbserver_power_console -device=MPC5746B -startserver -singlesession -serverport=7224 -gdbmiport=6224 -interface=USBMULTILINK -speed=5000 -Ô

CMD>RE

Initializing.
MPC574xB/C/D Device detected.
Target has been RESET and is active.
CMD>CM C:\NXP\S32DS_Power_v2017.R1\eclipse\plugins\com.pemicro.debug.gdbjtag.ppc_1.7.2.201709281658\win32\gdi\P&E\nxp_mpc5746b_1x32x736k_cflash.pcp

Initializing.
MPC574xB/C/D Device detected.
Initialized.

;version 1.06, 06/27/2017, Copyright P&E Microcomputer Systems, www.pemicro.com [5746C_2944k]

;device NXP, MPC5746B, 1x32x736k, desc=CFlash

;begin_cs device=$00F90000, length=$002F0000, ram=$40000000

Loading programming algorithm ...

WARNING - Selected .PCP file has been modified. CRC16 = $C167
Done.
CMD>VC
Verifying object file CRC-16 to device ranges ...
block 00FA0000-00FA0003 ...
Ok.
block 00FA0010-00FA0013 ...
Ok.
block 01000000-01000129 ...
Ok.
block 01001000-010010F3 ...
Ok.
block 01002000-01002C0B ...
Ok.
block 01002C10-0100780F ...
Ok.
Checksum Verification Successful. (Cumulative CRC-16=$A72C)
Application verified in memory. No need to reprogram.

CMD>RE

Initializing.
MPC574xB/C/D Device detected.
Target has been RESET and is active.

Starting reset script (C:\NXP\S32DS_Power_v2017.R1\eclipse\plugins\com.pemicro.debug.gdbjtag.ppc_1.7.2.201709281658\win32\gdi\P&E\s32e200_mpc574xc.mac) ...
REM This script is compatible with MPC574xC devices.
REM Clean GPRs to remove residual data after using algorithm
REM Initialize all of the Main SRAM - 512KB
Initializing RAM from $40000000 to $4007FFFF.

Reset script (C:\NXP\S32DS_Power_v2017.R1\eclipse\plugins\com.pemicro.debug.gdbjtag.ppc_1.7.2.201709281658\win32\gdi\P&E\s32e200_mpc574xc.mac) completed.

MPC574xB/C/D Device detected.

Version history
Last update:
‎10-25-2017 07:31 AM
Updated by: