Programming the On-Chip Flash Memory in a Stellaris Microcontroller. Application Note. Copyright 2007 2009 Texas Instruments



Similar documents
APPLICATION NOTE BUILDING A QAM MODULATOR USING A GC2011 DIGITAL FILTER CHIP

LM5030 LM5030 Application: DC - DC Converter Utilizing the Push-Pull Topology

Design Note DN304. Cebal CCxxxx Development Tools USB Driver Installation Guide By Åsmund B. Bø. Keywords. 1 Introduction

Application Note AN107

ZigBee Sensor Monitor SWRU157D 2008 Low-Power RF

Evaluating the complex configuration options of the Texas Instruments advanced fuel gauges can be

Using C to Access Data Stored in Program Memory on the TMS320C54x DSP

Application Report. 1 Description of the Problem. Jeff Falin... PMP Portable Power Applications ABSTRACT

Design Note DN004. Folded Dipole Antenna for CC25xx By Audun Andersen. Keywords. 1 Introduction CC2500 CC2550 CC2510 CC2511

TI and ibiquity Introduce Industry s Lowest Cost Single-Chip AM/FM and HD Radio Baseband John Gardner Digital Radio Marketing Manager

Data sheet acquired from Harris Semiconductor SCHS067B Revised July 2003

LM556 LM556 Dual Timer

TRF7960 Evaluation Module ISO Host Commands

SDLS068A DECEMBER 1972 REVISED OCTOBER Copyright 2001, Texas Instruments Incorporated

Data sheet acquired from Harris Semiconductor SCHS087D Revised October 2003

Providing Continuous Gate Drive Using a Charge Pump

54LS174,54LS175,DM54LS174,DM54LS175, DM74LS174,DM74LS175

LM709 LM709 Operational Amplifier

Smart Codec Features in TMS320DM365

Data sheet acquired from Harris Semiconductor SCHS020C Revised October 2003

AMC1100: Replacement of Input Main Sensing Transformer in Inverters with Isolated Amplifier

Calculating Gain for Audio Amplifiers

Using Code Coverage and Multi-event Profiler in Code Composer Studio v2.3 for Robustness and Efficiency Analyses


Importing a SPICE NetList Into TINA9-TI

Optical Implementation Using IEEE-1394.b

LM388 LM W Audio Power Amplifier

Data sheet acquired from Harris Semiconductor SCHS078C -- Revised October 2003

Application Report. 1 Introduction. 2 Resolution of an A-D Converter. 2.1 Signal-to-Noise Ratio (SNR) Harman Grewal... ABSTRACT

µa7800 SERIES POSITIVE-VOLTAGE REGULATORS

6 Output With 1 kω in Series Between the Output and Analyzer Output With RC Low-Pass Filter (1 kω and 4.7 nf) in Series Between the Output


Design Note DN002. Practical Sensitivity Testing By Morten Engjom. Keywords. 1 Introduction. Receiver Testing Sensitivity

Ultrasonic Sensing Basics for Liquid Level Sensing, Flow Sensing, and Fluid

Analysis of Power Supply Topologies for IGBT Gate Drivers in Industrial

DS8907 DS8907 AM/FM Digital Phase-Locked Loop Frequency Synthesizer

ORDERING INFORMATION. TOP-SIDE MARKING PDIP N Tube SN74LS07N SN74LS07N PACKAGE. SOIC D Tape and reel SN74LS07DR

Wireless Subwoofer TI Design Tests

Choosing Inductors and Capacitors for DC/DC Converters

Ultra-Low Power Comparison: MSP430 vs. Microchip XLP Tech Brief A Case for Ultra-Low Power Microcontroller Performance

LM1851 LM1851 Ground Fault Interrupter

Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

AN-1963 IEEE 1588 Synchronization Over Standard Networks Using the

SDLS940A MARCH 1974 REVISED MARCH Copyright 1988, Texas Instruments Incorporated

Multi-Transformer LED TV Power User Guide. Anderson Hsiao

Texas Instruments. FB PS LLC Test Report HVPS SYSTEM AND APPLICATION TEAM REVA

DC/DC LED Lighting Developer s Kit Hardware

AN-1733 Load Transient Testing Simplified

SN54165, SN54LS165A, SN74165, SN74LS165A PARALLEL-LOAD 8-BIT SHIFT REGISTERS

LM138,LM338. LM138/LM338 5-Amp Adjustable Regulators. Literature Number: SNVS771A

Design Note DN041. Using CC253X or CC254X with Dipole PCB Antennas. Keywords. 1 Introduction. By Espen Wium CC2530 CC2531 CC2533 CC2540 CC2541

