Datasheet

Copyright © 2013 ARM Ltd. All rights reserved
CAN: Controller Area Network Lab using ST STM32 Cortex-M processors. www.keil.com
22
Running the Example CAN Program on the Discovery:
1. Consider making a copy of the CAN project directory: C:\Keil\ARM\Boards\ST\STM32F4-Discovery\CAN
2. Connect the STM32F4 Discovery CN1 USB connector to a USB port on your PC.
3. Start µVision by clicking on its icon on your Desktop.
You need MDK 4.70 or later for the CAN software.
4. Select Project/Open Project. Open the file C:\Keil\ARM\Boards\ST\STM32F4-Discovery\CAN\CAN.uvproj.
5. Make sure “STM32F407 Flash” is selected in the Target window.
Compile the project:
6. Compile the source files by clicking on the Rebuild icon.
. They will compile with 0 errors and 0 warnings.
7. Click the “Target Options” icon.
Select Debug tab and confirm it is set to “ST-Link Debugger”.
Confirm the Serial Wire Viewer (SWV) Configuration: (this is set by default with this project).
8. Select Settings: and then the Trace tab. Confirm SWV is configured as such: 168 MHz and Trace Enable is set.
9. Select EXCTRC and unselect Periodic. Select Timestamps Enable.
10. Select ITM Stimulus Ports 31 and 0.
11. Click OK twice. Optional: Select File/Save All.
Program the Flash: (you can also run in RAM by selecting RAM in Step 4.
12. Program the STM32F4 Flash by clicking on the Load icon.
The COM led will blink red and green and stop red.
Enter Debug mode and RUN the program:
13. Enter the Debug mode by clicking on the debug icon.
Select OK if the Evaluation Mode box appears. The
COM led will go out and briefly blink when a subsequent command is sent over the USB link.
14. Select View/Serial Windows and select Debug (printf) Viewer if it is not already open. The window below opens:
15. Click on the RUN icon.
Note: you can stop the program with the STOP icon.
16. The four colour LEDs will blink in succession.
17. Select View/Serial Windows and select Debug (printf) Viewer.
18. CAN messages with Tx and Rx values will appear in the Debug Viewer as shown below:
19. If you see this you have a successful minimum two CAN nodes network operating.
TIP: If Tx changes and Rx doesn’t – the most likely cause is the CAN ports
are not wired together correctly or SWV is not configured correctly. The
most likely problem is Core Clock: has the wrong value entered.
Setup Watch Window:
9. In CanDemo.c, find the global variable val_Tx near line 23.
10. Right click on it and select Add val_Tx to… and select Watch 1.
11. Repeat for the variable val_Rx. Note these were configured and are
updated while the program is running.
TIP: If Watch 1 data changes and Debug Viewer is blank: the most likely cause is the SWV is not configured correctly.
1. In the function val_display in CanDemo.c near line 51,
click in the left margin on a grey block to set a hardware
breakpoint. The program will stop here.
2. Click on RUN several times and CAN frames are added.
3. Please remove the breakpoint.
TIP: You can set/unset hardware breakpoints while the program is
running on any ARM Cortex processor.