Embedded System design in Tiva C launchpad
1 | P a g e Embedded Systems X TABLE OF CONTENTS Table of Contents 1 Table of Figures 6 Table of Tables 8 Table of Programs 9 1 Fundamental Concepts 10 1.1 Embedded Systems 10 1.1.1 Component of an Embedded System: 10 1.1.2 Embedded System Considerations 10 1.1.3 Hardware 11 1.1.4 Real-Time 12 1.1.5 Embedded System Characteristics 13 1.2 Introduction to computers 13 1.3 I/O Ports 16 1.3.1 TM4C123 I/O ports 16 1.3.2 Type of I/O 16 1.4 CPU Registers 17 1.4.1 An ISA must address the following things 17 1.4.2 Popular ISA 17 1.4.3 Registers in ARM ISA 18 1.5 Assembly Language 19 1.5.1 Assembly Language 19 1.5.2 Instruction Format 22 1.5.3 Addressing Modes and Operands 22 1.6 Address Space 28 1.7 Software Development Process 29 1.8 Using Keil 31 2 | P a g e 1.8.1 Debug in simulation mode 31 1.8.2 Debug in real board 31 1.8.3 Troubleshooting 31 2 Introduction to C 34 3 Microcontroller Ports 39 3.1 Introduction – Overview of I/O Ports Mixed Signals 39 3.2 Stellaris LM4F120 and Tiva TM4C123 Launchpad I/O Pins 40 3.3 Basic concept of Input and Output ports 44 3.4 I/O Programming and the Direction Register 46 3.4.1 How to initialize parallel port? E.g. Port F 46 3.4.2 Software to initialize Port F 47 3.4.3 Writing friendly code 48 3.4.4 Bit-specific Addressing 49 3.5 Debugging Monitor Using an LED 51 3.6 Hardware Debugging Tools 52 3.7 Timing in Embedded Systems 52 4 Design and Development Process 53 4.1 Introduction 53 4.2 Product Life Cycle 53 4.2.1 Product life cycle and Requirements 53 4.2.2 Product life cycle – Design considerations 54 4.2.3 Requirements Document 55 4.2.4 Call graph 56 4.3 Successive Refinement 59 4.3.1 Structure programming 59 4.3.2 How to write software 61 5 Switches and LEDS 63 6 Arrays and Functional Debugging 64 6.1 Introduction 64 6.2 Debugging Theory 64 3 | P a g e 6.2.1 Intrusiveness 64 6.2.2 Black-box and White-box Testing 66 6.3 SysTick Timer 67 6.3.1 Working of the SysTick Timer 67 6.3.2 SysTick Initialization 68 6.3.3 Measuring time 70 6.4 Arrays 71 6.5 Strings 71 6.6 Functional Debugging 71 6.6.1 Testing and Debugging 71 6.6.2 Functional Debugging 72 6.6.3 Single Stepping 72 6.6.4 Print statement 73 6.6.5 Debugging dump 74 6.6.6 Safety Critical Situations 75 6.6.7 Debugging using Logic Analyzer 76 6.6.8 Debugging using Instrumentation 76 7 Finite State Machine 79 7.1 Introduction 79 7.2 Phase-Lock-Loop 79 7.2.1 Phase-Lock-Loop PLL 79 7.2.2 Crystal Timing 80 7.2.3 Controlling the clock source 83 7.2.4 Software work 84 7.2.5 Battery powered system 85 7.2.6 Low power design 85 7.3 Accurate Time Delays Using SysTick 86 7.4 Structures 87 7.5 FSMs with Indexed Structures 89 7.5.1 Introduction to FSMs 89 4 | P a g e 7.5.2 FSM concepts 91 7.5.3 Translation from graph to code 95 7.5.4 FSM controller 95 7.5.5 Traffic light demo 97 7.5.6 Advanced Topics 101 7.5.7 Line tracking robot 106 7.6 Stepper Motors 109 8 UART – The Serial Interface 110 8.1 Introduction 110 8.2 I/O Synchronization 110 8.2.1 Blind cycle 112 8.2.2 Busy Wait 112 8.2.3 Interrupt 116 8.2.4 Periodic Polling 117 8.2.5 DMA 117 8.3 Universal Asynchronous Receiver Transmitter – UART 117 8.3.1 How UARTs are used 117 8.3.2 Fundamentals of UART Operations 118 8.3.3 Definitions 119 8.3.4 RS232 120 8.3.5 Serial Transmission 121 8.3.6 Software to transmit and receive 122 8.3.7 TM4C123 UART 123 8.3.8 Setting the baud rate 125 8.3.9 Busy-Wait Software 125 8.4 Conversion 128 8.4.1 Conversion 128 8.4.2 Output decimal number 131 8.5 Distributed System 133 8.5.1 Topology 133 5 | P a g e 8.5.2 Distributed Systems 134 8.5.3 Chat tool program 135 8.5.4 Interfacing the Nokia 5110 using a Synchronous Serial Port 137 9 Interrupts 143 9.1 Introduction 143 9.2 Interrupt concepts 143 6 | P a g e TABLE OF FIGURES Figure 1: The basic components of a von Neumann computer include processor, memory and I/O. 14 Figure 2: Harvard architecture of an ARM® Cortex-M-based microcontroller. 14 Figure 3: Architecture of TM4C123 microcontroller. 16 Figure 4: Registers on the ARM® Cortex-M processor. 18 Figure 5: The program status register of the ARM® Cortex-M processor. 19 Figure 6: An example of immediate addressing mode, data is in the instruction. 23 Figure 7: An example of indexed addressing mode, data is in memory. 24 Figure 8: An example of indexed addressing mode with offset, data is in memory. 25 Figure 9: Indexed addressing using R1 as a register pointer to access memory. Data is moved into R0. Code space is where we place programs and data space is where we place variables. 26 Figure 10: Memory map of the TM4C123. 29 Figure 11: Assembly language or C development process. 30 Figure 12: Flowchart symbols. 35 Figure 13: Flowchart showing the basic building blocks of structured programming. 36 Figure 14: Flowchart illustrating the process of making toast. 36 Figure 15: Flowchart illustrating the process waiting for four events. 37 Figure 16: I/O port pins for the LM4F120H5QR / TM4C123GH6PM microcontrollers 41 Figure 17: I/O Pin configuration 42 Figure 18: Switch and LED interfaces on the Tiva LaunchPad Evaluation Board. The zero ohm resistors can be removed so the corresponding pin can be used for its regular purpose 43 Figure 19: Interface connectors on the Tiva LM4F120/TM4C123 LaunchPad Evaluation Board 44 Figure 20: A read only input port allows the software to sense external digital signals 44 Figure 21: A readable output port allows the software to generate external digital signals 45 Figure 22: A bidirectional port can be configured as a read-only input port or a readable output port 46 Figure 23: Product life cycle 54 Figure 24: A data flow graph showing how the position signal passes through the system. 56 Figure 25: A call graph for a simple position measurement system. 57 Figure 26: We can decompose a task using the building blocks of structured programming. 60 Figure 27: Successive refinement 62 7 | P a g e Figure 28: Block diagram of the main clock tree on the LM4F/TM4C including the PLL. 81 Figure 29: A current sense amplifier can be used to measure instantaneous current to the target. The blue trace shows the current path from supply to target. 85 Figure 30: Instantaneous current measured on a battery powered system. 86 Figure 31: A structure collects elements of different sizes and/or types into one object. 88 Figure 32: System's schematic which can be abstracted as an FSM 89 Figure 33: FSM Graph of bit 1 recognizing System 91 Figure 34: The output in a Moore depends just on the state. In a Mealy the output depends on state and input 93 Figure 35: Traffic light interface with two sensors and 6 lights 97 Figure 36: Graphical form of a Moore FSM that implements a traffic light 98 Figure 37: A vending machine interfaced to a microcontroller 102 Figure 38: This Moore FSM implements a vending machine 103 Figure 39: Synchronization Mechanisms 111 Figure 40: The output device sets a flag when it has finished outputting the last data 112 Figure 41: The software must wait for the input device to be ready (I/O bound input interface) 114 Figure 42: The software must wait for the output device to finish the previous operation (I/O bound) 115 Figure 43: A FIFO queue can be used to pass data from a producer to a consumer. At any given time there can be a variable number of elements stored in the FIFO. The order in which data are removed is the same as the order the data are entered 115 Figure 44: UART usages on the LaunchPad 118 Figure 45: Basic UART operations 118 Figure 46 A serial data frame with 8-bit data, 1 start bit, 1 stop bit, and no parity bit 119 Figure 47: Hardware interface implementing an asynchronous RS232 channel. The TM4C123 has eight UART ports 121 Figure 48: Flowcharts of InChar and OutChar using busy-wait synchronization 126 Figure 49: Successive refinement method for the iterative solution 132 Figure 50: A simple ring network with three nodes, linked using the serial ports 133 Figure 51: Distributed processing places input, output and processing at multiple locations connected together with a network 134 Figure 52: Distributed using two LaunchPads connected together by the UARTs 136 Figure 53: Optional Nokia 5110 LCD. Notice the PCB gives the signal names. Use the signal names not the pin numbers when connecting 138 8 | P a g e TABLE OF TABLES Table 1: Condition code suffixes used to optionally execution instruction. 21 Table 2: Address offsets used to specify individual data port bits 50 Table 3: Base Addresses for bit-specific addressing of ports A-F 50 Table 4: SysTick registers. 68 Table 5: Main clock registers (RCC2 in LM4F/TM4C only). 81 Table 6: Tabular form of a Moore FSM that implements a traffic light 99 Table 7: The commonly-used signals on the EIA-574 protocol 120 Table 8: Some UART registers. Each register is 32 bits wide. Shaded bits are zero 124 9 | P a g e TABLE OF PROGRAMS Program 1: Initialization of SysTick. 70 Program 2: Use of SysTick to measure elapsed time. 70 Program 3: Instrumentation dump. 75 Program 4: Instrumentation dump with filter 75 Program 5: Instrumentation to record the first 49 time differences. 76 Program 6: Instrumentation to count the number of mistakes. 77 Program 7: Inappropriate Delay function for the real board. 78 Program 8: Appropriate Delay function for the real board. 78 Program 9: Activate the LM4F/TM4C with a 16 MHz crystal to run at 80 MHz (C10_PLL.zip). 83 Program 10: Use of SysTick to delay for a specified amount of time (C10_SysTick_Wait). 87 Program 11: A function that accesses a structure. 89 Program 12: Data Structure Realization of a FSM of Bit 1 recognizing System 95 Program 13: FSM controller 96 Program 14: Linked data structure implementation of the traffic light controller 100 Program 15: Low-level input/output functions for the vending machine 104 Program 16: Vending machine controller 105 Program 17: Tracking robot controller 108 Program 18: Low level I/O functions for tracking robot 109 Program 19: Device driver functions that implement serial I/O (CC11_UART and C11_Network): 127 Program 20: Unsigned ASCII string to decimal conversion 128 Program 21: Input an unsigned decimal number 129 Program 22: Print the voltage value to an output device (0≤n≤999) 130 Program 23: Unsigned decimal to ASCII string conversion 130 Program 24: Print unsigned 32-bit decimal number to an output device 131 Program 25: Iterative implementation of output decimal: 133 Program 26: High-level communication network (C11_Network) 137 Program 27: I/O port connections and the Nokia display: 140 Program 28: Some of the prototypes for LCD 141 10 | P a g e 1 FUNDAMENTAL CONCEPTS 1.1 EMBEDDED SYSTEMS An embedded system is a microcomputer with mechanical, chemical, or electrical devices attached to it, programmed for a specific dedicated purpose, and packaged up as a complete system. 1.1.1 Component of an Embedded System: It has a computer inside, and is embedded in many things: • Automotive • Bodies • Toys • Consumer Electronics • Home • Military • Cell phones • Industry • Computer: hidden inside of devices • x86: PC • ARM: A-series in Handheld devices • ARM computer: • A-series: in handheld devices • M-series: microcontrollers • R-series: Real-time Inside of a computer: • Memory • I/O interface: connect components together, including hardware and software 1.1.2 Embedded System Considerations Testing & Verifications Profit: Market share + Cost Power Size Time: correct answer + right response time [...]... flexible second operand can be a constant in the form #constant ADD Rd, Rn, #constant ;Rd = Rn+constant Where constant is calculated as one of these four, X and Y are hexadecimal digits: Constant produced by shifting an unsigned 8-bit value left by any number of bits Constant of the form 0x0 0XY00XY Constant of the form 0xXY00XY00 Constant of the form 0xXYXYXYXY We can also specify a flexible... -dedXLab2 3 If the simulator starts but you do not see the grading window, start the simulator and execute Peripherals->TExaSPortF 4 If there is an error “The specified DLL was not found:” look in the Keil\ARM\BIN folder Sort the files by date You should see edXLab2.dll edXLab5.dll edXLab6.dll edXLab7.dll TExaS.dll and LaunchPadDLL.dll If not, then you need to install TExaS, see step 2 of http://edx-orgutaustinx.s3.amazonaws.com/UT60 1x/ download.html... bit 0 will always be 0 The listing is a text file containing a mixture of the object code generated by the assembler together with our original source code Address Object code Label Opcode Operand Comment 0x0 00005E2 0x0 00005E6 0x0 00005EA 0x0 00005EE F04F0164 FB00F001 F100000A 4770 ; ; ; ; Func MOV MUL ADD BX R1,# 0x6 4 R0,R0,R1 R0,R0,# 0x0 A LR R1=100 R0=100*input R0=100*input+10 return 00*input+10 When... step 2 of http://edx-orgutaustinx.s3.amazonaws.com/UT60 1x/ download.html 3 In the Keil folder, there is a TOOLS.INI file View it in NotePad and make sure there is a line RTOS2=TExaS.DLL ("TExaS") show here as 2, but any number is OK 4 Look in the Keil\ARM\BIN folder Sort the files by date You should see TExaS.dll If not, then you need to install/reinstall TExaS When reinstalling TExaS, change the 32... Alt+F7 3 In the Debug Tab, tick on option: Use Simulator > OK 4 Compile the project by executing Project->Build Target 5 Click Debug > Start/Stop Debug Session or Ctrl+F5 6 Click Peripherals > TExaS … 7 Paste the number from EdX into the box: Number from edX 8 Click Grade 9 Copy the string from Copy this to edX box 10 Close the Debug: Click Debug > Start/Stop Debug Session or Ctrl+F5 1.8.2 Debug in... better understand the expression "embedded microcomputer system", consider each word separately The word embedded means hidden inside so one can’t see it The term “micro” means small, and a “computer” contains a processor, memory, and a means to exchange data with the external world The word “system” means multiple components interfaced together for a common purpose Systems have structure,... Keil, execute Project->OptionsForTarget In the Target tab, select TExaS in the Operating System drop-down menu In the Debug tab, click the Use radio on the right and select the Stellaris ICDI 3 Compile the project by executing Project->Build Target 4 Download the object code into Flash EEPROM by executing Flash->Download 5 Start the debugger by executing Debug->Start/StopDebuggingSession 6 Show the TExaS... actually run 1.1.5 Embedded System Characteristics • The microcontroller will be programmed to perform a specific dedicated application Software for embedded systems typically solves only a limited range of problems • The software is usually programmed into ROM and therefore fixed Software maintenance (e.g., verification of proper operation, updates, fixing bugs, adding features, extending to new applications,... run the real board grader 1 Make sure the Options->Target selects TExaS as the Operating System 2 In the debugger, you can activate the Real board grader by executing Debug>OSsupport and selecting TExaS Grader 2.0 If the TExaS Grader2.0 window opens but shows a Red error, then you need to install/reinstall TExaS When reinstalling TExaS, change the folder name of any Lab code that you have edited, so... called the address space Each memory location hold 8 bit of information Various banks within the memory of TM4C123: 0x0 0000000 - 0x0 003FFFF: 256kB of Flash or ROM (store our code, constant) 0x2 0000000 - 0x2 0007FFF: 32kB of RAM (store our data, variables, stack memory) 0x4 0000000 - 0x4 00FFFFF: I/O devices, we refer to I/O using a technique called memory-mapped I/O (When we want to refer to a device,