AN2183 Freescale Semiconductor / Motorola, AN2183 Datasheet

no-image

AN2183

Manufacturer Part Number
AN2183
Description
Using FLASH as EEPROM on the MC68HC908GP32
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Semiconductor Products Sector
Application Note
Using FLASH as EEPROM on the MC68HC908GP32
By Derrick H.J. Klotz
Introduction
Order this document
by AN2183/D
Field Applications Engineer
Toronto, Canada
This application note describes a method for using the on-chip FLASH
memory of the MC68HC908GP32 as one would typically use EEPROM
(electrically erasable programmable read-only memory). For the
purposes of this application note, the FLASH memory that is
manipulated via this method is referred to as "FlashEE." It is expected
that the reader is somewhat familiar with the
MC68HC908GP32/08GP32 Technical Data book, Motorola document
order number MC68HC908GP32/H, as well as typical EEPROM device
usage.
In many projects, EEPROMs are used as nonvolatile storage for
calibration data, control information, data logging, etc. The FLASH
memory technology employed in the M68HC908 Family of
microcontrollers (MCU) is capable of being reprogrammed easily while
the application software is executing. Project cost savings can be
realized by simply using an appropriate section of the on-chip FLASH
memory as one would use an off-chip EEPROM device.
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
TM
© Motorola, Inc., 2001
AN2183

Related parts for AN2183

AN2183 Summary of contents

Page 1

... Freescale Semiconductor, Inc. Order this document by AN2183/D Semiconductor Products Sector Application Note Using FLASH as EEPROM on the MC68HC908GP32 By Derrick H.J. Klotz Field Applications Engineer Toronto, Canada Introduction This application note describes a method for using the on-chip FLASH memory of the MC68HC908GP32 as one would typically use EEPROM (electrically erasable programmable read-only memory) ...

Page 2

... FlashEE space when there is no more room for the next data block. Each FLASH erase page consists of two program rows. The FLASH erase page size for the MC68HC908GP32 is 128 bytes. 2 For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 3

... FlashEE sections, each occupying one FLASH erase page (i.e., 128 bytes on the MC68HC908GP32). If multiple FlashEE sections are used, they must be manipulated separately. This is demonstrated with the test program provided. AN2183 MOTOROLA For More Information On This Product, FlashEE data is written in blocks of multiple bytes. ...

Page 4

... Figure 1 — FlashEE subroutine operational parameter flashee.equ definitions — FlashEE subroutines flashee.asm — FlashEE test program eetest.asm — MC68HC908GP32 microcontroller definitions gp32.equ For More Information On This Product, Go to: www.freescale.com that demonstrate that neither five nor MOTOROLA AN2183 ...

Page 5

... FlashEE1 FlashEE2 8080 8100 FLASH MEMORY 32,256 BYTES FE00 CONTROL REGISTERS AND MONITOR ROM FFDC VECTORS FFFF Figure 1. MC68HC908GP32 Memory Map and FlashEE Implementation AN2183 MOTOROLA For More Information On This Product, FlashEE1 8000 12 8040 34 8041 8001 8002 56 8042 RAM 8003 ...

Page 6

... The size of each FlashEE data block is also defined. Note that each FlashEE section can have its own unique data block size. 6 Microcontroller FLASH memory parameters FlashEE data parameters Microcontroller bus frequency parameters equ 128 equ 64 equ $FF For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 7

... This file contains the FlashEE subroutine source code and must be included in the application program file. These subroutines only use local variables on the stack and, hence, do not require any other predefined global variable space resources. The maximum available stack space AN2183 MOTOROLA For More Information On This Product, equ ...

Page 8

... RAM, all interrupts are disabled. 8 Figure 3 EERead — Read the current valid FlashEE data block EEErase — Erase an entire FlashEE section EEWrite — Write a new FlashEE data block subroutine in the eetest.asm. This Check_Read For More Information On This Product, Go to: www.freescale.com through Figure 8. AN2183 MOTOROLA ...

Page 9

... The serial bit rate is configured for 115.2 kbaud. The software implements four single ASCII character commands (case insensitive) and provides the ability to test and interrogate two separate AN2183 MOTOROLA For More Information On This Product, gp32.equ Go to: www ...

Page 10

