T p martin the insiders guide to the philips ARM7 based microcontrollers an engineers introduction to the LPC2100 series hitex (2005)

200 75 0
T  p martin the insiders guide to the philips ARM7 based microcontrollers   an engineers introduction to the LPC2100 series hitex  (2005)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

The Insider's Guide To The Philips ARM7-Based Microcontrollers An Engineer's Introduction To The LPC2100 Series Trevor Martin BSc (hons.) CEng MIEE www.hitex.co.uk/arm Introduction to the LPC2000 Introduction Published by Hitex (UK) Ltd ISBN: 0-9549988 First Published February 2005 First Reprint April 2005 Hitex (UK) Ltd Sir William Lyons Road University Of Warwick Science Park Coventry, CV4 7EZ Credits Author: Illustrator: Editors: Cover: Trevor Martin Sarah Latchford Alison Wenlock & Michael Beach Michael Beach Acknowledgements The author would like to thank Kees van Seventer and Chris Davies of Philips Semiconductors for their assistance in compiling this book © Hitex (UK) Ltd., 21/04/2005 All rights reserved No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical or photocopying, recording or otherwise without the prior written permission of the Publisher Introduction to the LPC2000 Introduction Introduction to the LPC2000 Introduction Introduction Chapter 1: The ARM7 CPU Core 10 Outline .10 The Pipeline 10 Registers 11 Current Program Status Register 12 Exception Modes 13 ARM Instruction Set 16 Branching .18 Data Processing Instructions 19 Copying Registers 20 Copying Multiple Registers .20 Swap Instruction 21 Modifying The Status Registers 21 Software Interrupt 22 MAC Unit 23 THUMB Instruction Set 24 Summary 26 Chapter 2: Software Development 27 Outline .27 Which Compiler? .27 uVISION IDE .28 Tutorial 28 Startup Code 29 Interworking ARM/THUMB Code 31 STDIO Libraries 32 Accessing Peripherals 33 Interrupt Service Routines 34 Exception source Constants table C function prototype 34 Software Interrupt 36 Locating Code In RAM 36 Operating System Support 38 Fixing Objects At Absolute Locations 38 Inline Assembler .38 Hardware Debugging Tools 39 Introduction to the LPC2000 Introduction Important! 40 Even More Important 40 Summary 40 Chapter 3: System Peripherals 42 Outline .42 Bus Structure 42 Memory Map 44 Register Programming 45 Memory Accelerator Module 45 Example MAM Configuration .49 FLASH Memory Programming 50 Memory Map Control 50 Bootloader 51 Philips ISP Utility 52 In-Application Programming 53 External Bus Interface .54 External Memory Interface 54 Using The External Bus Interface 57 Booting From ROM 58 Phase Locked Loop 60 VLSI Peripheral Bus Divider 62 Example Code: PLL And VPB Configuration 63 Power Control 64 LPC2000 Interrupt System .66 Pin Connect Block 66 External Interrupt Pins 66 Interrupt Structure 67 FIQ interrupt 68 Leaving An FIQ Interrupt 68 Example Program: FIQ Interrupt 69 Vectored IRQ 70 Leaving An IRQ Interrupt 71 Leaving An IRQ Interrupt 72 Example Program: IRQ interrupt .72 Non-Vectored Interrupts 73 Leaving A Non-Vectored IRQ Interrupt 73 Example Program: Non-Vectored Interrupt .73 Nested Interrupts 75 Summary 76 Chapter 4: User Peripherals 78 Outline .78 Introduction to the LPC2000 Introduction General Purpose I/O 78 General Purpose Timers 79 PWM Modulator 82 Real Time Clock .85 Watchdog 88 UART .90 I2C Interface 94 SPI Interface .99 Analog To Digital Converter .101 Digital To Analog Converter .104 CAN Controller 105 ISO Layer Model 105 CAN Node Design .106 CAN Message Objects 107 CAN Bus Arbitration 109 Bit Timing 110 CAN Message Transmission 112 CAN Error Containment 115 CAN Message Reception .118 Acceptance Filtering 119 Configuring The Acceptance Filter 120 Summary 122 Chapter 5: Keil Tutorial 124 Installation 124 Using the Keil UVISION IDE .125 Exercise 1: Using the Keil Toolset 126 Using The Debugger .133 Using The ULINK Hardware Debugger 138 Setting up the ULINK JTAG hardware debugger: .138 Exercise 2: Startup code 141 Exercise 3: Using THUMB code .142 Exercise 4: Using STDIO libraries 144 Exercise 5: Simple interrupt 146 Exercise 6: Software Interrupt 148 Exercise 7: Memory Accelerator Module 149 Exercise 8: In-Application programming .152 Exercise 9: External Bus Interface 153 Exercise 10 Phase Locked Loop 157 Exercise 11: Fast Interrupt .159 Exercise 12: Vectored Interrupt .160 Exercise 13 : Non Vectored Interrupt 162 Exercise 14: Nested Interrupts 163 Introduction to the LPC2000 Introduction Exercise 15: General purpose IO pins 164 Exercise 16: Timer Capture 165 Exercise 17: Timer Match 167 Exercise 18: Dual-Edge (Symmetrical) PWM Generation 170 Exercise 19: Real Time Clock 172 Exercise 20: UART 173 Exercise 21: I2C interface 174 Exercise 22: SPI .175 Exercise 22: SPI .176 Exercise 23: Analog To Digital Converter .177 Exercise 24: Digital to Analogue Converter 178 Exercise 25: Transmitting CAN Data 179 Exercise 26: Receiving CAN Data 180 Chapter 6: Tutorial With GNU Tools 182 Intoduction 182 GCC Startup Code 182 Interworking ARM/THUMB Code 182 Accessing Peripherals 182 Interrupt Service Routines 182 Software Interrupt 183 Inline Functions 183 Exercise 1: Using The Keil Toolset With The GNU Compiler .184 Exercise 2: Startup Code 189 Exercise 3: Using THUMB Code 190 Exercise 4: Using The GNU Libraries .192 Exercise 5: Simple Interrupt 193 Exercise 6: Software Interrupt 195 Appendices 197 Appendix A .197 Bibliography .197 Webliography .197 Reference Sites .197 Tools and Software Development 197 Evaluation Boards And Modules 197 Introduction to the LPC2000 Introduction Introduction This book is intended as a hands-on guide for anyone planning to use the Philips LPC2000 family of microcontrollers in a new design It is laid out both as a reference book and as a tutorial It is assumed that you have some experience in programming microcontrollers for embedded systems and are familiar with the C language The bulk of technical information is spread over the first four chapters, which should be read in order if you are completely new to the LPC2000 and the ARM7 CPU The first chapter gives an introduction to the major features of the ARM7 CPU Reading this chapter will give you enough understanding to be able to program any ARM7 device If you want to develop your knowledge further, there are a number of excellent books which describe this architecture and some of these are listed in the bibliography Chapter Two is a description of how to write C programs to run on an ARM7 processor and, as such, describes specific extensions to the ISO C standard which are necessary for embedded programming In this book a commercial compiler is used in the main text, however the GCC tools have also been ported to ARM Appendix A details the ARM-specific features of the GCC tools Having read the first two chapters you should understand the processor and its development tools Chapter Three then introduces the LPC2000 system peripherals This chapter describes the system architecture of the LPC2000 family and how to set the chip up for its best performance In Chapter Four we look at the on-chip user peripherals and how to configure them for our application code Throughout these chapters various exercises are listed Each of these exercises are described in detail in Chapter Five, the Tutorial section The Tutorial contains a worksheet for each exercise which steps you through an important aspect of the LPC200 All of the exercises can be done with the evaluation compiler and simulator which come on the CD provided with this book A low-cost starter kit is also available which allows you to download the example code on to some real hardware and “prove” that it does in fact work It is hoped that by reading the book and doing the exercises you will quickly become familiar with the LPC2000 Introduction to the LPC2000 Introduction Introduction to the LPC2000 – Tutorial With GNU Tools From the menu bar select Project\New Project In the New Project dialog navigate to your desired project directory In the New Project dialog name the project first.uv2 and select Save A ‘select new device for target’ dialog will appear Navigate through the device data base and select the Philips\LPC2129 folder and select OK 185 Introduction to the LPC2000 – Tutorial With GNU Tools In the project browser highlight the ‘Target1’ root folder and select the local menu by pressing the right mouse button In this menu select ‘Options for Target’ In the ‘Target’ tab set the simulation frequency to 12.000 MHz In the Linker tab select the linker file flash.ld and tick the “Garbage collection” and not use “standard startup files” boxes 186 Introduction to the LPC2000 – Tutorial With GNU Tools Note: To build the project so it will run within the on-chip RAM of the LPC2100 device, configure the Text start as select the linker file RAM.ld In the debug tab make sure the “Use Simulator” radio button is active Also make sure “Load Application at Startup” and “Go till main()” are checked Select OK to complete the target options In the project browser expand the ‘Target1’ root node to show the Source group folder Highlight the ‘Source Group 1’ folder, open the local menu with a right click and select ‘Add Files to group Source Group1’ 187 Introduction to the LPC2000 – Tutorial With GNU Tools In the ‘Add files to Group’ dialog add the file blinky.c and serial.c Change the ‘Type of file’ filter to ASM and add the file startup.s These are all the source files necessary for the project so select close You can view the source code contained in a file by double-clicking on the file name in the project browser window Once you have added all the source files the project can be built via the program menu or by the build button on the toolbar Once the code is built, you can start the simulator by pressing the debugger button The use of the simulator and JTAG debugger are detailed in Exercise One in the Tutorial and are the same for the GNU compiler 188 Introduction to the LPC2000 – Tutorial With GNU Tools Exercise 2: Startup Code In this exercise we will configure the compiler startup code to configure the stack for each operating mode of the ARM7 We will also ensure that the interrupts are switched on and that our program is correctly located on the interrupt vector Open the project in EX2 Startup\work Open the file Startup.s and using the graphical editor configure the operating mode stacks as follows: Compile the code Start the simulator and when the PC reaches main, examine the contents of each R13 register Each stack is allocated a space of 0x80 The user stack is 0x400 bytes so user data will start at 0x40003d80 – 0x400 Start of stack space at the top of on-chip memory 189 Introduction to the LPC2000 – Tutorial With GNU Tools Exercise 3: Using THUMB Code In this example we will build a very simple program to run in the ARM 32-bit instruction set and call a 16-bit THUMB function and then return to the 32-bit ARM mode Open the project in EX3 THUMB code\work In the files browser select thumb.c open the local menu (right-click) and select “options for thumb.c” Select the CC tab and in the misc controls add –mthumb or tick the “compile thumb code” box and click OK Again in the file browser select the root target (FLASH) and in the local menu “options for target” 190 Introduction to the LPC2000 – Tutorial With GNU Tools In the CC tab tick the “enable APCS option and the “support calls between THUMB and ARM” Compile and download the code into the debugger Open the disassembly window and single step through the code using the F11 key Observe the switch from 32-bit to 16-bit code and the THUMB flag in the CPSR The processor is running in ARM (32-bit ) mode, the T-bit is clear and the instructions are bytes long A call to the THUMB function is made which executes a BX instruction forcing the processor into THUMB mode (16-bit) The THUMB bit is set and on entry to the THUMB function a PUSH instruction is used to preserve registers on to the stack 191 Introduction to the LPC2000 – Tutorial With GNU Tools Exercise 4: Using The GNU Libraries In this exercise we will look at tailoring the GNU Printf function to work with the LPC2100 UART We will look at the registers of the UARTs in more detail later Open the project in EX4 printf\work In main.c add a message for transmission to the printf statement while(1) { printf("Your Message Here \n"); //Call the prinfF function } Add the file syscalls.c in the work directory to the project In syscalls.c add modify the write function as follows: Complete the for loop statement so it runs for the length of the printf string (len ) Inside the for loop add the putchar statement to write a single character to the stdio channel ( putchar (*ptr)) Increment the pointer to the character string ptr++ int write (int file, char * ptr, int len) { int i; for (i = 0; i < len; i++) putchar (*ptr++); return len; } Compile the code and download it to the development board Run the code and observe the output within hyper terminal If you are using the simulator, select view/serial window #1 This opens a terminal window within the simulator which displays the UART0 output 192 Introduction to the LPC2000 – Tutorial With GNU Tools Exercise 5: Simple Interrupt In this exercise we will setup a basic FIQ interrupt and see it serviced Open the project in EX5-Interrupt\work In main.c complete the definition of the EXTintFIQ function prototype to define it as the FIQ interrupt service routine void EXTintFIQ (void) attribute ((interrupt("FIQ"))); In startup.s complete the vector constants table to define EXTintFIQ as the FIQ ISR .global EXTintFIQ Declare the name of the C ISR function as a global global _startup func _startup _startup: Vectors: LDR Reset_Addr: Undef_Addr: SWI_Addr: PAbt_Addr: DAbt_Addr: IRQ_Addr: FIQ_Addr: PC, Reset_Addr LDR PC, Undef_Addr LDR PC, SWI_Addr LDR PC, PAbt_Addr LDR PC, DAbt_Addr long 0xB8A06F58 LDR PC, [PC, #-0xFF0] LDR PC, FIQ_Addr word word word word word word word word Reset_Handler Undef_Handler SWI_Handler PAbt_Handler DAbt_Handler IRQ_Handler EXTintFIQ Vector Table Constants table Insert the name of the C ISR function in the constants table Compile the code and download it onto the board Step through the code and observe the following using the disassembly window and the registers window Step through the code until you reach the while loop c Set a breakpoint in the EXTintFIQ function Press F5 to set the program running On the MCB2100 board press the INT button to generate the interrupt If you want to see the entry and exit mechanisms to the exception, it is best to use the simulator and single step in the disassembly window This way you can watch the program flow and the actions on the CPU registers 193 Introduction to the LPC2000 – Tutorial With GNU Tools To control the interrupt in the simulator, open the peripherals/GPIO port window Pin 0.14 is set high by the map.ini startup script If you set the program running unchecking, the Pin1.4 box will generate the interrupt You must raise the pin high again to stop interrupts Alternatively in the toolbox there is a “Generate EINT1” button This button will generate a simulated pulse on to the interrupt pin Toolbox button Toolbox with user configurable scripts Within uVISION there is a full scripting language which allows you to simulate external events These scripts are based on the C language and are stored in text files The script used to simulate the pulse is shown below: signal void Toggle(void) { PORT0 = (PORT0 ^ 0x4000); twatch (200); PORT0 = (PORT0 ^ 0x4000); } KILL BUTTON * DEFINE BUTTON "GenerateEINT1","Toggle()" This script is stored in the file signal.ini and is added to the project in the debug window For more details on the scripting language see the uVISION documentation 194 Introduction to the LPC2000 – Tutorial With GNU Tools Exercise 6: Software Interrupt In this exercise we will define an inline Assembler function to call a software interrupt and place the value 0x02 in the calling instruction In the software interrupt SWI we will decode the instruction to see which SWI function has been called and then use a case statement to run the appropriate code Open the project in EX6 SWI\work In main.c add the following code As the first instruction in main add the assembler define which calls the swi instruction #define SoftwareInterrupt2 asm (" swi #02") In the SWI ISR complete the register definition to access R14 register unsigned * link_ptr asm ("r14"); Complete the code to pass value of the SWI ordinal into the temp variable temp = *(link_ptr-1) & 0x00FFFFFF; Compile and download the code into the debugger Step the code and observe the SWI being serviced In the disassembly window the first SWI instruction has been encoded with the value at location 0x0000015C On entry to the ISR the supervisor link register contains the value 0x00000160 The calculation for temp is temp = *(link_ptr-1) & 0x00FFFFFF or 0x164 – ( word-wide pointer remember) which is 0x15C which points to the instruction which generated the SWI The top bits are masked off which yields a value of This is used in the case statement to run the required code 195 Introduction to the LPC2000 – Tutorial With GNU Tools 196 Appendices Appendix A Bibliography ARM7TDMI datasheet LPC2119/2129/2194/2292/2294 User Manual ARM System on chip architecture Architecture Reference Manual ARM System developers guide MicroC/OS-II GCC The complete reference Webliography Reference Sites http://www.arm.com http://www.philips.com http://www.lpc2000.com Tools and Software Development http://ww.hitex.co.uk http://www.keil.co.uk http://www.ucos-ii.com http://www.ristancase.com http://gcc.gnu.org/onlinedocs/gcc/ Evaluation Boards And Modules http://www.phytec.co.uk http://www.embeddedartists.com 197 ARM Philips Steve Furber David Seal Andrew N Sloss, Domonic Symes, Chris Wright Jean J Labrosse Arthur Griffith 198 The LPC2000 family from Philips semiconductors is the first of a new generation of microcontrollers based on the ARM7-TDMI 16/32-bit RISC processor This book is written as both an introduction to the ARM7-TDMI processor and the LPC2000 microcontroller architecture The content is based on a series of one day seminars held for professional engineers interested in learning how to use the LPC2000 family as quickly as possible Topics covered in this book include: - Introduction to the ARM7 processor - Software development tools - LPC2000 system architecture - LPC2000 peripherals In addition a comprehensive tutorial is included that takes you through practical exercises to reinforce the topics discussed in the main text By reading this book and performing the accompanying exercises, you will quickly become well versed in the ARM7 processor and the LPC2000 microcontroller The CD accompanying the book includes an evaluation version of the popular uVISION3 IDE and compiler from Keil Elektronik plus all the example exercises for both the Keil CARM and the GCC ARM compilers www.hitex.co.uk/arm I SBN - 9549988 - - 780954 998813 Hitex (UK) Ltd., Sir William Lyons Road, Science Park, Coventry, UK, CV4 7EZ Tel +44 (0) 2476 692066 ... bit test and set However in the ARM instruction set the top four bits of the operand are compared to the condition codes in the CPSR If they not match then the instruction is not executed and passes... the result register and the S flag is set, this will cause the SPSR of the current mode to be copied to the CPSR This is used at the end of an exception to restore the PC and switch back to the. .. Introduction to the LPC2000 - The ARM7 CPU Core Chapter 1: The ARM7 CPU Core Outline The CPU at the heart of the LPC2000 family is an ARM7 You not need to be an expert in ARM7 programming to

Ngày đăng: 16/12/2019, 17:03

Từ khóa liên quan

Mục lục

  • important.pdf

    • Local Disk

      • articlopedia.gigcities.com

Tài liệu cùng người dùng

Tài liệu liên quan