Texas Instruments MSP430x1xx User Manual

Page 435

Advertising
background image

Flash Memory Access via JTAG and Software

C-23

Flash Memory

C.5.3.1 Example: Programming One Word Into a Flash Memory Module via Software

Execution Outside this Module

This example assumes that the code to program the flash location is not
executed from the target flash memory module.

BUSY = 1

yes

yes

no

no

BUSY = 1

Lock = 1

Lock = 0, WRT = 1

Write Data to Flash Address

Disable all Interrupt Sources

and Watchdog

Restore or Enable Required

Interrupt Sources and Watchdog

Fxkey .set 03300h
Fwkey .set 0A500h

; No interrupt request may happen while the flash is programmed

Test_Busy1

BIT

#BUSY,&FCTL3

JNZ

Test_Busy1

MOV

#Fwkey,&FCTL3

: Clear lock bit

MOV

#(Fwkey+WRT),&FCTL1: : Enable write to flash

MOV

#123h,&0FF1Eh

: Write a word to flash

Test_Busy2

BIT

#BUSY,&FCTL3

; still busy?

JNZ

Test_Busy2

; yes, repeat busy test

MOV

#Fwkey,&FCTL1

: Reset write bit

XOR

#(Fxkey+Lock),&FCTL3

: Change lock bit to 1

; Enable those interrupt sources that should be accepted

The BUSY bit can be tested before the write to the flash memory module is
done, or after a write (program) starts:

-

For flash memory locations that hold data, it is a good practice to test the
BUSY bit before the write is executed. This has some time benefits, since
the write process is executed via the flash memory timing generator with-
out further CPU intervention. It is important that the clock source remains
active until BUSY is reset by the flash memory hardware.

The power or clock management, responsible for entering low-power
modes, has to make sure that it does not switch off the clock source used
by the flash controller.

-

For flash memory blocks that hold program code, it is a good practice to
test the BUSY bit after the write is executed. The program can only pro-
ceed if the module can be accessed again. No special attention is needed
during execution of software code. Every write to the flash memory mod-
ule has to leave the programming cycle with the BUSY bit reset.

Testing the BUSY bit before writing to a flash memory block that holds pro-
gram code ensures that the active program will not access the flash
memory module. Two types of access are visible: execute program code,
or read and write data on this flash memory module.

Advertising