Thumbus2300. User's Guide. 1 Introduction. 1.1 Features. 1.2 Kit Contents

Controlling TAS5026 Volume After Error Recovery

TL081 TL081 Wide Bandwidth JFET Input Operational Amplifier

AN-225 IC Temperature Sensor Provides Thermocouple Cold-Junction

AN-311 Theory and Applications of Logarithmic Amplifiers

Filter Design in Thirty Seconds

with Ultra-Fast Transient Response and High Light-Load Efficiency

AN-1405 DP83848 Single 10/100 Mb/s Ethernet Transceiver Reduced Media Independent Interface (RMII ) Mode

RF37S114 Tag-it HF-I Type 5 NFC, ISO/IEC Transponder, 4 mm 4 mm

CUSTOM GOOGLE SEARCH PRO. User Guide. User Guide Page 1

LM5025,LM5026,LM5034 Operation and Benefits of Active-Clamp Forward Power Converters

TVP5146 VBI Quick Start

Motor Speed Measurement Considerations When Using TMS320C24x DSPs

Designing Gain and Offset in Thirty Seconds

Application Report. Jim Patterson... Americas Field Applications

How To Close The Loop On A Fully Differential Op Amp

description V CC A CLR BO CO LOAD C D B Q B Q A DOWN UP Q C Q D GND D OR N PACKAGE (TOP VIEW) SDFS031A D3693, JANUARY 1991 REVISED OCTOBER 1993

Using Texas Instruments Spice Models in PSpice

Application Report. Vincent Chan, Steve Underwood... MSP430

TVP51471M1 VBI Quick Start

The main goal of this tutorial is to get familiar with SmartRF Studio 7: Learn how it works and what it can do.

Analysis Toolkit v1.3 for Code Composer Studio User s Guide

TrxEB RF PER Test Software Example. User s Guide SWRU296

Evaluation Criteria for ADSL AFE1302

AN-1900 LM3150 Evaluation Boards

LMS8117A LMS8117A 1A Low-Dropout Linear Regulator

Component Reliability After Long Term Storage

V OUT. I o+ & I o- (typical) 2.3A & 3.3A. Package Type

Demystifying digital signal processing (DSP) programming: The ease in realizing implementations with TI DSPs

CC USB Software Examples User s Guide

Bluetooth Low Energy CC2540 Mini Development Kit User s Guide

Data sheet acquired from Harris Semiconductor SCHS049C Revised October 2003

CD4071B Quad 2-Input OR Gate CD4072B Dual 4-Input OR Gate CD4075B Triple 3-Input OR Gate

LM2747,LM3100,LM5035 Synchronous Rectification in High-Performance Power Converter Design

User s Guide. 100-W Universal Line Input PFC Boost Converter Using the UCC User s Guide

LM3444 MR16 Boost Reference Design for Non-Dimming & Dimming LED Applications

Standard Linear & Logic Semiconductor Marking Guidelines

LM2900,LM3301,LM3900. LM2900/LM3900/LM3301 Quad Amplifiers. Literature Number: SNOSBV6

MM58274C MM58274C Microprocessor Compatible Real Time Clock

Floating Point C Compiler: Tips and Tricks Part I

IMPORT/EXPORT CUSTOMER REVIEWS. User Guide. User Guide Page 1

LM3203,LM3204,LM3205 Optimizing RF Power Amplifier System Efficiency Using DC-DC Converters

SN74ACT STROBED FIRST-IN, FIRST-OUT MEMORY

Transcription:

Programming the On-Chip Flash Memory in a Stellaris Microcontroller Application Note AN01237-06 Copyright 2007 2009 Texas Instruments

Copyright Copyright 2007 2009 Texas Instruments, Inc. All rights reserved. Stellaris and StellarisWare are registered trademarks of Texas Instruments. ARM and Thumb are registered trademarks, and Cortex is a trademark of ARM Limited. Other names and brands may be claimed as the property of others. Texas Instruments 108 Wild Basin, Suite 350 Austin, TX 78746 Main: +1-512-279-8800 Fax: +1-512-279-8879 http:www.luminarymicro.com July 9, 2009 2

Table of Contents Introduction... 4 Programming Flash Memory with the Stellaris Peripheral Driver Library... 4 Programming Flash Memory with Direct Register Writes (Polled)... 6 Programming Flash Memory with Direct Register Writes (Interrupt-Driven)... 10 Issues to Consider... 11 Conclusion... 11 References... 11 July 9, 2009 3

