Apnt 304
Apnt 304
1 for S32K14x:
Examples Ported to Arm Keil MDK Toolkit.
® ®
1. Connect your computer to the internet. This is needed to download the Software Packs. Start µVision:
2. Open the Pack Installer by clicking on its icon: A Pack Installer Welcome screen will open. Read and close it.
3. This window opens up: Select the Devices tab:
4. Note “ONLINE” is displayed at the bottom right.
If “OFFLINE” is displayed, connect to the Internet
before continuing.
5. If there are no entries shown because you were not
connected to the Internet when Pack Installer opened,
select Packs/Check for Updates or to refresh once
you have connected to the Internet.
Install The S32K Software Pack:
1. In the Devices tab, select NXP and then S32K Series
as shown above: The devices supported are displayed.
2. Select Keil::S32_SDK_DFP.1.0.0.pack and click Install. This Pack will download and install in the MDK files. This
download can take several minutes.
3. Its status is indicated by the “Up to date” icon:
TIP: You can use this method to test the operation of other debug adapters.
9. Enter Debug mode by clicking on the Debug icon. The Flash memory will be programmed. Progress will be
indicated in the Output Window or in the P&E window. Select OK if the Evaluation Mode box appears.
TIP: If the Flash programs with P&E but does not enter Debug mode, select Debug mode again:
TIP: When you need to, but not right now, you stop the program with the STOP icon.
7) Hardware Breakpoints:
The S32K14x Cortex®-M4 has six hardware breakpoints that can be set or unset on the fly while the program is running and
when using a CMSIS-DAP or any Keil ULINK or a J-Link debug adapter. The Cortex-M0+ has two hardware breakpoints.
You must stop the program to set/unset breakpoints with P&E.
1. With Hello running, in the hello.c window, locate the line PTD->PSOR |= 1<<PTD0; which is near line 41.
2. Note the darker grey blocks on the left in hello.c. This grey block indicates assembly instructions are present.
3. Click on the grey block opposite PTD->PSOR |= 1<<PTD0;
4. A red circle will appear and the program will presently stop
as indicated by a yellow arrow. Remember to restart the
program if using P&E.
5. Note the breakpoint is displayed in both the Disassembly
and source windows: You can set/unset them in either window.
6. Leave the hardware breakpoint active for the next exercise.
TIP: Select Debug/Breakpoints or Ctrl-B and the Breakpoint window opens. You can manage Breakpoints and Watchpoints
in this window. You can temporarily disable/enable them. Close this window if you opened it.
TIP: If you set too many breakpoints, µVision will warn you.
TIP: Arm hardware breakpoints do not execute the instruction they are set to and land on. Arm CoreSight hardware
breakpoints are no-skid. This is a rather important feature for effective debugging.
TIP: µVision uses only hardware breakpoints in Flash memory. Soft or Flash breakpoints are not used. These breakpoints
have the disadvantage of substituting instructions and potentially modifying the program behavior.
2. Every time you click on the RUN icon , counter will increment.
3. Remove the breakpoint by clicking on it.
10) Single-Stepping:
1. With Blinky.c in focus (Blinky.c tab is underlined), click on the Step In icon or F11 a few times: You will see
the program counter jumps a C line at a time. The yellow arrow indicates the next C line to be executed.
2. Click on the top margin of the Disassembly window to bring it into focus. Clicking Step Into now jumps the program
counter one assembly instruction at a time.
3. Compile the source files . Enter Debug mode and click RUN .
4. In Watch 1, double click on <Enter expression> and enter SystemCoreClock.
5. SystemCoreClock will be displayed in Watch 1. Right click on its name and unselect Hexadecimal Display.
6. 48000000 (48 MHz) will be displayed.
TIP: SystemCoreClock is a calculated, not a measured value. A bug could give you an erroneous reading. For a method to
determine the core clock using SWV, see www.keil.com/appnotes/docs/apnt_297.asp.
1. Stop the program You can do this while the program runs but in this case the variable is overwritten too quickly.
2. In either the Watch 1 or PTD, change the value from 0x01 to zero. The blue LED will come on.
TIP: You must be careful what registers you modify in case it causes unintended consequences that can be difficult to find.
4. Select File/Save All or . Build the source files . Enter Debug mode and click RUN .
5. Right click on LED and select Add LED to … and select Watch 1. LED will be displayed in Watch 1.
6. As you press the SW2 button, LED will change value.
7. When you are finished, Stop the program and leave Debug mode .
What we have at this point:
Everything on the last two pages uses the DAP Read/Write mechanism. This is nearly always non-intrusive. These features
work with OpenSDA, Keil ULINK2, ULINK-ME, ULINKplus, ULINKpro and J-link. With OpenSDA in P&E mode, you
must stop the program to configure and update the displayed variables. Do not confuse DAP with CMSIS-DAP.
3. Select Options for Target or ALT-F7 and select the Debug tab.
4. Your debugger must be displayed beside Use:.
5. Select Settings: on the right side of this window.
6. Confirm Port: is set to SW and SWJ box is enabled for SWD operation. SWV will not work with JTAG.
7. Click on the Trace tab. The window below is displayed.
8. In Core Clock: enter 48 MHz. Select Trace Enable. This value must be set correctly to your CPU speed.
TIP: To find Core Clock: frequency: Enter the global variable SystemCoreClock in a Watch window and run the program.
9. Click on OK twice to return to the main µVision menu. SWV is now configured and ready to use.
Notes:
1. With a ULINKpro, select SWO Manchester.
2. Core Clock: must be accurately set for ULINK2,
ULINK-ME and J-Link. ULINKpro uses Core
Clock only to determine timing values.
Problems: The most probable cause of SWV not working is
an incorrect Core Clock: value. See
www.keil.com/appnotes/docs/apnt_297.asp
The only valid ITM frames in the trace window are ITM 0
and ITM 31. If you see any other values, this nearly always
means the Core Clock: value is incorrect.
8. Right click in the Trace Records and see the types of frames you can filter out.
TIP: These Data writes are created by each event created when a write occurs in this case, to the
variable LED. If there are too many writes or other types of frames, the SWO port (is 1 bit) is easily
overloaded. This will be seen a "x" in the Ovf and Dly columns. A solution is to sample the frames
to another variable and display it or use a ULINKpro. Manchester is better and 4 bit Trace Port is even better. Only the
S32K-148 has ETM trace and the corresponding 4 bit Trace Port.
3. Click on the Manage Run-Time Environment (MRTE) icon: The window below opens:
4. Expand Compiler/I/O and select STDOUT and ITM as shown:
5. Verify all blocks are green and not yellow or red.
6. Click OK.
7. This action adds the file retarget_io.c to the project.
TIP: Serial Wire Viewer (SWV) must be configured properly. ITM Port 0 must
be enabled. It is set by default and is shown here:
1. Build the source files . Enter Debug mode and click RUN .
2. Open View/Serial Windows and select Debug (printf) Viewer.
3. Each time you press SW2, the printf statement
writes to the Debug printf Viewer as shown here:
17b) printf using Event Recorder & DAP: This works with OpenSDA in CMSIS-DAP mode.
1. Use this method if using OpenSDA in CMSIS-DAP mode. This also works for Arm Cortex-M0 and Cortex-M0+.
Configure Event Recorder:
TIP: If you ever see orange or red blocs in the MRTE, try clinking the Resolve button. If it can, µVision will attempt to find
the required files.
10 Copyright © 2017 Arm Ltd. All rights reserved
TIP: If the Flash programs with P&E but does not enter debug mode, select Debug mode again:
8. Enter SystemCoreClock in Watch 1.
9. Right click on SystemCoreClock and unselect Hexadecimal Display.
10. 48 MHz will display in Watch 1.
6. Click RUN.
7. The blue LED will come on but it probably will not blink as expected.
8. The issue is the interrupt routine exits before the interrupt flag is cleared. This results in a second interrupt.
9. Set a breakpoint in the function LPIT0_Ch0_IRQHandler which is found near line 69.
10. Click RUN. and the blue LED will now toggle each time you click RUN.
11. Remove the breakpoint.
12. See www.keil.com/support/docs/3928.htm for an explanation.
Fix this Issue:
1. In hello_interrupts.c, there are several possible solutions:
2. Uncomment one of these.
3. If you use x = PTD->PTOR, also uncomment unsigned int x; near line 70.
4. Build the source files . Enter Debug mode and click RUN .
5. The blue LED will now blink.`
6. For rationale on which solution to use, review the Keil answer 3928 above.
3. Build the source files . Enter Debug mode and click RUN .
4. Right click on lpit0_ch0_flag_counter and add it to the Logic Analyzer.
5. Each time the interrupt routine is executed a step is displayed in the LA. The spike (blue circle) results from the test.
6. The time measured with Cursor and Signal Info is 1 second per step.
7. This is very useful to display and measure variables not visible with an outside instrument such as a scope.
Set lpit0_ch0_flag_counter to Zero:
1. In Watch 1, double-click on lpit0_ch0_flag_counter
and set this to 0x00.
2. This will be displayed in the LA
Displaying Exceptions (including Interrupts): SWV is used: any ULINK or J-Link is needed.
There are two windows used to display interrupts and their timings. If you are using Keil RTX and a ULINKpro, it is possible
to display when and for how long handler routines happen. This is in the Event Viewer in a manner similar to the LA.
Exceptions include interrupts in Arm documentation.
Trace Exceptions Window:
1. Click on the Trace Exceptions window tab or select View/Trace/Trace Exceptions or select:
2. The Trace exceptions window opens:
3. Click in the Count column header to bring
active exceptions to the top.
4. LPIT0_CH0 is displayed with various data.
Configure Watch 1:
1. DMA.c contains a array TCD0_Source[] and a variable TCD0_Dest near line 12. We will add them to Watch 1.
2. Right click on TCD0_Dest and add it into Watch 1. Right click on TCD0_Source and add it into Watch 1.
3. You can expand TCD0_Source to see all of its elements.
2. Click RUN.
3. Each time you click RUN, another letter is transferred from TCD0_Source to TCD0_Dest by the DMA controller.
4. This is visible in Watch 1.
5. When the transfer is complete, the program will be in the endless while (1) {} near line 50.
6. Click RESET to start the demo over.
3. Build the source files . Enter Debug mode and click RUN .
4. The three variables mentioned above are displayed plus a third: *((unsigned long *)0x40038010).
5. In the LA, select Setup and highlight *((unsigned long *)0x40038010). Set Max: to 0xFFFF. Click Close.
6. This is the COV register address in the FTM0. This addressed is displayed at the bottom of the FTM0 window when
COV is selected. It can them be added to the LA in the format provided. See below right:
7. Using Cursor and Signal Info, each step is 0.10 seconds. Period is 1 second. See below left:
8. It is easy to see how useful the Logic Analyzer can be for debugging.
6. Click RUN .
7. As you rotate the pot R13, the ADC reads the pot position and the LEDs will sequence accordingly.
Reading the ADC Output:
1. adcResultInMv_pot is a global variable in main.c near line 18 that contains the value of the pot as read by the ADC.
2. Right click on the variable adcResultInMv_pot and enter it in Watch 1.
3. adcResultInMv_pot will update while the program runs. Vary the pot R13.
Display adcResultInMv_pot in the Logic Analyzer: SWV is used: any ULINK or J-Link needed.
1. Stop the program . Exit Debug mode. SWV is preconfigured for 80 MHz in this project.
2. Select your debug adapter in the Select target box. ULINK2 is used here.
3. Near line 52 in main.c, uncomment this line: for ( int x = 0; x < 9000; x++ );
4. This slows the program down. There are so many Data Writes created that the SWO port is severely overloaded.
5. Build the source files . Enter Debug mode and click RUN .
6. Right click on adcResultInMv_pot and add it to Logic Analyzer (LA).
7. Click setup in the LA and set the Display Range: Max: to 0x1400. Click Close.
8. The LA will be displaying adcResultInMv_pot in real-time as shown below:
3. Click RUN .
4. The terminal program will display the text as shown here:
5. Type in any letter and it will be echoed.
6. Stop the program.
7. Watch 1 will contain the last letter you typed as shown:
1. Click RUN .
2. Each time you click RUN, variables will change accordingly.
3. Note the SR register changing in the
LPSPI1 window.
4. The program is running correctly
when receive contains 0xFDEF.
5. When you are finished, Stop the
program . Exit Debug mode.
Picture of CAN0: