Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
ECE 362 Microprocessor Systems and Interfacing Laboratory 01 Keil MDK-ARM Microcontroller Development Kit Tutorial This exercise introduces the Keil MDK-ARM Microcontroller Development Kit, which runs on a PC under windows. The objective of this exercise is to get you familiar with the Keil MDK-ARM IDE environment (downloading, installation of MDK-ARM core/package/devices/chip, creating projects, entering assembly language programs, assembling, simulating, and debugging). An assembly language program is entered and simulated in Keil MDK-ARM, and important features of assembly language programming with Keil MDKARM are explored. 1. Prelab Work Optional (but encouraged) You should plan to work on your own computer at home a lot during this semester. You should install the main software (evaluation version) we will use in this course: the Microcontroller Development Kit (MDK-ARM), which supports software development for and debugging of ARM7, ARM9, Cortex-M, and Cortex-R4 processor-based devices. Download it from ARM’s website and install it on your own computer. MDK-ARM is already installed on the computers in the lab room ET 307. MDK combines the ARM RealView compilation tools with the Keil μVision Integrated Development Environment (IDE). The Keil μVision IDE includes: Project Management and Device & Tool Configuration, Source Code Editor Optimized for Embedded Systems, Target Debugging and Flash Programming, Accurate Device Simulation (CPU and Peripheral). 2. Introduction Kiel ARM-MDK Lite versin 5.10 toolchain is used in the lab exercises. Though Keil ARM-MDK Lite has a code-size 32KB limit, it is enough for all the lab exercises in ECE 362. Keil MDK is the most comprehensive software development environment for Cortex-M processor based microcontrollers. From version 5, ARM-MDK is split into the MDK Core and Software Packs which makes new device support and middleware updates independent from the toolchain. The MDK Core contains all development tools including IDE, Compiler, and Debugger. The new Pack Installer adds and updates Software Packs for devices, CMSIS, and middleware. Some useful references can be found in the following links: Keil ARM-MDK Version Overview Keil ARM-MDK Download/Install Getting Started with ARM-MDK Keil ARM-MDK Primer 3. Procedure 3.1 Downloading and Installation Keil MDK-ARM 5.10 3.1.1 Go to the Keil MDK-ARM down/install website, fill the requested information and download Keil MDK-ARM 5.10 lite core installation package. 3.1.2 In the packinstaller window, please install the package for Keil::LPC1700_DFP, Board: MCB1700 Board, LC17xx series device, chip type: LPC1768. Note: For PCs at ET 307, Keil 5.10 may be pre-installed and you can skip this step. 3.2 Assembling Code Using Keil MDK-ARM 3.2.1 . Start Keil MDK-ARM’s uVision IDE. Click the start menu icon at the left the Windows task bar, then select All Programs, and finally select Keil uVision 5. The Keil uVision IDE will then open, as shown in Figure 1. Figure 1. Opening Keil ARM-MDK uVision IDE 3.2.2 . Create a new project From the Keil uVision IDE main menu, select Project -> New uVision Project ... to launch the create new Project window, shown in Figure 2, which is a standard Windows Explorer-style file save dialog box. Figure 2.Create a New Project Window a. Browse a location where you want to keep your project files b. Use New Folder to create a folder for your project, and name is Exercise01. (or other you like, such as lab01). c. In the file name field at the bottom, type Exercise01. d. Press the save button to create your project. Keil uVision IDE will then launch the Select Device for Target ‘Target 1’… window, shown in Figure 3. Figure 3. Select Device for Target Window e. To set the target as the LPC1768 micontroller on the Keil MCB1700 board, in the left pane below the Search field, successively click next to each of the following categories to select NXP LPC1700series LPC176xLPC1768, as shown in Figure 3: f. Click OK button to finish creating the exercise01 project. The project then opens in Keil uVision IDE,, as shown in Figure 4. Figure 4. Add a New Item to Project Open in uVision IDE 3.2.3 . Add an assembly source file to the project. a. In the Project pane along the top left side of the uVision IDE window, click next to Target to show Source Group 1, as shown in Figure 4. b. Right-click on Source Group 1, and in the resulting drop-down menu select Add New Item to group ‘Source Group 1’ .. to open the Add New item to Group ‘Source Group 1’ window, as shown in Figure 5. Figure 5. Adding New Assembly Source File to Project c. In the top left pane, click Asm file (.s) to change the Type field to ASM File (.s). d. In the Name field, type Exercise01. e. Click the Add I button to create exercise01.s. Exercise01.s is then opened in the editor pane on the right side of the uVision IDE windows, as shown in Figure 6. Figure 6. Source File in uVision IDE Editor 3.2.4 . Enter assembly source code. a. Type the code as shown in Figure 7 into the exercise 01.s editor pane. The full source code of exercise01.s can be downloaded in the course website. Figure 7. Lab01 Exercise Assembly code b. Click the save icon (or select menu File -> Save) to save the program. Note: Codes from line 38-44 (NVIC and stack setup in the following) should remain for all assembly language lab practices, your assembly codes start from line 45. 38 39 40 41 42 43 LDR R0, =ICER ; R0 MOVS R1, #0 ; R0 = MVNS R1, R1 ; R0 = STR R1, [R0, #0] ; ; initialize stack LDR R0, =SP_INIT = &ICER 0 0xFFFFFFFF icer = 0xFFFFFFFF pointer 44 MOV SP, R0 3.2.5. Edit target options for the project. Note: during assembly, a listing file will be produced, which has columns added to the left of the assembly source. Because the number of characters on a line increases in the listing file, it is best viewed in landscape mode. The settings below product a listing file suitable for printing in landscape mode from a text editor, such as Notepad++. a. On the second toolbar row, click the Target Options icon, (or select menu Project -> Options for Target ‘target 1’…) to launch the options for Target ‘Target1’ window, as shown in Figure 8. 3.2.6. Figure 8. Setting Options for Listing File b. Click on the listing tab along the top of the window to get the options shown in Figure 8. c. Change Page Width to 120. d. Change Page Length to 49. e. Click the OK to save the options and close the options window. Assembly Exercise01.s a. On the second toolbar row, click the Translate icon, (or select menu Project -> Translate<path>\exercise01.s) to assembly the source code. b. In the Build Output pane at the bottom of the window, the text assembling exercise01.s will appear. c. If the next text output is “exercise01.s”- 0 Errors(0), 0 Warnings(s), as shown in Figure 9, assembly is successful. Otherwise, any errors must be corrected before assembly can complete. Successful assembly produces an object file and a listing file. Figure 9. Project after Assembly 3.2.7. View the listing file: exercise01.lst a. From the uVision IDE main menu, select File->open to launch the Open File window, as shown in Figure 10. Figure 10. Opening Listing File b. Use the pull-down menu to the right of the File name field to select Listing (*.lst; *m; *.cod). c. Select exercise01.lst , and then click open. Understanding Assembly Listing Files 3.2.8. Examine the listing file and answer the following questions. Note that listing file has four columns: 1) the assembly source code line number, 2) the corresponding memory offset within an AREA, 3) the memory contents in hex for that address, and 4) the original assembly source code. Q1. What are the four words (in hexadecimal) assembled for ConstData by the assembly directive DCD? Q2. In ConstData, why does DCD produce different word values for 0x00000010 and 10? Q3. How much storage and what memory contents are shown for VarData in the listing file? Q4. At what offset within the RAM AREA does VarData begin? Q5. What opcode (in hexadecimal) is generated for the NOP instruction? ______________________ Q6. How many bytes of machine code are generated for each assembly instruction? Q7. Do assembly language program labels generate any code bytes? Explain why. Q8. According to the symbol table at the end of the listing file, how many times is SP_INIT used (not counting its definition). 3.2.9. Show your answers to your lab instructor for signature. Building Projects Code using Keil MDK-ARM 3.2.10. Building a project consists of liking all of assembled code. In the previous assembly step, the assembler produced an object file. Now that object file must be linked using target parameters (specified in the project’s target options) to produce an executable file. The executable file consists of memory contents, (i.e., images), to be loaded into specified areas of memory, (as specified in the project’s target options). a. On the second toolbar row, click the Build icon (or select menu Project -> Build target) to build the project. b. In the Build Output pane at the bottom of the window, the text Build Target ‘Target 1’ will appear followe3d on the next line by linking …. c. If the final line of text shows 0 Error(s), 0 Warning(s) appear as in Figure 9, the build is successful. Otherwise, any errors must be corrected before an executable file is produced. 3.2.11. View the project’s target options for mapping the project’s AREAs to memory. a. On the second toolbar row, click the Target options icon to launch the options for Target ‘Target 1’ window, as shown in Figure 11. Figure 11. Viewing Options for Target Microcontroller b. If the Target tab is not selected, click on the Target tab along the top of the window to get the options as shown in Figure 11. c. Answer the following questions about the target memory address options. Q9. Where in memory would you expect code and constants? _____________ Q10. Where in memory would you expect variables? ___________________ d. Click on the linker tab along the top of the window to get the options shown in Figure 12. Figure 12. Viewing Options for Linker 3.2.12. Viewing the listing file: exercise01.map. a. From the uVision IDE main menu, select File Open to launch the Open File window, as shown in Figure 13. Figure 13. Opening Map File b. Use the pull-down menu to the right of the File name field to select Listing (*.lst, *.m, *.cod). c. Select exercise01.map and then click Open. 3.2.13. Examine the linker map file and answer the following questions. Image Symbol Table Q11. Where do the variables VarData start in memory? _____________ Q12. How large (in bytes) is the MyCode area? _______________ Q13. What number base is used for Size of the symbols ? ___________ Q14. How much of RAM is used? _______________ Memory Map of the Image Q15. What is the starting address of the program ? _______________ Q16. What number base is used for Size of the regions? ______________ Q17. How many bytes are used for the constants in MyConst ? ___________ Q18. What is the starting address of RAM? _______________ 3.2.14. Show your answers to your lab instructor for signature. Simulate Using uVision Debug 3.2.15. Select simulation for debug. a. On the second toolbar row, click the Target Options icon to launch the Options for Target ‘Target 1’ window, as shown in Figure 14. Figure 14. Viewing Options for uVision Debug b. Click the Debug tab along the top of the window to get the options shown in Figure 14. c. At the top left, under the tables, select Use Simulator. d. Click the OK button to close the option windows and return to the uVision IDE. 3.2.16. To start a debug session, on the top toolbar row toward the right of the window, click the Start/Stop debug Session icon as shown in Figure 15. Figure 15. Start/Stop a Debug Session Note: For ARM-MDK Lite version, you will get a pop-up window that says the debugger will run in evaluation mode with a code size limit of 32KB. Just click OK in the pop-up window, and the debug session will start. 3.2.17. Explore the debug simulator. a. The register pane at the top left shows the current contents/status of all registers. Note: Expand xPSR to see the condition codes: N, Z, C, and V. b. The Disassembly pane at the top right shows the machine instruction in code memory. The actual machine instruction(s) used will show for any pseudo-instructions the programmer used in the assembly source code. c. The source pane at the center right shows the programmer’s original assembly code. d. The data pane at the bottom right can be toggled between Call Stack + Locals and Memory. For now select Memory 1 and enter 0x10000100 in the address field to view the VarData variables. Note: Right Clicking in this window gives a context menu, which can be used to change how the contents are displayed. e. The Command pane is at the bottom left. 3.2.18. Run the program in the simulator. a. In the source pane, position the mouse pointer over the first nop instruction, right click, and select Insert/Remove Breakpoint. Setting a breakpoint here will cause program execution to stop before executing this instruction. b. On the second toolbar row, either click the Run button, select Menu debug -> run or press F5. c. On the second toolbar row, either click the Step button, select menu Debug -> step, or press F11. Look at Register pane to see the effects of executing the instruction. 3.2.19. Start a new debug session and track all changes to the registers in Table 1. a. On the top toolbar row toward the right of the window, click the stop the debug session and return to the uVision IDE. Start/stop debug session icon to b. From the uVision IDE click, the Start/Stop Debug session icon to start a new debug session. c. Step through the program instructions to record each instruction’s register changes in Table 1. Note that xPSR will have to be expanded to show N, Z,, C, and V. If an instruction does not change the value of a register, you may leave its cell in the table blank rather than rewriting the same value. Caution: The double-line border before the last NOP instruction in the table indicates that other instructions are executed before this NOP. Step through the instructions not listed in the table and record the results after this NOP has executed for the first time. 3.2.20. Show your completed table to your lab instructor for signature. Report (No report is due for this lab exercise). Table 1. Register Contents (in HEX) after each program instruction Registers Instructions Initial debug state LDR R0, =ICER MOVS R1, #0 MVNS R1, R1 STR R1, [R0, #0] LDR R0, =SP_INIT MOV SP, R0 NOP LDR R2, =ConstData MOVS R3, #0x02 LDR R1, [R2,#0] LDR R0, =VarData STR R1, [R0,#0] LDR R1, [R2, #4] STR R1, [R0, #4] ADDS R2, #8 SUBS R3, #1 BNE LOOP LDR R1, [R2, #0] LDR R0, =VarData STR R1, [R0, #0] LDR R1, [R2, #4] STR R1, [R0,#4] ADDS R2, #8 NOP R0 00000000 R1 R2 R3 00000000 00000000 00000000 PC(R15) N 00000008 0 xPSR Z C 0 0 V 0