... Continuing with this method, the demo program provided was used to test and verify the correct operation of the FlashEE subroutines — Read FlashEE E — Erase FlashEE W — Write FlashEE D — Dump FlashEE For More Information On This Product, Go to: www.freescale.com Figure 2. The AN2183 MOTOROLA ...

Page 11

... Erase FlashEE (E) This command will directly execute the EEErase subroutine and erase the selected FlashEE section. AN2183 MOTOROLA For More Information On This Product, FlashEE> ...

Page 12

... EEPROM devices. A method for using the on-chip FLASH memory for such application purposes has been demonstrated with this application note. 12 For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 13

... READ FlashEE (’R’) COMMAND? N ERASE FlashEE (’E’) COMMAND? N WRITE FlashEE (’W’) COMMAND? N DUMP FlashEE (’D’) COMMAND? N Figure 3. eetest.asm Software Flow Diagram AN2183 MOTOROLA For More Information On This Product, PERFORM Y READ FlashEE PROCESS PERFORM Y ERASE FlashEE PROCESS PERFORM Y ...

Page 14

... IS FIRST LOCATION OF SECOND ROW ERASED? N PERFORM FIND FIRST ERASED FLASH LOCATION PROCESS ADJUST LOCATION POINTER BACK ONE DATA BLOCK SIZE RETURN WITH FIRST DATA BYTE FROM BLOCK For More Information On This Product, Go to: www.freescale.com Y RESTORE PREVIOUS LOCATION POINTER EXIT PROCESS MOTOROLA AN2183 ...

Page 15

... Freescale Semiconductor, Inc. PERFORM ERASE FlashEE PROCESS EXECUTE ERASE FLASH ROUTINE IN RAM Figure 5. Erase FlashEE Software Flow Diagrams AN2183 MOTOROLA For More Information On This Product, COPY ERASE FLASH ROUTINE ONTO STACK SAVE CONDITION CODE REGISTER AND DISABLE INTERRUPTS EXECUTE ERASE FLASH ROUTINE ...

Page 16

... For More Information On This Product, Go to: www.freescale.com COPY PROGRAM FLASH ROUTINE ONTO STACK PREPARE SOURCE AND DESTINATION POINTERS PREPARE BLOCK SIZE COUNTER SAVE CONDITION CODE REGISTER AND DISABLEINTERRUPTS EXECUTE PROGRAM FLASH ROUTINE IN RAM RESTORE EXIT CONDITION CODE REGISTER PROCESS AN2183 MOTOROLA ...

Page 17

... Freescale Semiconductor, Inc. EXECUTE PROGRAM FLASH ROUTINE IN RAM Figure 7. Write FlashEE RAM Routine Software Flow Diagram AN2183 MOTOROLA For More Information On This Product, SET PGM BIT IN FLCR, READ FLBPR AND WRITE TO POINTED PAGE WAIT > SET HVEN BIT IN FLCR AND WAIT > ...

Page 18

... Figure 8. Find First Erased FlashEE Data Block Software Flow Diagram 18 INITIALIZE BLOCK COUNTER IS CURRENT Y LOCATION ERASED? N SUBTRACT BLOCK SIZE FROM BLOCK COUNTER IS BLOCK Y COUNTER NEGATIVE? N ADVANCE LOCATION POINTER For More Information On This Product, Go to: www.freescale.com RETURN WITH EXIT BLOCK COUNTER PROCESS AN2183 MOTOROLA ...

Page 19

... Motorola products are not designed, intended, or authorized for AN2183 MOTOROLA For More Information On This Product, Current Release Level: Classification: : MC68HC908GP32 MCU definitions ...

Page 20

