APPLICATION NOTE 3575 In-Application Programming (IAP) of the MAXQ7665 Sector-Erasable Program and Data Flash

Similar documents
Keywords: maxq microcontrollers, data flash, in-application programming, in circuit programming, flash, microcontroller, MAXQ7663, MAXQ7664

Keywords: MAXQ7665C, page erasable, flash, MAXQ, In-application, programming

Implementing In-Application Programming on the ADuC702x

Kinetis Bootloader to Update Multiple Devices in a Field Bus Network

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465

Appendix A. Code Examples

Serial Boot Loader For CC2538 SoC

VORAGO VA108x0 Bootloader application note

AN1576 APPLICATION NOTE

Introduction. Keywords: MAXQ, IAR, memory allocation, flash data, flash storage, SRAM

Memory Map for the MCU320 board:

Implementing Bootloaders on Renesas MCUs

Programming in the MAXQ environment

Bootloader Design Techniques for MCUs. Jacob Beningo, CSDP

The MAXQ TM Family of High Performance Microcontrollers

ABSTRACT. Table of Contents

SimpleLink Bluetooth low energy CC26X0 Wireless MCU. Over-the-Air Download User s Guide. For BLE-Stack Version: 2.2.2

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 3006

F2MC-8FX EEPROM LIBRARY

F2MC-8FX EEPROM Library

Table of Contents List of Figures... 2 List of Tables Introduction Main features Function description On-chip Flash memo

AN4491 Application note

ISPV3 Programmer s Guide. This guide addresses the features, setup and operation of the CRD89C51xxx microcontrollers with ISPV3 firmware.

AN1070 APPLICATION NOTE

AN4894 Application note

OEM-Product Catalogue

S12 All-Access Bootloader for the HCS12 Microcontroller Family Rafael Peralez and Gabriel Sanchez RTAC Americas

AN LPC1700 secondary USB bootloader. Document information. LPC1700, Secondary USB Bootloader, ISP, IAP

MC9S12 Address Space

AN5123 Application note

The purpose of this course is to provide an introduction to the RL78's flash features and archectecture including security features, code and data

AN Entering ISP mode from user code. Document information. ARM ISP, bootloader

Contents. Cortex M On-Chip Emulation. Technical Notes V

SimpleLink Bluetooth low energy CC2640 wireless MCU. Over-the-Air Download User s Guide

Boot Loader. Bootloader

Application Note, V1.0, Aug AP08064 XC866/886/888. Safeguarding the Microcontroller under Out-of-Spec Noise Conditions.

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

Bootloader Design Techniques for Microcontrollers

ARM TrustZone for ARMv8-M for software engineers

MAX2990 INTEGRATED POWER-LINE DIGITAL TRANSCEIVER PROGRAMMING MANUAL

THE 8051 MICROCONTROLLER

FlashFlex Microcontroller In-Application Programming Example Using C

