AN2504 Freescale Semiconductor / Motorola, AN2504 Datasheet

no-image

AN2504

Manufacturer Part Number
AN2504
Description
On-Chip FLASH Programming API for CodeWarrior Software
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Application Note
AN2504/D
10/2003
On-Chip FLASH
Programming API for
CodeWarrior Software
By Mauricio Capistrán-Garza
Introduction
Application Engineer
Motorola SPS
Guadalajara, Mexico
This application note presents an easy-to-use C-language API for using
FLASH
MC68HC908GR8, MC68HC908KX8, MC68HC908JL3, MC68HC908JK3 and
MC68HC908JB8 microcontrollers (MCUs)
be used to program, erase, and verify FLASH memory as well as to
communicate serially.
The CodeWarrior API for ROM-resident routines was written in C language. By
using this API, the programmer takes advantage of these benefits:
When using the API, take into consideration that your code may be larger and
the available RAM might decrease. Techniques can be used to avoid
decreasing the available RAM. For more information, refer to the
section.
In addition to describing how to call the API functions (parameters needed and
return values), this document includes example software with typical API calls
to better illustrate the procedure.
1. This product incorporates SuperFlash
2. These routines are accessible in both user mode and monitor mode in all listed devices except
the MC68HC908GR8. This device allows access to these routines in monitor mode only.
Freescale Semiconductor, Inc.
For More Information On This Product,
There is no need to know the absolute address of routines
Changing from one MCU to another is easy; minimum code changes are
needed
Code is easy to understand and follow
No in-depth knowledge of the routines is needed
Enhancement of ROM-resident routines
Shorter development time
1
-programming routines that are stored in ROM in the
Go to: www.freescale.com
®
technology licensed from SST.
2
. These ROM-resident routines can
© Motorola, Inc., 2003
Techniques

Related parts for AN2504

AN2504 Summary of contents

Page 1

... Freescale Semiconductor, Inc. Application Note AN2504/D 10/2003 On-Chip FLASH Programming API for CodeWarrior Software By Mauricio Capistrán-Garza Application Engineer Motorola SPS Guadalajara, Mexico Introduction This application note presents an easy-to-use C-language API for using FLASH MC68HC908GR8, MC68HC908KX8, MC68HC908JL3, MC68HC908JK3 and ...

Page 2

... Freescale Semiconductor, Inc. AN2504/D FLASH Overview The ROM-resident routines that the API manages are found on devices that do not have enough RAM to allow for this functionality in a RAM routine. The type of FLASH for which these routines are applicable is called split-gate FLASH because of the type of technology used. ...

Page 3

... On-Chip FLASH Programming API for CodeWarrior Software For More Information On This Product, Table 1 shows the absolute address of these routines for each Table 1. Address of Routines MC68HC908KX8 MC68HC908JL3/JK3 0x1000 0xFC00 0x1003 0xFC03 0x1009 0xFC09 0x1006 0xFC06 0x100C 0xFC0C Go to: www.freescale.com AN2504/D ROM-Resident Routines MC68HC908JB8 0xFC00 0xFC03 0xFC09 0xFC06 0xFC0C 3 ...

Page 4

... Freescale Semiconductor, Inc. AN2504/D Defined Constants Table 2 FLASH-programming API serves a variety of microcontrollers, the constants are device specific. Constant Name Description RAM Start address of RAM COMMPORT Communication port FLASH block protect register FLBPR address FLCR FLASH control register address Address of routine to get a bit ...

Page 5

... The first letter of each word of the function’s name is capitalized All local variables are in lower case letters preceded by an underscore All assembly labels are written in all capital letters preceded by an underscore Go to: www.freescale.com AN2504/D Coding Conventions Table 3. Address RAM + 0x08 RAM + 0x09 RAM + 0x0A RAM + 0x0B ...

Page 6

... Freescale Semiconductor, Inc. AN2504/D Hardware Needed for Communication The API functions that provide serial communication need external hardware to couple with RS-232 standards. The hardware is very simple, and it is the same as described in the monitor ROM section of the data sheet. Figure 1 communication port is PTB0. ...

Page 7

... MC68HC908JB8. In this device, the bit rate for OP for this device considering USB part. The bit rate for the OP /313 to: www.freescale.com AN2504/D FLASH-Programming API Byte ReadByte (Void) Hardware Needed for 7 ...

Page 8

... Freescale Semiconductor, Inc. AN2504/D TransmitByte The TransmitByte function sends a byte through the communication port. This function uses the same NRZ communication protocol and baud rate that is used in monitor mode Entry Conditions Exit Conditions The communication port is different from one microcontroller to another. ...

Page 9

... SUCCESS or FAIL _num must be less than or equal to 64 The communication is done in TTL values; A TTL to RS- Remarks 232 converter is needed in order to interact with a PC serial port. Refer to Communication. Go to: www.freescale.com AN2504/D FLASH-Programming API ReadRange. The same Table 2 provides the Hardware Needed for Techniques 9 ...