... FlashEE *********************************************** ((N x bus clock 10us -> ((10us x 7372800 - 2 -> (( 7372800 ; 5us delay parameter ; 10us delay parameter ; 30us delay parameter ; 50us delay parameter For More Information On This Product, Go to: www.freescale.com * * * * * * * * * * * * * Each must be less than or For other = 23 10us AN2183 MOTOROLA ...

Page 21

... EERead : returns with H:X pointing to first FlashEE data block entry ;* EEWrite : programs FlashEE with data block pointed to by H:X ;* EEErase : erases entire FlashEE space pointed to by H:X ;* AN2183 MOTOROLA For More Information On This Product, Current Release Level: Classification: : MC68HC908GP32 MCU definitions : FlashEE parameters Version: ...

Page 22

... For More Information On This Product, Go to: www.freescale.com Motorola does not assume any If the next available AN2183 MOTOROLA * * * * * * * ...

Page 23

... Set ERASE, read the Flash Block Protect Register and write any data into Flash page. ; lda #{ERASE} sta flcr lda flbpr sta ,x ; AN2183 MOTOROLA For More Information On This Product, ; save current address lsb ; restore FlashEE address lsb ; H:X now points to second program row ; save previous address lsb on stack ; check if first location ; is erased ; skip if so ...

Page 24

... ERASE control bits ; in Flash Control Register ; wait ; for 5us ; clear HVEN control bit ; in Flash Control Register ; retreive previous CCR ; wait for at least 1us before ; returning ========================================================== ; save pointer ; on stack ; initialize pointer For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 25

... EEFindFirst1 AN2183 MOTOROLA For More Information On This Product, ; get program from Flash ; copy into Stack ; decrement pointer and loop back until done ; use H:X to point to RAM executable routine ; get CCR ; disable all interrupts ; erase Flash page ...

Page 26

... FlashEE row address lsb ; get first FlashEE ; row address ; msb ; H:X now points to second program row ; get FlashEE data block size ; go find next free location ; check if there’s room for another data block ; continue if so For More Information On This Product, Go to: www.freescale.com The AN2183 MOTOROLA ...

Page 27

... This subroutine controls the FlashEE block programming sequence. ;* This subroutine is copied into and executed from RAM called via "jsr ,x". ;* AN2183 MOTOROLA For More Information On This Product, ; get first FlashEE row address lsb ; get first FlashEE ; row address ; msb ...

Page 28

... Flash ; advance the destination address lsb ; skip if no overflow ; else, advance the destination address msb ; advance the source address lsb ; skip if no overflow ; else, advance the source address msb For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 29

... Step 5: ; Clear HVEN, wait >1us and return. ; clra sta flcr pula brn * rts RamWriteSize: equ {*-RamWriteEE} AN2183 MOTOROLA For More Information On This Product, ; wait ; for a total of 30us ; clear PGM control bit ; in Flash Control Register ; wait ; for 5us ; clear HVEN control bit ; ...

Page 30

... Current Release Level: Classification: : MC68HC908GP32 MCU definitions : FlashEE parameters : FlashEE routines Version: Rev 3 Description of Change ----------------------------------------------------------- Initial release. For More Information On This Product, Go to: www.freescale.com Copyright (c) Motorola, 2001 1.0 ES 3.16 Motorola does not assume any AN2183 MOTOROLA * * * * * * * * * * * * * * * ...

Page 31

... Initialize the CGM for 7.3728 MHz bus speed from 32.768 kHz crystal. ; ldhx #bus7372800 jsr PLLset AN2183 MOTOROLA For More Information On This Product, ; enable simulation situational assembly ***************************************************** ; include microcontroller definitions file ; initial Configuration Register 2 ; initial Configuration Register 1 ; initialize stack pointer to last RAM location ...

Page 32

... Read command ; skip if not ; get a character from the SCI ; echo character back ; check if target is 1st FlashEE ; continue check if target is 2nd FlashEE ; continue else, respond to unknown command For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 33

... PrintString bra main ; ; ; Check for Write command and execute. ; AN2183 MOTOROLA For More Information On This Product, ; point to start of 1st FlashEE ; get 1st FlashEE data block size ; continue ; point to start of 2nd FlashEE ; get 2nd FlashEE data block size ; save FlashEE data block size on stack ...

Page 34

... Dump command ; skip if not ; get a character from the SCI ; echo character back ; check if target is 1st FlashEE ; continue check if target is 2nd FlashEE ; continue else, respond to unknown command For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 35

... FlashEE erased’,0 msg_what: db ’ - what?’,0 msg_CRLF: db ascii_CR,ascii_LF,0 AN2183 MOTOROLA For More Information On This Product, ; point to start of 1st FlashEE ; continue ; point to start of 2nd FlashEE ; initialize ; line counter ; perform ; 16-bit subtraction ; in order to adjust ; FlashEE pointer ...

Page 36

... SCI transmitter is empty ; output character to the SCI ; return No error checking is performed. ; get a character from the SCI For More Information On This Product, Go to: www.freescale.com Note that this AN2183 MOTOROLA ...

Page 37

... PutChar bsr IsHex bne GetHexByte2 bsr ToHex nsa psha AN2183 MOTOROLA For More Information On This Product, ; clear the COP counter ; wait forever until SCI receiver is full ; get data ; return ; save ACC temporarily ; move upper nibble down ; convert it to ASCII ; output it ...

Page 38

... For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 39

... AUTO,pbwc bset PLLON,pctl AN2183 MOTOROLA For More Information On This Product, Otherwise, CCRZ check value against ’0’ ; not hex if lower ; check value against ’9’ hex if lower ; check value against ’A’ ; not hex if lower ...

Page 40

... SCI Baud Rate Register = 9600 ; LCD 100us delay parameter ; include FlashEE routines ********************************************************* ; Timebase vector ; ADC vector ; Keyboard vector ; SCI transmit vector ; SCI receive vector ; SCI error vector ; SPI transmit vector ; SPI receive vector ; Timer 2 overflow vector For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 41

... Dummy org vec_swi dw Dummy org vec_reset dw Start end AN2183 MOTOROLA For More Information On This Product, ; Timer 2 channel 1 vector ; Timer 2 channel 0 vector ; Timer 1 oveflow vector ; Timer 1 channel 1 vector ; Timer 1 channel 0 vector ; PLL vector ; IRQ vector ; SWI vector ; Reset vector Go to: www.freescale.com Application Note eetest ...

Page 42

... Motorola and the Motorola logo are registered trademarks of Motorola Ltd. ;* ;******************************************************************************************** 42 Copyright (c) Derrick HJ Klotz, 2001 Current Release Level: Classification: Version: Rev 3 Microcontroller Technical Data Location: Description of Change Initial release. For More Information On This Product, Go to: www.freescale.com * * * * * 1 3. TOR * * * * * * * * * * * * * * * * * * * * * * * * * * * AN2183 MOTOROLA ...

Page 43

... CPHA: equ 3 SPWOM: equ 2 SPE: equ 1 SPTIE: equ 0 ; AN2183 MOTOROLA For More Information On This Product, ; start of RAM ; last RAM location ; start of ROM ; last ROM location ; Timebase vector ; ADC vector ; Keyboard vector ; SCI transmit vector ; SCI receive vector ; SCI error vector ; SPI transmit vector ...

Page 44

... SCI Status Register 1 ; SCI transmitter empty bit ; transmission complete bit ; SCI receiver full bit ; receiver idle bit ; receiver overrun bit ; receiver noise flag bit ; receiver framing error bit ; receiver parity error bit For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 45

... Configuration Registers (CONFIG) *********************************************************** ;* config2: equ $1E config1: equ $1F AN2183 MOTOROLA For More Information On This Product, ; SCI Status Register 2 ; break flag bit ; reception in progress flag bit ; SCI Data Register ; SCI Baud Rate Register ; Keyboard Status and Control Register ; keyboard flag bit ; keyboard acknowledge bit ...

Page 46

... PLL Bandwidth Control Register ; automatic bandwidth control bit ; lock indicator bit ; acquisition mode bit ; PLL Multiplier Select High Register ; PLL Multiplier Select Low Register ; PLL VCO Select Range Register ; PLL Reference Divider Select Register For More Information On This Product, Go to: www.freescale.com AN2183 MOTOROLA ...

Page 47

... MASS: equ %00000100 ERASE: equ %00000010 PGM: equ %00000001 ; flbpr: equ $FF7E AN2183 MOTOROLA For More Information On This Product, ; ADC Status and Control Register ; conversions complete flag ; ADC interrupt enable bit ; ADC continuous conversion bit ; \ ; \ ; ADC channel select bits ; / ; / ...

Page 48

... Break Status and Control Register ; break enable bit ; break active bit ; LVI Status Register ; LVI output bit ; COP Control Register are registered trademarks of Motorola, Inc. Motorola, Inc Equal Opportunity/Affirmative Action Employer. For More Information On This Product, Go to: www.freescale.com © Motorola, Inc., 2001 AN2183/D ...

Related keywords