ELEC 3300 Homework 1: Introduction To Keil MDK A. Objective
ELEC 3300 Homework 1: Introduction To Keil MDK A. Objective
ELEC 3300 Homework 1: Introduction To Keil MDK A. Objective
A. OBJECTIVE:
B. READING:
An IDE (Integrated Development Environment) is a software that allows you to design and test
your microcontroller-based application. In this course, we will use Keil MDK (Microcontroller
Development Kit), for details of the software; you can refer to Getting Started with MDK from the
course website.
You need to download the software from the course website. We are using MDK-Lite, it is a
freeware for small project and education, you can download your own copy from the Keil website.
(www.keil.com) or from course website (MDK523.EXE)
After successful installation, you will have the Keil uVision5 on your Desktop
The installation also adds the Software Packs for ARM CMSIS and MDK Middleware.
MDK Version 5 is capable of using MDK Version 4 projects after installation of the Legacy
Support.
Legacy support for Cortex-M devices. (Available at course website MDKCM523.EXE,
only installed if you want to open some projects created by MDK Version 4)
Legacy support for ARM7, ARM9, and Cortex-R processor-based devices. (Available at
www.keil.com/mdk5/legacy)
After the MDK Core installation is complete, the Pack Installer is started automatically, which
allows you to add supplementary Software Packs.
1
Figure 2: Pack Installer
On the right side you will be able to see the Packs that are installed. Make sure you have the
following Packs and they are Up to date
We will be using STM32F1xx in this course, so on the left pane, click STMicroelectronics, and on
the right, the corresponding packs will be listed. On the right side you will be able to see the Packs
that can be installed.
2
Figure 4: STM32 Packs
Click Keil: STM32F1xx_DFP to install the Pack for STM32F1xx series. We will be using
STM32F1xx_DFP v2.2.0
3
D. WORKING WITH A PROJECT
Aim:
1. Understanding the Keil working environment by a Project.
2. Simulate and Debug program by running or step tracing the program.
3. View and trace the run-time values of registers, and memory during Simulation or Debug
process.
4. Show the output by Debug (printf) Viewer
Details:
1. Download the HW1.zip from the course website and unzip it.
2. Open Keil. Go Project Open Project... Navigate to the project file for this homework,
the project file should be under …/HW1/Project/RVMDK/HW1.uvprojx.
3. After you opened the Project, the Keil should look like this.
Project
Window
Code
Window
Output
Window
4
4. Right click on the Project Window HW1 You should be able to see Options for Target
‘HW1’ as shown and click on it.
5
6. Go to Debug Tab, make sure you are using Simulator as shown
7. Go to C/C++ Tab, make sure Optimization is set to Level 0 (-O0) as shown, then click OK
to close the Option Window
6
8. To Build the Project, Click Project Rebuild all target files. The status will be shown at
the Output Window
9. Modify your main.c such that it will give out 0 Error(s), 0 Warning (s), record the Program
Size: Code___________ . (In above example, it is 1232)
7
10. Now you can start simulating your project by clicking Project Start/Stop Debug Session.
It will prompt out a window saying
EVALUTION MODE
Running with Code Size Limit: 32K
just click OK.
11. You can see now the cursor start at main(). At the Tool bar below the menu, there are
several keys, you can use these keys to run your program.
Key Function
Step
Step Over
Step out
Run to Cursor Line
Run
Figure 15: Debugging Keys
These keys have the corresponding short-cut from the Project. You can check the short-cut by
choosing the Debug in the Menu.
8
You can add windows to check the running of the program. You can click
View
Command Window – Allows you to enter debug commands
Disassembly Window - Shows the program execution in assembly code
Register Windows – Shows the content of the microcontroller registers
Watch Windows Watch 1 – You can add specific variable in C program
Memory Windows Memory 1 – You can add specific address of memory
Serial Windows Debug (printf) Viewer – Allows you to view printf outputs
9
12. You will see the following screen
Disassembly
Window
Register Window
The Call / Debug (prinf) Viewer/ Watch / Memory Window are in tab.
After you type enter, you will be able to see the values of the variable and location of the
variable (for array) in the microcontroller, also the type of the variable.
15. Now you can add other variables. If you have an array added to watch, (like the stdid in the
Figure 21, you can click the tab on the left of stdid to expand the array.
16. Change variable i and j to display it in hexadecimal format. Right click choose
Hexadecimal Format.
11
17. You can now run the program step by step. Remember to click to the C source window and
click step over.
18. Step your program up to the instruction of the for loop as shown in Figure 23.
19. Check the variables that listed in the table of Part 2a from the Worksheet, add them to
Watch 1.
20. So, you should know where the variables being stored now. You can check if it is the case
by viewing the Memory 1
21. Type the location that you found in above table into the Go to box, make sure you type the
hexadecimal address (e.g. 0x00123456). See if you can find all the variables in the memory.
12
22. Now, execute the program up to the line printf, you can use Run to Cursor Line
23. You should be able to see the output in the Debug (printf) Viewer.
25. Execute your C instructions for AND, OR and XOR, answer Part 3 of the Worksheet
13
27. Execute your program up to the line dummy = x + y;
14
29. Click the Disassembly Window, make sure that the yellow arrow pointing to the instruction
ADDS, but not yet execute the instruction
30. Examine the C and V flags in the xPSR register *BEFORE* executing the ADDS
instruction.
31. Click Step Over in the assembly window and execute the ADDS instruction
32. Examine the C and V flags in the APSR register *AFTER* execution of the ADDS
instruction.
15
34. Continue to execute your program up to line dummy = x – y;
35. Click the Disassembly Window, make sure that the yellow arrow pointing to the instruction
SUBS, but not yet execute the instruction
36. Examine the C and V flags in the APSR register *BEFORE* execution of the SUBS
instruction.
37. Click Step Over in the assembly window and execute the SUBS instruction
38. Examine the C and V flags in the APSR register *AFTER* execution of the SUBS
instruction.
41. Now go back on the Project Window Right click on the Project Window HW1 You
should be able to see Options for Target ‘HW1’ as shown and click on it.
42. Go to C/C++ Tab, make sure Optimization is set to Level 2 (-O2) as shown, then click OK
to close the Option Window
43. Re-build your project again by clicking Project Rebuild all target files, pay attention to
the Build output.
45. Is the code size larger or smaller? Can you figure out where is the optimization being done?
(Hint: Check the assembly instructions.)
17
E. EXTENSIVE LEARNING PART (OPTIONAL)
As we are working with the compiler, there is nothing we can control how the compiler translates
our C code to assembly codes.
In the HW1 program, you might think we can use dummy = i + j; and dummy = i – j; instead of
using dummy = x + y; and dummy = x – y;
You can try to change it to use dummy = i + j; and dummy = i – j; and restart from Step 28 to see
the result. (Remember to change back your Optimization to Level 0)
18