Page 10

... Freescale Semiconductor, Inc. AN2504/D ProgramRange ProgramRange programs a range of FLASH memory with the contents of RAM. This routine doesn’t verify whether the range to be programmed is already blank. Programming new data to a location that is not blank is not legal. The resulting value in the FLASH location after such an illegal programming attempt will be incorrect or unreliable ...

Page 11

... Table 11. ErasePage Prototype void ErasePage (Word *_page) _page: the absolute address of any of the locations Parameters within the PAGE to be erased. None Interrupts are disabled. Return value None Remarks All bytes within that PAGE will be driven to 0xFF. Go to: www.freescale.com AN2504/D FLASH-Programming API 11 ...

Page 12

... Freescale Semiconductor, Inc. AN2504/D ErasePageX ErasePageX is the enhanced version of ErasePage. It erases a PAGE of FLASH. Entry Conditions Exit Conditions EraseFlash EraseFlash erases the entire FLASH. Entry Conditions Exit Conditions 12 On-Chip FLASH Programming API for CodeWarrior Software Table 12. ErasePageX Prototype void ErasePageX (Word *_page) ...

Page 13

... Call API function ProgramRange() to backup the DATA virtual register (from RAM+0x0C to RAM+0x4C). d. Use the FLASH-programming API for whatever needed. e. Before ending call API function ReadFlash() to restore the data from BACKUP_RAM to RAM. f. Finally, pop the first four bytes of the virtual registers (from RAM+0x08 to RAM+0x0B). Go to: www.freescale.com AN2504/D Techniques 13 ...

Page 14

... Freescale Semiconductor, Inc. AN2504/D Typical API Calls The following software performs typical FLASH-programming API calls: /*==================================================================* * * Copyright (c) 2002, Motorola Inc. * Motorola Application Note * * File name * Author * Department * * Description * * * * History * *==================================================================*/ /******************************************************************** INCLUDES ********************************************************************/ //#include "jl3.h" #include <MC68HC908JL3.h> #include <hidef.h> #include <stdtypes.h> #include "flash_api.h" ...

Page 15

... Timer Prescaled ||||| // ||||| // ||||| // |||||____________ Unimplemented // ||||_____________ Reset Bit = 0 -> No effect // |||______________ Stop Bit: Start Counter // ||_______________ TIM Overflow ints enabled // |________________ TIM Overflow Flag Go to: www.freescale.com AN2504/D Typical API Calls */ */ Int Bus Clk = 1.2288MHz 1229 counts, error = 0.58 sec/hour 15 ...

Page 16

... Freescale Semiconductor, Inc. AN2504 Receive one byte and echo it. This shows a typical usage * of API functions GetByte and Transmit Byte. * This functions can not be debugged with the In-Circuit * Debugger (ICD) since the Communication Port is used by the ICD. */ temp = ReadByte(); TransmitByte(temp); DATA(0) = temp; ...

Page 17

... Do anything wanted : MCU_constants.h : Mauricio Capistran-Garza : Guadalajara - SPS : It contains the defines needed for all constants used in flash_api.c for the following MCUs to: www.freescale.com AN2504/D API Source Code // save the received byte // point to next location in RAM // if DATA_END reached exit loop MC68HC908GR8, MC68HC908KX8, MC68HC908JL3, MC68HC908JK3, MC68HC908JB8 ...

Page 18

... Freescale Semiconductor, Inc. AN2504/D #ifndef __MCU_CONSTANTS_H__ #define __MCU_CONSTANTS_H__ #include <MC68HC908JL3.h> /* API Configuration */ #define MASSBIT #ifndef FLCR #define FLCR #endif #ifdef MC68HC908GR8 /* Communication Port Constants */ #define COMMPORT #define COMMPORT_DIR #define COMMPORT_ADDR /* FLASH Constants */ // #define FLASH_START #define PAGE_SIZE /* RAM Constants */ #define RAMSTART #define CTRLBYT ...

Page 19

... X)) {__asm jsr 0xFC00;} {__asm jsr 0xFC03;} {__asm jsr 0xFC06;} {__asm jsr 0xFC09;} {__asm jsr 0xFC0C;} {__asm jsr 0xFF00;} {__asm jsr 0xFED5;} // MC68HC908JB8 //__MCU_CONSTANTS_H__ Go to: www.freescale.com AN2504/D API Source Code 19 ...

Page 20

... Freescale Semiconductor, Inc. AN2504/D /*==================================================================* * * Copyright (c) 2002, Motorola Inc. * Motorola Application Note * * File name * Author * Department * * Description * * History * *==================================================================*/ #ifndef __FLASH_API_H__ #define __FLASH_API_H__ /******************************************************************** DEFINES ********************************************************************/ /* MCU used */ #ifndef MC68HC908JL3 #ifndef MC68HC908GR8 #ifndef MC68HC908KX8 #endif #endif #endif /* Frequency of operation */ #ifndef OSC #define OSC #endif #define ReadRange VerifyRange ...

