Texas Instruments Computer Drive TMS320F20x F24x DSP User Manual |
TMS320F20x/F24x DSP
Embedded Flash Memory
Technical Reference
This document contains preliminary data
current as of publication date and is subject
to change without notice.
Literature Number: SPRU282
September 1998
Printed on Recycled Paper
PRELIMINARY
Preface
Read This First
About This Manual
This reference guide describes the operation of the embedded flash EEPROM
module on the TMS320F20x/F24x digital signal processor (DSP) devices and
provides sample code that you can use in developing your own software. The
performance specifications of the embedded flash memory have been evalu-
ated using the algorithms and techniques described in this guide. TI does not
recommend deviation from these algorithms and techniques, since doing so
could affect device performance. The book does not describe the use of any
specific flash programming tool nor does it describe the external interface to
the DSP. For information about any aspect of the TMS320F20x/F24x devices
other than the embedded flash EEPROM module, see Related Documenta-
tion from Texas Instruments on page v.
How to Use This Manual
There are several stand-alone flash programming tools for TMS320F20x/
F24x generation of DSPs. Using one of these stand-alone tools with the
TMS320F20x/F24x requires only a basic understanding of the flash opera-
tions. More information about these flash programming tools is available on
the TI web page, http://www.ti.com. This guide is intended to provide a
complete understanding of the flash operations. This level of understanding
is necessary for making modifications to existing flash programming tools
or for developing alternative programming schemes.
If you are looking for in-
Turn to these locations:
formation about:
Algorithms
Chapter 3, Algorithm Implementations and
Software Considerations
Erasing the flash array
Section 1.1, Basic Concepts of Flash Memory
Technology
Section 2.1, Modifying the Contents of the
TMS320F20x/F24x Flash Array
Section 2.6, Erase Operation
Section 3.3, Erase Algorithm
iii
PRELIMINARY
PRELIMINARY
If you are looking for in-
formation about:
Turn to these locations:
Over-erasure (depletion) and
recovery
Section 1.1, Basic Concepts of Flash Memory
Technology
Section 2.7, Recovering From Over-Erasure
(Flash-Write Operation)
Section 3.4, Flash-Write Algorithm
Programming the flash array
Section 1.1, Basic Concepts of Flash Memory
Technology
Section 2.1, Modifying the Contents of the
TMS320F20x/F24x Flash Array
Section 2.5, Program Operation
Section 3.2, Programming Algorithm
Sample code
Appendix A, Assembly Source Listings and
Program Examples
Notational Conventions
This document uses the following conventions.
- The flash EEPROM is referred to as flash memory or the flash module.
The term flash array refers to the actual memory array within the flash
module. Theflashmoduleincludestheflashmemoryarrayandtheassoci-
ated control circuitry.
- The DSP generation and devices are abbreviated as follows:
J
J
J
TMS320F20x/24x generation: ’F20x/24x
TMS320F20x devices: ’F20x
TMS320F24x devices: ’F24x
- Program listings and code examples are shown in a special type-
face.
Here is a sample program listing:
0011 0005 0001
0012 0005 0003
0013 0005 0006
0014 0006
.field
.field
.field
.even
1, 2
3, 4
6, 3
iv
PRELIMINARY
PRELIMINARY
Related Documentation From Texas Instruments
Related Documentation From Texas Instruments
The following books describe the ’F20x/24x and related support tools. To ob-
tain a copy of any of these TI documents, call the Texas Instruments Literature
Response Center at (800) 477–8924. When ordering, please identify the book
by its title and literature number.
TMS320C24x DSP Controllers Reference Set, Volume 1: CPU, System,
and Instruction Set (literature number SPRU160) describes the
TMS320C24x 16-bit, fixed-point, digital signal processor controller.
Covered are its architecture, internal register structure, data and
program addressing, and instruction set. Also includes instruction set
comparisons and design considerations for using the XDS510 emulator.
TMS320C24x DSP Controllers Reference Set Volume 2: Peripheral
Library and Specific Devices (literature number SPRU161) describes
the peripherals available on the TMS320C24x digital signal processor
controllers and their operation. Also described are specific device
configurations of the ’C24x family.
TMS320C240, TMS320F240 DSP Controllers (literature number SPRS042)
data sheet contains the electrical and timing specifications for these
devices, as well as signal descriptions and pinouts for all of the available
packages.
TMS320C2x/C2xx/C5x Optimizing C Compiler User’s Guide (literature
number SPRU024) describes the ’C2x/C2xx/C5x C compiler. This C
compiler accepts ANSI standard C source code and produces TMS320
assembly language source code for the ’C2x, ’C2xx, and ’C5x genera-
tions of devices.
TMS320F206 Digital Signal Processor (literature number SPRS050) data
sheet contains the electrical and timing specifications for the ’F206
device, as well as signal descriptions and the pinout.
TMS320F241, TMS320C241, TMS320C242 DSP Controllers (literature
number SPRS063) data sheet contains the electrical and timing
specifications for the ’F241, ’C241, and ’C242 devices, as well as signal
descriptions and pinouts.
TMS320F243 DSP Controller (literature number SPRS064) data sheet
contains the electrical and timing specifications for the ’F243 device, as
well as signal descriptions and the pinout.
TMS320C2xx User’s Guide (literature number SPRU127) discusses the
hardware aspects of the ’C2xx 16-bit, fixed-point digital signal proces-
sors. It describes the architecture, the instruction set, and the on-chip pe-
ripherals.
Read This First
v
PRELIMINARY
PRELIMINARY
Related Documentation From Texas Instruments
TMS320C2xx C Source Debugger User’s Guide (literature number
SPRU151) tells you how to invoke the ’C2xx emulator and simulator ver-
sions of the C source debugger interface. This book discusses various
aspects of the debugger interface, including window management, com-
mand entry, code execution, data management, and breakpoints. It also
includes a tutorial that introduces basic debugger functionality.
vi
PRELIMINARY
PRELIMINARY
If You Need Assistance . . .
If You Need Assistance . . .
- World-Wide Web Sites
TI Online
http://www.ti.com
Semiconductor Product Information Center (PIC)
DSP Solutions
http://www.ti.com/sc/docs/pic/home.htm
http://www.ti.com/dsps
320 Hotline On-linet
http://www.ti.com/sc/docs/dsps/support.htm
- North America, South America, Central America
Product Information Center (PIC)
TI Literature Response Center U.S.A.
Software Registration/Upgrades
U.S.A. Factory Repair/Hardware Upgrades
U.S. Technical Training Organization
DSP Hotline
(972) 644-5580
(800) 477-8924
(214) 638-0333
(281) 274-2285
(972) 644-5580
(281) 274-2320
(281) 274-2323
Fax: (214) 638-7742
Fax: (281) 274-2324
Email: [email protected]
DSP Modem BBS
DSP Internet BBS via anonymous ftp to ftp://ftp.ti.com/pub/tms320bbs
- Europe, Middle East, Africa
European Product Information Center (EPIC) Hotlines:
Multi-Language Support
Email: [email protected]
+33 1 30 70 11 69
Fax: +33 1 30 70 10 32
Deutsch
English
+49 8161 80 33 11 or +33 1 30 70 11 68
+33 1 30 70 11 65
Francais
+33 1 30 70 11 64
Italiano
+33 1 30 70 11 67
EPIC Modem BBS
+33 1 30 70 11 99
European Factory Repair
+33 4 93 22 25 40
Europe Customer Training Helpline
Fax: +49 81 61 80 40 10
- Asia-Pacific
Literature Response Center
Hong Kong DSP Hotline
Korea DSP Hotline
Korea DSP Modem BBS
Singapore DSP Hotline
Taiwan DSP Hotline
+852 2 956 7288
+852 2 956 7268
+82 2 551 2804
+82 2 551 2914
Fax: +852 2 956 2200
Fax: +852 2 956 1002
Fax: +82 2 551 2828
Fax: +65 390 7179
Fax: +886 2 377 2718
+886 2 377 1450
+886 2 376 2592
Taiwan DSP Modem BBS
Taiwan DSP Internet BBS via anonymous ftp to ftp://dsp.ee.tit.edu.tw/pub/TI/
- Japan
Product Information Center
+0120-81-0026 (in Japan)
Fax: +0120-81-0036 (in Japan)
+03-3457-0972 or (INTL) 813-3457-0972
+03-3769-8735 or (INTL) 813-3769-8735
Fax: +03-3457-1259 or (INTL) 813-3457-1259
Fax: +03-3457-7071 or (INTL) 813-3457-7071
DSP Hotline
DSP BBS via Nifty-Serve
Type “Go TIASP”
- Documentation
When making suggestions or reporting errors in documentation, please include the following information that is on the title
page: the full title of the book, the publication date, and the literature number.
Mail: Texas Instruments Incorporated
Technical Documentation Services, MS 702
P.O. Box 1443
Email: [email protected]
Houston, Texas 77251-1443
Note: When calling a Literature Response Center to order documentation, please specify the literature number of the
book.
Read This First
vii
PRELIMINARY
PRELIMINARY
viii
PRELIMINARY
Contents
1
2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Ć 1
Discusses basic flash memory technology; summarizes the features and benefits of the
TMS320F20x/F24x flash module
1.1
1.2
1.3
Basic Concepts of Flash Memory Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Ć 2
TMS320F20x/F24x Flash Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Ć 3
Benefits of Embedded Flash Memory in a DSP System . . . . . . . . . . . . . . . . . . . . . . . . . . 1Ć 5
Flash Operations and Control Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 1
Describes the operations that modify the content of the flash module; explains the role of the
control registers
2.1
2.2
Operations that Modify the Contents of the ’F20x/F24x Flash Array . . . . . . . . . . . . . . . 2Ć 2
Accessing the Flash Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 5
2.2.1 TMS320F206 Flash Access-Control Register . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 6
2.2.2 TMS320F24x Flash Access-Control Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 7
Flash Module Control Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 8
2.3.1 Segment Control Register (SEG_CTR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 8
2.3.2 Flash Test Register (TST) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 10
2.3.3 Write Address Register (WADRS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 10
2.3.4 Write Data Register (WDATA) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 11
Read Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 12
Program Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 13
Erase Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 14
Recovering From Over-Erasure (Flash-Write Operation) . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 15
Reading From the Flash Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 16
Protecting the Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 16
2.3
2.4
2.5
2.6
2.7
2.8
2.9
3
Algorithm Implementations and Software Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 1
Describes the algorithms used for the programming, erase, and flash-write operations; dis-
cusses considerations necessary for developing your software
3.1
3.2
3.3
3.4
How the Algorithms Fit Into the Program-Erase-Reprogram Flow . . . . . . . . . . . . . . . . . 3Ć 2
Programming (or Clear) Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 4
Erase Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 10
Flash-Write Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 14
A
Assembly Source Listings and Program Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 1
A.1 Assembly Source for Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 2
ix
Contents
A.1.1 Header File for Constants and Variables, SVAR20.H . . . . . . . . . . . . . . . . . . . . . AĆ 2
A.1.2 Clear Algorithm, SCLR20.ASM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 5
A.1.3 Erase Algorithm, SERA20.ASM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 10
A.1.4 Flash-Write Algorithm, SFLW20.ASM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 15
A.1.5 Programming Algorithm, SPGM20.ASM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 19
A.1.6 Subroutines Used By All Four Algorithms, SUTILS20.ASM . . . . . . . . . . . . . . . AĆ 25
A.2 C-Callable Interface to Flash Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 27
A.3 Sample Assembly Code to Erase and Reprogram the TMS320F206 . . . . . . . . . . . . . . AĆ 32
A.3.1 Assembly Code for TMS320F206 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 32
A.3.2 Linker Command File for TMS320F206 Sample Assembly Code . . . . . . . . . . AĆ 35
A.4 Sample C Code to Erase and Reprogram the TMS320F206 . . . . . . . . . . . . . . . . . . . . . AĆ 37
A.4.1 C Code That Calls the Interface to Flash Algorithms for TMS320F206 . . . . . AĆ 37
A.4.2 Linker Command File for TMS320F206 Sample C Code . . . . . . . . . . . . . . . . . AĆ 38
A.5 Sample Assembly Code to Erase and Reprogram the TMS320F240 . . . . . . . . . . . . . . AĆ 40
A.5.1 Assembly Code for TMS320F240 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 40
A.5.2 Linker Command File for TMS320F240 Sample Assembly Code . . . . . . . . . . AĆ 45
A.6 Using the Algorithms With C Code to Erase and Reprogram the ’F240 . . . . . . . . . . . . AĆ 47
A.6.1 C Code That Calls the Interface to Flash Algorithms for TMS320F240 . . . . . AĆ 47
A.6.2 Linker Command File for TMS320F240 Sample C Code . . . . . . . . . . . . . . . . . AĆ 48
A.6.3 C Function for Disabling TMS320F240 Watchdog Timer . . . . . . . . . . . . . . . . . AĆ 50
A.6.4 C Functions for Initializing the TMS320F240 . . . . . . . . . . . . . . . . . . . . . . . . . . . AĆ 51
x
Figures
1–1
2–1
2–2
2–3
3–1
3–2
3–3
3–4
3–5
3–6
3–7
TMS320F20x/F24x Program Space Memory Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Ć 4
Flash Memory Logic Levels During Programming and Erasing . . . . . . . . . . . . . . . . . . . . . . 2Ć 4
Memory Maps in Register and Array Access Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 6
Segment Control Register (SEG_CTR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 8
Algorithms in the Overall Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 3
The Programming Algorithm in the Overall Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 4
Programming or Clear Algorithm Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6
Erase Algorithm in the Overall Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 10
Erase Algorithm Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 13
Flash-Write Algorithm in the Overall Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 14
Flash-Write Algorithm Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 16
Contents
xi
Tables
1–1
2–1
2–2
2–3
2–4
3–1
3–2
3–3
TMS320 Devices With On-Chip Flash EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Ć 3
Operations that Modify the Contents of the Flash Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 4
Flash Module Control Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 8
Segment Control Register Field Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 9
Flash Array Segments Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Ć 10
Steps for Verifying Programmed Bits and Applying One Program or Clear Pulse . . . . . . 3Ć 8
Steps for Applying One Erase Pulse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 11
Steps for Applying One Flash-Write Pulse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Ć 15
xii
PRELIMINARY
Chapter 1
Introduction
TheTMS320F20x/F24xdigitalsignalprocessors(DSPs)containon-chipflash
EEPROM (electrically-erasable programmable read-only memory). The em-
bedded flash memory provides an attractive alternative to masked program
ROM. Like ROM, flash memory is nonvolatile, but it has an advantage over
ROM: in-system reprogrammability.
This chapter discusses basic flash memory technology, introduces the flash
memory module of the ’F20x/F24x DSP, and lists the benefits of flash memory
embedded in a DSP chip.
Topic
Page
1.1 Basic Concepts of Flash Memory Technology . . . . . . . . . . . . . . . . . . . 1-2
1.2 TMS320F20x/F24x Flash Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
1.3 Benefits of Embedded Flash Memory in a DSP System . . . . . . . . . . . 1-5
1-1
PRELIMINARY
PRELIMINARY
Basic Concepts of Flash Memory Technology
1.1 Basic Concepts of Flash Memory Technology
The term flash in this EEPROM technology refers to the speed of some of the
operations performed on the memory (these operations will be described in
greater detail later in this document). An entire block of bits is affected simulta-
neously in a block or flash operation, rather than being affected one bit at a
time. In contrast, writing data to the flash memory cannot be a block operation,
since normally a selection of ones and zeroes are written (all bits are not the
same value). Writing selected bits to create a desired pattern is known as pro-
gramming the flash memory, and a written bit is called a programmed bit.
Several different types of program and erase operations are performed on the
flash memory in order to properly produce the desired pattern of ones and ze-
roes in the memory. It should be noted that, under some conditions, flash
memory may become overerased, resulting in a condition known as depletion.
The ’F20x/F24x algorithms avoid overerasure by using an approach that
erases in small increments until complete erasure is achieved.
The ’F20x/F24x flash EEPROM includes a special operation, flash-write, that
is used only to recover from over-erasure. Because of the implementation of
the flash memory, when over-erasure occurs, any particular bit in depletion
mode is difficult to identify. For this reason, the ’F20x/F24x simply writes an
entire block of bits simultaneously; hence, the name flash-write.
The program and erase operations in flash memory must provide sufficient
charge margin on 1s and 0s to ensure data retention, so the ’F20x/F24x flash
module includes a hardware mechanism that provides margin for erasing or
programming. This mechanism implements voltage reference levels which
ensure this logic level margin when modifying the contents of the flash
memory.
1-2
PRELIMINARY
PRELIMINARY
TMS320F20x/F24x Flash Module
1.2 TMS320F20x/F24x Flash Module
The ’F20x/F24x flash EEPROM is implemented with one or two independent
flash memory modules of 8K or 16K words. Each flash module is composed
of a flash memory array, four control registers, and circuitry that produces ana-
log voltages for programming and erasing. The flash array size of the
TMS320F206 and TMS320F240 is 16K × 16 bits, while the TMS320F241 and
TMS320F243 incorporate an 8K × 16-bit flash array (see Table 1–1). Unlike
most discrete flash memories, the ’F20x/F24x flash module does not require
adedicatedstatemachine, becausethealgorithmsforprogramminganderas-
ing the flash are executed in software by the DSP core. The use of these so-
phisticated, adaptive programming algorithms results in reduced chip size and
greater programming flexibility. In addition, the application code can manage
the use of the flash memory without the requirement of external programming
equipment.
Table 1–1. TMS320 Devices With On-Chip Flash EEPROM
Device
TMS320F206
Array Size
16K
Total Flash Memory
†
32K
TMS320F240
TMS320F241
16K
8K
16K
8K
TMS320F243
8K
8K
†
Each array can be independently erased.
Introduction
1-3
PRELIMINARY
PRELIMINARY
TMS320F20x/F24x Flash Module
Simplified memory maps for the program space of the TMS320F20x/F24x de-
vices are shown in Figure 1–1 to illustrate the location of the flash modules.
Figure 1–1. TMS320F20x/F24x Program Space Memory Maps
TMS320F206
MP/MC = 0
TMS320F240
MP/MC = 0
TMS320F241
TMS320F243
MP/MC = 0
0000h
0000h
0000h
1FFFh
0000h
1FFFh
Flash0
Flash0
Flash0
Flash1
Flash0
3FFFh
4000h
3FFFh
4000h
7FFFh
8000h
FFFFh
FFFFh
FFFFh
1-4
PRELIMINARY
PRELIMINARY
Benefits of Embedded Flash Memory in a DSP System
1.3 Benefits of Embedded Flash Memory in a DSP System
The circuitry density of flash memory is about half that of conventional EE-
PROM memory, making it possible to approach DRAM densities with flash
memory. This increased density allows flash memory to be integrated with a
CPU and other peripherals in a single ’F20x/F24x DSP chip. Embedded flash
memoryexpandsthecapabilitiesofthe’F20x/F24xDSPsintheareasofproto-
typing, integrated solutions, and field upgradeable designs.
Embedded flash memory facilitates system development and early field test-
ing. Throughout the development process, the system software can be up-
dated and reprogrammed into the flash memory for testing at various stages.
Since flash is a non-volatile memory type, the resulting standalone prototype
can be tested in the appropriate environment without the need for battery
backup. In addition to its nonvolatile nature, embedded flash memory has the
advantage of in-system programming. Unlike some discreteflashorEEPROM
chips, embedded flash memory can be programmed without removing the de-
vicefromthesystemboard. Infact, theembeddedflashmemoryof’F20x/F24x
DSPs can be programmed using hardware emulators which are already an in-
tegral part of the DSP development process; no external programming equip-
ment is required.
The embedded flash memory of ’F20x/F24x DSPs also makes these devices
ideal for highly integrated, low-cost systems. The initial investment involved
with making a ROM memory is not justifiable for certain low-cost applications.
Accordingly, when on-chip ROM is not an option, DSP system designers usu-
ally resort to using expensive static RAM (SRAM), to store system software
and data. The SRAM provides the fast access times required by the DSP, but
has the disadvantage of being a volatile memory type. To address the issue
of memory volatility, designers often use a low-cost EPROM or flash device to
load the SRAM after system power-up. This approach is very expensive, and
the increased chip count is often prohibitive. The ’F20x/F24x DSPs, with their
on-chip flash memory modules, provide a single chip solution with nonvolatile
memory that supports full speed DSP access rates.
Another benefit of embedded flash memory in a DSP system is remote repro-
grammability. Field upgradeability is an extremely useful feature for em-
bedded systems. For example, many modem manufacturers offer algorithm
upgrades remotely, without requiring the modem to be removed from the host
computer system. The same type of feature is also being offered for many
handheld consumer products. Adding this capability to a product requires the
addition of EEPROM or flash devices, which increase chip count and system
cost. Since no external equipment is required to program the embedded flash
memory of the ’F20x/F24x DSPs, these devices enable field upgradeability
without impacting system cost.
Introduction
1-5
PRELIMINARY
PRELIMINARY
1-6
PRELIMINARY
PRELIMINARY
Chapter 2
Flash Operations and Control Registers
The operations that modify the contents of the ’F20x/F24x flash array are per-
formedinsoftwarethroughtheuseofdedicatedprogrammingalgorithms. This
chapterintroducestheoperationsperformedbythesealgorithmsandexplains
the role of the control registers in this process. The actual algorithms are dis-
cussed in Chapter 3.
Topic
Page
2.1 Operations that Modify the Contents of the ’F20x/F24x
Flash Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
2.2 Accessing the Flash Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
2.3 Flash Module Control Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
2.4 Read Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
2.5 Program Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13
2.6 Erase Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
2.7 Recovering From Over-Erasure (Flash-Write Operation) . . . . . . . . . 2-15
2.8 Reading From the Flash Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
2.9 Protecting the Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
2-1
PRELIMINARY
PRELIMINARY
Operations that Modify the Contents of the ’F20x/F24x Flash Array
2.1 Operations that Modify the Contents of the ’F20x/F24x Flash Array
Operations that modify the contents of the flash array are generically referred
to as either “programming,” which drives one or more bits toward the logic zero
state, or “erasing,” which drives all bits towards the logic one state. It should
be noted that since these operations are performed incrementally, a single
“programming” or “erasing” operation does not ALWAYS result in a valid logic
one or zero. The result of each of these types of operations depends on the
initial state of the bit(s) prior to the operation. This is described in more detail
below.
Within these two basic types of operations (which are related to the fact that
there are only two valid logic levels in the F20x/F24x device) are four distinctly
different types of functions which are actually performed.
In the category of “programming” operations, there are three actual types of
functions that are performed:
- Clear – which is used to write ALL array bits to a zero state,
- Program – which is used to write SELECTED array bits to zero, and
- Flash-Write – which is used to recover ALL array bits from depletion
In the category of “erase” operations, there is only one type of operation:
- Erase – which is used to write ALL array bits to a one state.
Clear, Program, Flash-Write, and Erase are the only four functions that are
used to modify the flash array.
Assuming that the intent of a modification of the contents of the flash array is
to program the array with a selection of ones and zeroes, the following se-
quence of operations must be performed for proper operation of the flash
memory:
1) The array is first CLEARED to all zeroes.
2) The array is then ERASED to all ones.
3) The array is then checked for depletion and recovered using FLASH-
WRITEif necessary (note that if Flash-Write is used to recover from deple-
tion, this sequence must be started over again with the Clear and Erase
functions).
4) Once the array is properly cleared and erased, and verified not to be in
depletion, the array is then PROGRAMMED with the desired selection of
zero bits.
2-2
PRELIMINARY
PRELIMINARY
Operations that Modify the Contents of the ’F20x/F24x Flash Array
This procedure is discussed in complete detail in Chapter 3.
During these operations that are used to modify the contents of the flash array,
threespecialreadmodes, andacorrespondingsetofreferencevoltagelevels,
are used when reading back data values to verify programming and erase op-
erations.
These read modes and reference levels are:
- VER0 – which is used to verify the logic zero level including margin,
- VER1 – which is used to verify the logic one level including margin, and
- Inverse Erase – which is used to verify depletion recovery.
These concepts are illustrated graphically in Figure 2–1 and summarized in
Table 2–1.
Note that ONLY the Erase and the Flash-Write functions are truly “flash” in the
sense that these functions actually affect all bits in the array simultaneously.
In contrast, bit programming levels in the Program and Clear functions can be
controlled individually on a bit-by-bit basis.
Therefore, when using the Erase or Flash-Write functions, the whole array is
modified, and then the whole array is read, word by word, to verify whether all
words have reached the same value (if not, further iterations of the Erase or
Flash-Write functions continue).
In these cases, as mentioned previously, all the bits in the array are modified
simultaneously, but some bits may react more quickly, potentially resulting in
variation in actual levels on different bits. Therefore, when performing an
Erase, it is possible that some bits may reach depletion even before other bits
reach the logic one reference level (VER1).
The reason that it is critical to clear the array to a consistent zero level before
erasing the array is to give maximum immunity to depletion when erasing.
Note, however, that even when following this sequence, some flash arrays
may experience depletion, and may require recovery using the Flash-Write
function.
In contrast to the true “flash” operations Erase and Flash-Write, after each in-
cremental Program or Clear operation, each bit is tested against the VER0 ref-
erence level to determine the exact point at which it has reached the proper
value, following which, no further incremental adjustment of the level is made
onthatbit. Therefore, whentheProgramorClearoperationiscomplete, allbits
are at the same zero level, which greatly increases proper data retention and
depletionimmunityforthedevice. Again, notethattheprogramminganderase
operations are discussed in complete detail in Chapter 3.
Flash Operations and Control Registers
2-3
PRELIMINARY
PRELIMINARY
Operations that Modify the Contents of the ’F20x/F24x Flash Array
Figure 2–1. Flash Memory Logic Levels During Programming and Erasing
Depletion Mode
Inverse Erase
Reference Level
Logic 1
Program operations
VER1
Reference Level
Clear
S
S
Program
1 Margin
Flash Write
S
(Towards logic
zero level)
Erase
S
(Towards logic
one level)
Erase operation
0 Margin
Logic 0
VER0
Reference
level
Table 2–1. Operations that Modify the Contents of the Flash Array
Change in Bit Level
Towards Logic 1
Towards Logic 0
Function
Reference
Level
Function
Reference
Level
Erase (all bits)
VER1
Program (selected bits) VER0
Clear (all bits)
VER0
Flash-Write (all bits)
Inverse Erase
2-4
PRELIMINARY
PRELIMINARY
Accessing the Flash Module
2.2 Accessing the Flash Module
In addition to the flash memory array, each flash module has four registers that
control operations on the flash array. These registers are:
- Segment control register (SEG_CTR)
- Test register (TST)
- Write address register (WADRS)
- Write data register (WDATA)
Theflashmoduleoperatesinoneoftwomodes:oneinwhichtheflashmemory
is accessed directly by the CPU, and one in which the memory array cannot
be accessed directly, but the four control registers are accessible. This mode
is used for programming. Each flash module has a flash access-control regis-
ter that selects between these two access modes. The register is a single-bit,
I/O-mapped register.
The two access modes are summarized as follows:
- Array-access mode. You can access the flash array in the memory space
decodedfortheflashmodule. Theflashmoduleremainsinthismodemost
of the time, because it allows the DSP core to read from the memory array.
- Register-access mode. You can access the four control registers in the
memory space decoded for the flash module. This mode is used for pro-
gramming. When the flash module is in register-access mode, the regis-
ters are repeated every four address locations within the flash module’s
address range.
The flash array is not directly accessible as memory in register-access mode,
and the control registers are not directly accessible in array-access mode.
Figure 2–2 shows memory maps of the flash array in register and array access
modes.
Flash Operations and Control Registers
2-5
PRELIMINARY
PRELIMINARY
Accessing the Flash Module
Figure 2–2. Memory Maps in Register and Array Access Modes
Flash access control register
(single bit)
MODE = 1: Array-access mode
MODE = 0: Register access mode
0100 ... 010
SEG_CTR register
0100 ... 011
TST register
WADRS register
WDATA register
4 registers duplicated
4 registers duplicated
Flash memory
array
1110 ...110
0110 ...111
4 registers duplicated
2.2.1 TMS320F206 Flash Access-Control Register
Because each flash module has an access-control register associated with it,
the ’F206 has two access-control registers. These registers are standard I/O-
mapped registers that can be read with an IN instruction and must be modified
with an OUT instruction.
- F_ACCESS0 is mapped in I/O space at 0FFE0h.
- F_ACCESS1 is mapped in I/O space at 0FFE1h.
The MODE bit (bit 0) of the access-control register selects the access mode:
MODE = 0
MODE = 1
Register-access mode
Array-access mode
Bits 15–1 of each access-control register are always read as 0 and are unaf-
fected by writes.
2-6
PRELIMINARY
PRELIMINARY
Accessing the Flash Module
Although the function is the same, the access control registers of the ’F206 de-
vice are mapped at different addresses from that of the ’F24x devices, and
their values are modified in a different way.
2.2.2 TMS320F24x Flash Access-Control Register
The access-control register of the ’F24x devices is a special type of I/O-
mapped register that cannot be read. The register is mapped at I/O address
0FF0Fh, and it functions as indicated below.
Note:
For both the IN and OUT instructions, the data operand (dummy) is not used,
and can be any valid memory location.
An OUT instruction using the register address as an I/O port places the flash
module in register-access mode.
For example:
OUT dummy,0FF0Fh;Selects register-access mode
An IN instruction using the register address as an I/O port places the flash
module in array-access mode.
The data operand (dummy) is not used, and can be any valid memorylocation.
For example:
IN
dummy,0FF0Fh;Selects array-access mode
Flash Operations and Control Registers
2-7
PRELIMINARY
PRELIMINARY
Flash Module Control Registers
2.3 Flash Module Control Registers
Table 2–2 lists the control registers and their relative addresses within the four
locations that repeat throughout the module’s address range.
Table 2–2. Flash Module Control Registers
Described in ...
Relative Register
Address Name
Section
Page
Description
0
SEG_CTR
Segment control register. The eight MSBs enable spe-
cific segments for programming. Setting a bit to 1 en-
ables the segment. The eight LSBs control the pro-
gram, erase, and verify operations of the module.
2.3.1
2-5
1
2
3
TST
Test register. Reserved for test; not accessible to the
user.
2.3.2
2.3.3
2.3.4
2-8
2-8
2-8
WADRS
WDATA
Write address register. Holds the address for a write
operation.
Write data register. Holds the data for a write operation.
2.3.1 Segment Control Register (SEG_CTR)
SEG_CTR is a 16-bit register that initiates and monitors the programming and
erasing of the flash array. This register contains the bits that initiate the active
operations (the WRITE/ERASE field and EXE bit), those used for verification
(VER0 and VER1), and those used for protection (KEY0, KEY1, and
SEG7–SEG0). All bits of SEG_CTR register are cleared to 0 upon reset.
SEG_CTR is shown in Figure 2–3 and the fields are described in Table 2–3.
Figure 2–3. Segment Control Register (SEG_CTR)
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
WRITE/
ERASE
SEG7 SEG6 SEG5 SEG4 SEG3 SEG2 SEG1 SEG0 Res KEY1 KEY0 VER0 VER1
EXE
RW–0 RW–0 RW–0 RW–0 RW–0 RW–0 RW–0 RW–0
X
RW–0 RW–0 RW–0 RW–0
RW–0
RW–0
Legend: R = read
W = write
–0 = value after reset
X = don’t care
2-8
PRELIMINARY
PRELIMINARY
Flash Module Control Registers
Table 2–3. Segment Control Register Field Descriptions
Bits Name
Description
15–8 SEG7–SEG0
Segment enable bits. Each of these bits protects the specified segment against pro-
gramming or enables programming for the specified segment in the array. Any number
of segments (from 0 to 7 in any combination) can be enabled at any one time. See
Table 2–4 for segment address ranges. EXE must be cleared to modify the SEGx bits.
SEGx = 1 enables programming of the corresponding segment.
SEGx = 0 protects the segment from programming.
7
Reserved
This bit is not affected by writes, and reads of this bit are undefined.
6–5
KEY1, KEY0
Execute key bits. A binary value of 10 must be written to these bits in the same DSP
core access in which the EXE bit is set for the selected operation (erase, program, or
flash-write) to start. KEY1 and KEY0 must be cleared in the same write access that
clears EXE. These bits are used as additional protection against inadvertent program-
ming or erasure of the array. These bits are read as 0s.
4–3
VER0, VER1
Verify bits. These bits select special read modes used to verify proper erasure or pro-
gramming.
Possible values:
00: Normal read mode
01: Verify 1s (VER1) read mode to verify margin of 1s for proper erasure
10: Verify 0s (VER0) read mode to verify margin of 0s for proper programming
11: Inverse-read mode; tests for bits erased into depletion
2–1
WRITE/ERASE Write/eraseenablefield. Thesebitsselecttheprogram, erase, orflash-writeoperation.
However, modification of the array data does not actually start until the EXE bit is set.
Reset clears these bits to zero.
Possible values:
00: Read operation is enabled. These bit values are required to read the array.
01: Erase operation is enabled
10: Write operation is enabled
11: Flash-write operation is enabled
0
EXE
Execute bit. In conjunction with WRITE/ERASE, KEY1, and KEY0, this bit controls the
program, erase, and flash-write operations. Setting EXE starts and stops program-
ming and erasing of the flash array. The KEY1 and KEY0 bits must be written in the
same write access that sets EXE, and EXE must be cleared in the same write access
that clears KEY1 and KEY0. EXE must be cleared to modify the SEGx bits.
Note: The segment enable bits are not intended for protection during the erase or flash-write operations. During these opera-
tions, all segments must be enabled.
Flash Operations and Control Registers
2-9
PRELIMINARY
PRELIMINARY
Flash Module Control Registers
Table 2–4. Flash Array Segments Summary
†
SEG7–SEG0 Bits
’F206/F240 Flash Module
’F241/F243
Flash Module
Array Segment
Enabled
15 14 13 12 11 10
9
0
1
0
0
0
0
0
0
8
1
0
0
0
0
0
0
0
Flash0 Flash1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0000–07FFh 4000–47FFh 0000–03FFh
0800–0FFFh 4800–4FFFh 0400–07FFh
1000–17FFh 5000–57FFh 0800–0BFFh
1800–1FFFh 5800–5FFFh 0C00–0FFFh
2000–27FFh 6000–67FFh 1000–13FFh
2800–2FFFh 6800–6FFFh 1400–17FFh
3000–37FFh 7000–77FFh 1800–1BFFh
3800–3FFFh 7800–7FFFh 1C00–1FFFh
0
1
2
3
4
5
6
7
†
The TMS320F206 has two flash modules. The TMS320F240 device uses the address ranges shown for Flash0.
Although segmentation is not supported during erase (i.e., the entire array
must be erased simultaneously), the segment enable bits can be used to pro-
tect portions of the array against unintentional programming. This is useful for
applications in which different portions of the array are programmed at differ-
ent times. For example, an application might program the flash module with
a large table in 2K × 16 blocks. Some time after the first block is programmed,
thenextblockisprogrammed. Thesegmentenablebitscanbeusedtoprevent
corruption of the first block while the second block is being programmed.
2.3.2 Flash Test Register (TST)
The flash test register (TST) is a 5-bit register used during manufacturing test
of the flash array. This register is not accessible to the DSP core.
2.3.3 Write Address Register (WADRS)
The write address register (WADRS) is a 16-bit register that holds the latched
write address for a programming operation. In array-access mode, this regis-
ter is loaded with the value on the address bus when you are writing a data
value to the flash module. It can be loaded directly in register-access mode by
writing to it.
2-10
PRELIMINARY
PRELIMINARY
Flash Module Control Registers
2.3.4 Write Data Register (WDATA)
The write data register (WDATA) is a 16-bit register that contains the latched
write data for a programming operation. In array-access mode, this register
can be loaded by writing a data value to the flash module. It can be loaded di-
rectly in register-access mode by writing to it. The WDATA register must be
loaded with the value FFFFh before an erase operation starts.
Flash Operations and Control Registers
2-11
PRELIMINARY
PRELIMINARY
Read Modes
2.4 Read Modes
The ’F20x/F24x flash module uses four read modes and corresponding sets
of reference levels:
- Standard
- Verify 0s (VER0)
- Verify 1s (VER1)
- Inverse-erase
Read mode selection is accomplished through the verify bits (bits 3 and 4) in
SEG_CTR during execution of the algorithms.
In the standard read mode of the ’F20x/F24x flash module, the supply voltage
(V ) is internally applied to the cell to select it for reading. The VER0, VER1,
DD
and inverse-erase read modes differ from the standard read mode in the inter-
nal voltage level applied to the flash cell.
Because the program and erase operations must provide sufficient margin on
1s and 0s to ensure data retention, the verify 0s (VER0) and verify 1s (VER1),
are provided on the flash module to check for sufficient margin.
The VER0 and VER1 read modes provide a method for adjusting the level on
the cells during programming or erasing, beyond the point required for reading
a 0 or a 1, creating the required logic level margin. In VER0 mode, a voltage
closertoanideallogiczerolevelthannecessarytoreadalogiczeroisinternal-
ly applied to the cell to select it for reading. This is the worst-case condition for
reading a programmed cell, and if a cell can be read as 0 in VER0 mode, then
it can also be read as 0 in standard read mode. Similarly, in the VER1 read
mode, avoltageclosertoanideallogiconelevelthannecessarytoreadalogic
one is internally applied to the cell to select it for reading. This is the worst-case
condition for reading an erased cell, and if a cell can be read as 1 in the VER1
mode, then it can be read as 1 in standard read mode.
The inverse-erase read mode detects flash bits that are in depletion mode.
This read mode applies a voltage to all array cells so that all cells are dese-
lected. The entire array can be tested for bits in depletion mode by reading the
first row (32 words) of the array in inverse-erase read mode. If there are no bits
in depletion mode, all 32 words are read as 0000h.
2-12
PRELIMINARY
PRELIMINARY
Program Operation
2.5 Program Operation
The program operation of the ’F20x/F24x flash module loads the application-
specific data (a pattern of 0s) into the flash array. The basis of the operation
is applying a program pulse to a single word of flash memory. The term pro-
grampulsereferstothetimeduringtheprogramoperationbetweenthesetting
and the clearing of the EXE bit ( bit 0 of SEG_CTR). During the program pulse,
charge is added to the addressed bits via the programming mechanism. Sev-
eral program pulses may be required to fully program the bits of a word, and
the application of program pulses is controlled by the programming algorithm.
TheflashlocationtobeprogrammedisspecifiedbytheaddressintheWADRS
register, and the data pattern to be programmed is loaded into the WDATA reg-
ister. Only the bits that contain a 0 are programmed; any bit positions contain-
ing a 1 remain unchanged. (See sections 2.3.3 and 2.3.4 for information about
how to load the WADRS and WDATA registers.)
To assure that the 0 bits are programmed with enough margin, the reads asso-
ciated with programming are performed using the VER0 read mode. After a
programpulsehasbeenapplied, thebyteisreadbackinVER0modetoassure
that programmed bits can be read as 0 over the entire operating range of the
device.
The flash module supports programming of up to eight bits of data. Therefore,
althoughtheflashbitsareaddressedon16-bitwordboundaries, onlyeightbits
can be programmed at a time. The algorithm must limit the programming to
eight bits by masking the word to be programmed before writing it to the WDA-
TA register. For example, to mask off the upper byte while programming the
lower byte, the data value is logically 0Red with 0FF00h in software. When a
program pulse is applied, only the selected bits are programmed.
Flash Operations and Control Registers
2-13
PRELIMINARY
PRELIMINARY
Erase Operation
2.6 Erase Operation
The erase operation of the ’F20x/F24x flash module prepares the flash array
for programming and enables reprogrammability of the flash array. Before the
array can be erased, all bits must be programmed to 0s. This procedure of pro-
gramming all array locations in preparation for the erase is called clearing the
array. During the erase, all bits in the array are changed from 0s to 1s. After
the erase is finished, a depletion mode test is made to determine whether any
bits have been over-erased. If over-erased bits are detected, they must be re-
covered with the flash-write algorithm, and the clear and erase algorithms
must be repeated.
An erase pulse is the time during the erase operation between the setting and
the clearing of the EXE bit ( bit 0 of SEG_CTR). During the erase pulse, the
level on all array bits is modified via the erase mechanism.
Erasing the flash array is a block operation. During the erase pulse, all array
bitsareaffectedsimultaneously. (See Figure 2–1, Flash Memory Logic Lev-
els During Programming and Erasing, on page 2-4 for an illustration of
this mechanism.) Multiple erase pulses may be required to fully erase all bits
in the array, and the application of erase pulses is controlled by the erase algo-
rithm.
The erase operation uses the VER1 read mode to determine when erasure is
complete. After erasure is complete, the inverse-erase read mode is used to
determine if any bits are over-erased. For more information about these read
modes, see section 2.4, Read Modes, on page 2-12.
2-14
PRELIMINARY
PRELIMINARY
Recovering From Over-Erasure (Flash-Write Operation)
2.7 Recovering From Over-Erasure (Flash-Write Operation)
Generally, not all bits in the flash array have the same amount of charge re-
moved with each erase pulse. By the time all bits have reached the VER1 read
margin (and erase is complete), some of the bits in the array may be over-
erased. They are said to be in depletion mode. If even one single flash cell is
over-erased into depletion mode, it is always read as logic 1 and can corrupt
the reading of other bits. This condition must be detected and corrected, be-
cause it also inhibits reprogramming of the flash array.
The ’F20x/F24x flash array employs the flash-write operation to recover bits
that are erased into depletion mode. The flash-write operation is similar to the
erase operation in that it affects all bits in the array simultaneously. This en-
ables recovery of multiple bits from depletion mode, but requires the flash-
write operation to be followed by the clear and erase operations to restore the
erase margin on all bits.
A flash-write pulse is the time during the flash-write operation between the set-
ting and the clearing of the EXE bit (bit 0 of SEG_CTR). During the flash-write
pulse, all array bits are affected simultaneously. (See Figure 2–1, Flash
Memory Logic Levels During Programming and Erasing, on page 2-4 for an
illustration of this mechanism.) Multiple flash-write pulses may be required to
fully recover all bits in the array, and the application of flash-write pulses is con-
trolled by the flash-write algorithm.
The flash-write operation uses the inverse-erase read mode and inverse-
erase reference level to detect bits that are in depletion mode. For more infor-
mation about the inverse-erase read mode, see section 2.4, Read Modes, on
page 2-12.
Flash Operations and Control Registers
2-15
PRELIMINARY
PRELIMINARY
Reading From the Flash Array
2.8 Reading From the Flash Array
Once the array is programmed, it is read in the same manner as other memory
devices on the DSP memory interface. The flash module operates with zero
wait states. When you are reading the flash module, the flash segment control
register (SEG_CTR) bits should be 0 and the flash array must be in the array-
access mode.
2.9 Protecting the Array
After the flash memory array is programmed, it is desirable to protect the array
against corruption. The flash module of the ’F20x/F24x DSPs includes several
protection mechanisms to prevent unintentional modification of the array.
Flash programming is facilitated via the supplyvoltageconnectedtotheVCCP
pin. Ifthispinisgrounded, theprogramoperationwillnotmodifytheflasharray.
Note, thatgroundingtheVCCPpindoesnotpreventtheeraseoperation;other
protection mechanisms for the erase operation are discussed below.
The control registers provide the following mechanisms for protecting the flash
array from unintentional modification.
- Segment enable bits
- EXE, KEY0, and KEY1 bits
- WDATA register
An array segment is prevented from being programmed when the correspond-
ingsegmentenablebitintheSEG_CTRisclearedtozero. Additionally, allseg-
ment enable bits are cleared by reset, making unintentional programming less
likely. Even if the segment enable bits are set to one, the program, erase, and
flash-write operations are not initiated unless the appropriate values are set
in the EXE, KEY0, and KEY1 bits of the SEG_CTR.
At the start of an operation, the KEY1 and KEY0 bits must be written in the
same write access that sets EXE. When the program pulse, erase pulse, or
flash-write pulse is finished, EXE must be cleared in the same write that clears
KEY1 and KEY0. The data and address latches are locked whenever the EXE
bit is set, and all attempts to read from or write to the array are ignored (read
data is indeterminate). Once the EXE bit is set, all register bits are latched and
protected. You must clear EXE to modify the SEGx bits. This protects the array
from inadvertent change. Unprotected segments cannot be masked in the
sameregisterloadwiththedeactivationofEXE. Additionalsecurityisprovided
by a function of the WDATA register to prevent unintentional erasure. The
WDATA register must be loaded with FFFFh before the erase operation is initi-
ated. If the register is not loaded with this value, the array will not be modified.
2-16
PRELIMINARY
PRELIMINARY
Chapter 3
Algorithm Implementations
and Software Considerations
This chapter discusses the implementations of the algorithms for performing
the operations described in the previous chapter. It also discusses items you
must consider when incorporating the algorithms into your ’F20x/F24x DSP
application code.
Topic
Page
3.1 How the Algorithms Fit Into the Program-Erase-Reprogram
Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
3.2 Programming (or Clear) Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
3.3 Erase Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
3.4 Flash-Write Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14
3-1
PRELIMINARY
PRELIMINARY
How the Algorithms Fit Into the Program-Erase-Reprogram Flow
3.1 How the Algorithms Fit Into the Program-Erase-Reprogram Flow
The algorithms discussed in this chapter can be used to reprogram the
’F20x/F24x flash module multiple times. The clear algorithm, erase algorithm,
and flash-write algorithm are used to prepare the flash memory for program-
ming, while the programming algorithm is used to write a desired pattern of 0s
to the array (program the array).
The programming algorithm and the clear algorithm are both implementations
of the program operation. The difference between the two is the data that is
written: the programming algorithm programs the user data, while the clear al-
gorithm uses all 0s. All of the algorithms can be viewed as portions of a single
flow diagram, as shown in Figure 3–1.
Note that in the algorithm flowcharts, the variable X represents the number of
attempts at depletion recovery using the flash-write algorithm. It has been
shown that if flash-write is not successful in depletion recovery after ten at-
tempts, depletion recovery is not possible, and a device failure has occurred.
Therefore, if ten flash-write attempts at depletion recovery are not successful,
the algorithm returns a device failure error message.
3-2
PRELIMINARY
PRELIMINARY
How the Algorithms Fit Into the Program-Erase-Reprogram Flow
Figure 3–1. Algorithms in the Overall Flow
Initialization flow
Start
X = 1
Clear
algorithm
Clear the
array
Yes
No
Flash-write
algorithm
Recover using
flash-write
X = X+1
Reprogram?
Erase the
array
Erase
algorithm
Yes
Done/Stop
Yes
Bits in
depletion?
X < 10 ?
No
Program
the array
No
Fail
Programming
algorithm
Algorithm Implementations and Software Considerations
3-3
PRELIMINARY
PRELIMINARY
Programming (or Clear) Algorithm
3.2 Programming (or Clear) Algorithm
The programming algorithm sequentially writes any number of addresses with
a specified bit pattern.This algorithm is used to program application code or
data into the flash array. With a slight modification, the same algorithm per-
forms the clear portion of the initialization flow (i.e., programs all bits to zero).
In this role, the algorithm is called the clear algorithm. For the clear algorithm,
the values programmed are always 0000h, while the values for application
code can be any combination of 1s and 0s. Figure 3–2 highlights the program-
ming and clear algorithms’ place in the overall flow.
Figure 3–2. The Programming Algorithm in the Overall Flow
Initialization flow
Start
X = 1
Clear
algorithm
Clear the
array
Yes
No
Flash-write
algorithm
Recover using
flash-write
X = X+1
Reprogram?
Erase the
array
Erase
algorithm
Yes
Yes
Done/Stop
Bits in
depletion?
X < 10 ?
No
Program
the array
No
Fail
Programming
algorithm
3-4
PRELIMINARY
PRELIMINARY
Programming (or Clear) Algorithm
The main feature of the program/clear algorithm is the concept of program-
ming an entire row of bits in a group. The ’F20x/F24x flash array is organized
in rows of 32 words. That is, addresses 0000h through 001Fh are physically
located on the same row of the flash memory array. The array is designed so
that there is a dependence between the charge levels on adjacent (even–odd)
addresses during programming. Programming the bits of an odd address re-
duces the charge margin of the programmed bits (the 0s) in the preceding ad-
jacent (even) address within the row. Similarly, programming the bits of an
even address reduces the charge margin of the programmed bits in the next
adjacent (odd) address within the row. Because of this dependence, if each
address is programmed individually, the charge levels among programmed
bits is not uniform. The programming algorithm improves the uniformity of
charge levels on programmed bits by programming all of the words of a row
in a group. For example, the contents of address 0000h is compared with the
data to be programmed and one program pulse is applied if necessary. The
same procedure is performed on addresses 0001h through 001Fh. The proce-
dure repeats starting at address 0000h until no more program pulses are re-
quired for any address in the row. The number of iterations of this loop equals
the maximum number of program pulses required to program the bits in the
row.
The flow for the programming algorithm is shown in Figure 3–3, and the as-
sembly code is given in Appendix A.
An important consideration for programming the flash array is the CPU fre-
quency range for the application. Because of the actual implementation of the
flash memory circuitry, a 0 bit is most easily read at high frequency; pro-
grammed bits have less margin when read at lower frequency. So, if the ap-
plication requires a variable CPU clock rate, programming should be per-
formed at the lowest frequency in the range. (A similar condition exists for the
eraseoperation, whichrequiresexecutionoftheerasealgorithmatthehighest
frequency in the range. See section 3.3, page 3-10.)
Only the read portion of the program operation must be performed at the lower
frequency, because the read is used to determine margin. The read operation
can be extended by sequentially executing multiple reads on the same loca-
tion. Because the same address is selected the entire time and internal control
signals are maintained between reads, the final read is equivalent to a slow
read. For example, if the DSP core is executing the programming algorithm at
a CLKOUT rate of 20 MHz (50 ns), sequentially reading a location three times
is equivalent to reading it once at 6.67 MHz (150 ns). This is important, be-
cause it facilitates execution of the program and erase algorithms at the same
CLKOUT rate.
Algorithm Implementations and Software Considerations
3-5
PRELIMINARY
PRELIMINARY
Programming (or Clear) Algorithm
Figure 3–3. Programming or Clear Algorithm Flow
Start
New row
Save row start
address
Same row
Current address
= row start address;
row_done = true
Verify con-
tents
Steps 2–5 in Table 3–1
of current
address
Steps 7–25
in Table 3–1
Step 6 in Table 3–1
Apply program
pulse;
row_done = false
Program
pulse
required?
Yes
No
Increment
address
End
No
No
of
Pulsecount
ꢀ=max ?
†
row?
Yes
Yes
Row_done
No
=
true?
Yes
Current
address >
No
end address?
Yes
Continue
†
See the device data sheet for the timing
parameter values.
Device failure
3-6
PRELIMINARY
PRELIMINARY
Programming (or Clear) Algorithm
Another important consideration is the total amount of time required to do the
programming. The number of programming pulses required to completely pro-
gram a flash memory cell increases as ambient temperature increases and/or
supply voltage decreases. More programming pulses are required when the
minimum supply voltage is used than when the nominal or maximum supply
voltage is used. The number of program pulses required also increases
throughout the life of the device, as more program-erase cycles are carried
out. The device data sheet specifies the maximum number of program pulses
under all operating conditions; use this number when you calculate the maxi-
mum amount of time required for programming.
The algorithm incorporates the steps for applying a program pulse (outlined
in Table 3–1) along with some other techniques to ensure margin. In general,
not all flash bits require the same number of program pulses to reach the pro-
grammed margin level. For this reason, the programming algorithm applies a
series of short program pulses until the memory location is programmed. How-
ever, to understand how the series of program pulses works, you must first un-
derstand how the algorithm applies a single program pulse. Table 3–1 outlines
the steps involved in verifying programmed bits and applying a single pulse to
each of the upper and lower bytes of a single location. This process corre-
sponds to the steps enclosed in the dashed box in the flowchart in Figure 3–3.
Table 3–1. Steps for Verifying Programmed Bits and Applying One Program or Clear
Pulse
Step Action
Description
1
Power up the V
pin.
Set the V
pin to V
If the V
pin for the flash module to be pro-
CCP
CCP
DD.
CCP
grammed is not set to V , then the array will not be programmed.
DD
2
3
Activate VER0 mode.
Set the VER0 bit in SEG_CTR (load SEG_CTR with 0010h).
†
Delay for VER0 reference The CPU executes a delay loop for the t
voltage stabilization.
time period.
d(VERIFY-SETUP )
4
Readflasharraycontentsfor The CPU reads the addressed location. The flash module must be in
verification.
array-access mode (see section 2.2, Accessing the Flash Module, page
2-5).
5
6
Deactivate VER0 mode.
Clear the VER0 bit in SEG_CTR (load SEG_CTR with 0000h).
Compare contents of flash If the verification passes (i.e., if the data read in step 4 is equal to the de-
location (16 bits) with de- sired data value), then no further program pulses are required. The flash
sired data.
word has been programmed with the desired data value. The program
or clear function is completed and this algorithm is exited.
If the verification fails (i.e., if the data read in step 4 is not equal to the
desired data value), then proceed to step 7.
Algorithm Implementations and Software Considerations
3-7
PRELIMINARY
PRELIMINARY
Programming (or Clear) Algorithm
Table 3–1. Steps for Verifying Programmed Bits and Applying One Program or Clear
Pulse (Continued)
Step Action
Description
7
Mask the data to program Mask any bits in the lower byte that do not require programming (are al-
lower byte.
ready read as zero), and mask off upper byte. Recall that the algorithm
shouldmaskonebytewhileprogrammingtheotherbecauseamaximum
of eight bits can be programmed simultaneously.
8
Load WADRS and WDATA If the flash module is in array access mode, write the data to be pro-
registers.
grammed to its address. If the flash module is in register access mode,
load the individual registers directly.
10
Activate the WRITE/ERASE Set the WRITE/ERASE field in SEG_CTR to 10 and set the correspond-
field and enable segments. ing segment enable bits (SEG0–SEG7) for the segments where the pro-
grammed word resides.
†
See the device data sheet for the timing parameter values.
†
11
Wait for internally generated The CPU executes a delay loop for the t
time period.
d(PGM–MODE )
supply voltage stabilization
time.
12
Initiate the program pulse.
Load the EXE, KEY1, and KEY0 bits with 1, 1, and 0, respectively. All
three bits must be loaded in the same write cycle.
The segment enable bits and the WRITE/ERASE field must also be
maintained.
†
13
14
15
Delay for program pulse The CPU executes a delay loop for the t
time.
time period.
d(PGM )
Terminate the program Clear the WRITE/ERASE field and EXE bit in SEG_CTR (e.g., load
pulse. SEG_CTR with 0000h).
†
Delay for array stabilization The CPU executes a delay loop for the t
time.
time period.
d(BUSY )
16–25 Program upper byte if nec- Repeat steps 7–15 for the upper byte. Mask the lower byte to 1s when
essary. programming the upper byte.
†
See the device data sheet for the timing parameter values.
3-8
PRELIMINARY
PRELIMINARY
Programming (or Clear) Algorithm
Before each program pulse is applied, a read of the byte is performed to deter-
mine which bits have reached the programmed level. Any bits that have
reached the programmed level are masked (set to 1 in the WDATA register).
This method of programming provides uniform charge levels among pro-
grammed bits, whereas using a single, long program pulse could result in
some bits having much more charge than others. The uniformity of charge lev-
els among bits has the primary effect of reducing programming time and the
secondary effect of reducing the time for a subsequent erase operation. To as-
sure that the bits are programmed with enough margin, the reads associated
with programming use the VER0 read mode.
Algorithm Implementations and Software Considerations
3-9
PRELIMINARY
PRELIMINARY
Erase Algorithm
3.3 Erase Algorithm
The erase algorithm follows the clear algorithm in executing the entire initial-
ization flow. Figure 3–4 highlights the erase algorithm’s place in the overall
flow.
Figure 3–4. Erase Algorithm in the Overall Flow
Initialization flow
Start
X = 1
Clear
algorithm
Clear the
array
Yes
No
Flash-write
algorithm
Recover using
flash-write
X = X+1
Reprogram?
Erase the
array
Erase
algorithm
Yes
Yes
Done/Stop
Bits in
depletion?
X < 10 ?
No
Program
the array
No
Fail
Programming
algorithm
The erase algorithm consists of multiple iterations of a loop with one erase
pulse applied in each iteration. Table 3–2 outlines the steps involved in apply-
ing a single erase pulse.
3-10
PRELIMINARY
PRELIMINARY
Erase Algorithm
Table 3–2. Steps for Applying One Erase Pulse
Step
Action
Description
Set V pin to V
1
Power up the V
pin.
If the V pin for the flash module to be erased
CCP
CCP
CCP
DD.
is not set to V , then the array will not be erased properly.
DD
2
3
Load WDATA register with This load overrides the erase protection mechanism.
FFFFh.
Activate the erase mode and Set the WRITE/ERASE field to 01 and set SEG0–SEG7 bits in the
enable segments.
SEG_CTR register. The flash module must be in register-access
mode (see section 2.2).
†
4
5
Wait for internally generated The CPU executes a delay loop for the t
supply voltage stabilization
time.
timeperiod.
d(ERASE-MODE )
Initiate the erase pulse.
Load the EXE, KEY1, and KEY0 bits with 1, 1, and 0, respectively. All
three bits must be loaded in the same write cycle.
The segment enable bits and the WRITE/ERASE field must also be
maintained.
†
6
7
Delay for erase pulse time. The CPU executes a delay loop for the t
time period.
d(ERASE )
Terminate the erase pulse.
Clear the EXE bit and WRITE/ERASE field in the SEG_CTR register
(load SEG_CTR with 0000h to clear all bits).
†
8
Delay for mode deselect CPU executes a delay loop for the t
time.
time period.
d(BUSY )
†
See the device data sheet for the timing parameter values.
At the beginning of each iteration, a read operation is performed on all the bits
in the array to determine if an erase pulse is required. Erasure is complete
when all array locations are read as FFFFh. To assure that the flash array is
erased with enough margin, the reads associated with the erase use the VER1
read mode. Additional margin can be gained during the erase operation if the
reads are performed using address complementing. When the array is read
with address complementing, the following sequence is used for each address
read:
1) All of the bits of the address to be read are complemented.
2) The contents of the resulting address are read.
3) The value read at the complemented address is discarded.
Algorithm Implementations and Software Considerations
3-11
PRELIMINARY
PRELIMINARY
Erase Algorithm
4) The actual address is restored.
5) The contents of the restored address are read.
Theadvantageofthisapproachisthatitforcestheworst-caseswitchingcondi-
tion on the flash addressing logic during the reads, thus improving the margin
of the erase. Address complementing on the ’F20x/F24x can be accomplished
easily by using the XOR instruction to complement the bits of the address.
An important consideration for erasing the flash array is the CPU frequency
range for the application. Because of the actual implementation of the flash
memory circuitry, a logic 1 is most easily read at low frequency; erased bits
have less margin when read at higher frequency. Accordingly, if the application
requires a variable CPU clock rate, the erase should be performed at the high-
est frequency in the range. (A similar condition exists for the programming op-
eration, which requires execution of the programming algorithm at the lowest
frequency in the range. See section 3.2, page 3-4.)
Another important consideration is the total amount of time required to erase
the array. The number of erase pulses required to completely erase a flash
memory cell increases as ambient temperature increases or decreases rela-
tive to the nominal temperature and as supply voltage decreases. More erase
pulses are required when the ambient temperature is toward the extremes of
the operating range. Also, more erase pulses are required when the minimum
supply voltage is used than when the nominal or maximum supply voltage is
used. The number of erase pulses required also increases throughout the life
of the device, as more program-erase cycles are carried out. The device data
sheet specifies the maximum number of erase pulses under all operating con-
ditions; use this number when you calculate the maximum amount of time re-
quired for the erase algorithm.
The complete erase algorithm including depletion check is shown in the flow-
chart in Figure 3–5.
3-12
PRELIMINARY
PRELIMINARY
Erase Algorithm
Figure 3–5. Erase Algorithm Flow
Start
(all words=0000h)
Set VER1
bit in SEG_CTR
Wait for
d(BUSY-VERIFY)
t
Verify
erase
Read all locations
using address
complementing
Clear all bits
in SEG_CTR
All
words =
FFFFh
?
Yes
Set VER0 and
VER1 bits in
SEG_CTR
No
Apply one
erase pulse
to flash array
(see Table 3–2)
Wait for
d(BUSY-INVERSE)
t
Depletion
check
Read first
32 words
Erase
No
pulse count
†
≥ Max ?
All
32 words
= 0000h?
No
Yes
Yes
†
See the device data sheet for
the timing parameter values.
Depletion
recovery
Device failure
Program array
Algorithm Implementations and Software Considerations
3-13
PRELIMINARY
PRELIMINARY
Flash-Write Algorithm
3.4 Flash-Write Algorithm
The flash-write operation recovers bits in depletion mode, which can be
caused by over-erasure. The flash-write algorithm’s place in the overall flow
is highlighted in Figure 3–6.
Figure 3–6. Flash-Write Algorithm in the Overall Flow
Initialization flow
Start
X = 1
Clear
algorithm
Clear the
array
Yes
No
Flash-write
algorithm
Recover using
flash-write
X = X+1
Reprogram?
Erase the
array
Erase
algorithm
Yes
Yes
Done/Stop
Bits in
depletion?
X < 10 ?
No
Program
the array
No
Fail
Programming
algorithm
A flash-write pulse is the time during the flash-write operation between the set-
ting and the clearing of the EXE bit (bit 0 of SEG_CTR). Charge is added to
the bits of the flash memory array via the flash-write mechanism. The flash-
write algorithm may require multiple flash-write pulses. The steps required to
apply one flash-write pulse are outlined in Table 3–3.
3-14
PRELIMINARY
PRELIMINARY
Flash-Write Algorithm
Table 3–3. Steps for Applying One Flash-Write Pulse
Steps
Action
Description
1
Power up the V
pin.
Set the V
pin to V . If the V pin for the flash module to be re-
CCP
CCP
CCP
DD
covered is not set to V , then the flash-write operation will not be ef-
DD
fective.
2
3
4
Activate the flash-write Set the WRITE/ERASE field to 10 and set SEG0–SEG7 in the
mode and enable all seg- SEG_CTR register. The flash module must be in register access
ments.
mode (see section 2.2).
†
Wait for the internally gener- The CPU executes a delay loop for the t
time period.
d(FLW-MODE )
ated supply voltage stabi-
lization time.
Initiate the flash-write pulse. Load the EXE, KEY1, and KEY0 bits with 1, 1, and 0, respectively. All
three bits must be loaded in the same write cycle.
ThesegmentenablebitsandWRITE/ERASEfieldmustalsobemain-
tained.
†
5
6
7
Delay for the flash-write The CPU executes a delay loop for the t
pulse time.
time period.
d(FLW )
Terminate the flash-write Clear all bits in the SEG_CTR register (load SEG_CTR with 0000h).
pulse.
†
Delay for mode deselect CPU executes a delay loop for the t
time.
time period.
d(BUSY )
†
See the device data sheet for the timing parameter values.
Theflash-writealgorithmconsistsofmultipleiterationsofaloopwithoneflash-
writepulseappliedineachiteration. Atthebeginningofeachiteration, adeple-
tion test is performed to determine if a flash-write pulse is required. Figure 3–7
shows the flow of the flash-write algorithm.
The flash-write operation uses the inverse-erase read mode to detect bits that
are in depletion mode. For more information about the inverse-erase read
mode, see section 2.4, Read Modes, on page 2-12.
Algorithm Implementations and Software Considerations
3-15
PRELIMINARY
PRELIMINARY
Flash-Write Algorithm
Figure 3–7. Flash-Write Algorithm Flow
Start
Set VER0 and VER1
bits in SEG_CTR
Wait for
d(RD-VERIFY)
t
Depletion
check
Read first 32 words
All 32
words =
0000h?
Yes
No
Apply one flash-write
pulse to flash array
(see Table 3–3)
Flash-write
pulse count
≥ Max ?
No
†
Yes
†
See the device data sheet for the timing
parameter values.
Device failure
Go to clear
3-16
PRELIMINARY
PRELIMINARY
Flash-Write Algorithm
The CPU frequency range for the application is an important consideration for
the depletion test, as well as for the program and erase operations. Because
of the actual implementation of the flash memory circuitry, a bit in depletion
mode is most easily detected at low frequency. Accordingly, if the application
requires a variable CPU clock rate, the depletion test should be performed at
the lowest frequency in the range. Only the read portion of the depletion test
must be performed at the lower frequency, because it is the read that is used
to detect depletion. The effective duration of the read operation can be ex-
tended by sequentially executing multiple reads on the same location. Be-
cause the same address is selected the entire time and internal control signals
are maintained between reads, the final read is equivalent to a slow read. For
example, if the DSP core is executing the programming algorithm at a
CLKOUT rate of 20 MHz (50 ns), sequentially reading a location three times
is equivalent to reading it once at 6.67 MHz (150 ns). The erase and flash-write
algorithm implementations given in Appendix A use three reads to check for
depletion.
Algorithm Implementations and Software Considerations
3-17
PRELIMINARY
PRELIMINARY
3-18
PRELIMINARY
PRELIMINARY
Appendix A
Assembly Source Listings and
Program Examples
The flash array is erased and programmed by code running on the DSP core.
This code can originate from off-chip memory or can be loaded into on-chip
RAM. The available flash programming tools for the ’F20x/F24x allow you to
program the on-chip flash module without having knowledge or visibility of the
algorithms. One scheme uses the scan emulation feature of the ’F20x/F24x to
load the algorithms onto the DSP and control execution, and another scheme
relies on boot loader code preprogrammed into the flash memory at the facto-
ry. You can find more information about these stand-alone flash programming
tools on the Texas Instruments web page at http://www.ti.com. This appendix
explains how to use the algorithm source files to program the flash module.
You need this information to create new flash programming tools or to add
such features as remote reprogrammability to a design.
Topic
Page
A.1 Assembly Source for Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2
A.2 C-Callable Interface to Flash Algorithms . . . . . . . . . . . . . . . . . . . . . . . A-27
A.3 Sample Assembly Code to Erase and Reprogram
the TMS320F206 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-32
A.4 Sample C Code to Erase and Reprogram the TMS320F206 . . . . . . A-37
A.5 Sample Assembly Code to Erase and Reprogram
the TMS320F240 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-40
A.6 Using the Algorithms with C Code to Erase and Reprogram the
TMS320F240 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-47
A-1
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
A.1 Assembly Source for Algorithms
The algorithm source files implement the flows given in Chapter 3. Each algo-
rithm is written as an assembly language subroutine, beginning with a label at
an entry point and ending with a return instruction. The algorithms share a set
of 16 relocatable variables for which pointers are defined in the header file,
SVAR20.H.
ThevariablesaredefinedatthebeginningofB1RAM, andanuninitializedsec-
tion should be declared at link time to reserve this space. Also, the data page
pointer (DP) should be initialized to point to this space before a call is made to
any of the algorithms.
In addition to these variables, each algorithm references parameters that
should be declared globally in the calling code. These parameters are listed in
the introduction to each of the algorithm source files below.
The source files given are:
- SVAR20.H: header file that defines variables and constants
- SCLR20.ASM: clear algorithm
- SERA20.ASM: erase algorithm
- SFLW20.ASM: flash-write algorithm
- SPGM20.ASM: programming algorithm
- SUTILS20.ASM: subroutines common to all four algorithms
The same algorithm files can be used for the TMS320F206 and the
TMS320F240/1/3 devices. A conditional assembly variable is provided in the
header file, SVAR20.H, for assembling the algorithms for the correct device.
For more details on this conditional assembly variable, see A.1.1.
A.1.1 Header File for Constants and Variables, SVAR20.H
This header file is included in each of the algorithm files using the .include di-
rective. All of the constants used for flash programming are defined in this file.
Also, the conditional assembly constant, F24x, is defined here to allow reuse
of the algorithms for multiple device types. This constant should be modified
to select the correct device when the algorithms are assembled. The
SVAR20.Hheaderfilecanalsobeincludedinthecallingcode, toallowvisibility
to the variable names.
A-2
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
**************************************************************
** Variable declaration file
*
* TMS320F2XX Flash Utilities.
**
**
**
**
**
**
**
**
**
*
*
*
Revision: 2.0, 9/10/97
Revision: 2.1, 1/31/98
* Filename: svar20.asm
*
*Note:
*DLOOP is a delay loop variable used in flash algorithms. **
*This is a function of CLKOUT1. If the F206 device runs at **
*any CLKOUT1 speed other than 20 MHz, DLOOP value should be **
*redefined per the equation explained below. Use of
*current DLOOP for flash programming at speeds other than **
*20 MHz is not recommended. **
**
**************************************************************
.mmregs
BASE .set 0300h
;Base address for variables
;can be changed to relocate
;variable space in RAM.
BASE_0
BASE_1
BASE_2
BASE_3
BASE_4
BASE_5
BASE_6
SPAD1
.set
.set
.set
.set
.set
.set
.set
.set
.set
BASE+0
BASE+1
BASE+2
BASE+3
BASE+4
BASE+5
BASE+6
BASE+7
BASE+8
;Scratch pad registers.
;
;
;
;
;
;
;
;
SPAD2
FL_ADRS .set
FL_DATA .set
BASE+10 ;Flash load address.
BASE+11 ;Flash load data.
BASE+15 ;Error flag register.
ERROR
.set
*Variables for ERASE and CLEAR
RPG_CNT .set BASE+12 ;Program pulse count.
FL_ST
FL_END
*
.set
.set
BASE+13 ;Flash start addr/Seg Cntrl Reg.
BASE+14 ;Flash end address.
Assembly Source Listings and Program Examples
A-3
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
*CONSTANTS
*
*********************************************************
*Conditional assembly variable for F24X vs F206.
*If F24X = 1, then assemble for F24X; otherwise,
*assemble for F206.
*
*
*
*********************************************************
F24X
;F24X
.set
.set
0
1
;Assemble for F206
;Assemble for F24X
***********************************************
* Delay variables for CLEAR,ERASE and PROGRAM*
***********************************************
D5
.set
.set
.set
.set
.set
0
1
19
999
1399
;5 us delay
;10 us delay
;100 us delay
;5 ms delay
;7 ms delay
D10
D100
D5K
D7K
*************************************************************
*DLOOP constant proportional to CLKOUT1
*Calculate DLOOP in decimal using the following equation: *
*
* DLOOP=FLOOR{(5us/tCLKOUT1)–6};
*Examples
*a.@ 15 MHz, DLOOP= 69;
*b.@ 9.8304 MHz, DLOOP= 43;
*c.@ 16.384 MHz, DLOOP= 75;
*
*
*
*
*
**************************************************************
;DLOOP
;DLOOP
;DLOOP
;DLOOP
;DLOOP
.set 14
.set 19
.set 44
.set 75
.set 94
;5–us delay loop @ 4.032 MIPs
;5–us delay loop @ 5 MIPs
;5–us delay loop @ 10 MIPs
;5–us delay loop @ 16.384 MIPs
;5–us delay loop @ 20 MIPs
*************************
* On–chip I/O registers *
*************************
F_ACCESS0 .set 0FFE0h ;F206 ACCESS CNTRL REGISTER 0.
F_ACCESS1 .set 0FFE1h ;F206 ACCESS CNTRL REGISTER 1.
PMST
.set 0FFE4h ;Defines SARAM in PM/DM and MP/MC bit.
F24X_ACCS .set 0FF0Fh ;F240 ACCESS CNTRL REGISTER.
;–––––––––––––––––––––––––––––––––––––––––––
;Register Declarations for F240 Peripherals |
;–––––––––––––––––––––––––––––––––––––––––––
;Watch–Dog(WD)/Real Time Int(RTI)/Phase–Locked Loop (PLL)
;Registers
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RTI_CNTR .set 07021h
WD_CNTR .set 07023h
;RTI Counter reg
;WD Counter reg
;WD Key reg
WD_KEY
.set 07025h
RTI_CNTL .set 07027h
WD_CNTL .set 07029h
PLL_CNTL1 .set 0702Bh
PLL_CNTL2 .set 0702Dh
;RTI Control reg
;WD Control reg
;PLL control reg 1
;PLL control reg 2
A-4
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
A.1.2 Clear Algorithm, SCLR20.ASM
This code is an implementation of the clear (programming) algorithm de-
scribed in section 3.2 on page 3-4. Recall that the clear algorithm is identical to
the programming algorithm with the data forced to 0000h for all flash address-
es.
Memory section: fl_clr
Entry point: GCLR
Parameters to be declared and initialized by the calling code are:
- PROTECT defines the values of bits 8–15 of SEG_CTR during the clear
algorithm.
- SEG_ST defines the start address of the flash array to be cleared.
- SEG_END defines the end address of the flash array to be cleared.
Return value: ERROR (@BASE+15); 0 = Pass, 1 = Fail
**************************************************************
** CLEAR Subroutine
*
* TMS320F2XX Flash Utilities.
**
**
**
**
**
**
**
**
*
*
*
Revision: 2.0, 9/10/97
Revision: 2.1, 1/31/98
* Filename: sclr20.asm
*
* Called by: c2xx_bcx.asm or flash application programs. **
**
* !!CAUTION – INITIALIZE DP BEFORE CALLING THIS ROUTINE!! **
*
*
**
**
**
**
**
**
**
*
* Function: Clears one or more contiguous segments of
*
*
*
*
*
*
array 0/1 as specified by the following
variables.
SEG_ST
Segment start address
SEG_END Segment end address
PROTECT Sector protect enable
* The algorithm used is ”row-horizontal”, which means that *
* an entire flash row (32 words) is programmed in parallel.*
* This method provides better uniformity of programming
* levels between adjacent bits than if each address were *
* programmed independently. The algorithm also uses a
*
*
* 3-read check for VER0 margin (i.e.,the flash location is *
* read three times and the first two values are discarded.)*
* This provides low–frequency read–back margin on
*
Assembly Source Listings and Program Examples
A-5
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
* programmed bits. For example, if the flash is programmed *
* using a CLKOUT period of 50 ns, the flash can be read back
* reliably over the CLKOUT period range of 50 ns to 150 ns *
* (6.67 MHz–20 MHz). The programming pulse-duration is
*
* 100 us, and a maximum of 150 pulses is applied per row. *
*
*
* The following resources are used for temporary storage: *
*
*
*
*
*
*
*
*
*
*
*
*
AR0
AR1
AR2
AR6
Used for comparisons
*
*
*
*
*
*
*
*
*
*
*
**
Used for pgm pulse count
Used for row banz loop.
Parameter passed to Delay
FL_ADRS Used for flash address
FL_DATA Used for flash data.
FL_ST
BASE_0
BASE_1
SPAD1
SPAD2
Used for flash start address
Used for row–done flag
Used for row start address
Flash commands
Flash commands
**************************************************************
.include ”svar20.h”
*
MAX_PGM .set
VER0 .set
WR_CMND .set
150
010h ;VER0 command.
;Write command.
045h ;Write EXEBIN command.
;Only allow 150 pulses per row.
4
WR_EXE
STOP
.set
.set
.def
.ref
.ref
0
;Reset command.
GCLR
PROTECT,SEG_ST,SEG_END
DELAY,REGS,ARRAY
.sect
*************************************************************
* GCLR: This routine performs a clear operation on the
* flash array defined by the FL_ST variable. The segments *
”fl_clr”
*
* to be cleared are defined by the SEG_ST, SEG_END, and
* PROTECT variables.
* The following resources are used for temp storage:
*
*
*
*
*
*
*
*
*
*
*
* AR0
* AR1
* AR2
Used for comparisons
Used for pgm pulse count
Used for row banz loop
* FL_ADRS Used for flash address
* FL_DATA Used for flash data
* BASE_0
* BASE_1
* BASE_2
Used for row–done flag
Used for row start address
Used for byte mask.
*************************************************************
GCLR:
SETC
CLRC
SPLK
LACL
SACL
AND
INTM
SXM
#0,ERROR
SEG_ST
FL_ADRS
#04000h
;Disable all ints.
;Disable sign extension.
;Reset error flag
;Get segment start address.
;Save as current address.
;Get array start address.
A-6
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
SACL
LACL
FL_ST
FL_ADRS
;Save array start address.
;Get segment start address.
NEWROW
;********Begin a new row.*
SACL
LAR
BASE_1
AR1,#0
;Save row start address.
;Init pulse count to zero.
SAMEROW
SPLK
;********Same row, next pulse.*
#1,BASE_0
BASE_1
;Set row done flag = 1(True).
LACL
SACL
LAR
;Get row start address.
;Save as current address.
;Init row index.
FL_ADRS
AR2,#31
********Repeat the following code 32 times until end of row.*
LOBYTE ;********First, do low byte.*
SPLK
CALL
SPLK
CALL
#0FFh,BASE_2
PRG_BYTE
#0FF00h,BASE_2 ;Get hi–byte mask.
PRG_BYTE ;Check/Program hi–byte.
;********Next word in row.
;Get lo–byte mask.
;Check/Program lo–byte
NEXTWORD
LACL
FL_ADRS
#1
;Load address for next word.
;Increment address.
ADD
SACL
MAR
BANZ
FL_ADRS
*,AR2
LOBYTE
;Save as current address.
;Point to row index.
;Do next word,and dec AR2.
********Reached end of row. Check if row done.*
BIT
BASE_0,15
;Get row_done flag.
BCND ROW_DONE,TC
;If 1, then row is done.
;Else, row is not done, so
;inc row pulse count.
;Check if passed allowable max.
;If AR1>MAX_PGM, then
;fail, don’t continue.
;else, go to beginning
;of same row.
MAR
MAR
LAR
*,AR1
*+
AR0,#MAX_PGM
CMPR 2
BCND EXIT,TC
B
SAMEROW
********If row done, then check if Array done.*
ROW_DONE ;Check if end of array.
SUB
SEG_END
;Subtract segment end address.
;If >0, then done.
BCND DONE,GEQ
********Else, go to next row.*
LACL FL_ADRS
;Get current address.
;Start new row.
B
NEWROW
********If here, then done.
DONE CALL ARRAY
RET
;Access flash in array mode.
********If here, then unit failed to program.*
EXIT SPLK #1,ERROR
;Update error flag.
;Get outa here.
B
DONE
.page
*************************************************************
* THIS SECTION PROGRAMS THE VALUE STORED IN FL_DATA INTO *
* THE FLASH ADDRESS DEFINED BY FL_ADRS.
*
*
*
* The following resources are used for temporary storage: *
*
*
AR6
Parameter passed to Delay.
*
*
SPAD1 Flash program and STOP commands.
Assembly Source Listings and Program Examples
A-7
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
*
SPAD2 Flash program + EXE command.
*
*************************************************************
EXE_PGM ;*
CALL ARRAY
*LOAD WADRS AND WDATA
;ACCESS ARRAY
*
**
LACL
TBLW
CALL REGS
FL_ADRS
FL_DATA
;ACCESS FLASH REGS
;ACC => PROGRAM ADRS *
;LOAD WADRS AND WDATA *
*
*SET UP WRITE COMMAND WORDS
**
;GET SEGMENT PROTECT MASK **
LACL
OR
SACL
OR
PROTECT
#WR_CMND
SPAD1
#WR_EXE
SPAD2
;OR IN WRITE COMMAND
;SPAD1 = WRITE COMMAND
;OR IN EXEBIN COMMAND
**
**
**
SACL
;SPAD2 = WRITE EXE COMMAND **
*
*
LACL
FL_ST
;ACC => 0 (FLASH0)
*
* ACTIVATE WRITE BIT
**
**
**
**
**
**
**
**
*
TBLW
LAR
SPAD1
AR6,#D10
;EXECUTE COMMAND
;SET DELAY
CALL DELAY,*,AR6 ;WAIT
* SET EXEBIN BIT
TBLW
LAR
SPAD2
AR6,#D100
;EXECUTE COMMAND
;SET DELAY
CALL DELAY,*,AR6 ;WAIT
* STOP WRITE OPERATION
SPLK
TBLW
LAR
#0,SPAD1
SPAD1
AR6,#D10
;SHUTDOWN WRITE OPERATION *
;EXECUTE COMMAND
;SET DELAY
*
*
*
*
CALL DELAY,*,AR6 ;WAIT
*
RET
;RETURN TO CALLING SEQUENCE*
************************************************************
.page
************************************************************
* ACTIVATE VER0 ON FLASH READS
*
* LOADS FLASH WORD AT ADDR FL_ADRS TO FL_DATA.
* Uses SPAD1 for temporary storage of flash commands.
*
*
************************************************************
SET_RD_VER0
CALL
LACL
SPLK
TBLW
LAR
;*
;ACCESS FLASH REGISTERS*
REGS
FL_ST
;ACC => FLASH
;ACTIVATE VER0
;EXECUTE COMMAND*
;SET DELAY
*
*
#VER0,SPAD1
SPAD1
AR6,#D10
DELAY,*,AR6
ARRAY
FL_ADRS
FL_DATA
FL_DATA
FL_DATA
REGS
*
*
*
*
*
*
*
*
*
*
CALL
CALL
LACL
TBLR
TBLR
TBLR
CALL
LACL
SPLK
;WAIT
;ACCESS FLASH ARRAY
;POINT TO ADRS
;GET FLASH WORD 1x read
;2x read
;3x read
;ACCESS FLASH REGISTERS
;ACC => FLASH
FL_ST
#STOP,SPAD1
;DEACTIVATE VER0
A-8
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
TBLW
LAR
CALL
CALL
RET
SPAD1
;EXECUTE COMMAND
;SET DELAY
;WAIT
;ACCESS FLASH ARRAY
*
*
*
*
AR6,#D10
DELAY,*,AR6
ARRAY
;RETURN TO CALLING SEQUENCE*
*************************************************************
*************************************************
* PRG_BYTE: Programs hi or lo byte depending on *
*
byte mask (BASE_2).
*
*************************************************
PRG_BYTE:
CALL
LACL
AND
BCND
XOR
SACL
CALL
SPLK
SET_RD_VER0 ;Read word at VER0 level.
BASE_2
;Get lo/hi byte mask.
;Xor with read–back value.
;If zero, then done.
;else, mask off good bits.
;New data.
FL_DATA
PB_DONE,EQ
#0FFFFh
FL_DATA
EXE_PGM
#0,BASE_0
;PGM Pulse.
;Set row done flag = 0(False).
PB_DONE RET
************************************************
.end
Assembly Source Listings and Program Examples
A-9
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
A.1.3 Erase Algorithm, SERA20.ASM
This code is an implementation of the erase algorithm described in section 3.3
on page 3-10.
Memory section: fl_ers
Entry point: GERS
Parameters to be declared and initialized by the calling code are:
- PROTECT defines the values of bits 8–15 of SEG_CTR during the erase
algorithm.
- SEG_ST defines the start address of the flash array to be erased.
- SEG_END defines the end address of the flash array to be erased.
Return value: ERROR (@BASE+15); 0 = Pass, 1 = Fail
**************************************************************
* ERASE subroutine
*
* TMS320F2XX Flash Utilities.
**
**
**
**
**
**
**
**
*
*
*
Revision: 2.0, 9/10/97
Revision: 2.1, 1/31/98
* Filename: sera20.asm
*
* Called by: c2xx_bex.asm or flash application programs. **
**
* !!CAUTION – INITIALIZE DP BEFORE CALLING THIS ROUTINE!! **
*
*
**
**
**
**
**
**
**
**
**
* Function: Erases one or more contiguous segments of
*
*
*
*
*
*
flash array 0/1 as specified by the
following variables.
SEG_ST
Segment start address
SEG_END Segment end address
PROTECT Sector protect enable
* The algorithm used is XOR–VER1, which means that in
* addition to the VER1 read mode, an XOR readback is used **
* to gain more margin. During the read portion of the **
* erase, two reads are performed for each address; for the **
* first read, all address bits are complemented using a
* logical XOR with the array end address. The data read
**
**
* during the first read is discarded, and the second read **
* is performed on the actual address. This scheme
* simulates the worst–case branching condition for code
* executing from the flash array.
**
**
**
A-10
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
* The erase pulse duration is 7ms, and a maximum of
* 1000 pulses is applied to the array.
*
**
**
**
* The following resources are used for temporary storage: **
*
*
*
*
*
*
*
*
*
*
*
AR0
AR1
AR2
AR6
BASE_0
BASE_1
BASE_2
BASE_3
BASE_4
BASE_5
BASE_6
Used for comparisons
**
**
**
**
**
**
**
**
**
**
**
Used for erase pulse count
Used for main banz loop
Parameter passed to DELAY
Parameter passed to Set_mode
Used for flash address.
Used for flash data
Used for flash checksum
Used for segment size
Flash Erase command
Flash Erase+EXE command
*************************************************************
.include ”svar20.h” ;defines variables for flash0
;or for flash1 array
*
MAX_ER
VER1
.set 1000
.set 8
;Allow only 1000 erase pulses.
;VER1 command.
ER_CMND .set 2
;ERASE COMMAND WORD
ER_EXE
INV_ER
FL_WR
FLWR_EX .set 047h
STOP
.set 043h
.set 018h
.set 6
;ERASE EXEBIN COMMAND WORD
;INVERSE ERASE COMMAND WORD
;FLASH WRITE COMMAND WORD
;FLASH WRITE EXEBIN COMMAND WORD
;RESET REGISTER COMMAND WORD
.set 0
.def GERS
.ref PROTECT,SEG_ST,SEG_END
.ref DELAY,REGS,ARRAY
.sect ”fl_ers”
*************************************************************
* GERS: This routine performs an erase to
* xorver1 level. The Seg to erase is defined by
* the vars SEG_ST and SEG_END. The following
* resources are used for temporary storage:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
AR0
AR1
AR2
BASE_0
BASE_1
BASE_2
BASE_3
BASE_4
Used for comparisons
Used for erase pulse count
Used for main banz loop
Parameter passed to Set_mode
Used for flash address.
Used for flash data
Used for flash checksum
Used for segment size
*************************************************************
GERS:
*************************************************************
* Code initialization section
* Initialize test loop counters:
*
*
*
*
AR1 is the number of ERASE pulses.
*************************************************************
SETC INTM
SETC SXM
;Disable all maskable ints.
;Enable sign extension.
Assembly Source Listings and Program Examples
A-11
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
CLRC OVM
;Disable overflow mode.
LACL SEG_ST
;Get segment start address.
;Get array start address.
;Save array start address.
;Get array end address.
;Save array end address.
;Reset error flag
AND
#04000h
SACL FL_ST
OR
#03FFFh
SACL FL_END
SPLK #0,ERROR
LAR
AR1,#0
;Set erase count to 0.
SPLK #STOP, BASE_0;Stop command.
CALL SET_MODE ;Disable any flash cmds.
XOR_ERASE
** Compute checksum for flash, using address complementing.**
LACC SEG_END
SUB
SAC
LAR
ADD
SEG_ST
BASE_4
AR2,BASE_4
#1
;Segment length–1.
;load n–1 to loop n times.
SACL BASE_4
SPLK #VER1,BASE_0
CALL SET_MODE
;Segment length.
;VER1 command.
;Set VER1 mode.
MAR
*,AR2
BLDD #SEG_ST,BASE_1 ;Segment start address.
SPLK #0,BASE_3
RD1_LOOP
LACC BASE_1
XOR FL_END
;Clear checksum.
;For I = SEG_ST to SEG_END.
;ACC => CURRENT ADDR.
;XOR addr with flash end addr.
;Dummy Read.
;Get actual addr again.
;True Read.
TBLR BASE_2
LACC BASE_1
TBLR BASE_2
ADD
#1
;Increment flash addr.
;Store for next read.
;Get old check sum.
;ACC=>ACC+FL_DATA.
SACL BASE_1
LACC BASE_3
ADD
BASE_2
SACL BASE_3
;Save new check sum.
BANZ RD1_LOOP,*–
ADD
BASE_4
;Should make ACC = 0 for
;erased array.
BCND XOR_ERFIN,EQ
;If BASE_3 = 0, finished.
***** If not erased, apply an erase pulse.
CALL ERASE_A ;Else, pulse it again.
MAR
MAR
*,AR1
*+
;ARP–>AR1 (Erase pulse count)
;Increment Erase count.
LAR
AR0,#MAX_ER
CMPR2
;If AR1>MAX_ER then
BCND EXIT,TC
XOR_ERASE
;fail, don’t continue erasing.
;Else, check again.
B
***** If here, then erase passed; now check for depletion.
XOR_ERFIN
SPLK #STOP, BASE_0
CALL SET_MODE
CALL INV_ERASE
;Stop command.
;Disable any flash cmds.
;Check for depletion.
;Return to calling code.
DONE RET
A-12
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
***** If here, then an error has occurred.
EXIT SPLK #1,ERROR
SPLK #STOP,BASE_0
CALL SET_MODE
;Update error flag
;Stop command.
;Disable any flash cmds.
;Get outa here.
B
DONE
************************************************************
.page
**************************************************
* SET_MODE: This routine sets the flash in the *
* mode specified by the contents of BASE_0. This *
* can be used for VER0,VER1,INVERASE, or STOP. *
*
AR6: Parameter passed to DELAY.
*
**************************************************
SET_MODE
CALL REGS
LACL FL_ST
TBLW BASE_0
;ACCESS FLASH REGS
;ACC => SEG_CTR.
;Activate MODE.
;SET DELAY
LAR
AR6,#D10
CALL DELAY,*,AR6 ;WAIT
*
*
CALL ARRAY
;ACCESS FLASH ARRAY
RET
************************************************
* INV_ERASE: This routine is used to check for *
* depletion in the flash array.
*
*
*
*
*
AR2
Used for main banz loop
Parameter passed to Set_mode
Used for flash address
Used for flash data
*
BASE_0
BASE_1
BASE_2
*
*
*
************************************************
INV_ERASE
SPLK #INV_ER,BASE_0
CALL SET_MODE
;Set inverse–erase mode.
BLDD #FL_ST,BASE_1;Array start address.
LAR
MAR
AR2,#31
*,AR2
;Loop count.
NEXT_IVERS
LACL BASE_1
TBLR BASE_2
TBLR BASE_2
;Get address.
;Dummy read.
;Read data.
ADD
#1
;Increment address.
;Save address.
SACL BASE_1
ZAC
ADD
BASE_2
;Add data.
BCND EXIT,NEQ
;If ACC<>0, then fail.
*Else continue, until until done with row.
BANZ NEXT_IVERS ;Loop 32 times.
SPLK #STOP,BASE_0 ;Stop command.
CALL SET_MODE
;Disable any flash cmds.
RET
;If here then test passed.
.page
*************************************************************
* ERASE_A: This subroutine applies one erase pulse to the *
* flash array.
*
Assembly Source Listings and Program Examples
A-13
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
*
*
* The following resources are used for temporary storage: *
*
*
*
BASE_0
BASE_5
BASE_6
Flash STOP command, and FFFF for WDATA.
Flash erase command.
Flash erase + EXE command.
*
*
*
*************************************************************
ERASE_A
* SET UP FLASH ERASE COMMANDS FOR PROTECT MASK.
LACL PROTECT ;GET SEGMENT PROTECT MASK
OR #ER_CMND
SACL BASE_5
OR #ER_EXE
SACL BASE_6
**
**
**
**
**
;OR IN ERASE COMMAND
;BASE_5 = ERASE COMMAND
;OR IN EXEBIN COMMAND
;BASE_6 = ERASE EXE COMMAND **
*
**
**
* MUST LOAD WDATA WITH FFFF.
SPLK #0FFFFh,BASE_0 ;WDATA VALUE FOR ERASE
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
LACC FL_ST
TBLW BASE_0
;ACC => FLASH
;SET WDATA = FFFF
*
* THIS SECTION ACTIVATES THE WRITE COMMAND.
SPLK #STOP,BASE_0
CALL SET_MODE
CALL REGS
;Stop command.
;Disable any flash cmds.
;ACCESS FLASH REGS
;ACC => FLASH
;ACTIVATE ERASE
;SET DELAY
;WAIT
LACC FL_ST
TBLW BASE_5
LAR
AR6,#D10
CALL DELAY,*,AR6
*
* THIS SECTION ACTIVATES THE EXEBIN COMMAND.
TBLW BASE_6
LAR AR6,#D7K
CALL DELAY,*,AR6
SPLK #STOP,BASE_0
CALL SET_MODE
RET
;START ERASURE
;SET DELAY to 7 ms
;WAIT
;STOP COMMAND
;STOP ERASE
;RETURN TO CALLING CODE
**************************************************************
.end
A-14
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
A.1.4 Flash-Write Algorithm, SFLW20.ASM
This code is an implementation of the flash-write algorithm described in sec-
tion 3.4 on page 3-14.
Memory section: fl_wrt
Entry point: FLWS
Parameters to be declared and initialized by the calling code are:
- PROTECT defines the values of bits 8–15 of SEG_CTR during the flash-
write algorithm.
- SEG_ST defines the start address of the flash array to be recovered.
- SEG_END defines the end address of the flash array to be recovered.
Return value: ERROR (@BASE+15) 0=Pass, 1=Fail
**************************************************************
** FLASH–WRITE subroutine
*
* TMS320F2XX Flash Utilities.
* Revision: 2.0, 9/10/97
* Revision: 2.1, 1/31/98
*
* Filename: sflw20.asm
*
**
**
**
**
**
**
**
**
* Called by : c2xx_bfx.asm or flash application programs. **
**
* !!CAUTION – INITIALIZE DP BEFORE CALLING THIS ROUTINE!! **
*
*
**
**
**
**
**
*
* Function: Performs flash writes on flash array 0/1 as
*
*
*
*
specified by the following vars:
SEG_ST Array segment start address
PROTECT Sector protect enable
* The flash–write pulse duration used is 14 ms, and a
* maximum of 10000 pulses is applied until the device
* passes the depletion test.
*
*
*
*
*
* The following resources are used for temp storage:
*
*
*
*
*
*
*
*
AR0
AR1
AR2
AR6
BASE_0
BASE_1
BASE_2
Used for comparison
*
*
*
*
*
*
*
Flash–Write Pulse Count
Used for main BANZ loop
Parameter passed to DELAY
Parameter passed to SET_MODE
Used for flash address
Used for flash data
Assembly Source Listings and Program Examples
A-15
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
*
BASE_3
Used for EXE + flw cmd
*
**************************************************************
.include ”svar20.h”
;defines variables for flash0
;or for flash1 array
*
MAX_FLW .set 10000
;Allow only 10000 flw pulses.
;INVERSE ERASE COMMAND WORD
;FLASH WRITE COMMAND WORD
INV_ER
FLWR
.set 018h
.set 6
FLWR_EX .set 047h
;FLASH WRITE EXEBIN COMMAND WORD
;RESET REGISTER COMMAND WORD
STOP
.set 0
.def FLWS
.ref PROTECT,SEG_ST,SEG_END
.ref DELAY,REGS,ARRAY
.sect ”fl_wrt”
******************************************************
* FLWS: This routine is used to check for bits
* in depletion mode. If any are found, flash–
* write is used to recover.
*
*
*
*
*
*
*
*
*
*
*
*
*
AR1
AR2
Flash–write pulse count.
Used for main banz loop.
BASE_0 Parameter passed to Set_mode.
BASE_1 Used for flash address.
BASE_2 Used for flash data.
******************************************************
FLWS:
******************************************************
* Code initialization section
* Initialize test loop counters:
*
*
*
*
AR1 is the number of flash–write pulses.
******************************************************
SETC INTM
LACL SEG_ST
;Disable maskable ints.
;Get segment start address.
;Get array start address.
;Save array start address.
;Reset error flag.
AND
#04000h
SACL FL_ST
SPLK #0,ERROR
LAR
AR1,#0
;Set FLW count to 0.
SPLK #STOP,BASE_0
CALL SET_MODE
;Flash STOP command.
;Disable any flash commands.
INV_ERASE
SPLK #INV_ER,BASE_0
CALL SET_MODE
BLDD #FL_ST,BASE_1
;Set inverse–erase mode.
;Array start address.
;Loop count.
LAR
MAR
AR2,#31
*,AR2
NEXT_IVERS
LACL BASE_1
TBLR BASE_2
TBLR BASE_2
TBLR BASE_2
;Get address.
;Dummy read.
;Dummy read.
;Read data.
ADD
#1
;Increment address.
;Save address.
SACL BASE_1
ZAC
ADD BASE_2
;Add data.
A-16
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
BCND FL_WRITE, NEQ;If ACC<>0, then flwrite.
*Else, continue until until done with row.
BANZ NEXT_IVERS ;Loop 32 times.
SPLK #STOP,BASE_0 ;Flash STOP command.
CALL SET_MODE
;Disable flash commands.
;If here then test passed.
;Return to calling code.
DONE RET
* If here, then an error has occurred.
EXIT SPLK #1,ERROR ;Update error flag
SPLK #STOP,BASE_0 ;Flash STOP command.
CALL SET_MODE
CALL ARRAY
;Disable flash commands.
;ACCESS FLASH ARRAY
;Get outa here.
B
DONE
.page
***************************************************
* FL_WRITE: This routine performs a fl_write on *
* the flash until a maximum is reached. The
* array is defined by the variable FL_ST
*
*
* and the segment(s) is defined by the PROTECT *
* mask. The following resources are used for
* temporary storage:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
AR0
AR1
AR6
Used for comparison
Used for pulse count (Global)
Parameter passed to DELAY
Parameter passed to SET_MODE
Used for flw cmd
BASE_0
BASE_2
BASE_3
Used for EXE + flw cmd
***************************************************
FL_WRITE
SPLK #STOP,BASE_0 ;Flash STOP command.
CALL SET_MODE
LACL PROTECT
;Disable flash commands.
;Get sector_prot mask.
;Or in fl_write cmd.
;BASE_2 = fl_write cmd.
;Or in EXE + fl_write cmd.
;BASE_3 = EXE + fl_write cmd.
OR
SACL BASE_2
OR #FLWR_EX
SACL BASE_3
*Set the flash–write command.
#FLWR
CALL REGS
LACC FL_ST
TBLW BASE_2
;Access flash regs.
;ACC => SEG_CTL.
;Initiate fl_write.
;Set delay.
LAR
AR6,#D10
CALL DELAY,*,AR6 ;Wait,10US flw stabilization time.
*Set the EXE bit (start flash–write pulse).
TBLW BASE_3
LAR AR6,#D7K
;Start flw pulse.
;Set delay to 7 ms.
CALL DELAY,*,AR6 ;WAIT,7 ms.
LAR AR6,#D7K ;Set delay to 7 ms.
CALL DELAY,*,AR6 ;WAIT 7 ms.
*A 14–mS flash write pulse has been applied.
SPLK #STOP,BASE_0 ;Flash STOP command.
CALL SET_MODE
;Disable flash commands.
MAR
MAR
*,AR1
*+
;Increment flw count.
Assembly Source Listings and Program Examples
A-17
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
LAR
AR0,#MAX_FLW
CMPR 2
;If AR1>MAX_FLW then
BCND EXIT,TC
;Fail, don’t continue recovery.
;Else, perform iverase again.
B
INV_ERASE
**************************************************
* SET_MODE: This routine sets the flash in the *
* mode specified by the contents of BASE_0. This *
* can be used for VER0,VER1,INVERASE,or STOP.
*
**************************************************
SET_MODE
CALL REGS
LACL FL_ST
TBLW BASE_0
;ACCESS FLASH REGS
;ACC => SEG_CTR.
;Activate MODE.
;SET DELAY
LAR
AR6,#D10
CALL DELAY,*,AR6 ;WAIT
CALL ARRAY ;ACCESS FLASH ARRAY
RET
*************************************************
.end
A-18
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
A.1.5 Programming Algorithm, SPGM20.ASM
This code is an implementation of the program algorithm described in section
3.2 on page 3-4.
Memory section: fl_prg
Entry point: GPGMJ
Parameters to be declared and initialized by the calling code are:
- PRG_bufaddr defines the destination start address.
- PRG_length defines the source buffer length.
- PRG_paddr defines the source buffer start address (data space).
- PROTECT defines the values of bits 8–15 of SEG_CTR during the pro-
gramming algorithm.
Return value: ERROR (@BASE+15); 0 = Pass, 1 = Fail
**************************************************************
** PROGRAM Subroutine
*
* TMS320F2XX Flash Utilities.
**
**
**
**
**
**
**
**
**
*
*
*
*
Revision: 2.0, 9/10/97
Revision: 2.0b, 12/5/97
Revision: 2.1, 1/31/98
* Filename: spgm20.asm
*
* Called by: c2xx_bpx.asm or flash application programs. **
**
* !!CAUTION – INITIALIZE DP BEFORE CALLING THIS ROUTINE!! **
*
*
**
**
**
*
*
*
* Function: This routine programs all or part of the
*
*
*
*
*
flash as specified by the variables:
PRG_paddr
PRG_length
Destination start address
Source buffer length
PRG_bufaddr Source buffer start address
*
* The algorithm used is ”row–horizontal”, which means that *
* an entire flash row (32 words) is programmed in parallel.*
* This method provides better uniformity of programming
* levels between adjacent bits than if each address were *
* programmed independently. The algorithm also uses a
*
*
* 3–read check for VER0 margin (i.e., the flash location is*
* read three times and the first two values are discarded.)*
* This provides low–freq read–back margin on programmed
*
Assembly Source Listings and Program Examples
A-19
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
* bits. For example, if the flash is programmed using a
*
* CLKOUT period of 50 ns, the flash can be reliably read *
* back over the CLKOUT period range of 50 ns to 150 ns
* (6.67MHz–20 MHz). The programming pulse duration is
*
*
* 100 us, and a maximum of 150 pulses is applied per row. *
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* The following variables are used for temp storage:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
AR0
AR1
AR2
AR3
AR4
AR6
SPAD1
SPAD2
Used for comparisons
Used for pgm pulse count
Used for row banz loop
Used for buffer addr index
Used for flash address.
Parameter passed to Delay
Flash program and STOP commands
Flash program + EXE command
FL_ADRS Used for flash address
FL_DATA Used for flash data
BASE_0
BASE_1
BASE_2
BASE_3
BASE_4
BASE_5
Used for row–done flag
Used for row start address
Used for row length–1
Used for buffer/row start addr
Used for destination end addr
Used for byte mask
*************************************************************
.include ”svar20.h”
*
MAX_PGM .set 150
;Allow only 150 pulses per row.
VER0
.set 010h ;VER0 command.
WR_CMND .set 4
;Write command.
WR_EXE
STOP
.set 045h ;Write EXEBIN command.
.set 0
;Reset command.
.def GPGMJ
.ref PRG_bufaddr,PRG_length,PRG_paddr
.ref PROTECT,DELAY,REGS,ARRAY
.sect ”fl_prg”
*********************************************************
* GPGMJ: This routine programs all or part of
*
*
*
*
*
*
the flash as specified by the variables:
*
*
PRG_paddr
PRG_length
Destination start address
Source buffer length
*
*
*
*
*
*
*
*
*
*
*
*
*
*
PRG_bufaddr Buffer start address
* The following variables are used for temp
* storage:
*
*
*
*
*
*
*
*
*
AR0
AR1
AR2
AR3
Used for comparisons
Used for pgm pulse count
Used for row banz loop
Used for buffer addr index
FL_ADRS Used for flash address
FL_DATA Used for flash data
BASE_0
BASE_1
BASE_2
Used for row–done flag
Used for row start address
Used for row length–1
A-20
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
*
*
*
BASE_3
BASE_4
BASE_5
Used for buffer/row start addr
Used for destination end addr
Used for byte mask
*
*
*
******************************************************
GPGMJ: SPLK #0,IMR
SETC INTM
;MASK ALL INTERRUPTS
;GLOBALLY MASK ALL INTERRUPTS
;Initialize error flag (no error).
;Get destination start address.
;Save as current address.
;Determine destination end addr.
;
SPLK #0,ERROR
LACL PRG_paddr
SACL FL_ADRS
ADD
SUB
PRG_length
#1
SACL BASE_4
LACL PRG_paddr
;Save destination end addr.
;Get destination start addr.
LAR
AR3,PRG_bufaddr ;Get buffer start address.
********Begin a new row.*
NEWROW
SACL BASE_1
;Save row start address.
SAR
LAR
AR3,BASE_3
AR1,#0
;Save buffer/row start address.
;Init pulse count to zero.
;Init row length–1 to 31.
;Is start addr on row boundary?
;If not then adjust row length.
;Get row start address.
SPLK #31,BASE_2
AND
CC
#001Fh
ADJ_ROW,NEQ
LACL BASE_1
OR
#001Fh
;Get row end address.
SUB
CC
BASE_4
ADJ_ROW,GT
;Is end address on row boundary?
;If not then adjust row length.
********Same row, next pulse.*
SAMEROW SPLK #1,BASE_0
LACL BASE_1
;Set row done flag = 1(True).
;Get row start address.
;Save as current address.
;Get buffer/row start addr.
;Init row index.
SACL FL_ADRS
LAR
LAR
AR3,BASE_3
AR2,BASE_2
** Repeat the following code 32 times or until end of row.*
LOBYTE ;********First, do low byte.*
CALL SET_MODULE,AR4
;Determine which flash module.
;Set lo–byte mask.
;Check/Program lo–byte.
SPLK #0FFh,BASE_5
CALL PRG_BYTE
SPLK #0FF00h,BASE_5 ;Set hi–byte mask.
CALL PRG_BYTE
NEXTWORD
LACL FL_ADRS
ADD #1
SACL FL_ADRS
;Check/Program hi–byte.
;********Next word in row.
;Load address for next word.
;Increment address.
;Save as current address.
;ARP –> buffer addr index.
;Inc, and ARP –> row index.
;Do next word,and dec AR2.
MAR
MAR
*,AR3
*+,AR2
BANZ LOBYTE
** Reached end of row. Check if row done. *
BIT
BASE_0,15
;Get row_done flag.
BCND ROW_DONE,TC
;If 1 then row is done.
;Else, row is not done, so
;inc row pulse count.
;Check if passed allowable max.
;If AR1>MAX_PGM then
MAR
MAR
LAR
*,AR1
*+
AR0,#MAX_PGM
CMPR 2
Assembly Source Listings and Program Examples
A-21
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
BCND EXIT,TC
SAMEROW
;fail, don’t continue.
;else, go to beginning
;of same row.
B
** If row done, then check if Array done. *
ROW_DONE
LACL FL_ADRS
SUB BASE_4
BCND DONE, GT
** Else, go to next row. *
LACL FL_ADRS
;Check if end of array.
;Subtract end addr.
;If >0 then done.
B
NEWROW
;Start new row.
** If here, then done.
DONE
CALL ARRAY
RET
;Access flash in array mode.
;Return to calling program.
** If here, then unit failed to program. *
EXIT SPLK #1,ERROR ;Update error flag (error).
DONE ;Get outa here.
B
************************************************
.page
************************************************
* ADJ_ROW: This routine is used to adjust the *
* row length, if the start or end address of *
* code being programmed does not fall on a row *
* boundary. The row length is passed in the
*
* BASE_2 variable, and the adjustment value to *
* be subtracted is passed in the accumulator. *
***********************************************
ADJ_ROW
NEG
ADD
;Take twos complement.
;Add row length.
BASE_2
SACL BASE_2
RET
;Save new row length.
*************************************************
* SET_MODULE: This routine is used to point to *
* the appropriate flash array control register *
* This is only important for ’F2XX devices with *
* multiple flash modules like the 320F206. The *
* variable FL_ST is returned with the correct*
* register address.
* The following resources are used
* temporarily:
*
*
*
*
*
*
*
AR0
AR4
Used for comparisons
Used for flash address
***************************************************
SET_MODULE
LAR
SPLK #0,FL_ST
LAR AR0,#4000H
AR4,FL_ADRS ;AR4 = current address.
;FL_ST = FLASH0 CTRL REGS
;AR0 = compare value.
;If AR4 < AR0 then
CMPR 1
;FL_ADRS < 4000H; SET TC
;Address is in FL0.
BCND FL0,TC
*
;Else address is in FL1.
A-22
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
SPLK #04000h,FL_ST;FL_ST = FLASH1 CTRL REGS
RET
FL0
*************************************************************
.page
*************************************************************
* THIS SECTION PROGRAMS THE VALUE STORED IN FL_DATA INTO *
* THE FLASH ADDRESS DEFINED BY FL_ADRS.
*
*
*
* The following resources are used for temporary storage: *
*
*
*
AR6
Parameter passed to Delay
*
*
*
SPAD1 Flash program and STOP commands
SPAD2 Flash program + EXE command.
**************************************************************
EXE_PGM
*
;
*
*
CALL ARRAY
;ACCESS ARRAY
*
* LOAD WADRS AND WDATA
LACL FL_ADRS
**
*
*
;ACC => PROGRAM ADRS
;LOAD WADRS AND WDATA
;ACCESS FLASH REGS
TBLW FL_DATA
CALL REGS
*
* SET UP WRITE COMMAND WORDS
LACL PROTECT
**
**
**
**
**
**
*
;GET SEGMENT PROTECT MASK
;OR IN WRITE COMMAND
;SPAD1 = WRITE COMMAND
;OR IN EXEBIN COMMAND
;SPAD2 = WRITE EXE COMMAND
;ACC => (FLASH)
OR
#WR_CMND
SACL SPAD1
OR
#WR_EXE
SACL SPAD2
LACL FL_ST
*
*
* ACTIVATE WRITE BIT
TBLW SPAD1
**
**
**
**
**
**
**
**
*
*
*
*
*
;EXECUTE COMMAND
;SET DELAY
LAR
AR6,#D10
CALL DELAY,*,AR6 ;WAIT
* SET EXEBIN BIT
TBLW SPAD2
;EXECUTE COMMAND
;SET DELAY
LAR
AR6,#D100
CALL DELAY,*,AR6 ;WAIT
* STOP WRITE OPERATION
SPLK #0,SPAD1
;SHUT DOWN WRITE OPERATION
;EXECUTE COMMAND
;EXECUTE COMMAND
;SET DELAY
TBLW SPAD1
TBLW SPAD1
LAR
AR6,#D10
CALL DELAY,*,AR6 ;WAIT
*
*
*
RET
;RETURN TO CALLING SEQUENCE
*
*************************************************************
.page
*************************************************************
* ACTIVATE VER0 ON FLASH READS
* LOADS FLASH WORD AT ADDR FL_ADRS TO FL_DATA.
* Uses SPAD1 for temporary storage of flash commands.
*
*
*
*************************************************************
SET_RD_VER0
CALL REGS
;
*
*
;ACCESS FLASH REGISTERS
Assembly Source Listings and Program Examples
A-23
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
LACL FL_ST
SPLK #VER0,SPAD1 ;ACTIVATE VER0
TBLW SPAD1
LAR AR6,#D10
;ACC => FLASH
*
*
*
*
*
*
*
;EXECUTE COMMAND
;SET DELAY
CALL DELAY,*,AR6 ;WAIT
CALL ARRAY ;ACCESS FLASH ARRAY
LACL FL_ADRS ;POINT TO ADRS
TBLR FL_DATA
TBLR FL_DATA
TBLR FL_DATA
;GET FLASH WORD 1x read
; 2x read
; 3x read
*
*
*
*
*
*
*
*
*
*
*
CALL REGS
LACL FL_ST
;ACCESS FLASH REGISTERS
;ACC => FLASH
SPLK #STOP,SPAD1 ;DEACTIVATE VER0
TBLW SPAD1
LAR AR6,#D10
;EXECUTE COMMAND
;SET DELAY
CALL DELAY,*,AR6 ;WAIT
CALL ARRAY
RET
;ACCESS FLASH ARRAY
;RETURN TO CALLING SEQUENCE
*************************************************************
.page
*************************************************
* PRG_BYTE: Programs hi or lo byte depending on*
*
byte mask (BASE_5).
*
*************************************************
PRG_BYTE:
CALL SET_RD_VER0
MAR *,AR3
LACL *
;Read word at VER0 level.
;ARP –> buffer addr index.
;Get word to program.
;Xor with read–back value.
;Mask off hi/lo byte.
;If zero then done.
;else, mask off good bits.
;New data.
;PGM Pulse.
XOR
AND
FL_DATA
BASE_5
BCND PB_END,EQ
XOR #0FFFFh
SACL FL_DATA
CALL EXE_PGM
SPLK #0,BASE_0
;Set row done flag = 0(False).
PB_END RET
**************************************************************
.end
A-24
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
A.1.6 Subroutines Used By All Four Algorithms, SUTILS20.ASM
This assembly file includes two subroutines that change the flash module ac-
cess mode and one subroutine that performs software delays. More details on
the individual functions are given in the comments.
**************************************************************
** Delay And Access Mode Subroutines
*
* TMS320F2XX Flash Utilities.
**
**
**
**
**
**
**
**
**
**
**
**
**
*
*
*
Revision: 2.0, 9/10/97
Revision: 2.1, 1/31/98
* Filename: sutils20.asm
*
* Called by:
These utilities are used by CLEAR,ERASE,
*
*
PROGRAM algorithms written for F2xx
devices.
* Function: DELAY Delay loop specified by AR6.
*
*
*
*
REGS Clears MODE bit of F_ACCESS0/1 to
access flash module control registers. **
ARRAY Sets MODE bit of F_ACCESS0/1 to access **
the flash array.
**
**************************************************************
.include ”svar20.h”
.def DELAY,REGS,ARRAY
.sect ”DLY”
*************************************
*Delays as follows:
* LAR AR6,#N
* CALL DELAY
*
*
*
*
*
*
*
2 Cycles
4 Cycles
* RPT
* NOP
#DLOOP 2*(N+1) Cycles
DLOOP*(N+1) Cycles
* BANZ DLY_LP
* RET
4*N+2 Cycles
4 Cycles
*
*
–––––––––––––––––––––––– *
= DLOOP(N+1)+6*N+14 Cycles *
* Set N and DLOOP appropriately to *
* get desired delay.
**************************************
*
DELAY
DLY_LP
;AR6 = OUTER LOOP COUNT
;APPROX 5US DELAY
RPT
NOP
#DLOOP
BANZ DLY_LP,*– ;LOOP UNTIL DONE
RET
;RETURN TO CALLING SEQUENCE
.page
**************************************************
* REGS
*
Clears MODE bit of F_ACCESS0/1 to
access flash module control registers. **
**
*******************************************************
.sect ”REG”
REGS
Assembly Source Listings and Program Examples
A-25
PRELIMINARY
PRELIMINARY
Assembly Source for Algorithms
SPLK #0000h,SPAD2
***********The next instruction is for F240 only*************
.if
OUT
F24X = 1
SPAD2,F24X_ACCS
;Assemble for F24X only.
;Enable F240 flash reg mode.
;SPAD1 is dummy value.
.endif
*************************************************************
.if
LACC FL_ST
SUB #4000h
BCND reg1,geq
F24X = 0
;Assemble for F206 only.
;if address>= 4000h,set
;set reg mode for flash1 array
OUT
RET
reg1 OUT
SPAD2,F_ACCESS0 ;Change mode of flash0.
SPAD2,F_ACCESS1 ;Change mode of flash1.
;RETURN TO CALLING SEQUENCE
.endif
RET
.page
****************************************************
* ARRAY Sets MODE bit of F_ACCESS0/1 to access **
*
the flash array.
**
****************************************************
.sect ”ARY”
ARRAY
SPLK #0001h,SPAD2
***********The next instruction is for F240 only*************
.if
IN
F24X = 1
;Assemble for F240 only.
SPAD1,F24X_ACCS ;Enable F240 flash array mode.
;SPAD1 is dummy value.
.endif
*************************************************************
.if
LACC FL_ST
SUB #4000h
BCND ary1,geq
F24X = 0
;Assemble for F206 only.
;if address>= 4000h,set
;set reg mode for flash1 array
OUT
RET
ary1 OUT
SPAD2,F_ACCESS0 ;Change mode of flash0.
SPAD2,F_ACCESS1 ;Change mode of flash1.
;RETURN TO CALLING SEQUENCE
.endif
RET
.end
A-26
PRELIMINARY
PRELIMINARY
C-Callable Interface to Flash Algorithms
A.2 C-Callable Interface to Flash Algorithms
The two functions erase() and program() are intended for in-application pro-
gramming of the ’F20x/F24x flash module. These functions were written to be
C callable, but they can also be called from assembly as long as the C stack
calling convention is used.
*****************************************************
* This file contains two C–callable functions:
program(), and erase()
*
*
*
*
*
*
* These functions are used for programming and
* erasing the on–chip flash EEPROM of the ’F2XX
* product family.
*****************************************************
* The functions provide a C–callable, interface to *
* the standard ’F2XX flash algorithms. They can
* also be used from assembly code, as long as the *
*
* C stack calling convention is used. Since the
* standard flash algorithms are actually used to
*
*
* perform the various flash operations, they must *
* must be combined with this code at link time.
*
*
*
*
* The erase function includes all the operations
* (clear+erase+flw) required to prepare the flash *
* for programming. In addition to providing the
* C–callable interface, this function is very
*
*
* useful since it provides a single call to erase *
* the flash memory.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* Since programming the device requires a single
* algorithm, the only purpose for the program()
* function is to provide a C–callable interface.
* The program() function transfers a specified
* block of data memory into a specified, erased
* flash array.
*
* The parameters for each function are described
* in detail below. Note these functions cannot
* reside in the same flash module that they are
* meant to modify.
*
*
*
*
*
*
10/29/97 Ruben D. Perez
DSP Applications Team
Texas Instruments, Inc.
03/20/98 Updated for inclusion in flash
technical reference.
***************************************************
.title ”C–callable Interface to ’F2XX Flash Algorithms**”
;**C–callable functions defined in this file.
.global _erase, _program
Assembly Source Listings and Program Examples
A-27
PRELIMINARY
PRELIMINARY
C-Callable Interface to Flash Algorithms
;**Variables included from flash algorithms.
.include ”svar20.h”
.ref GCLR
.ref GPGMJ
.ref GERS
.ref FLWS
;Variable declarations
;References clear algo.
;References program algo.
;References erase algo.
;References flash–write algo.
;**Parameters used by flash algorithms.
.def PRG_bufaddr, PRG_paddr
.def PRG_length, PARMS
.def SEG_ST,SEG_END,PROTECT
*************************************************************
VARS: .usect ”PRG_data”,16;This is an uninitialized data
*
;section required by the standard*
;flash algos for temporary
;variables. Pointers to this
*
*
;space are hardcoded in SVAR20.H,*
;and variables are init’d at
;run time.
*
*
*************************************************************
PARMS: .usect ”PRG_parm”,10;This is an uninitialized data
;section used for temporary
;variables and for passing
*
*
*
*
*
;parameters to the flash
;algorithms.
*************************************************************
PROTECT .set PARMS ;Segment enable bits.
*
*************************************************************
***** Parameters needed for Programming algorithm. ********
*************************************************************
PRG_bufaddr .set PARMS+1 ;Addr of buffer for pgm data *
PRG_paddr
PRG_length
.set PARMS+2 ;First flash addr to program *
.set PARMS+3 ;Length of block to program *
*************************************************************
** Parameters needed for CLEAR, ERASE, and FLW algorithms. *
*************************************************************
SEG_ST
SEG_END .set PARMS+5
.set PARMS+4
;Segment start address.
;Segment end address.
*
*
*************************************************************
**** Other misc variables. ****
*************************************************************
ERS_COUNT .set PARMS+6 ;Used for erase fail count. *
SV_AR1 .set PARMS+7 ;Used to save AR1.
*
**************************************************************
.sect ”PRG_text”
**********************************************************
* function erase(PROTECT,SEG_ST,SEG_END)
* Status is returned in the accumulator.
*
*
*
*
0 = Fail,1 = Pass
**********************************************************
* This function performs the clear and erase operation *
* on the ’F2XX flash. If the erase operation fails, the*
* flash–write operation is used to try to recover from *
* depletion. If the array recovers, the entire process *
* (clr+ers+flw) is repeated a maximum of 10 times. The *
* return value indicates the status. If this function *
A-28
PRELIMINARY
PRELIMINARY
C-Callable Interface to Flash Algorithms
* passes, the flash is ready to be reprogrammed. The
*
* operations are performed on the segments of the flash*
* module described by the parameter list:
*
*
*
*
1)PROTECT–defines which flash segments to protect.*
2)SEG_ST –start address of segment to be erased. *
3)SEG_END–end address of segment to be erased.
*
*
*
* To erase flash0 use erase(0xff00,0x0000,0x3fff).
* To erase flash1 use erase(0xff00,0x4000,0x7fff).
*********************************************************
* CAUTION: Erasing individual segments is not allowed. *
*
*
*
*
The PROTECT parameter should always be set to
enable all segments, and SEG_ST and SEG_END
should be set to the end and start address of
the array to be erased.
*
*
*
*
*********************************************************
_erase:
ERS_PARAMS
AR_STACK
AR_PROTECT
AR_SEG_ST
AR_SEG_END
.set 3
.set ar1
.set ar2
.set ar3
.set ar4
;Begin C Preprocessing
POPD *+ ;pop return address, push on software stack
ar0,*+ ;save FP
ar6,* ;save ar6
sar
sar
sbrk #3
;get arguments and place them properly – take them from
;the software stack and place them into their correct
;positions
lar
lar
lar
AR_PROTECT,*–
AR_SEG_ST,*–
AR_SEG_END,*–
adrk #ERS_PARAMS+4 ;ar1 = next empty point on stack (SP)
;End C Preprocessing
LDP
SAR
#PARMS
AR1,SV_AR1
;Save AR1.
SPLK #0,ERS_COUNT ;Set erase fail count to 0.
SPLK #0,ERROR
;Set algo error flag to 0 (no errors).
**********Put parameters where they belong.**********
SAR
SAR
SAR
AR_PROTECT,PROTECT
AR_SEG_ST,SEG_ST
AR_SEG_END,SEG_END
***********Next Setup to clear flash ************
ers_loop:
CALL GCLR
LACL ERROR
;Clear flash.
;Check for CLEAR/ERASE error
BCND ers_error,neq;If error, then hard fail.
***********Next Setup to erase flash ************
CALL GERS
LACL ERROR
;Erase flash.
;Check for CLEAR/ERASE error
BCND depletion,neq;If error, try Flash–write.
LACL #1
;Else, no errors erasing.
;Restore registers and return.
B
ers_done
depletion:
LACL ERS_COUNT
;Get erase fail count.
Assembly Source Listings and Program Examples
A-29
PRELIMINARY
PRELIMINARY
C-Callable Interface to Flash Algorithms
ADD
#1
;Increment fail count.
;Save new count.
;CHECK for max of 10.
SACL ERS_COUNT
SUB #10
BCND ers_error,GT ;If ers_cout>10 then hard fail.
CALL FLWS
LACL ERROR
;Else, try to recover from depletion.
;Check for FLASH–WRITE error.
BCND ers_error,neq;If couldn’t recover, then hard fail.
B
ers_loop
;Else, try erase again.
;Error while erasing.
ers_error:
LACL #0
ers_done:
LAR
CLRC OVM
AR1,SV_AR1
;Restore AR1.
;Disable overflow.
********************************************
;Begin C Post Processing
mar*,ar1
sbrk #1
lar
lar
ar6,*–
ar0,*–
;save FP
;save ar6
pshd *
;pop return address, push on s/w stack
;End C Post Processing
ret
*****************END of _erase****************************
**********************************************************
* function program(PROTECT,PRG_bufaddr,PRG_paddr,
PRG_length)
* Status will be returned in the accumulator.
0 = Fail, 1 = Pass
*
*
*
*
*
*
*********************************************************
* This function performs the program operation on the *
* ’F2XX flash. The values to be programmed will be read*
* from a buffer in data memory. The function can program*
* one to n words of flash in a single call; restricted *
* only by the data buffer size. If the function passes,*
* the flash was programmed correctly. The function is *
* controlled by the following parameter list:
*
*
*
*
*
*
*
*
*
1)PROTECT
–flash segments to protect.
2)PRG_bufaddr–Start address of program buffer in *
data memory.
3)PRG_paddr –Start address of flash locations to *
be programmed.
4)PRG_length –Number of words to be programmed. *
*
*
*
* To program 20 words of flash1 starting at address
* 0x4020, from a buffer at 0x0800@data use this:
*
*
*
*
program(0xff00,0x0800,0x4020,20).
*********************************************************
_program:
PRG_PARAMS
AR_STACK
.set 4
.set ar1
;**Parameters to be popped from s/w stack.
AR_PROTECT
AR_bufaddr
AR_paddr
.set ar2
.set ar3
.set ar4
.set ar5
AR_length
A-30
PRELIMINARY
PRELIMINARY
C-Callable Interface to Flash Algorithms
;Begin C Preprocessing
POPD *+
sarar0,*+
sarar6,*
sbrk #3
; pop return address, push on s/w stack
; save FP
; save ar6
; Local variables (and parameters) are set up as follows:
;
;get arguments and place them properly – take them from
;the software stack and place them into their correct
;positions
lar AR_PROTECT,*–
lar AR_bufaddr,*–
lar AR_paddr,*–
lar AR_length,*–
adrk #PRG_PARAMS+4 ; ar1 = next empty point on stack (SP)
; End C Preprocessing
LDP
SAR
#PARMS
AR1,SV_AR1
;Save AR1.
;Set algo error flag to 0
;(no errors).
SPLK #0,ERROR
**********Put parameters where they belong.**********
SAR AR_PROTECT,PROTECT
SAR AR_bufaddr,PRG_bufaddr
SAR AR_paddr,PRG_paddr
SAR AR_length,PRG_length
***********Next, program flash ************
CALL GPGMJ
LACL ERROR
;Program flash from buffer.
;Check for program error.
BCND prg_error,neq;If error then clear ACC.
LACL #1
;Else, No errors programming.
B
prg_done
prg_error:
LACL #0
;Error while programming.
prg_done:
LAR
AR1,SV_AR1
;Restore AR1.
;Disable overflow.
CLRC OVM
********************************************
;Begin C Post Processing
mar *,ar1
sbrk #1
lar
lar
ar6,*–
ar0,*–
;save FP
;save ar6
pshd *
;End C Post Processing
ret
;pop return address, push on s/w stack
*****************END of _program************************
Assembly Source Listings and Program Examples
A-31
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F206
A.3 Sample Assembly Code to Erase and Reprogram the TMS320F206
The algorithm files can be used from assembly in a straightforward manner. In
general, the algorithms can reside anywhere in program space. However, the
algorithms cannot be executed from the flash module that is being modified,
andthealgorithmsmustexecutewithzerowaitstates. Theassemblycodeand
linker command file in this section provide a working example for the ’F206. In
this example, the algorithms reside in SARAM, and flash1 is erased and repro-
grammed.
A.3.1 Assembly Code for TMS320F206
*******************************************************
* Filename: ASMEXAMP.ASM
* Description:
* This file contains an example of how to erase
* and program the TMS320F206 flash from assembly
*
*
*
*
* code using the standard flash algorithm modules. *
* The example erases one of the ’F206 flash
* modules, then programs the first three words.
*
*
* Since the standard flash algorithms are actually *
* used to perform the various flash operations,
* they must must be combined with this code at
* link time.
*
*
*
*
*
*
*
* 03/20/98 Updated for inclusion in flash
*
technical reference.
*******************************************************
.title”**Example of Using ’F2XX Flash Algorithms**”
;**Variables included from flash algorithms.
.include ”svar20.h” ;Variable declarations
.ref GCLR
.ref GPGMJ
.ref GERS
.ref FLWS
;References clear algo.
;References program algo.
;References erase algo.
;References Flash–write algo.
;**Parameters used by flash algorithms.
.def PRG_bufaddr, PRG_paddr
.def PRG_length, PARMS
.def SEG_ST,SEG_END,PROTECT
**********************************************************
VARS: .usect”PRG_data”,16 ;This is an uninitialized *
;data section required by *
;the standard flash algos *
;for temporary variables. *
;Pointers to this space
*
;are hardcoded in SVAR20.H, *
;and variables are
;init’d at run time.
*
*
**********************************************************
PARMS:.usect”PRG_parm”,10 ;This is an uninitialized *
A-32
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F206
;data section used for
;temporary variables, and *
;for passing parameters
*
*
;to the flash algorithms. *
*********************************************************
PROTECT .set PARMS
**********************************************************
***Parameters needed for Programming algorithm. ***
**********************************************************
;Segment enable bits.
*
PRG_bufaddr .set PARMS+1 ;Address of buffer for
;program data.
*
*
*
*
PRG_paddr
.set PARMS+2 ;First flash address to
;program.
PRG_length .set PARMS+3 ;Length of block to program.*
**********************************************************
* Parameters needed for CLEAR, ERASE, and FLW algorithms.
*
**********************************************************
SEG_ST
.set PARMS+4 ;Segment start address.
*
*
SEG_END .set PARMS+5 ;Segment end address.
**********************************************************
**** Other misc variables. ****
**********************************************************
ERS_COUNT.set PARMS+6 ;Used for erase fail count.
*
**********************************************************
.text
*********************************************************
** First, erase flash1 by invoking the clear and erase *
** algorithms.
** Note: three parameters must be initialized before
** calling the algorithms.
*
*
*
*********************************************************
LDP #PARMS
SPLK #0,ERS_COUNT;Set erase fail count to 0.
**********Put parameters where they belong.**********
SPLK #0ff00h,PROTECT
SPLK #04000h,SEG_ST
SPLK #07FFFh,SEG_END
***********First clear flash ************
ers_loop:
CALL GCLR
LACL ERROR
;Clear flash.
;Check for CLEAR error
BCND ers_error,neq ;If error, then hard fail.
***********Next erase flash ************
CALL GERS
LACL ERROR
;Erase flash.
;Check for CLEAR error
BCND depletion,neq ;If error, then try
;flash–write.
B
ers_done
;Else, no errors erasing.
depletion:
LACL ERS_COUNT
ADD #1
SACL ERS_COUNT
;Get erase fail count.
;Increment fail count.
;Save new count.
Assembly Source Listings and Program Examples
A-33
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F206
SUB #10
BCND ers_error,GT
;CHECK for max of 10.
;If ers_cout>10 then hard
;fail.
CALL FLWS
;Else, try to recover from
;depletion.
LACL ERROR
;Check for FLASH–WRITE error.
BCND ers_error,neq ;If couldn’t recover, then
;hard fail.
B
ers_loop
;Else, try erase again.
ers_error:
********************************************************
** If here, then an unrecoverable error has occurred **
** during erase. In an actual application, the system**
** takes some action to indicate that service is
** required.
**
**
********************************************************
B
ers_error
;Error while erasing.
ers_done:
********************************************************
** If here, then flash is erased and ready to be **
** reprogrammed. This is a good place in the example **
** to set a breakpoint so that erasure can be
** verified (i.e., all flash bits should be 1).
**
**
********************************************************
**********************************************************
** At this point, an actual application fills a buffer **
** with the data to be programmed. To simulate this in **
** the example, three SARAM locations are initialized. **
**********************************************************
LAR AR1, #0c00h;Using last 3K of SARAM as
;buffer.
MAR *,AR1
SPLK #0AAAAh,*+ ;Use dummy data for buffer.
SPLK #05555h,*+
SPLK #0AAAAh,*
**********************************************************
** Now that the data to be programmed is ready, the
** programming algorithm is invoked. Note that four
** parameters must be initialized before calling the
** algorithm.
**
**
**
**
**********************************************************
LDP #PARMS
**********Put parameters where they belong.**********
splk #0ff00h,PROTECT
splk #0c00h,PRG_bufaddr
splk #04000h,PRG_paddr
splk #3,PRG_length
***********Next program flash ************
CALL GPGMJ
LACL ERROR
;Program flash from buffer.
;Check for program error.
BCND prg_error,neq ;If error then clear ACC.
B
prg_done
;Else, No errors programming.
A-34
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F206
prg_error:
********************************************************
** If here, then an error has occurred during **
** programming. In an actual application, the system **
** takes some action to indicate that service is
** required.
**
**
********************************************************
B
prg_error
;Error while programming.
prg_done:
**********************************************************
*********
** If here, then flash has been successfully programmed.**
**********************************************************
B
prg_done
;Done programming.
A.3.2 Linker Command File for TMS320F206 Sample Assembly Code
/********************************************************************************/
/* Filename: ASMEXAMP.CMD
/* Description: Linker command file for ’F206 example of on–chip
*/
*/
/* flash programming from assembly. This command file links the example to addr */
/* 0x8000 of the on–chip SARAM so that the debugger can be used to set
/* breakpoints. Another benefit of linking the example to SARAM is that the
/* code can be modified to operate on either flash module0, or module1, or
/* both.
*/
*/
*/
*/
*/
/* Notes:
/*
/*
/*
/*
1. This example expects the ’F206 SARAM to be mapped in both data space */
and program space (DON=PON=1). */
2. The object modules for the standard flash algos are expected to be in */
a subdirectory (ALGOS) of the path of this file. */
/********************************************************************************/
/* Rev1.0 3/98 RDP */
/********************************************************************************/
/*****************************Command Line Options*******************************/
–e .text
–o asmexamp.out
–m asmexamp.map
/**************************Input Files*******************************************/
asmexamp.obj
/*User assembly code that calls flash algos.
/*Standard Programming algorithm.
/*Standard Clear algorithm.
/*Standard Erase algorithm.
/*Standard Flash–write algorithm.
*/
*/
*/
*/
*/
*/
algos\spgm20.obj
algos\sclr20.obj
algos\sera20.obj
algos\sflw20.obj
algos\sutils20.obj /*Subroutines used by standard algos.
/*****************************Memory Map*****************************************/
MEMORY
{
PAGE 0: /* PM – Program memory */
FLASH0: origin = 0x0000, length = 0x3fff
FLASH1: origin = 0x4000, length = 0x3fff
PSARAM: origin = 0x8000, length = 0x400 /*Use 1K of SARAM for PROGRAM
B0: origin = 0xff00, length = 0x1ff
*/
Assembly Source Listings and Program Examples
A-35
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F206
PAGE 1: /* DM – Data memory */
BLK_B2: origin = 0x60,length = 0x20
DSARAM: origin = 0xc00, length = 0xC00
EX1_DM: origin = 0x4000, length = 0x4000
B1: origin = 0x300, length = 0x1ff
/*BLOCK B2
/*Use 3K of SARAM for data DON=1 */
/*External data RAM
/*B1 Ram (Used for algo vars )
*/
*/
*/
}
/*************************Section Allocation************************************/
SECTIONS
{
.text : {} > PSARAM PAGE 0/* asmexamp.asm */
/*All these sections are for flash programming.*/
fl_prg
fl_clr
fl_ers
fl_wrt
DLY
REG
ARY
: {} > PSARAM PAGE 0
: {} > PSARAM PAGE 0
: {} > PSARAM PAGE 0
: {} > PSARAM PAGE 0
: {} > PSARAM PAGE 0
: {} > PSARAM PAGE 0
: {} > PSARAM PAGE 0
/**Programming Algorithm*****/
/******Clear Algorithm*******/
/******Erase Algorithm*******/
/****Flash–write Algorithm***/
/******Delay Subroutine******/
/*******Regs Subroutine******/
/******Array Subroutine******/
/*Reserved in asmexamp.asm **/
/*for flash algo variables.**/
/*Reserved in asmexamp.asm **/
/*for param passing to algos*/
PRG_data : {} > B1
PAGE 1
PRG_parm : {} > B1
PAGE 1
/*End of sections for flash programming.
*/
}
A-36
PRELIMINARY
PRELIMINARY
Sample C Code to Erase and Reprogram the TMS320F206
A.4 Sample C Code to Erase and Reprogram the TMS320F206
Because the algorithm implementations do not follow the C-calling convention
of the ’C2000 C environment, they cannot be used directly from C. The assem-
bly code of section A.2, C-Callable Interface to Flash Algorithms, is provided
as a C-callable interface to the programming algorithms. The following C
source file and linker command file provide a working example for the ’F206. In
this example, the algorithms reside in the on-chip SARAM, and either flash0 or
flash1 can be reprogrammed. The code can be relocated anywhere in pro-
gram space, with the exceptions described in section A.3, Using the Algo-
rithms With Assembly Code.
A.4.1 C Code That Calls the Interface to Flash Algorithms for TMS320F206
/***************************************************/
/* Filename: sample.c
*/
*/
*/
*/
*/
*/
/* Description: This is an example of how to
/* program the ’F2XX flash from C code.
/* The C–callable interface for the standard
/* flash algorithms is used. This interface is
/* defined in the file <flash.asm>, as two
/* C–callable functions: erase(), and program() */
/* At link time, this example must be combined */
/* with the code in <flash.asm> as well as with */
/* the object modules for the standard algos. */
/***************************************************/
/* This example is set up for the TMS320F206, */
/* and uses the SARAM as a buffer for programming */
/* data. The code first erases module1,
/* then programs the first three locations.
*/
*/
/***************************************************/
/* Rev1.0 10/97 RDP */
/***************************************************/
extern
extern
main()
{
int
int
erase();
program();
/* Declare external func for flash erase. */
/* Declare external func for flash programming. */
int *a;
if (erase(0xff00,0x4000,0x7fff))
{ /*Flash is erased, now let’s program it.*/
/* Init program buffer. */
a=(int *)0xC00; /*Use last 3K of SARAM for data buffer*/
a[0]=0x7A80;
a[1]=0x0FDF;
a[2]=0x7A80;
/*Program the flash from the buffer*/
if (program(0xff00,0xc00,0x4000,0x3))
{ /*Flash programmed ok.*/
while(1){} /*Spin here forever*/
}
else
Assembly Source Listings and Program Examples
A-37
PRELIMINARY
PRELIMINARY
Sample C Code to Erase and Reprogram the TMS320F206
{ /*Flash fails programming, EXIT*/
while(1){} /*Spin here forever*/
}
}
else
{ /*Flash fails erase, EXIT*/
while(1){} /*Spin here forever*/
}
}
A.4.2 Linker Command File for TMS320F206 Sample C Code
/*************************************************************************/
/* Filename: F206_SA.CMD */
/* Description: Linker command file for ’F206 example of on–chip flash */
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
programming from C code. This command file links the
example to addr 0x8000 of the on–chip SARAM so that
the debugger can be used to set breakpoints. Another
benefit of linking the example to SARAM is that the
C code can be modified to operate on either flash
module0, or module1, or both.
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
Notes:
1. This example expects the ’F206 SARAM to be
mapped in both data space and program space
(DON=PON=1).
2. The object modules for the standard flash algos
are expected to be in a subdirectory (ALGOS) of
the path of this file.
/**********************************************************************/
/* Rev1.0 10/97 RDP */
/**********************************************************************/
/************************Command Line Options**************************/
–cr
/*Use Ram init model.
*/
*/
*/
*/
–heap 0x0
–stack 0x96
–x
/*No heap needed for this example.
/*150–word stack is enough for this example.
/*Force rereading of libraries.
–l c:\dsptools\rts2xx.lib
–o sample_S.out
–m sample_S.map
/*****************************Input Files******************************/
sample.obj
flash.obj
algos\spgm20.obj
algos\sclr20.obj
algos\sera20.obj
algos\sflw20.obj
/*User C code with calls to erase() and program() */
/*C–callable interface to standard algorithms.
/*Standard Programming algorithms.
/*Standard Clear algorithm.
*/
*/
*/
*/
*/
*/
/*Standard Erase algorithm.
/*Standard Flash–write algorithm.
algos\sutils20.obj /*Subroutines used by standard algorithms.
/*****************************Memory Map*******************************/
MEMORY
{
PAGE 0: /*
PM – Program memory */
A-38
PRELIMINARY
PRELIMINARY
Sample C Code to Erase and Reprogram the TMS320F206
FLASH0: origin = 0x0000, length = 0x3fff
FLASH1: origin = 0x4000, length = 0x3fff
PSARAM: origin = 0x8000, length = 0x400 /*Use 1K of SARAM for PROGRAM*/
B0:
origin = 0xff00, length = 0x1ff
PAGE 1: /* DM – Data memory */
BLK_B2: origin = 0x60,
DSARAM: origin = 0xc00,
length = 0x20 /*BLOCK B2
length = 0xC00 /*Use 3K of SARAM for data */
/*DON=1*/
*/
EX1_DM: origin = 0x4000, length = 0x4000 /*External data RAM */
B1: origin = 0x300, length = 0x1ff /*B1 RAM (Used for algo vars )*/
}
/*************************Section Allocation***************************/
SECTIONS
{
.text
: {} > PSARAM PAGE 0
/* sample.c */
/*All these sections are for flash programming.*/
PRG_text : {} > PSARAM PAGE 0 /**erase() and program()*****/
/*****from flash.asm file****/
fl_prg
fl_clr
fl_ers
fl_wrt
DLY
REG
ARY
: {} > PSARAM PAGE 0 /**Programming Algorithm*****/
: {} > PSARAM PAGE 0 /******Clear Algorithm*******/
: {} > PSARAM PAGE 0 /******Erase Algorithm*******/
: {} > PSARAM PAGE 0 /****Flash–write Algorithm***/
: {} > PSARAM PAGE 0 /******Delay Subroutine******/
: {} > PSARAM PAGE 0 /*******Regs Subroutine******/
: {} > PSARAM PAGE 0 /******Array Subroutine******/
PRG_data : {} > B1 PAGE 1
/*Reserved in flash.asm for**/
/***flash algo variables.****/
/*Reserved in flash.asm for**/
/*parameter passing to algos*/
PRG_parm : {} > B1 PAGE 1
/*End of sections for flash programming.
*/
.bss
: {} > B1 PAGE 1
: {} > B1 PAGE 1
: {} > B1 PAGE 1
: {} > B1 PAGE 1
: {} > B1 PAGE 1
.cinit
.const
.data
.stack
/*C stack.
*/
}
Assembly Source Listings and Program Examples
A-39
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F240
A.5 Sample Assembly Code to Erase and Reprogram the TMS320F240
The algorithm files can be used from assembly in a straightforward manner. In
general, the algorithms can reside anywhere in program space. However, the
algorithms cannot be executed from the flash module that is being modified,
andthealgorithmsmustexecutewithzerowaitstates. Theassemblycodeand
linker command file in this section provide a working example for the ’F240.
Note:
This is not an actual application example since a boot mechanism is required
to load the external SRAM on powerup. This example uses the ’C2xx C-
source Debugger to download the code to the external SRAM. In addition,
no reset or interrupt vectors are initialized.
The system requirements are F240 EVM or target board with external pro-
gram space SRAM located at 0x8000 and a minumum of 1K words.
A.5.1 Assembly Code for TMS320F240
*************************************************************
* Filename: ASMEXA24.ASM
* Description:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* This file contains an example of how to erase
* and program the TMS320F240 flash from assembly
* code using the standard flash algorithm modules.
* The example erases the ’F240 flash
* modules, then programs the first three words.
* Since the standard flash algorithms are actually
* used to perform the various flash operations,
* they must must be combined with this code at
* link time.
*
* 03/25/98 Updated for inclusion in flash
*
technical reference.
*************************************************************
.title ”**Example of Using ’F2XX Flash Algorithms**”
A-40
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F240
;**Variables included from flash algorithms.
.include ”svar20.h”
.ref GCLR
.ref GPGMJ
.ref GERS
;Variable declarations
;References clear algo.
;References program algo.
;References erase algo.
;References flash–write algo.
.ref FLWS
;**Parameters used by flash algorithms.
.def PRG_bufaddr, PRG_paddr
.def PRG_length, PARMS
.def SEG_ST,SEG_END,PROTECT
;**F240 Register definitions
RTICR
WDCR
CKCR0
CKCR1
SYSSR
DP_PF1
.set 07027h
.set 07029h
.set 0702Bh
.set 0702Dh
.set 0701Ah
.set 224
;RTI Control Register
;WD Control Register
;Clock Control Register 0
;Clock Control Register 1
;System Module Status Register
;page 1 of peripheral file
;(7000h/80h)
*************************************************************
VARS: .usect ”PRG_data”,16;This is an uninitialized data
;section required by the standard*
*
;flash algos for temporary
;variables. Pointers to this
*
*
;space are hardcoded in SVAR20.H,*
;and variables are init’d at
;run time.
*
*
*************************************************************
PARMS: .usect ”PRG_parm”,10;This is an uninitialized data
;section that is used for
*
*
*
;temporary variables and for
;passing parameters to the flash *
;algorithms.
*************************************************************
PROTECT .set PARMS ;Segment enable bits.
**************************************************************
***** Parameters needed for Programming algorithm. ***
*
*
*************************************************************
PRG_bufaddr .set PARMS+1 ;Addr of buffer for pgm data. *
PRG_paddr
PRG_length
.set PARMS+2 ;1st flash addr to program. *
.set PARMS+3 ;Length of block to program. *
*************************************************************
***Parameters needed for CLEAR, ERASE, and FLW algorithms. **
*************************************************************
SEG_ST
SEG_END
.set PARMS+4 ;Segment start address.
.set PARMS+5 ;Segment end address.
*
*
*************************************************************
**** Other misc variables. ****
*************************************************************
ERS_COUNT .set PARMS+6 ;Used for erase fail count. *
*************************************************************
.text
*************************************************************
** First, initialize the key F240 registers for use with
** the EVM.
*
*
*************************************************************
Assembly Source Listings and Program Examples
A-41
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F240
F240INIT: ;Set Data Page pointer to page 1 of the
;peripheral frame
LDP#DP_PF1
;Page DP_PF1 includes WET through*
;EINT frames
;initialize WDT registers
SPLK #06Fh, WDCR ;clear WDFLAG, Disable WDT
;(if Vpp=5V), set WDT
;for 1 second overflow (max)
SPLK #07h, RTICR ;clear RTI Flag,
;set RTI for 1 second overflow
;(max)
;EVM 10–MHz oscillator settings.
;(XTAL2 open, OSCBYP_=GND)
SPLK #00B1h,CKCR1 ;CLKIN(OSC)=10MHz,
;Mult by 2, Div by 1.
SPLK #00C3h,CKCR0 ;CLKMD=PLL Enable,SYSCLK=CPUCLK/2
;Clear reset flag bits in SYSSR
;(PORRST, PLLRST, ILLRST, SWRST, WDRST)
LACL SYSSR
AND#00FFh
SACL SYSSR
;ACCL <= SYSSR
;Clear upper 8 bits of SYSSR
;Load new value into SYSSR
**********************************************************
** First, erase flash1 by invoking the clear and erase **
** algorithms.
** Note: Three parameters must be initialized before
** calling the algorithms.
**
**
**
**********************************************************
LDP #PARMS
SPLK #0,ERS_COUNT ;Set erase fail count to 0.
**********Put parameters where they belong.**********
SPLK #0ff00h,PROTECT
SPLK #00000h,SEG_ST
SPLK #03FFFh,SEG_END
***********First, clear flash ************
ers_loop:
CALL GCLR
LACL ERROR
;Clear flash.
;Check for CLEAR/ERASE error
;If error, then hard fail.
clrerr: BCND ers_error,neq
***********Next erase flash ************
CALL GERS
LACL ERROR
BCND depletion,neq
;Erase flash.
;Check for CLEAR/ERASE error
;If error, then try Flash–write.
;Else, no errors erasing.
B
ers_done
A-42
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F240
depletion:
ADD
LACL ERS_COUNT
;Get erase fail count.
;Increment fail count.
;Save new count.
;CHECK for max of 10.
;If ers_cout>10 then hard fail.
;Else, try to recover from
;depletion.
#1
SACL ERS_COUNT
SUB #10
BCND ers_error,GT
CALL FLWS
LACL ERROR
BCND ers_error,neq
;Check for FLASH–WRITE error.
;If couldn’t recover, then hard
;fail.
B
ers_loop
;Else, Try erase again.
ers_error:
**************************************************************
** If here, then an unrecoverable error occurred during
** erase.
**
**
** In an actual application, the system takes some action **
** to indicate that service is required. **
**************************************************************
B
ers_error
;Error while erasing.
ers_done:
**********************************************************
** If here, then flash is erased and ready to be
** reprogrammed.
** This is a good place in the example to set a
** breakpoint so that erasure can be verified (i.e.,
** all flash bits should be 1).
**
**
**
**
**
**********************************************************
**************************************************************
** At this point, an actual application fills a buffer with **
** the data to be programmed. To simulate this in the
** example, three DARAM locations are initialized.
**
**
**************************************************************
LAR
AR1, #0380h ;Using last 128 words of B1 DARAM
;as buffer.
*,AR1
MAR
SPLK #0AAAAh,*+
SPLK #05555h,*+
SPLK #0AAAAh,*
;Use dummy data for buffer.
Assembly Source Listings and Program Examples
A-43
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F240
**************************************************************
** Now that the data to be programmed is ready, the **
** programming algorithm is invoked. Note: Four parameters **
** must be initialized before calling the algorithm. **
**************************************************************
LDP #PARMS
**********Put parameters where they belong.**********
splk #0ff00h,PROTECT
splk #0380h,PRG_bufaddr
splk #00000h,PRG_paddr
splk #3,PRG_length
***********Next, program flash************
CALL GPGMJ
LACL ERROR
;Program flash from buffer.
;Check for program error.
BCND prg_error,neq;If error then clear ACC.
B
prg_done
;Else, No errors programming.
prg_error:
**********************************************************
** If here, then an error occurred during programming. **
** In an actual application, the system takes some
** action to indicate that service is required.
**
**
**********************************************************
B
prg_error
;Error while programming.
prg_done:
**********************************************************
** If here, then flash has been successfully programmed.*
**********************************************************
B
prg_done
;Done programming.
A-44
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F240
A.5.2 Linker Command File for TMS320F240 Sample Assembly Code
/************************************************************/
/* Filename: ASMEXA24.CMD
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
/* Description: Linker command file for ’F240 example of
/* on–chip flash programming from assembly. This command
/* file links the example to addr 0x8000 of the off–chip
/* pgm RAM, so that the debugger can be used to set
/* breakpoints.
/*
/*
/*
/*
Notes:
1. The object modules for the standard flash
algos are expected to be in a subdirectory
(ALGOS) of the path of this file.
/************************************************************/
/* Rev1.0 3/98 JGC */
/************************************************************/
/*******************Command Line Options*********************/
–e .text
–o asmexa24.out
–m asmexa24.map
/************************Input Files*************************/
asmexa24.obj
/*User assembly code that calls flash algos. */
algos\spgm20.obj
algos\sclr20.obj
algos\sera20.obj
algos\sflw20.obj
/*Standard Programming algorithm.
/*Standard Clear algorithm.
*/
*/
*/
*/
*/
/*Standard Erase algorithm.
/*Standard Flash–write algorithm.
algos\sutils20.obj /*Subroutines used by standard algorithms.
/************************Memory Map**************************/
MEMORY
{
PAGE 0: /* PM – Program memory
*/
FLASH0: origin = 0x0000, length = 0x4000
EXTRAM: origin = 0x8000, length = 0x400 /*Use 1K of Ext. RAM for PROGRAM*/
B0PGM: origin = 0xfe00, length = 0x100
PAGE 1:
BLK_B2: origin = 0x60, length = 0x20
/* DM – Data memory */
/* BLOCK B2*/
EX1_DM: origin = 0x8000, length = 0x4000 /* External data RAM */
B0:
B1:
origin = 0x200, length = 0x100
origin = 0x300, length = 0x100
/* B0 Ram (Used for temp data )*/
/* B1 Ram (Used for algo vars )*/
}
/*************************Section Allocation***************************/
SECTIONS
{
.text :{} > EXTRAM PAGE 0
/* asmexa24.asm */
Assembly Source Listings and Program Examples
A-45
PRELIMINARY
PRELIMINARY
Sample Assembly Code to Erase and Reprogram the TMS320F240
/*All these sections are for flash programming.*/
fl_prg
fl_clr
fl_ers
fl_wrt
DLY
REG
ARY
: {} > EXTRAM
: {} > EXTRAM
: {} > EXTRAM
: {} > EXTRAM
: {} > EXTRAM
: {} > EXTRAM
: {} > EXTRAM
PAGE 0 /**Programming Algorithm*****/
PAGE 0 /******Clear Algorithm*******/
PAGE 0 /******Erase Algorithm*******/
PAGE 0 /****Flash–write Algorithm***/
PAGE 0 /******Delay Subroutine******/
PAGE 0 /*******Regs Subroutine******/
PAGE 0 /******Array Subroutine******/
PAGE 1 /*Reserved in asmexamp.asm **/
/*for flash algo variables.**/
PRG_data : {} > B1
PRG_parm : {} > B1
PAGE 1 /*Reserved in asmexamp.asm **/
/*for param passing to algos*/
/*End of sections for flash programming.
*/
}
A-46
PRELIMINARY
PRELIMINARY
Using the Algorithms With C Code to Erase and Reprogram the ’F240
A.6 Using the Algorithms With C Code to Erase and Reprogram the ’F240
Because the algorithm implementations do not follow the C-calling convention
of the ’C2000 C environment, they cannot be used directly from C. The assem-
bly code of section A.2, C-Callable Interface to Flash Algorithms, is provided
as a C-callable interface to the programming algorithms. The C source file and
linker command file provide a working example for the ’F240.
In this example, the algorithms reside in external SRAM. The code can be relo-
cated anywhere in program space, with the exceptions described in section
A.3, Using the Algorithms With Assembly Code.
Note:
This is not an actual application example since a boot mechanism is required
to load the external SRAM on powerup. This example uses the ’C2xx C-
source Debugger to download the code to the external SRAM. In addition,
no reset or interrupt vectors are initialized.
The system requirements are F240 EVM or target board with external pro-
gram space SRAM located at 0x8000 and a minimum of 1K words.
A.6.1 C Code That Calls the Interface to Flash Algorithms for TMS320F240
/***********************************************/
/* Filname: sample24.c
/* Description: This is an example of how to
/* program the ’F2XX flash from C code.
/* The C–callable interface for the standard
/* flash algorithms is used. This interface is
/* defined in the file <flash.asm>, as two
*/
*/
*/
*/
*/
*/
/* C–callable functions: erase(), and program() */
/* At link time, this example must be combined */
/* with the code in <flash.asm> as well as with */
/* the object modules for the standard algos. */
/***************************************************/
/* This example is setup for the TMS320F240, */
/* and uses the B1 DARAM as a buffer for program– */
/* –ming data. The code first claers, erases,
/* then programs the first three locations.
*/
*/
/***************************************************/
/* Rev1.0 03/98 JGC */
/***************************************************/
Assembly Source Listings and Program Examples
A-47
PRELIMINARY
PRELIMINARY
Using the Algorithms With C Code to Erase and Reprogram the ’F240
extern int
extern int
extern c240init();
extern wdtoff();
main()
erase();
program();
/* Declare external func for flash erase. */
/* Declare external func for flash programming */
/* Declare external func for C240 register init’l’n */
/* Declare external func for wdt disable */
{
int *a;
asm(” CLRC CNF ”);
c240init();
wdtoff();
/* map B0 to data space */
/* initialize key ’240 registers */
/* disable WD timer (works when VCCP=5v) */
if (erase(0xff00,0x0000,0x3fff))
{ /*Flash is erased, now let’s program it.*/
/* Init program buffer. */
a=(int *)0x200;
a[0]=0x7A80;
a[1]=0x0FDF;
a[2]=0x7A80;
/*Use last 128 words of B1 DARAM for data buffer*/
/*Program the flash from the buffer*/
if (program(0xff00,0x200,0x0000,0x3))
{ /*Flash programmed ok.*/
while(1){} /*Spin here forever*/
}
else
{ /*Flash fails programming, EXIT*/
while(1){} /*Spin here forever*/
}
}
else
{ /*Flash fails erase, EXIT*/
while(1){} /*Spin here forever*/
}
}
A.6.2 Linker Command File for TMS320F240 Sample C Code
/**********************************************************************/
/* Filename: F240_EXT.CMD
*/
/* Description: Linker command file for ’F240 example of on–chip flash */
/*
/*
/*
/*
/*
/*
/*
programming from C–code. This command file links the
example to addr 0x8000 of the offchip SRAM, so that
the debugger can be used to set breakpoints.
Notes:
1. The object modules for the standard flash algos
are expected to be in a subdirectory (ALGOS) of
the path of this file.
*/
*/
*/
*/
*/
*/
*/
/**********************************************************************/
/* Rev1.0 03/98 JGC
*/
/**********************************************************************/
A-48
PRELIMINARY
PRELIMINARY
Using the Algorithms With C Code to Erase and Reprogram the ’F240
/************************Command Line Options**************************/
–cr
/*Use Ram init model.
/*No heap needed for this example.
/*150 word stack is enough for this example. */
/*Force re–reading of libraries. */
*/
*/
–heap 0x0
–stack 0x96
–x
–l c:\dsptools\fix\rts2xx.lib
–o sample24.out
–m sample24.map
/*****************************Input Files******************************/
sample24.obj
c240init.obj
wdtoff.obj
flash.obj
algos\spgm20.obj
algos\sclr20.obj
algos\sera20.obj
algos\sflw20.obj
/*User C–code with calls to erase() and program() */
/*C–callabe asm function to init ’240 regs
/*C–callable asm function to disable the wdt
/*C–callable interface to standard algorithms.
/*Standard Programming algorithms.
/*Standard Clear algorithm.
*/
*/
*/
*/
*/
*/
*/
*/
/*Standard Erase algorithm.
/*Standard Flash–write algorithm.
algos\sutils20.obj /*Subroutines used by standard algorithms.
/*****************************Memory Map*******************************/
MEMORY
{
PAGE 0: /* PM – Program memory */
FLASH0: origin = 0x0000, length = 0x4000
EXTRAM: origin = 0x8000, length = 0x400
B0: origin = 0xfe00, length = 0x100
/*Use 1K of EXT SRAM for PROGRAM*/
PAGE 1: /* DM – Data memory */
BLK_B2: origin = 0x60, length = 0x20
/*BLOCK B2
*/
DSRAM:
B0DAT:
origin = 0x8000, length = 0x4000 /*External data RAM */
origin = 0x200, length = 0x100
/*B0 RAM
*/
/*(Used for pgm data buffer)*/
/* B1 RAM (Used for algo vars )*/
B1:
origin = 0x300, length = 0x100
}
/*************************Section Allocation***************************/
SECTIONS
{
.text :{} > EXTRAM PAGE 0
/*All these sections are for flash programming.*/
PRG_text : {} > EXTRAM PAGE 0 /**erase() and program()*****/
/* sample.c */
/*****from flash.asm file****/
/**Programming Algorithm*****/
/******Clear Algorithm*******/
/******Erase Algorithm*******/
/****Flash–write Algorithm***/
/******Delay Subroutine******/
/*******Regs Subroutine******/
/******Array Subroutine******/
/*Reserved in flash.asm for**/
/***flash algo variables.****/
/*Reserved in flash.asm for**/
/*parameter passing to algos*/
fl_prg : {} > EXTRAM
fl_clr : {} > EXTRAM
fl_ers : {} > EXTRAM
fl_wrt : {} > EXTRAM
PAGE 0
PAGE 0
PAGE 0
PAGE 0
PAGE 0
PAGE 0
PAGE 0
PAGE 1
DLY
REG
ARY
: {} > EXTRAM
: {} > EXTRAM
: {} > EXTRAM
PRG_data : {} > B1
PRG_parm : {} > B1
PAGE 1
/*End of sections for flash programming.
*/
Assembly Source Listings and Program Examples
A-49
PRELIMINARY
PRELIMINARY
Using the Algorithms With C Code to Erase and Reprogram the ’F240
.bss
.cinit
.const
:{} > B1 PAGE 1
:{} > B1 PAGE 1
: load = EXTRAM PAGE 0, run = DSRAM PAGE 1
{
}
/* GET RUN ADDRESS */
__const_run = .;
/* MARK LOAD ADDRESS */
*(.c_mark)
/* ALLOCATE .const */
*(.const)
/* COMPUTE LENGTH */
__const_length = .– __const_run;
.data :{} > B1 PAGE 1
.stack :{} > B1 PAGE 1
/*C stack.
*/
}
A.6.3 C Function for Disabling TMS320F240 Watchdog Timer
***********************************************************************
* Watchdog Timer Disable function
* Arguments passed from Caller: None
*
*
*
* Local Variables:
None
***********************************************************************
SYSSR .set 0701Ah
WDCR .set 07029h
DP_PF1 .set 224
; System Module Status Register
; WDT Control reg
; 7000h/80h = 100h or 224
.globl _wdtoff
.text
.def _wdtoff
_wdtoff:
; presume ARP = AR1 (SP)
*****************************************************************************
* On entry, presume ARP = AR1 (SP)
*
* Step 1. Pop the return address off the h/w stack and push to s/w stack
*
*
*
*****************************************************************************
POPD *+
; pop return address, push on software stack
; ARP=AR1, SP=SP+1
*****************************************************************************
* Step 2. Push the frame pointer onto s/w stack
*
*****************************************************************************
SAR
AR0,*+
; push AR0 (FP) onto SP
; ARP=AR1, SP=SP+2
*****************************************************************************
* Step 3. Allocate the local frame
*
*****************************************************************************
SAR
LAR
LAR
AR1,*
AR0,#1
AR0,*0+
; *SP = FP
; FP = size of local frame, 1
; FP = SP, SP += size ==> allocate frame
*****************************************************************************
* Step 5. Begin code that will disable the WDT
*
*****************************************************************************
LDP#DP_PF1
LACL WDCR
; Page DP_PF1 includes WET through EINT frames
; ACC = WDTCR, watchdog timer control register
A-50
PRELIMINARY
PRELIMINARY
Using the Algorithms With C Code to Erase and Reprogram the ’F240
OR
#06fh
; set WDDIS bit and WDCHK2:0 bits, WDCLK to max.
; write ACC out to WDTCR
SACL WDCR
*****************************************************************************
* Step 9. Deallocate the local frame
*
*****************************************************************************
SBRK 1+1
; deallocate frame, point to saved FP
***************************************************************************
* Step 10. restore the frame pointer
*
*****************************************************************************
LAR AR0,*– ; pop FP
***************************************************************************
* Step 11. copy the return address from the s/w stack and push onto h/w *
*
stack
*
***************************************************************************
PSHD *
RET
; push return address on h/w stack
; return
.en
A.6.4 C Functions for Initializing the TMS320F240
***********************************************************************
* TMS320x240 Initialization Function
* Arguments passed from Caller: None
*
*
*
* Local Variables:
None
***********************************************************************
SYSSR
SYSCR
WDTCR
CKCR0
CKCR1
DP_PF1
.set 0701Ah
.set 07018h
.set 07029h
.set 0702ah
.set 0702ch
.set 224
;WD Control reg
;PLL Clock Control Register 0
;PLL Clock Control Register 1
.globl _c240init
.text
.def _c240init
_c240init:
; presume ARP = AR1 (SP)**
***************************************************************************
* On entry, presume ARP = AR1 (SP)
*
*
*
*
* Step 1. pop the return address off the h/w stack and push to s/w stack
*****************************************************************************
POPD *+
; pop return address, push on software stack
; ARP=AR1, SP=SP+1
*****************************************************************************
* Step 2. push the frame pointer onto s/w stack
*
*****************************************************************************
SAR AR0,*+
; push AR0 (FP) onto SP
; ARP=AR1, SP=SP+2
*****************************************************************************
* Step 3. Allocate the local frame
*
*****************************************************************************
SAR AR1,*
LAR AR0,#1
LAR AR0,*0+
; *SP = FP
; FP = size of local frame, 1
; FP = SP, SP += size ==> allocate frame
*****************************************************************************
Assembly Source Listings and Program Examples
A-51
PRELIMINARY
PRELIMINARY
Using the Algorithms With C Code to Erase and Reprogram the ’F240
* Step 5. begin code that will initialize the ’240 registers
*
*****************************************************************************
CLRC SXM
CLRC OVM
; Clear Sign Extension Mode
; Reset Overflow Mode
* Set Data Page pointer to page 1 of the peripheral frame
LDP#DP_PF1 ; Page DP_PF1 includes WET through EINT frames
* Clear system status register reset bits (PORRST, ILLADR, SWRST, & WDRST)
LACL #020h
SACL SYSSR
; load mask pattern to clear rst flags
; write ACC to SYSSR
* Set Watchdog timer period to 1 second
LACL #02Fh
SACL WDTCR
; set WDCHK2 & 0 bits, WDCLK divider to max (1s)
; write ACC out to WDTCR
* Configure PLL for 4–MHz xtal, 10–MHz SYSCLK, and 20–MHz CPUCLK
*
*
SPLK #00E4h,CKCR1 ;CLKIN(XTAL)=4 MHz,CPUCLK=20 MHz
SPLK #00C3h,CKCR0 ;CLKMD=PLL Enable,SYSCLK=CPUCLK/2
* Configure PLL for 10–MHz osc, 10–MHz SYSCLK, and 20–MHz CPUCLK
SPLK #00B1h,CKCR1 ;CLKIN(OSC)=10 MHz,CPUCLK=20 MHz
SPLK #00C3h,CKCR0 ;CLKMD=PLL Enable,SYSCLK=CPUCLK/2
* Set VCCAON bit and CLKSRC1:0; leave other bits at their reset values.
SPLK #40C8h,SYSCR ; SYSCR <= 40C8h
***************************************************************************
* Step 9. Deallocate the local frame
***************************************************************************
SBRK 1+1 ; deallocate frame, point to saved FP
***************************************************************************
* Step 10. restore the frame pointer
***************************************************************************
LAR AR0,*– ; pop FP
*
*
***************************************************************************
* Step 11. copy the return address from the s/w stack and push onto h/w *
* stack
*
***************************************************************************
PSHD *
RET
; push return address on h/w stack
; return
.en
A-52
PRELIMINARY
Index
block erase (flash erase) 1-2
boot loader code A-1
A
access modes
code for changing A-25
array access 2-5, 2-10, 2-11, 2-16, 3-8
register access 2-5, 2-10, 2-11, 3-11
C
C source listings
code that calls the interface to the algo-
rithms A-37, A-47
disabling TMS320F240 watchdog timer A-50
initializing the TMS320F240 A-51
interface to flash algorithms A-27
access–control register 2-5 to 2-7
modifying in TMS320F206 2-6
modifying in TMS320F24x 2-7
reading in TMS320F206 2-6
accessing the flash module 2-5
address complementing 3-11
C–callable interface to flash algorithms A-27
charge levels for progamming and erasing 2-4
charge margin. See margin
algorithms
erase 3-10 to 3-13
flash–write 3-14 to 3-18
in the overall flow 3-2
limiting number of bits to be programmed 2-13
programming 3-4 to 3-9
clear algorithm code (SCLR2x.ASM) A-5
clearing the array (clear operation) 2-14, 2-15
code origin for programming and erasing A-1
composition of flash module 1-3
applying a single erase pulse 3-11
applying a single flash–write pulse 3-15
applying a single program pulse 3-8
array protection 2-16
control registers
accessing 2-5
described 2-5 to 2-12
array segment locations 2-10
array size 1-3
D
data page pointer initialization A-2
array–access mode 2-5, 2-10, 2-11, 2-16, 3-8
See also register–access mode
data retention 1-2, 2-12
assembly source listings
delay, in software (code listing) A-25
algorithms, variables, and common subrou-
tines A-2 to A-26
depletion mode
described 2-15
sample code for TMS320F206 A-32 to A-35
sample code for TMS320F240 A-40 to A-44
inverse–erase read mode 2-12
test and detection 2-12, 2-14, 3-15
assistance from TI vii
devices with embedded flash EEPROM 1-3
B
E
basic concepts of flash memory 1-2
embedded versus discrete flash memory 1-5
benefits of flash EEPROM 1-1, 1-5
embedded flash memory described 1-1
Index-1
PRELIMINARY
PRELIMINARY
Index
erase algorithm
flash–write algorithm
assembly code (SERA2x.ASM) A-10
described 3-10 to 3-13
flow diagram 3-13
assembly code (SFLW2x.ASM) A-15
described 3-14
flow diagram 3-16
in overall flow 3-10
in overall flow 3-14
flash–write operation
described 1-2, 2-15
similarity to erase 2-15
erase() function (C code listing) A-27
erase operation
described 2-14
following flash–write operation 2-15
frequency range 3-12
logic levels 2-4
role of WDATA 2-11
VER1 read mode 2-12
verification of erased bits 2-12
worst–case voltage for reading erased cell 2-12
flash–write pulse 2-15, 3-14
frequency range
erasing 3-12
flash–write 3-17
programming 3-5
G
erase protection 3-11
erase pulse 2-14
global parameters in the calling code A-2
example for TMS320F206
assembly code A-32, A-40
C code that calls flash.asm A-37, A-47
linker command file A-35, A-38, A-45, A-48
H
header file for constants and variables
(SVAR2x.H) A-2
execute bit (EXE)
described 2-9
in mechanism for array protection 2-16
location in SEG_CTR register 2-8
relation to erase pulse 2-14
relation to flash–write pulse 2-15, 3-14
relation to program pulse 2-13
role in single erase pulse 3-11
role in single flash–write pulse 3-15
role in single program pulse 3-9
I
IN instruction 2-7
inverse–erase read mode 2-12, 2-15, 3-15
K
KEY1, KEY0 bits
execute key bits (KEY1, KEY0)
described 2-9
described 2-9
in mechanism for array protection 2-16
location in SEG_CTR register 2-8
role in single erase pulse 3-11
role in single flash–write pulse 3-15
role in single program pulse 3-9
in mechanism for array protection 2-16
location in SEG_CTR register 2-8
role in single erase pulse 3-11
role in single flash–write pulse 3-15
role in single program pulse 3-9
extending a read 3-5, 3-17
L
limited number of bits programmed at one
time 2-13
F
linker command files
for TMS320F206 sample assembly code A-35
for TMS320F206 sample C code A-38
for TMS320F240 sample assembly code A-45
for TMS320F240 sample C code A-48
flash memory size 1-3
flash module 1-3
flash operation (block operation) 1-2
Index-2
PRELIMINARY
PRELIMINARY
Index
described 3-4 to 3-9
flow diagram 3-6
in overall flow 3-4
M
margin
versus clear algorithm 3-2
determining 3-5, 3-11
programming the flash memory. See program opera-
tion
ensuring data retention 1-2
improving 3-12
protection from unintentional erasure 2-16, 3-11
in programming 2-13
restoring after flash–write operation 2-15
special read modes for ensuring 2-12
R
masking data in program operation 3-8
memory maps 1-4
read mode, standard 2-12
MODE bit 2-6
read modes 2-12
See also flash access–control register
reading from the array 2-16
recovery from over–erasure 2-15
mode selection for access 2-6
modifying the array contents 2-2, 2-16
module–control register 2-8
register–access mode 2-5, 2-10, 2-11
See also array–access mode
multiple reads at same location 3-5, 3-17
related documentation
v
reprogrammability 1-1, 2-14, 2-15, A-1
reserving space for code A-2
N
retention of data. See data retention
notational conventions iv
S
O
SCLR2x.ASM file A-5
OUT instruction 2-7
segment control register (SEG_CTR) 2-8
described 2-8
over–erasure 2-14, 2-15, 3-14
in erase operation 2-14
in flash–write operation 2-15
in mechanism for array protection 2-16
in mode selection 2-6
P
program operation
in program operation 2-13
described 2-13
frequency range 3-5
relation to flash–write pulse 3-14
role in single erase pulse 3-11
role in single flash–write pulse 3-15
role in single program pulse 3-8
latching the write address 2-10
latching the write data 2-11
logic levels 2-4
masking off upper or lower bits 2-13
specifying write address 2-13
VER0 read mode 2-13
verification of programmed bits 2-12
worst–case voltage for reading programmed
cell 2-12
segment enable bits (SEG0–SEG7)
described 2-9
in mechanism for array protection 2-16
location in SEG_CTR register 2-8
role in single erase pulse 3-11
role in single flash–write pulse 3-15
role in single program pulse 3-8
program pulse
segment locations in array 2-10
applying a series 3-8
defined 2-13
SERA2x.ASM file (erase algorithm code) A-10
SFLW2x.ASM file (flash–write algorithm code A-15
space for code A-2
program() function (code listing) A-27
programming algorithm
assembly code (SPGM2x.ASM) A-19
SPGM2x.ASM file (program algorithm code) A-19
Index-3
PRELIMINARY
PRELIMINARY
Index
subroutines used by all algorithms (SU-
TILS2x.ASM) A-25
verify bits (VER1, VER0)
described 2-9
location in SEG_CTR register 2-8
SUTILS2x.ASM file (code for subroutines) A-25
voltage level for standard read 2-12
SVAR2x.H file (header file for constants and vari-
ables) A-2
W
T
web page iii
worst–case voltage for reading erased cell 2-12
test register (TST) 2-6, 2-8, 2-10
worst–case voltage for reading programmed
cell 2-12
U
write address register (WADRS) 2-10
described 2-8
uniformity of charge 3-5, 3-9
in mode selection 2-6
in program operation 2-13
role in single program pulse 3-8
unintentional erasure, protection 2-16
using the algorithms with assembly code A-32,
A-40
write data register (WDATA) 2-11
described 2-8
using the algorithms with C code A-37, A-47
in mechanism for array protection 2-16
in mode selection 2-6
in program operation 2-13
role in single erase pulse 3-11
role in single program pulse 3-8, 3-9
V
variable CPU clock rate 3-5, 3-12, 3-17
variable declaration file. See header file for
constants and variables (SVAR2x.H)
WRITE/ERASE field
described 2-9, 3-8
VCCP pin 2-16, 3-8, 3-11, 3-15
VER0 read mode 2-12, 2-13, 3-8, 3-9
VER1 read mode 2-12, 2-15, 3-11
location in SEG_CTR register 2-8
role in single erase pulse 3-11
role in single flash–write pulse 3-15
Index-4
PRELIMINARY
|