Introduction The flash memory of any system is routinely updated and re-programmed. This application note provides three methods for updating (erasing and programming) flash memory: the Stellaris driver library provided by Luminary Micro, software polling for completed updates, and interrupt-driven updates. This application note does not cover other issues related to flash memory management, such as the protection of flash memory pages. For more details on programming the on-chip flash memory, review the flash sections in the appropriate Stellaris family data sheet and the Stellaris Peripheral Driver Library User s Guide. In particular, it is important to understand the flash memory controller s interface registers functions. Programming Flash Memory with the Stellaris Peripheral Driver Library The Luminary Micro StellarisWare peripheral driver library provides an efficient and convenient method to program the integrated flash memory. The driver library is documented in the Stellaris Peripheral Driver Library User s Guide. Three API calls are required to program a page of flash memory: FlashUsecSet, FlashErase, and FlashProgram. FlashUsecSet Function The FlashUsecSet function sets internal timing parameters in the system s flash memory controller. The memory controller uses the supplied parameter as a prescale timer to provide a constant frequency clock to the flash controller. This function must be called before other functions that erase or program memory to assure proper timing. The prototype for FlashUsecSet is: void FlashUsecSet(unsigned long ulclocks); where ulclocks is the internal operating frequency of the processor (in MHz). For example, if the processor is executing at 20 MHz, the correct parameter value is 20. FlashErase Function The FlashErase function erases a 1 KB page of on-chip flash memory. After erasing, the memory is left in a state where all bits in the page are set. Protected pages (those marked as unreadable and unprogrammable) cannot be erased. The prototype for FlashErase is: long FlashErase(unsigned long uladdress); where uladdress is the start address of the flash block to be erased and must be a 1 KB-aligned address. The function returns 0 on success or -1 on failure (if an invalid block address was specified or the block is write-protected). July 9, 2009 4

FlashProgram Function The FlashProgram function programs a sequence of words into the on-chip flash memory. Programming consists of ANDing the existing flash memory contents with the new data; the resulting AND of the data being stored in the on-chip memory. If a bit in flash memory is a zero, it cannot be set to a one using the FlashProgram function. Restoring a bit to a one is accomplished only using the FlashErase function. Moreover, a word may be subject to one or two calls to FlashProgram. Additional calls must follow a FlashErase function call. Excessive calls to FlashProgram degrade a flash memory cell s ability to retain data, and so to guarantee maximal data retention, it is best to completely erase and reprogram a flash page following two calls to FlashProgram that affect the same word locations. The prototype for FlashProgram is: long FlashProgram(unsigned long *puldata, unsigned long uladdress, unsigned long ulcount); where puldata is a pointer to the data to be programmed, uladdress is the starting address in flash to be programmed, and ulcount is the number of bytes to be programmed. Since the flash is programmed a word at a time, the starting address and byte count must both be multiples of four. Only one call to each function is required per flash memory page since the FlashErase function call erases a page of flash memory, and the FlashProgram function call is capable of programming an arbitrary size of memory. Examples Example 1 shows the setup of the USECRL register. Example 2 shows a single erase call. Example 3 shows a single programming call. Note that in these and the examples that follow, the path for DriverLib needs to be adjusted relative to the installed location. Example 1. USECRLR Setup The processor operates at 20 MHz. Set USECRL accordingly. #include "driverlib/flash.h" unsigned long uloperatingfrequency = 20; in MHz FlashUsecSet(ulOperatingFrequency); Example 2. Single Erase Sequence Erase the first page in the flash #include "driverlib/flash.h" unsigned long uladdress = 0x0; long ret_val; July 9, 2009 5

ret_val = FlashErase(ulAddress); if (ret_val == -1) Handle an error (for example, protection)... No error (continue)... Example 3. Single Program Sequence Program the first word (4 bytes) in the flash #include "DriverLib/src/flash.h" long ret_val; unsigned long uldata = 0xA5A5A5A5; unsigned long ulflashoffset = 0x0; unsigned long ullength = 4; ret_val = FlashProgram(&ulData, ulflashoffset, ullength); if (ret_val == -1) Handle an error (for example, protection)... No error (continue)... Programming Flash Memory with Direct Register Writes (Polled) Although efficient and recommended, the Stellaris driver library is not required to program the flash memory. The flash memory interface registers are available for direct control. This section explains how to program the flash memory using these registers. USECRL, FMD, FMA and FMC Registers There are four registers used in erase and programming operations. These registers are written in the following order and provide the following functions. Note: Flash protection is provided through the FMPRE and FMPPE registers. Although the page erase size is 1 KB, a protection block is 2 KB. See the data sheet for details. 1. USECRL: U Second Reload register. The flash memory control logic contains a divider that takes the processor clock and divides it down to a 1-MHz reference clock to synchronize the timing of flash memory operations; in particular erase operations. The USECRL register contains an 8-bit field that is used for reloading this counter. The value programmed into this register is of July 9, 2009 6

