Datasheet
Copyright © 2013 ARM Ltd. All rights reserved
CAN: Controller Area Network Lab using ST STM32 Cortex-M processors. www.keil.com
23
Exception Tracing:
CAN1 (the receiver) and CAN2 (the transmitter) use interrupts to tell the processor that a) a CAN message has been received
and b) the controller is ready to be loaded with a frame to transmit. These interrupts can easily be displayed with SWV.
1. Enter the Debug mode by clicking on the debug icon.
Select OK if the Evaluation Mode box appears.
2. Click on the RUN icon.
3. Click on the arrow beside the Trace Windows icon and select Exceptions:
4. The window similar to the one below appears. Note all exceptions (RESET, NMI etc.) are listed
5. Scroll down to Num: 36 ExtIRQ 20:
Note interrupt 20 is occurring.
ExtIRQ 20 is CAN1_RX0.
6. Scroll down to Num: 79 ExtIRQ 63.
This is being updated in real-time.
ExtIRQ 63 is CAN2_TX.
7. This window shows how many times
this exception has occurred with
various times. This is a very useful
feature to debug IRQs and determine
how often they are triggered or if not at all because of a bug in the program.
TIP: Exceptions (including interrupts) are listed in the ST document RM0090 in the Vector table section.
TIP: Num is the exception number: RESET is 1. NMI is 2 and so on. They are listed in the Exception Trace window.
External exceptions start at Num 16. For example, ExtIRQ 20 is the same CAN1 RX0 listed in RM0090 in the Vector
Table. Num 41 is also known as 41-20 = External IRQ 20. Num is not the same as the ST Priority Levels listed in RM0090.
8. Click on the arrow beside the Trace icon
and select Records. (similar to Step 4).
9. The Trace window that opens will
contain many ITM frames. Right click in
this window and deselect ITM Events.
TIP: ITM Events are sending ASCII characters
out to the Debug (printf) Viewer window. You
can also deselect ITM 0 in the Trace setup menu.
10. In CAN.c, set a breakpoint on the Tx
function CAN2_TX_IRQHandler near
line 256. The program will stop when
IRQ Num 79 occurs. Scroll to the
bottom of the Trace Records window. The entry of Num 79 (ExtIrq 63) will be displayed.
11. Click RUN to see the interrupts occur.
12. You can set a breakpoint at the receive interrupt handler in a similar fashion in CAN1_RX0_IRQHandler line 267.
13. Remove all breakpoints. Select Debug/Breakpoints (3or Ctrl-B) and select Kill All and then Close.
TIP: - Exception Entry is when the exception occurs.
- Exception Exit is when the exception returns.
- Exception Return is when the ALL exceptions return. They are all unloaded from the stack.
In this example, Num 79 does not return to 0: this is Cortex “tail-chaining” happening. 79 goes directly to 36 saving time.
The “x” in Dly (delay) means the timestamp was delayed and might not be accurate due to overloading of the SWO pin.
An “x” in the Ovf (overflow) column means at least one frame was lost for probably the same reason.
TIP: Double-click inside any trace window to clear it.
TIP: All of these features and more are included with the Keil MDK. There is nothing more to purchase. SWV works with
the Keil ULINK2, ULINK-ME, ULINKpro, J-Link (V 6 and later black case) and St-Link V2. (V1 does not support SWV)