Embedding Flash Programming Into TMS320LF240x Applications: Rev 1.3 23 Jan 2002 1
Embedding Flash Programming Into TMS320LF240x Applications: Rev 1.3 23 Jan 2002 1
ABSTRACT
allowing customization of the functionality of the device in system. This can enable field
programming must be integrated into the end application. To accelerate this process TI
has implemented an API based interface to the flash programming algorithms. This
document describes these algorithms and how to integrate these into your TMS320LF240x
Application.
1 Introduction .................................................................................................................................. 3
1.1 Why embed flash programming into the application ?............................................................. 3
1.2 Flash API ................................................................................................................................ 3
2 Working with the Flash API ......................................................................................................... 4
2.1 Clock Rate Configuration ........................................................................................................ 4
2.2 Run Time Considerations ....................................................................................................... 5
2.3 Programming Voltage Supply ................................................................................................. 5
2.4 Linker Command File Sections ............................................................................................... 5
2.5 Overlaid linker command file allocation................................................................................... 9
2.6 Device Type setting ................................................................................................................ 9
3 API Reference ...............................................................................................................................9
3.1 List of Functions implemented by the API ............................................................................... 9
3.2 CLEAR ................................................................................................................................. 11
3.3 ERASE ................................................................................................................................. 16
3.4 PROGRAM ........................................................................................................................... 21
3.5 COPY ................................................................................................................................... 26
Figures
Flash API
Flash Algorithms
Flash Control Registers
Flash Memory Core
This helps abstraction of the flash memory details from the application, and leads to better
organization of the system. TI provides flash algorithms for performing the operations such as
Clear, Erase, and Program on the LF240x Controllers. Using TI supplied algorithms allows you to
focus on your application, and frees up developer time to concentrate on your value proposition.
The flash API has been written to be easy to integrate into client applications. This means that
you are freed up from managing complex timing requirements and verification levels, to focus on
getting your application done faster.
Step 1 is used only by the JTAG based front-end programs to set the PLL pre-scalar. This does
not actually get used in the embedded algorithms. However the CPU clock speed combination,
so that the final clock speed at which your system runs must be determined from the (known)
input clock speed and the PLL multiplier put in by the system boot function.
The linker command file shown in Figure 2 does not overlay these algorithms in RAM. This
allows the ENTIRE flash array to be cleared and erased, without requiring a sector to remain un-
modified. To reduce the RAM usage, the algorithms can be overlaid in memory, and this is
discussed in section 2.5. It may be noted that this RAM is used only during programming, that is,
it is free for other usage at runtime, when the flash is not being programmed. However if it
contains data, this data must be expendable, for it will be trashed with the flash algos are copied
into RAM.
'LF2401A LF2401A
'LF2407 LF2407
'LF2407A LF2407
'LF2406 LF2407
'LF2406A LF2407
'LF2402 LF2407
'LF2402A LF2407
'LF2403A LF2407
2. Set the device type setting. (Change ONLY the DEV_TYPE setting line.)
DEV_TYPE .set LF2401A
3 API Reference
This section describes the API interface to the flash programming algorithms and utility functions.
Description
The Clear functions pre-conditions the flash sector(s) in preparation for the erase.
SECTOR_CMD ALGO_STATUS
Clear
Availability
Module Properties
Outputs
0x000a: The algo was called with a zero sector mask, i.e. the
algo was asked to clear ‘no sectors’.
Variable Declaration:
In the system file include the following statements:
.include var.h
Memory map:
All variables are mapped to a named section ‘.flshvar’
Code is mapped into the CLR_text and CSPL_text sections.
Special Variables
.globl flashAlgoVars
flshvar .struct
ADDR .int
PAD .int
READ .int
Example code:
Outputs
0x000a: The algo was called with a zero sector mask, i.e. the
algo was asked to clear ‘no sectors’.
Module Usage
Structure Reference
extern FlashAlgoVars flashAlgoVars;
Calling the Clear function
The following example calls the clear algo:
Description
SECTOR_CMD ALGO_STATUS
Erase
Availability
Module Properties
0x000a: The algo was called with a zero sector mask, i.e. the
algo was asked to erase ‘no sectors’.
Variable Declaration:
In the system file include the following statements:
.include var.h
Memory map:
All variables are mapped to a named section ‘.flshvar’
Code is mapped into the ERA_text and ESPL_text sections.
Special Variables
.globl flashAlgoVars
flshvar .struct
ADDR .int
PAD .int
READ .int
DATA .int
PAD1 .int
PLS_CNT .int
Example code:
0x000a: The algo was called with a zero sector mask, i.e. the
algo was asked to erase ‘no sectors’.
Module Usage
Structure Reference
extern FlashAlgoVars flashAlgoVars;
Calling the Erase function
The following example calls the erase algo:
flashAlgoVars.SECTOR_CMD=(0xf);
if(0 != flashAlgoVars.ALGO_STATUS)
{
/* Handle failure */
}
Description
DATA_PTR
SECTOR_CMD ALGO_STATUS
NumWords Program
(FL_SECEND)
ADDR
Availability
Module Properties
Variable Declaration:
In the system file include the following statements:
.include var.h
Memory map:
All variables are mapped to a named section ‘.flshvar’
Code is mapped into the PGM_text and PSPL_text sections.
Special Variables
.globl flashAlgoVars
Thus the flashAlgoVars is instanced and assigned the characteristics of flshvar structure.
Example code:
Module Usage
Structure Reference
extern FlashAlgoVars flashAlgoVars;
Calling the Program function
The following example calls the program algo:
flashAlgoVars.SECTOR_CMD=(SECTOR1+SECTOR2+SECTOR3);
flashAlgoVars.FL_SECEND=0x4;
/* Block address */
flashAlgoVars.ADDR=0x1023;
programFlash(&flashAlgoVars);
Description
Copies the flash algorithms into RAM at runtime from their load addresses.
This module is implemented as four separate function calls. Each of these calls copies the clear, erase, program and kernel
routines into the RAM block specified by the ‘run’ addresses from the load address.
Availability
Module Properties
Variable Declaration:
In the system file include the following statements:
.include var.h
Memory map:
Special Variables
;-----------------------------------------------------------
; Define a template to put the counter variables in the
; flashAlgoVars block. This is unused at the time the
; copy is invoked, so the flashAlgoVars are not
; subject to trashing (since they are not yet created).
;-----------------------------------------------------------
counterStruct .struct
source .int
dest .int
counter .int
temp .int
counter_len .endstruct
;------------------------------------------------------------
; Assign template to the flashAlgoVars block.
;------------------------------------------------------------
flashAlgoVars .tag counterStruct
Thus the flashAlgoVars is instanced and assigned the characteristics of flshvar structure.
(The copy algo actually assigns the flashAlgoVars structure a private template and uses these locations as
variables to complete the copy)
Example code:
CALL COPY_CLEAR_ALGO
CALL COPY_ERASE_ALGO
CALL COPY_PROGRAM_ALGO
CALL COPY_KERNEL
The COPY module doesn’t define a C structure for the flashAlgoVars. It is entirely implemented in assembly and
the caller does not need to pass the copy routines any parameters. See the section on the linker command file for
details on how the copy routine finds the algos and run addresses.
Module Usage
Calling the copy functions
The following example copies and calls the clear and erase algorithms:
copyClearAlgo();
flashAlgoVars.SECTOR_CMD=(SECTOR1+SECTOR2+SECTOR3);
clearFlash(&flashAlgoVars);
copyEraseAlgo();
flashAlgoVars.SECTOR_CMD=(SECTOR1+SECTOR2+SECTOR3);
eraseFlash(&flashAlgoVars);