the formula frequency (in MHz) minus 1. This register must be programmed before performing any memory operations. The symbolic define for this register is FLASH_USECRL_R. 2. FMD: Flash Memory Data register. This 4-byte register contains the data to write when the programming cycle is initiated. This register is not used during erase cycles. The symbolic define for this register is FLASH_FMD_R. 3. FMA: Flash Memory Address register. During a write operation, this register contains a 4-bytealigned address and specifies where the data is written. During erase operations, this register contains a 1 KB-aligned address and specifies which page is erased. Note that the alignment requirements must be met by software or the results of the operation are unpredictable. The symbolic define for this register is FLASH_FMA_R. 4. FMC: Flash Memory Control register. This is the final register written and initiates the memory operation. There are four control bits in the lower byte of this register that, when set, initiate the memory operation. The most used of these register bits are the ERASE and WRITE bits. It is a programming error to write multiple control bits and the result of such an operation is unpredictable. The symbolic define for this register is FLASH_FMC_R. The symbolic defines for the control bits are: FLASH_FMC_WRITE, FLASH_FMC_ERASE (page erase), and FLASH_FMC_MERASE (mass erase entire flash). To protect against accidental access, all writes to FMC must contain the fixed value 0xA442 in bits 31:16. If these bits are not set correctly, the register write will be ignored and no programming operation will take place. These bits can be set by ORing FLASH_FMC_WRKEY into the value written to the register. After the operation is initiated, software can check for the completion of the operation by examining the FMC register. The FMC register keeps the control bit set (step 4) until the operation completes. After the operation completes, the register is cleared. This allows software to spin and wait until the operation completes. Examples Examples 4, 5, and 6 show direct register access implementations equivalent to the peripheral driver library FlashUsecSet, FlashErase, and FlashProgram functions respectively. Each example requires the appropriate IC header file, lm3sxxx.h, which can be found in the StellarisWare/inc subdirectory. The header file for the LM3S811 part is shown here but this should be replaced with the appropriate header for your target IC. Example 4. FlashUsecSet-Equivalent Call #include "inc/lm3s811.h" void DirectFlashUsecSet(unsigned long ulclocks) FLASH_USECRL_R = ulclocks - 1; July 9, 2009 7

Example 5. FlashErase-Equivalent Call #include "inc/lm3s811.h" long DirectFlashErase(unsigned long uladdress) The address must be block aligned. if(uladdress & (FLASH_ERASE_SIZE - 1)) return(-1); Clear the flash access interrupt. FLASH_FCMISC_R = FLASH_FCMISC_AMISC; Erase the block. FLASH_FMA_R = uladdress; FLASH_FMC_R = FLASH_FMC_WRKEY FLASH_FMC_ERASE; Wait until the block has been erased. while(flash_fmc_r & FLASH_FMC_ERASE) Return an error if an access violation occurred. if(flash_fcris_r & FLASH_FCRIS_ARIS) return(-1); Success. return(0); July 9, 2009 8

Example 6. FlashProgram-Equivalent Call long DirectFlashProgram(unsigned long *puldata, unsigned long uladdress, unsigned long ulcount) The address and count must be word aligned. if((uladdress & 3) (ulcount & 3)) return(-1); Clear the flash access interrupt. FLASH_FCMISC_R = FLASH_FCMISC_AMISC; Loop over the words to be programmed. while(ulcount) Program the next word. FLASH_FMA_R = uladdress; FLASH_FMD_R = *puldata; FLASH_FMC_R = FLASH_FMC_WRKEY FLASH_FMC_WRITE; Wait until the word has been programmed. while(flash_fmc_r & FLASH_FMC_WRITE) Increment to the next word. puldata++; uladdress += 4; ulcount -= 4; Return an error if an access violation occurred. July 9, 2009 9