Page 21

... The checksum is stored in _ini; SUCCESS or FAIL _num must be less to or equal to 64 _num); _*ini: pointer to the starting address of the range. _num: length of the range. None. None. _num must be less to or equal to 64 _num); Go to: www.freescale.com AN2504/D API Source Code 21 ...

Page 22

... Freescale Semiconductor, Inc. AN2504/D /******************************************************************** * ProgramRangeX: Programs a range of FLASH after verifying * * * * Parameters Entry Conditions: DATA contains the data to be programmed * * Exit Conditions Return Remarks: */ Byte ProgramRangeX(Word *_ini, Byte /******************************************************************** * VerifyRange: Verifies a range of FLASH against the data * * * * Parameters Entry Conditions: DATA contains the data to be verified. ...

Page 23

... None. None. None. All bytes will be driven to 0xFF. No code in FLASH will be executed after this function has been called. // __FLASH_API_H__ : flash_api.c : Mauricio Capistran-Garza : Guadalajara - SPS : This files contains the API functions definition to: www.freescale.com AN2504/D API Source Code 23 ...

Page 24

... Freescale Semiconductor, Inc. AN2504/D /******************************************************************** * ReadByte: It reads a byte from the communication port * * * Parameters Entry Conditions: None Exit Conditions Return Remarks Byte ReadByte(void) { Byte _backup1, _backup2; Byte _data; _backup1 = COMMPORT; _backup2 = COMMPORT_DIR; COMMPORT_DIR &= 0xFE; COMMPORT &= 0xFE; GETBYTE(); __asm sta _data; COMMPORT = _backup1; ...

Page 25

... Configure COMMPORT as input. // Define Last Address High & Low ldhx _first; // Define first address. lda #0x00; // Configure RDVRRNG() to transmit. // Call ROM-resident routine. sta _backup3; // Store checksum. clra; adc #0; sta _status; // Store status. // Restore port values. Go to: www.freescale.com AN2504/D API Source Code 25 ...

Page 26

... Freescale Semiconductor, Inc. AN2504/D /******************************************************************** * ProgramRange: Programs a range of FLASH Parameters Entry Conditions: DATA contains the data to be programmed * * Exit Conditions Return Remarks: */ void ProgramRange(Word *_ini, Byte Word _first; _first = *_ini; FLBPR = 0xFF; CPUSPD = OSC; LADDRH = ((_first + _num - 1) & 0xFF00) >> 8; LADDRL = ((_first + _num - 1) & 0x00FF); ...

Page 27

... FAIL Disables write protection. // Set Clock Bus Operation speed. // Define Last Address High & Low ldhx _first; // Define first address. // Call ROM-resident routine. // Enables write protection. Go to: www.freescale.com AN2504/D API Source Code _num ...

Page 28

... Freescale Semiconductor, Inc. AN2504/D /******************************************************************** * VerifyRange: Verifies a range of FLASH against the data * * * * Parameters Entry Conditions: DATA contains the data to be verified Exit Conditions Return Remarks: */ Byte VerifyRange(Word *_ini, Byte Byte _backup1; Byte _status = 0; Word _first; _first = *_ini; LADDRH = ((_first + _num - 1) & 0xFF00) >> 8; ...

Page 29

... Backup Condition Code Register // Enables erase/write protection. // Set Clock Bus Operation speed. // Clear bit 6 to page erase mode. // Set the page to be erased. // Call ROM-resident routine. __asm CLI; Go to: www.freescale.com AN2504/D API Source Code 29 ...

Page 30

... Freescale Semiconductor, Inc. AN2504/D /******************************************************************** * EraseFlash: It erases the entire FLASH Parameters Entry Conditions: None Exit Conditions Return Remarks void EraseFlash(void) { FLBPR = 0xFF; CPUSPD = OSC; CTRLBYT |= 0x40; ERARNGE(); } 30 On-Chip FLASH Programming API for CodeWarrior Software None. None. None. All bytes will be driven to 0xFF. ...

Page 31

... Freescale Semiconductor, Inc. MOTOROLA On-Chip FLASH Programming API for CodeWarrior Software For More Information On This Product, Go to: www.freescale.com AN2504/D API Source Code 31 ...

Page 32

... Motorola and the Stylized M Logo are registered in the U.S. Patent and Trademark Office. digital dna is a trademark of Motorola, Inc. All other product or service names are the property of their respective owners. Motorola, Inc Equal Opportunity/Affirmative Action Employer. © Motorola, Inc. 2003 AN2504/D Go to: www.freescale.com ...

Related keywords