Errata details published in this document refer to the following silicon: netx100, Revision A (Step A, ROM Rev. 2, Boot loader major vers.

AN2792 Application note

,$5$SSOLFDWLRQ1RWH$95 (IILFLHQWSURJUDPPLQJRI$WPHO V $95 PLFURFRQWUROOHUV

EEPROM Emulation with the ez80f91 MCU. Discussion

Engineer-to-Engineer Note

THE 8051 MICROCONTROLLER

F²MC-8FX FAMILY MB95200H/210H SERIES FLASH OPERATION 8-BIT MICROCONTROLLER APPLICATION NOTE

XC800 Family AP Application Note. Microcontrollers. Programming the BMI value in the XC82x and XC83x products V1.0,

AN4872 Application note

HT32 Series In-System / In-Application Programmer User Manual

EasyIAP Software Example User s Guide

The Bootconcept. of Fujitsu s MB91360 Devices

ST7 FAMILY. FLASH Programming REFERENCE MANUAL

)8-,768'HY.LW 2YHUYLHZ. )XMLWVX0LNURHOHNWURQLN*PE+ Am Siebenstein Dreieich-Buchschlag, Germany

Application Note: JN-AN-1003 JN51xx Boot Loader Operation

Memory Management. CSE 2431: Introduction to Operating Systems Reading: , [OSC]

Centre for Instrumentation, Control and Automation User s Guide to the MAD 2 Microcontroller Board

_äìé`çêé» VM Memory Mapping and Memory Usage. Application Note. November CSR Cambridge Science Park Milton Road Cambridge CB4 0WH United Kingdom

XC800 Family AP Application Note. Microcontrollers. Capacitive-Touch Color Wheel Implementation V1.0,

UM0560 User manual 1 Introduction STM8 bootloader

C Language Programming

PM0062 Programming manual

MSP430F149 P3.4/UTXD0 P3.5/URXD0 P1.5 P1.6 P1.7 MSP430F149 P1.0 P5.4 P5.3 P5.2 P5.1. Figure B-1. BSL Replicator Block Diagram

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

AN4045 Application note

DS4830 Optical Microcontroller User s Guide Rev 0.3 8/2012

Bootloader project Project with a Bootloader Component and communication Component.

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

HCS12 BDM Getting Started V4.3

AN2659 Application note

AN2659 Application note

Implementing Secure Software Systems on ARMv8-M Microcontrollers

AN2061 APPLICATION NOTE

MegaAVR-DEVelopment Board Progressive Resources LLC 4105 Vincennes Road Indianapolis, IN (317) (317) FAX

UM LPC2101/02/03 User manual. Document information

ibl ingenia dspic bootloader Users s guide 2007, ingenia-cat S.L. 06/06/07 Version 1.4

Boot ROM Design Specification

AN-1471 APPLICATION NOTE

AN10210 Using the Philips 87LPC76x microcontroller as a remote control transmitter

The task of writing device drivers to facilitate booting of the DSP via these interfaces is with the user.

TMS320F2802x SDFlash JTAG Flash Programming Utilities

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

UFCETW-20-2 Examination Answer all questions in Section A (60 marks) and 2 questions from Section B (40 marks)

April 4, 2001: Debugging Your C24x DSP Design Using Code Composer Studio Real-Time Monitor

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission.

AN4894 Application note

Bootloader project Project with a Bootloader component and communication component.

Evaluation board for NXP LPC2103. User Guide. Preliminary Version updated 27 th Aug TechToys Company All Rights Reserved

EE251: Thursday November 15

Embedded Systems Design (630414) Lecture 1 Introduction to Embedded Systems Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

APPLICATION NOTE 655 Supervisor ICs Monitor Battery-Powered Equipment

Getting Started with Keil's µvision2

AN-881 APPLICATION NOTE

AN3154 Application note

Application Note 606 Configuring Keil PK51 Tools to Support 24-Bit Contiguous Addressing Mode

NEC 78K0- Family On-Chip Emulation

AN3965 Application note

UM MPT612 User manual. Document information

Transcription:

Maxim > Design Support > Technical Documents > Application Notes > Automotive > APP 3575 Maxim > Design Support > Technical Documents > Application Notes > Basestations/Wireless Infrastructure > APP 3575 Keywords: Sector Erasable Program, MAXQ76XX APPLICATION NOTE 3575 In-Application Programming (IAP) of the MAXQ7665 Sector-Erasable Program and Data Flash By: Jon Wallace Nov 27, 2006 Abstract: This application note describes how to erase/write the program and data flash in the MAXQ7665 microcontrollers (µc) using the built-in utility ROM. This information applies only to the MAXQ7665 flash-based microcontrollers (µc) with sector-erasable (SE) flash. Introduction This application note describes how to manage the internal data and program flash in the MAXQ7665 flash-based microcontrollers (µc) with sector-erasable (SE) flash memory. This discussion includes general information for performing in-application programming (IAP) of the program flash. Memory Maps This section details the general flash information and memory organization for various memory sizes of the MAXQ7665 devices. There are two types of flash memory available on the MAX7665 devices. This document only covers the MAXQ7665 devices with SE flash and does not apply to the page-erasable (PE) devices. For information on MAXQ7665 PE devices, please refer to application note, "In-Application Programming (IAP) of the MAXQ7665 Page-Erasable (PE) Program and Data Flash". Table 1 shows the flash memory maps for the 128KB, 64KB, 48KB, and 32KB devices. Other flash options may exist, so please consult the MAXQ7665 data sheet for a complete list. Table 1. Flash Memory Maps Page 1 of 10

Using Flash to Store Data The flash can be used to reliably store system data that needs to be programmed once or periodically during system operation. While any sector of flash can be used to store data, the two 4K x 16 sectors usually provide the best fit. Unlike EEPROM, flash on the MAXQ7665 cannot be word erased. A complete sector must be erased at one time. Erasing a sector typically takes 0.7 seconds, but can take as long as 15 seconds under worst-case conditions. During this time the user code is stalled so no other processing can occur. These limitations must be considered carefully when you choose the software technique appropriate to your system requirements. For most periodic data-storage needs, a bounded queue and/or a bank switching technique will meet the reliability requirements and needs of the system. Page 2 of 10

Simple examples of both techniques follow. Bounded Queue A bounded queue is a queue limited by a fixed number of items. This technique is commonly used whenever periodic data is processed. For example, the 4K x 16 flash sector can be divided into 64 64- word entries, which would result in the memory map in Table 2 for the 128kB part. Upon initialization, a startup routine can scan the queue entries to determine the next available entry in the queue. Once the queue is full, it must be erased before another entry can be written. (Note: if all entries are needed, then you must also use bank switching to maintain all the data.) Once the flash is erased, the new entry can be written. The drawback to this approach is that all data can be lost if there is a drop in power during the erasing process. If the bounded-queue technique does not meet the system's requirements, then bank switching will also be needed. Figure 1 illustrates the flow of entries into a bounded queue. See Appendix A for a simple C source-code example. Table 2. Example of a Bounded-Queue Memory Map FLASHQueue[ ] Queue Index Data Flash Address 63 0xFFC0-0xFFFF 62 0xFF80-0xFFBF 61 0xFF40-0xFF7F........ 2 0xF080-0xF0BF 1 0xF040-0xF07F 0 0xF000-0xF03F Figure 1. Bounded queue flow. Bank Switching Bank switching is an effective method of preventing data loss or corruption during the long sector-erase cycles. This method works well when the sector size is only slightly larger than the total data size. The Page 3 of 10

drawback to bank switching is that it requires minimally two sectors of flash. When the total data size to be written is much smaller than the sector size, the best approach combines bank switching and bounded queue techniques. If bank switching is necessary for the application then, the two 4K x 16 flash sectors of the MAXQ7665 can be used as data storage. Table 3 is an example of a memory map when using two 4K x 16 flash sectors. Figure 2 illustrates the bank-switching write/erase flow. See Appendix A for a simple C source-code example. Table 3. Example of a Bank-Switching Memory Map Flash Sectors Sector Number Data Flash Address 0 0xF000-0xFFFF 1 0xE000-0xEFFF Figure 2. Bank switching flow. Bounded Queue and Bank Switching Using the bounded-queue and bank-switching techniques together is the most reliable and flexible approach. This combined approach works well when small amounts of data need to be stored to flash periodically, and when data integrity must be maintained. Table 4 shows an example of a memory map using the two 4K x 16 sectors divided into 64 equal entries. Figure 3 illustrates the flow of data in the bounded queue between the two sectors. The coding for this combined technique is only slightly more complex than a bounded queue alone. See Appendix A for a simple C source-code example. Table 4. Example of a Bounded-Queue Memory Map FQueueBank0[ ] Queue Index Data Flash Address 63 0xFFC0-0xFFFF 62 0xFF80-0xFFBF 61 0xFF40-0xFF7F........ 2 0xF080-0xF0BF 1 0xF040-0xF07F Page 4 of 10

0 0xF000-0xF03F FQueueBank1[ ] Queue Index Data Flash Address 63 0xEFC0-0xEFFF 62 0xEF80-0xEFBF 61 0xEF40-0xEF7F........ 2 0xE080-0xE0BF 1 0xE040-0xE07F 0 0xE000-0xE03F Figure 3. Flowchart for bounded queue and bank switching. Utility ROM Flash Routines To program, erase, and verify flash, the MAXQ7665 microcontroller has on-chip flash-support routines residing in ROM (read-only memory). There are two ways to access these routines. The first and fastest method is direct access, that is to directly call the routine. To do this, provide a header file with the following lines: u16 flasherasesector(void *); u16 flasheraseall(void); u16 flashwrite(void *paddress, u16 idata); Next, add linker defines to assign the appropriate address for each routine. For the IAR linker file, the added lines would look like this: Page 5 of 10

-DflashEraseSector=0x8XXX -DflashEraseAll=0x8XXX -DflashWrite=0x8XXX Replace 0x8XXX with the appropriate memory address for each routine. Other compilers might use a different method for adding these references. Note: the direct-access method does not provide forward compatibility with future ROM versions. The second method of indirect addressing uses a table lookup. While this method provides greater compatibility with future ROM versions, it consumes greater execution time. After each routine described below, an assembly routine uses the table-lookup method to obtain the address of the ROM Utility routine. Table 5 shows the flash routines supplied by the Utility ROM. For a complete listing of ROM Utility routines, please refer to the MAXQ7665 User's Guide which can be found o the Maxim website. Table 5. Flash Utility ROM Routines Routine Number Routine Name Entry Point ROMTable = ROM[800Dh] 2 flasherasesector ROM[ROMTable + 1] 0x8XXX 3 flasheraseall ROM[ROMTable + 2] 0x8XXX 15 flashwrite ROM[ROMTable + 14] 0x8XXX Entry Point Physical Address flashwrite Routine: u16 flashwrite(void *paddress, u16 idata) Summary: Programs a single word of flash memory. A[0] Word address in flash memory to which to write. Inputs: A[1] Word value to write to flash memory. Carry: Set on error and cleared on success. If set, then A[0] contains one of the following error codes: 1: failure due to software timeout Outputs: 2: failure reported by hardware (DQ5/FERR) 4: command not supported SW_FERR Set on error, cleared on success. The watchdog must not be active, or the watchdog timeout must be set long enough to Notes: complete this routine without triggering a reset. The following example of assembly code calls the flashwrite() utility routine using the indirect addressing method (lookup table). This routine is callable by C code. ; This routine is callable by C code using the following prototype ; u16 flashwrite(void *paddress, u16 idata); ; flashwrite: move APC, #0 ; No auto inc/dec of accumulator. move DP[0], #0800Dh ; This is where the address of the table is ; stored. move ACC, @DP[0] ; Get the location of the routine table. add #14 ; Add the index to the flashwrite routine. move DP[0], ACC move ACC, @DP[0] ; Retrieve the address of the routine. call ACC ; Execute the routine. ret ; Status returned in A[0]. flasherasesector Page 6 of 10

Routine: u16 flasherasesector(void *paddress) Summary: Erases a single sector of flash memory. Inputs: Outputs: Notes: A[0] Address located in the sector to erase. Carry: Set on error and cleared on success. If set, then A[0] contains one of the following error codes: 1: failure due to software timeout 2: failure reported by hardware (DQ5/FERR) 4: command not supported SW_FERR Set on error, cleared on success. The watchdog must not be active, or the watchdog timeout must be set long enough to complete this routine without triggering a reset. ; This routine is callable by C code using the following prototype ; u16 flasherasesector(void *paddress); ; flasherasesector: move APC, #0 ; No auto inc/dec of accumulator. move DP[0], #0800Dh ; This is where the address of the table is ; stored. move ACC, @DP[0] ; Get the location of the routine table. add #1 ; Add the index to the flasherasesector routine. move DP[0], ACC move ACC, @DP[0] ; Retrieve the address of the routine. call ACC ; Execute the routine. ret ; Status returned in A[0] flasheraseall Routine: void flasheraseall(void) Erases the entire program and data flash memory, including the boot-loader sector. This Summary: routine is not normally used for IAP, as great care must be taken to insure that the erase/programming sequence is not interrupted. Inputs: None Carry: Set on error and cleared on success. Outputs: SW_FERR Set on error, cleared on success. The watchdog must not be active, or the watchdog timeout must be set long enough to Notes: complete this routine without triggering a reset. ; This routine is callable by C code using the following prototype ; void flasheraseall(void); ; flasheraseall: move APC, #0 ; No auto inc/dec of accumulator. move DP[0], #0800Dh ; This is where the address of the table is ; stored. move ACC, @DP[0] ; Get the location of the routine table. add #2 ; Add the index to the flasheraseall routine. move DP[0], ACC move ACC, @DP[0] ; Retrieve the address of the routine. call ACC ; Execute the routine. ret In-Application Programming (IAP) Page 7 of 10

Most flash-based systems must have the ability to update firmware while the system is installed in the end product. This procedure is known as In-Application Programming (IAP). The following discussion outlines general guidelines for creating an IAP application. The Utility ROM flash routines outlined in the previous section perform all the actions necessary to erase and write the flash ROM. It is, therefore, possible for an end-user application to perform operations on the flash memory. Like any other subroutine call, control will return to the end-user's code after completion of the routine. Care must be taken when executing an IAP sequence on sector-erase-only versions of the MAXQ7665 since no dedicated boot-loader flash sector exists. To design a fully fault-tolerant IAP, the boot-loader application must be separate from the main application. This ensures that the reprogramming procedure can be retried even after an incomplete reprogramming sequence has occurred. If IAP must tolerate failures such as power loss during the reprogramming sequence, then select a MAXQ7665 version with page-erase capability. This will allow the boot-loader application to start at 0x0000 (the reset entry point), and be fully separate from the main application code. For applications that do not require a fully faulttolerant IAP, then IAP can be accomplished using a RAM-based reflash routine. IAP Using a RAM-Based Flash Routine A RAM-based flash routine can be used to reflash the MAXQ7665 when fault recovery is not required. This method requires that the main application copy a small relocatable flash-programming routine into RAM and then jump to the routine. When executing code from RAM, there are several restrictions that must be considered. Table 6. Restrictions When Executing Code from RAM SC.UPA must be set to 0 before executing a RAM-based routine. This means that the application must jump to the RAM routine from the code segments P0 and P1. RAM cannot be accessed as data and program at the same time. This means that only the registers and hardware stack are available for data storage. The Interrupt Vector must point to a RAM routine if interrupts are enabled. Typically interrupts are turned off and polling is used due to the simplicity of the RAM reflash routine. Typically, the flash routine will communicate through either the UART or CAN interface. It is usually best to receive small packets of data and send an acknowledgement to allow for a more robust error-recovery mechanism. Figure 4 is a flowchart showing how a reflash routine can work. If reprogramming is not successfully completed before loss of power, remember that the microcontroller will need to be reprogrammed through the JTAG port. Page 8 of 10

Figure 4. Flowchart of a simplified RAM reflash routine. Appendix A. Code Examples Page 9 of 10

Download (DOC 53.5kB) More Information For Technical Support: http://www.maximintegrated.com/support For Samples: http://www.maximintegrated.com/samples Other Questions and Comments: http://www.maximintegrated.com/contact Application Note 3575: http://www.maximintegrated.com/an3575 APPLICATION NOTE 3575, AN3575, AN 3575, APP3575, Appnote3575, Appnote 3575 Copyright by Maxim Integrated Products Additional Legal Notices: http://www.maximintegrated.com/legal Page 10 of 10