if(flash_fcris_r & FLASH_FCRIS_ARIS) return(-1); Success. return(0); Programming Flash Memory with Direct Register Writes (Interrupt-Driven) The flash memory controller is capable of generating an interrupt at the completion of a memory operation. Using interrupts potentially allows an application to utilize the time spent waiting for the operation to complete (especially given the low interrupt latencies of the ARM Cortex -M3 core). The software polling loop is removed and replaced with an update to local programming registers. FCRIS, FCIM, and FCISC Registers There are three registers used in managing the Flash controller while using interrupts: 1. FCRIS: Flash Controller Raw Interrupt Status register. This register contains the raw interrupt status. It is set whenever a flash operation is complete. There are two bits defined in the FCRIS register. Bit 0 is set if the logic detects that a programming operation is attempted on a protected page. Bit 1 is set when the logic completes a flash operation. The symbolic define for this register is FLASH_FCRIS_R. The symbolic define of the two bits are FLASH_FCRIS_PRIS and FLASH_FCRIS_ARIS, for bits 1 and 0 respectively. 2. FCIM: Flash Controller Interrupt Mask register. This register contains bits that control whether a raw interrupt condition is promoted to an interrupt sent to the processor. If a mask bit is set, the raw interrupt is promoted; otherwise, if a mask bit is clear, the raw interrupt is suppressed. The symbolic define for this register is FLASH_FCIM_R. The symbolic define for the two bits are FLASH_FCIM_PMASK and FLASH_FCIM_AMASK, for bits 1 and 0 respectively. 3. FCISC: Flash Controller Interrupt Status and Clear register. This register contains bits that have a dual purpose. If the register is read, the bits indicate that an interrupt has been generated and sent to the processor. If written, an interrupt can be cleared. Writing a 1 to the register clears the bit. Writing a 0 does not affect the state of the bit. The symbolic define for this register is FLASH_FCISC_R. The symbolic define for the two bits are FLASH_FCMISC_PMISC and FLASH_FCMISC_AMISC, for bits 1 and 0 respectively. The conventional use of this register is as follows. In the interrupt handler, software reads the FCISC register and handles the appropriate condition. When complete, the content of the FCISC register is written back to itself, which clears the handled condition. July 9, 2009 10

Note that in order to implement an interrupt-driven programming method, all code that executes during the flash program operation must execute out of SRAM memory. Moreover, potential interrupt sources must be masked off. These requirements are to ensure that the flash memory is not accessed while processing the write/erase operation. Issues to Consider One issue that this application note does not address is the need for exclusive access of the flash memory during an update operation. If more than one process can update the flash memory, the updates must be safely sequenced. Also keep in mind the limitations documented in the data sheet. The data sheet specifies the values of each of these limits. The flash memory is limited to the number of erase and program cycles. Each word may not be subject to more than a specific number of programming cycles before an erase cycle is required. In other words, for any given word, FlashProgram can only be called twice before FlashErase is called. Conclusion There are a number of methods to erase and program the flash memory on the Stellaris family of microcontrollers; from easy to less-than-easy-but-not-complex. References The following are available for download at www.luminarymicro.com: Stellaris microcontroller data sheet, Publication Number DS-LM3Snnn (where nnn is the part number for that specific Stellaris family device) Stellaris Peripheral Driver Library User s Guide, Document order number SW-DRL-UG Stellaris Peripheral Driver Library, Order number SW-DRL July 9, 2009 11

Important Notice Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are sold subject to TI s terms and conditions of sale supplied at the time of order acknowledgment. TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI s standard warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where mandated by government requirements, testing of all parameters of each product is not necessarily performed. TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and applications using TI components. To minimize the risks associated with customer products and applications, customers should provide adequate design and operating safeguards. TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI. Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional restrictions. Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements. TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonably be expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governing such use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and acknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products and any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may be provided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in such safety-critical applications. TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet military specifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at the Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use. TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designated products in automotive applications, TI will not be responsible for any failure to meet such requirements. Following are URLs where you can obtain information on other Texas Instruments products and application solutions: Products Applications Amplifiers amplifier.ti.com Audio www.ti.com/audio Data Converters dataconverter.ti.com Automotive www.ti.com/automotive DLP Products www.dlp.com Broadband www.ti.com/broadband DSP dsp.ti.com Digital Control www.ti.com/digitalcontrol Clocks and Timers www.ti.com/clocks Medical www.ti.com/medical Interface interface.ti.com Military www.ti.com/military Logic logic.ti.com Optical Networking www.ti.com/opticalnetwork Power Mgmt power.ti.com Security www.ti.com/security Microcontrollers microcontroller.ti.com Telephony www.ti.com/telephony RFID www.ti-rfid.com Video & Imaging www.ti.com/video RF/IF and ZigBee Solutions www.ti.com/lprf Wireless www.ti.com/wireless Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265 Copyright 2009, Texas Instruments Incorporated July 9, 2009 12