Download presentation
Presentation is loading. Please wait.
Published byEthel Carson Modified over 9 years ago
1
UBI >> Contents Chapter 2 Software Development tools Code Composer Essentials v3: Laboratory Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar, António Espírito Santo, Bruno Ribeiro, Humberto Santos University of Beira Interior, Electromechanical Engineering Department www.msp430.ubi.pt MSP430 Teaching Materials Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt
2
UBI >> Contents 2 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Contents Code Composer v3: Laboratory 1: “Hello World” Beginner’s project: Code Composer v3:Laboratory 1: “Hello World” Beginner’s project: Lab1.1: Introduction to the application debug Lab1.1: Introduction to the application debug Lab1.2: Using breakpoints to save/load data to/from file Lab1.2: Using breakpoints to save/load data to/from file Lab1.3: Advanced breakpoints with triggers Lab1.3: Advanced breakpoints with triggers Lab1.4: Memory and usage Register Lab1.4: Memory and usage Register >> Contents
3
UBI >> Contents 3 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Laboratory 1: “Hello World” Beginner’s project The following laboratories provide an overview of the features of CCE: Lab1.1: Introduction to debugging an application; Lab1.2: Using breakpoints to save and load data to/from a file; Lab1.3: Advanced breakpoints with triggers; Lab1.4: Memory and register usage.
4
UBI >> Contents 4 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Overview: This laboratory demonstrates the IDE features that allow you build and debug an application using CCE; Examples are given of all the steps required to create a project and set up its configuration; After successful project compilation, the application is downloaded to the device; The main debug actions are explained: Step-by-step execution; Analysis of the contents of local and global variables; Resetting the device etc…
5
UBI >> Contents 5 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Step 1: Creation of the project: An application will be developed that sends a series of Fibonacci numbers to the CCE console. The numbers corresponding to the Fibonacci series are defined recursively using the mathematical expression: The algorithm that solves this problem is not difficult to implement; Beginning with the first two values of the sequence, the remaining numbers are successively calculated; The sequence of tasks required to build the project are now described. Lab1.1 Introduction to debugging an application
6
UBI >> Contents 6 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application A. Creating the project: Create a new project in Project> New Managed C/ASM Project; In the project name field write Project1; Accept the default settings in Select a type of project; There should be no dependencies with other existing projects; In Device Selection Page, choose in the option Device Variant, then select MSP430FG4618; Automatically, CCE will select the appropriate debug command file (lnk_msp430fg4618.cmd) and the support library (rts430x.lib); Finalize the creation of the project by clicking the finish button.
7
UBI >> Contents 7 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 1. Creating the project B. Add a source code file: The project created is visible in the C/C++ Projects window of the C/C++ perspective; Add a file to the project where the source code will be written by selecting File > New > Source File; The file to create should be named Lab1a.c; Write the following code that solves the problem:
8
UBI >> Contents 8 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 1. Creating the project //************************************************************************* // Basic debug introduction using CCE. Application conditional execution // author: aes // data: 10/08/2008 // version: 1.0 //************************************************************************* #include //************************************************************************* // Global data //************************************************************************* unsigned int a, b, i; //************************************************************************* // Main routine //************************************************************************* void main (void) { // Stop watch dog WDTCTL = WDTPW + WDTHOLD; // Stop WDT // Global data initialization a = 0; b = 1; // First message to CIO printf("Lab 1 - Introduction to Debug with CCE V3\n"); printf("Fibonacci sequence computation\n"); printf("Number n = 0 - %d\n", a); printf("Number n = 1 - %d\n", b); for(i = 0; i < 7; i++){ int c; c = a + b; a = b; b = c; printf("Number n = %d - %d\n", i, c); }
9
UBI >> Contents 9 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 1. Creating the project B. Add a source code file (continued): The code starts with a descriptive header: Contents of the file; Authors; Date and revision… Then the file msp430xG46x.h is included. This contains the definitions necessary for programming the device; The global variables a, b are defined as type unsigned integer, and are used to store the Fibonacci numbers of order N and N-1, respectively; These variables are initialized with the values {0, 1}, respectively; The control variable i is used as the iterations counter.
10
UBI >> Contents 10 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 1. Creating the project B. Add a source code file (continued): The first message is sent to the console using the function printf; (Note: this is printf, not print); The message consists of a sequence of text lines, so the escape character \n is used to cause a change of line on the console; Within a code structure, the numbers of the Fibonacci sequence are calculated successively using the mathematical expression stated earlier; Finally, the code ends with the directive _NOP() corresponding to the execution of a no operation, which has no effect, except taking time to execute.
11
UBI >> Contents 11 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 2. Configuration The project must be configured after writing the code: Go to Project > Properties > C/C++ Build > MSP430 Linker 3.0 Runtime Environment to: Specify heap Size for C/C++ dynamic memory allocation (--heap_size) with the value 400; set C system stack size (--stack_size) with the value 200; Because the printf function is used, the type of implementation must also be specified; In MSP430 Compiler V3.0 > Library Function Assumption option select full; Confirm in the Run Time Model Options that the silicon version (--silicon_version) is defined as mspx.
12
UBI >> Contents 12 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 2. Configuration In the TI Debug Settings field, specify the connection type between the PC and hardware: Choose the link TI MSP430 USB1; At the Debugger tab, confirm the selection of options Connect to exact CPU and load Program in loading options; At the Target tab, ensure through Program load options that the use of the IO console CIO is active in Enable CIO Function Use and that the verified program is written to the device in Perform Verification During Program Load; Ensure that in Auto run option, the program begins to run at the main routine; Select the two options On the Load or Restart Program and On reset.
13
UBI >> Contents 13 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 3. Compilation Once the configuration is made, the project must be compiled using the option Project > Build Active Project:
14
UBI >> Contents 14 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 4. Project debug To debug the code, it is also necessary to process the code using Run > Debug Active Project; CCE will automatically switch to the Debug perspective; The following tasks will show how the application can be verified using the debug features of CCE.
15
UBI >> Contents 15 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 4. Project debug A. Observe the contents of variables and expressions: In the Variables view, click on the icon and mark the global variables a, b, and i to identify them; The contents of these variables will be available immediately; As the program has not yet begun to run, the values are undefined; In the Expressions view, add an expression that the debug will automatically calculate during the debugging process; Example: using the context menu option, the global variables addresses are available through the expressions &a, &b and &i; Request the number of Fibonacci numbers yet to be calculated by using the expression 7-i.
16
UBI >> Contents 16 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 4. Project debug B. Run the code step by step: Execute the application step by step; Press the F6 key to execute the first instruction; The program’s status indicator will indicate the next instruction to be executed and stop the watchdog timer; Note that after the execution of the lines that initialize the values of variables a and b, the Variables view displays its new values; Observe the messages sent to the IO console; Display the CIO console by pressing the icon, then choosing console 3;
17
UBI >> Contents 17 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 4. Project debug B. Run the code step by step (continued): To ensure that the display remains visible press the icon ; Later, as the application runs step-by-step (F6), the messages will appear in the CIO console: Lab 1 - Introduction to Debug with CCE V3 Fibonacci sequence computation Number n = 0 – 0 Number n = 1 – 1 At the end of this sequence of instructions, the variables have the following values: a = 0, b = 1.
18
UBI >> Contents 18 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 4. Project debug C. Run the application until a specific code line: Putting the cursor on line of code 48, corresponding to: printf("Number n = %d - %d\n", i, c); Select the command Run to line, to set the program execution status indicator to that line; The sequence of instructions that led up to this point has been executed, modifying the program variables on the way; The local variable c was automatically added to the Variables view.
19
UBI >> Contents 19 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 4. Project debug D. Restart the debugging task: Once the application is finished, or whenever a repeated debug of code is required, it is possible to restart the device; Choose the reset CPU option in Run > Reset; Note that the memory of the processor remains unchanged; Re-run the application. Place the cursor at the line of code 36 and run the program until it reaches the cursor position; Using the Variables view, change the contents of variables a and b to 3 and 4, respectively; Execute the application until line of code 52; Observe the new sequence of values for the Fibonacci numbers.
20
UBI >> Contents 20 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.1 Introduction to debugging an application Step 4. Project debug E. Include the project in the workspace: The project built during this laboratory can be found in the Chapter 2 > Lab1_CCE directory of the CD ROM; To include it in the workspace, choose the project using Project > Open Existing Project; Perform this laboratory starting at point B.
21
UBI >> Contents 21 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Overview: During debugging, it is useful to be able to exchange information between the application and files on disk; This laboratory will make use of this capability, using the project developed in Lab1.1; This time, the two initial values required to determine the sequence of Fibonacci numbers are collected from a data file; The numbers are successively calculated by the application and are then stored in a data file.
22
UBI >> Contents 22 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 1. Include the project in the workspace This task is identical to that carried out point E of Lab 1.1; Compile the lab with the file Lab1a.c.
23
UBI >> Contents 23 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 2. Creating input and output data files The code debugger can access binary files in COFF (Common Object File Format) format or files in text format; The latter format is used in this laboratory; This file has a header line followed by several lines with one value per line; The data can be stored in the following formats: Hexadecimal (representation of all header number); Integer; Long; Float. The information contained in the header line uses the following syntax: MagicNumber Format InitialAddress PageNumber Length
24
UBI >> Contents 24 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 2. Creating input and output data files MagicNumber Format InitialAddress PageNumber Length where: MagicNumber : Constant value equal to 1651; Format : Value between 1 and 4, indicating the format used in the file samples; InitialAddress : Address of the start of the data block; PageNumber : Page number from which the data block was obtained; Length : Number of samples in the block.
25
UBI >> Contents 25 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 2. Creating input and output data files A. Create the data files: CCE can create this file through File > New > File; Include the name DataIn_a.txt on file dialog box to create the file containing the data to be allocated to the variable a: 1651 1 135c 0 2 2 Repeat the process for the data file of variable b: 1651 1 135c 0 2 3 Note that CCE expects that the read values are represented using 5-digit of values with 4 digits. If the data values are represented in hexadecimal, the CCE expects the first digit to be zero.
26
UBI >> Contents 26 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 2. Creating input and output data files B. Associate the input data files with the project: This file is available in the directory Chapter_2 > Lab1_CCE There are two different ways to add the file to the project: Copying the file to the project directory: –Loses the freedom to control the file contents if it is used in several projects; Link the file to the project: –This option allows the file to be stored in a common location and associated with the project; –The same file can be used on different projects (a change to its content will be observed by all projects that use it). In this example, the files are in the project directory.
27
UBI >> Contents 27 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 3. Adding and associating breakpoints The easiest way to set a breakpoint is through the Breakpoint view; This view allows choice of action, including the reading or writing data on file; Choosing one of these actions allows a file to be linked to the breakpoint. A. Activate the Breakpoint view: If the breakpoint window is not already open, then do so in Windows > Show View > Breakpoints.
28
UBI >> Contents 28 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 3. Adding and associating breakpoints B. Create Breakpoints: Create two breakpoints, one at line of code 36 and another at line of code 37; Move the cursor to the line of code and add the breakpoint by clicking on the left mouse button to provide access to the C editor content menu; In this menu choose the option Toggle Breakpoint. C. Setting the Breakpoint: In Breakpoint view, after selecting line of code 36 breakpoint, edit its properties; Choose the option Action and open the list of options then choose Read Data from File.
29
UBI >> Contents 29 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 3. Adding and associating breakpoints D. Filling the Breakpoint options: It is necessary to input several items of data: File: Location and file name from where the data will be read; Wrap around: Mark this selection to start reading at the beginning of the file again after it reaches the end; Start Address: Location to send the data that has been read from the file. This address can be changed, because it is always accessed at the beginning of each read; Length: The length of memory. This parameter can also be modified through the debug process.
30
UBI >> Contents 30 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 3. Adding and associating breakpoints D. Filling the Breakpoint options (continued): To set the Breakpoint associated with line of code 36: File: DataIn_a.txt Warp around: Yes Start Address: &a Length: 1 Name: Breakpoint Load a. To set the Breakpoint associated with line of code 37: File: DataIn_b.txt Warp around: Yes Start Address: &b Length: 1 Name: Breakpoint Load b.
31
UBI >> Contents 31 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 3. Adding and associating breakpoints D. Filling the Breakpoint options (continued): Create a breakpoint at line 48 to associate the file used to write the values of variable c (Fibonacci numbers); Follow the same steps for setting this breakpoint, edit its properties and choose Write Date to File in option Action; The data values to fill in are: File: DataOut_c.txt Format: Hex Start Address: &b Length: 1 Name: Breakpoint Write c. Finally, add a breakpoint on line of code 52 named Final Point to suspend the execution of the application at the end of the Fibonacci numbers calculation.
32
UBI >> Contents 32 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 4. Save file and load files with the breakpoints The breakpoints created in this laboratory are read and written; This feature is useful to reuse the breakpoints configuration; A. Export the breakpoints to file: After creating and setting up breakpoints, this information can be saved by exporting it to a file; Go to File > Export; In the General item, choose the option Breakpoints; All breakpoints defined in the debugger will be shown. Select them all; Inform the file name to make, name it Lab1_breakpoint. B. Import breakpoints from the file: To import the breakpoint use the Import feature; Indicate the file name and select the two options to automatically create and update the breakpoint imported.
33
UBI >> Contents 33 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 5. Code debugging Tasks required to debug the code: To debug the code, perform the following tasks: Verify that the execution state indicator points to line of code 27. If this does not happen, restart the device; Verify that the CIO console is clean and visible. If these conditions are not fulfilled, use the context menu to order its cleaning and activate the icon to always make the console visible; Execute the application step by step until the variables a and b are initialized; Verify in the Variables view that they are assigned the values 0 and 1, respectively;
34
UBI >> Contents 34 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 5. Code debugging Tasks required to debug the code (continued): When the line of code 36 is reached (before being executed), variable a is assigned the value 2, read from the associated data file; The same thing happens when it reaches line of code 37, because when it is reached, it leads to the execution of breakpoint Load B, resulting in reading the value 3 for the variable b; The Fibonacci numbers calculation is initiated within the computing cycle, using these initial conditions ; Whenever the line of code is reached, the breakpoint Save c runs;
35
UBI >> Contents 35 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.2 Breakpoint to save/load data Step 5. Code debugging Tasks required to debug the code (continued): Successive data values are stored in the data file; Start execution of the application using the command run; The execution runs until the breakpoint Final Point is reached. In this execution state, the application has already determined and stored all the Fibonacci numbers in the file; Switching to the C/C++ perspective, in the C/C++ Projects view, the data file DataOut_c created is visible ; Edit this file to see the results. Observe that the mathematical process returned the sequence: 2, 3, 5, 8, 13, 21, 34, 55 and 89.
36
UBI >> Contents 36 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.3 Advanced breakpoints with triggers Overview: Laboratory 1.2 has shown how breakpoints can be used to run code to certain points in the program and control access. It has also shown how, under specific conditions, data can be exchanged with files; The use of these features assists the debugging task of some complex applications; This laboratory shows how breakpoints can be set through the appropriate use of triggers; Continue to use code example from Laboratory 1.2, since the changes to be introduced are only small; This time breakpoints will be implemented under special conditions.
37
UBI >> Contents 37 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.3 Advanced breakpoints with triggers Step 1: Preliminary conditions The change introduced in the source code of this project is to add a data array to store the calculated results; The file Lab1b.c incorporates this modification. Compile the project with this new source file then debug it; There is a wide variety of available triggers that can generate an appropriate response by the debugger; To understand the logic associated with the configuration of these features, let us perform some actions for that purpose. Remove all existing breakpoints by selecting the icon in the Breakpoint view.
38
UBI >> Contents 38 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.3 Advanced breakpoints with triggers Step 1: Preliminary conditions A. Read access to a variable: Set up a new breakpoint using the icon of the Breakpoint view; Chose the option watchpoint; Introduce the following configuration: Location: &a Access type: Read. Execute the application with Run; Note that at the first access read of variable a, the execution of the application is suspended.
39
UBI >> Contents 39 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.3 Advanced breakpoints with triggers Step 1: Preliminary conditions B. Access to a variable using a condition: Specify and provide that the suspension should only occur if a particular value is read; Remove the last breakpoint and set a new one (watchpoint with Data type); Introduce the following configuration: Location: &a Data value: 5 Access type: Read. Execute the application with Run; At the first access, read the variable: a = 5.
40
UBI >> Contents 40 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Overview: The assessment of memory resources used by the application is crucial to the development of the application; This laboratory illustrates how to access to the memory and registers of the device ; The use of the system stack by the C/C++ is described; The practical process is illustrated by an example; For this, the program will change from C/C++ to assembly language. Some of the tools used to analyze programs in assembly language are briefly described.
41
UBI >> Contents 41 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 1. Using the stack with C/C++ The C/C++ compiler uses a system stack in memory to: Store local variables; Pass necessary arguments to execute a task; Save the register contents for subsequent restores. The system stack grows from high value addresses to low value addresses; Its management is done using the device register R1, commonly referred to as the Stack Pointer ( SP); The size of the system stack is specified in the process of building the application(_stack_size): The default value is 128 bytes; Can be modified using the option _stack_size.
42
UBI >> Contents 42 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 1. Using the stack with C/C++ The size of registers is greater in MSP430X devices; Saving and restoring stack contents requires the use of a 32-bit stack (2 words); To reuse code originally written for 16-bit devices, it is necessary to increase the system stack size; When the application boots up: The SP points to the address at the top of the system stack; This address is the first location after the end of the section reserved for the system stack; Before performing a function, the C/C++ automatically decreases the SP to reserve the space needed for its execution (push operation); When the function returns, the SP is increased to restore the original value (pop operation).
43
UBI >> Contents 43 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 1. Using the stack with C/C++ By convention, some registers are dedicated to specific operations in the C/C++ environment:
44
UBI >> Contents 44 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 1. Using the stack with C/C++ The debugger uses each of these registers: (1) The parent function refers to function making the function call. The child function refers to function being called. (2) The SP is preserved by the convention that everything pushed on the stack is popped before returning.
45
UBI >> Contents 45 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 1. Using the stack with C/C++ Any function (Parent function) that calls or is called by another function (Child function), must follow a set of rules; How a function call is processed: Argument block: Part of the local frame used to pass arguments to other functions; The arguments are passed to the functions by moving them to this data block instead of placing them on the system stack; A local frame and the argument block are preserved simultaneously;
46
UBI >> Contents 46 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 1. Using the stack with C/C++ How a function call is processed (continued): Register save area: Part of the local frame used to store the contents of registers when the application invokes a function, allowing it to be restored on return; Save-on-call register: Registers R11-R15. The function invoked does not preserve the values of these registers, so the function that performs their invocation must save their contents then restore them, as necessary; Save-on-entry registers: Registers R4-R10. It is responsibility of the function preserve the values of these registers; If the function invoked modifies the contents of these registers, their contents are stored and restored when the function returns.
47
UBI >> Contents 47 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 1. Using the stack with C/C++ Typical function invocation:
48
UBI >> Contents 48 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 2. Include the project in the workspace Start the task, including the compilation of the file Lab1c.c; Alternatively, create of the project from the beginning, following the steps described in previous laboratories; The source code may be imported or you may write the code from scratch into a new file; The task performed by this application is similar to that performed so far; In this laboratory, the determination of the new number of the Fibonacci sequence is performed by a function; This function receives the addresses of the variables a and b, and returns the result of the mathematical operation.
49
UBI >> Contents 49 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 3. Program and assembly view Once the compiling process is completed, observe the Debug perspective; It is possible to observe the assembly code in the Disassembly view.
50
UBI >> Contents 50 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 4. Analysis of the device's memory The contents of the device’s memory are accessible through the Memory view: The Memory view has two panels: Memory Monitors panel: Collects the memory monitors added during the debug session; Memory Renderings panel: The content of this panel is controlled by the selection made in Memory Monitors panel and lists the contents of the desired memory address.
51
UBI >> Contents 51 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 4. Analysis of the device's memory Add memory addresses to monitor some of the application’s variables. Use the button to add the address to be monitored. Examine: Global Variables a and b: Insert &a and &b Top C system stack: Insert &_stack Address pointed by SP: Insert SP.
52
UBI >> Contents 52 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 4. Analysis of the device's memory Determine the locations of variables. From the project compilation results: Address 0x01344 is used for variable a; Address 0x01346 is used for variable b.
53
UBI >> Contents 53 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function During the introduction to this laboratory, a brief description was given of the procedure used by the system to pass and receive data from a function; Use the CCE debugging tools to see an example of this process. A. Reinitiate the debug process: The first task is to ensure that the application is ready to be launched; The starting point is the main position; Proceed with device restart through the icon.
54
UBI >> Contents 54 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function B. Preparation to call a function: Put the cursor at line 50 and then execute the application until this line is reached, using the feature Run to line; In the Disassembly view, the instructions before the addData function execution call are shown:
55
UBI >> Contents 55 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function B. Preparation to call a function (continued): The address of the variable a is 0x1344 and the address of variable b is 0x1346; In this case, the compiler begins by loading the address of each of these variables into the registers R12 and R13, respectively, through the instructions: MOV.W#0x1344, R12 MOV.W#0x1346, R13 Verify these instructions (Registers view); Stack address pointed by SP is 0x0030F0 ; Stack begins at 0x03038 (supports 180 bytes).
56
UBI >> Contents 56 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function B. Preparation to call a function (continued): Using the instruction: CALLA #addData The function is then invoked; Following the call, the processor automatically puts the return address on the system stack ; It requires 2 bytes to store the 16-bit address, being stored on the system stack at addresses 0x30EC and 0x30ED.
57
UBI >> Contents 57 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function C. Analysis of the execution in assembly language: The function begins by reserving space on the system stack then passing two arguments on the stack: SUB.W#0x0006,SP MOV.WR13,0x0002(SP) MOV.WR12,0x0000(SP) Initially, the SP points to the address 0x30EC, then the constant value #6 is subtracted from it. This makes the stack base address 0x030E6 ; Next the parameters passed by the register R12 and R13 are saved on the stack at SP+0 and SP+2 (addresses of variables a and b).
58
UBI >> Contents 58 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function C. Analysis of the execution in assembly language (continued): The new Fibonacci number is now determined ; Start by adding the contents of the memory addresses sent; This is accomplished with the following sequence of instructions: MOV.W0x0002(SP),R15 MOV.W@R15,R15 ADD.W@R12,R15 MOV.WR15,0x0004(SP) The processor begins by copying the value stored on the system stack at SP+2 (variable b address) to R15. Then the contents of the register pointed to by R15 (variable b address) is copied to register R15 itself.
59
UBI >> Contents 59 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function C. Analysis of execution in assembly language (continued): Following this statement, register R15 contains variable b; The addition operation is then performed by adding the value contained at the address stored in register R12 (variable a) with the value contained in register R15 (variable b); The result of the addition in R15 is placed on the system stack at the address SP+4, which is the space reserved for the local variable c; Next part of code updates variable a: MOV.W0x0002(SP),R15 MOV.W@SP,R14 MOV.W@R15,0x0000(R14)
60
UBI >> Contents 60 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function C. Analysis of execution in assembly language (continued): The first instruction moves the address stored on the system stack at position SP+2 (address of variable a) into register R15; The second instruction moves the address contained on the system stack at position SP+0 (address of variable b) into register R14; Finally, the contents of the data memory location whose address is stored in R15 (variable b) are moved to the contents of the data memory location whose address is stored in the register R14 (variable a); With this sequence of operations, the value in variable a will be equal to the value of variable b;
61
UBI >> Contents 61 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function C. Analysis execution in assembly language (continued) The next part of code is to update of variable b by writing to it the result stored in local variable c; MOV.W0x0002(SP),R15 MOV.W0x0004(SP),0x0000(R15) Initially, the address stored on the system stack at SP+2 is moved into register R15. Register R15 now holds the address of variable b; Next, the value stored on the system stack at SP+4 (local variable c) is copied to the data memory value whose address is stored in R15 (address of variable b); This copies variable c to the variable b.
62
UBI >> Contents 62 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function D. Returning the results function The final task is to return the result in register R12 then restore the SP to its original value ; MOV.W0x0004(SP),R12 ADD.W#0x0006,SP RETA The code begins by moving the value stored on the system stack at SP+4 (local variable c) to register R12; Add to SP register SP the value subtracted at the beginning to restore the original stack state; The register SP will point back to the position 0x030EC ; Finally, return to the main function.
63
UBI >> Contents 63 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab1.4 Memory and register use Step 5. Interface with a function E. Function result storage After returning to the main function, the result is again stored on the restored the system stack using the instruction: MOV.W R12,0x0006 (SP)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.