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

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

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

Kinetis Bootloader to Update Multiple Devices in a Field Bus Network

Implementing In-Application Programming on the ADuC702x

Memory Map for the MCU320 board:

AN4491 Application note

Serial Boot Loader For CC2538 SoC

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

Appendix A. Code Examples

VORAGO VA108x0 Bootloader application note

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

Programming in the MAXQ environment

Boot Loader. Bootloader

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

ABSTRACT. Table of Contents

Implementing Bootloaders on Renesas MCUs

AN5123 Application note

The Bootconcept. of Fujitsu s MB91360 Devices

AN1576 APPLICATION NOTE

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

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

MAX2990 INTEGRATED POWER-LINE DIGITAL TRANSCEIVER PROGRAMMING MANUAL

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

The MAXQ TM Family of High Performance Microcontrollers

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

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

DS4830 Optical Microcontroller User s Guide Rev 0.3 8/2012

Bootloader project Project with a Bootloader Component and communication Component.

AN4872 Application note

Bootloader Design Techniques for Microcontrollers

THE 8051 MICROCONTROLLER

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

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

AN4894 Application note

THE 8051 MICROCONTROLLER

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

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

Bootloader project Project with a Bootloader component and communication component.

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

Flash Self-programming Library

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

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

Bootloader Design Techniques for MCUs. Jacob Beningo, CSDP

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

F2MC-8FX EEPROM LIBRARY

F2MC-8FX EEPROM Library

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

NAND/MTD support under Linux

Engineer-to-Engineer Note

OEM-Product Catalogue

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

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

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

Keywords: CRC, CRC-7, cyclic redundancy check, industrial output, PLC, programmable logic controller, C code, CRC generation, microprocessor, switch

C Language Programming

EasyIAP Software Example User s Guide

Course Introduction. Purpose: Objectives: Content: 27 pages 4 questions. Learning Time: 20 minutes

UM0560 User manual 1 Introduction STM8 bootloader

ST7 FAMILY. FLASH Programming REFERENCE MANUAL

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

Boot ROM Design Specification

AN4045 Application note

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

Kinetis Flash Tool User's Guide

Getting Started with Keil's µvision2

MC9S12 Address Space

FlashFlex Microcontroller In-Application Programming Example Using C

Microcontroller VU

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

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

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

1 Do not confuse the MPU with the Nios II memory management unit (MMU). The MPU does not provide memory mapping or management.

Bootloader project - project with Bootloader and Communication components

RH850 Family. User s Manual. Code Flash Library, Type T01. RENESAS MCU RH850 Family. Installer: RENESAS_FCL_RH850_T01_V2.

Debugging Applications with the JTAG In-Circuit Emulator

AN-881 APPLICATION NOTE

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

EFILive USB driver Error Code Error Description Cause Action

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

EE 332 Real Time Systems Midterm Examination Solution Friday February 13, :30 pm to 4:30 pm

Getting Started with STK200 Dragon

XMC4800 EtherCAT APP SSC Firmware Update Slave Example. Getting Started Version 3.0

AN2792 Application note

Aptio 5.x Status Codes

AN-946 APPLICATION NOTE

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

CPCI-IPC. Intelligent DSP Based Dual IndustryPack Carrier for CompactPCI systems REFERENCE MANUAL Version 2.

EMBEDDED SOFTWARE DEVELOPMENT. George Hadley 2017, Images Property of their Respective Owners

ARM TrustZone for ARMv8-M for software engineers

µtasker Document µtasker Bare-Minimum Boot Loader

INTERRUPTS in microprocessor systems

Chapter 8: Main Memory

netx DPM Interface Manual DPM Interface Manual for netx based Products Language: English

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

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

Bootloader Solution for Kinetis MCUs

EEPROM Driver for MC56F84xxx and MC56F82xxx DSC Family

AN1070 APPLICATION NOTE

ingenia dspic bootloader User s Guide

The BlueNRG-1, BlueNRG-2 BLE OTA (over-the-air) firmware upgrade

Transcription:

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 3569 Keywords: maxq microcontrollers, data flash, in-application programming, in circuit programming, flash, microcontroller, MAXQ7663, MAXQ7664 APPLICATION NOTE 3569 In-Application Programming of Sector Erasable Program, and Data Flash in a MAXQ Microcontroller By: Jon Wallace Aug 10, 2005 Abstract: This application note describes the program and data flash and how to erase/write the flash using the built-in utility ROM. This application note applies to the MAXQ flash-based microcontrollers that use a sector erasable flash. Introduction This application note describes how to manage the internal data and program flash for the MAXQ microcontrollers that use sector erasable flash. General information explains how to construct a boot-loader application to perform in-application programming of the program flash. Note: this document is not applicable for MAXQ microcontrollers that use a page-erasable flash, i.e., that allow small amounts of the flash to be erased. Each MAXQ data sheet describes the type of flash used on that microcontroller. Flash Overview Memory Maps This application note shows flash memory map examples for various memory sizes, which do not precisely match any MAXQ part. These maps are only references for the examples in this document. Each MAXQ data sheet will list the memory map options for that part. There is no operational difference among the boot, program, and data flash sectors. If the boot-loader application needs more space than the first flash sector provides, the application can extend into the next sector. However, labeling does differ in the examples below to illustrate how the different sectors are used in this document. Table 1. Example of Flash Memory Maps Page 1 of 11

Data Flash Data flash can be used to reliably store system data that needs to be programmed either once or periodically during system operation. While the size of the data flash depends on the specific MAXQ part, it is typically between 128 to 2k words. There are limitations to using data flash. Unlike EEPROM, the data flash 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, user code is stalled so no other processing can occur. These limitations must be considered carefully when you select the software technique appropriate for your system requirements. For most periodic data-storage needs, a bounded queue and/or bank switching technique can meet system reliability requirements. Simple examples of the bank switching and bounded queue techniques follow below. Bounded Queue A bounded queue technique is a queue limited by a fixed number of items. This approach is commonly used whenever periodic data is processed. A 2k word data flash, for example, can be divided into 32 to 64 word entries, which would result in the memory map in Table 2. 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. If all entries are needed, then you must also alternate between two different sectors 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 power drops during the erase process. Figure 1 illustrates the flow of entries into a bounded queue. See Appendix A for a simple C source code example. Page 2 of 11

If this bonded-queue approach does not meet system requirements, then bank switching will also be needed. Table 2. Example of a Bounded-Queue Memory Map FLASHQueue[ ] Queue Index Data Flash Address 31 0xF7C0-0xF7FF 30 0xF780-0xF7BF 29 0xF740-0xF77F........ 2 0xF080-0xF0BF 1 0xF040-0xF07F 0 0xF000-0xF03F Figure 1. Bounded queue flow. Bank Switching Bank switching is an effective method for preventing data loss or corruption during the long sector erase cycles. For this document, the term 'Bank' is equivalent to the term 'Sector.' Bank switching works well when the sector size is slightly larger than the total data size. The negative to bank switching is that it requires minimally two sectors of data flash. When the total data size to be written is much smaller than the sector size, the best approach combines the bank switching and bounded queue methods. If bank switching is necessary for the application, then select a version of the MAXQ with at least two dataflash sectors. Table 3 shows an example memory map of two 1K 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-0xF3FF 1 0xE000-0xE3FF Page 3 of 11

Figure 2. Bank switching flow. Bounded Queue and Bank Switching Together Using bounded queue and bank switching together is the most reliable and flexible approach for managing data flash. Their combination works well when small amounts of data need to be stored to flash periodically and data integrity must be maintained. Table 4 shows an example memory map of two 2K x 16 sectors divided into 32 equal entries. Figure 3 illustrates the flow of data in the bounded queue between two sectors. The coding for this combined approach is only slightly more complex than bounded queue alone. See Appendix A for a simple C source code example. Table 4. Example of a Bounded Queue with Bank-Switching Memory Map FQueueBank0[ ] Queue Index Data Flash Address FQueueBank0[ ] Queue Index Data Flash Address 31 0xF7C0-0xF7FF 31 0xE7C0-0xE7FF 30 0xF780-0xF7BF 30 0xE780-0xE7BF 29 0xF740-0xF77F 29 0xE740-0xE77F................ 2 0xF080-0xF0BF 2 0xE080-0xE0BF 1 0xF040-0xF07F 1 0xE040-0xE07F 0 0xF000-0xF03F 0 0xE000-0xE03F Page 4 of 11

Figure 3. Bounded queue and bank switch flow. Utility ROM Flash Routines To program, erase, and verify flash, the MAXQ microcontrollers have on-chip flash-support routines residing in ROM (read-only memory). There are two ways to access these routines. Direct access, the first and fastest method, directly calls the routine by providing a header file with the following lines: u16 flasherasesector(void *); u16 flasheraseall(void); u16 flashwrite(u16 *paddress, u16 idata); Then add linker defines to assign the appropriate address for each routine. For the IAR linker file, the added lines would look like this: -DflashEraseSector=0x8XXX -DflashEraseAll=0x8XXX -DflashWrite=0x8XXX Replace 0x8XXX with the appropriate memory address for each routine. Other compilers may use a different method for adding these references. Note that the direct access method does not provide forward compatibility with future ROM versions. The second method uses table lookup. Although this method provides greater compatibility, it consumes more time to execute. After each routine description 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, reference the User's Guide for the specific MAXQ part used. Table 5. Flash Utility ROM Routines Page 5 of 11

Routine Number Routine Name Entry Point Entry Point ROMTable = ROM[800Dh] Physical Address 2 flasherasesector ROM[ROMTable + 1] 0x8XXX 3 flasheraseall ROM[ROMTable + 2] 0x8XXX 15 flashwrite ROM[ROMTable + 14] 0x8XXX flashwrite Routine u16 flashwrite(u16 *paddress, u16 idata) Summary Programs a single word of flash memory. Inputs Outputs Notes A[0] - Word address in flash memory to which to write. 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 2 : failure reported by hardware (DQ5/FERR) 4 : command not supportedsw_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. The following assembly code example calls the flashwrite() utility routine using the indirect addressing method (lookup table). This routine is called by C code. ; This routine is callable by C code using the following prototype ; u16 flashwrite(u16 *paddress, u16 idata); ; flashwrite: move APC, #0 ; No auto inc/dec of accumulator. move AP, #2 ; Set ACC to A[2] 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 Routine u16 flasherasesector(void *paddress) Summary Erases a single sector of flash memory Inputs 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 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 complete Notes this routine without triggering a reset. ; This routine is callable by C code using the following prototype ; u16 flasherasesector(void *paddress); Page 6 of 11

; flasherasesector: move APC, #0 move AP, #1 move DP[0], #0800Dh move ACC, @DP[0] add #1 move DP[0], ACC move ACC, @DP[0] call ACC ret ; No auto inc/dec of accumulator. ; Set ACC to A[1] ; This is where the address of the table is stored. ; Get the location of the routine table. ; Add the index to the flasherasesector routine. ; Retrieve the address of the routine. ; Execute the routine. ; Status returned in A[0] flasheraseall Routine void flasheraseall(void) Erases the entire program and data flash memory, including the boot loader sector. This routine is Summary not normally used for IAP, as great care must be taken to ensure that the erase/programming sequence is not interrupted. Inputs None Outputs Carry: Set on error and cleared on success.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 Notes 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 AP, #0 ; Set ACC to A[0] 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 An important requirement for most flash-based systems is the ability to update firmware while the system is installed in the end product. This is referred to as In-Application Programming (IAP). This section will outline general guidelines for creating an IAP application. The Utility ROM flash routines outlined above perform all the actions necessary to erase and write the flash ROM. It is thus 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. For a reliable IAP, the boot-loader application must be separate from the main application. This ensures that the reprogramming procedure can be retried after an incomplete reprogramming sequence. Boot Loader Because the ROM jumps to address 0x0000 after initialization, the entry point of the boot-loader application must be placed at 0x0000. The boot-flash sector size varies depending on the MAXQ part selected. The bootloader application can extend into as many flash sectors as needed, and any sector used will not be available for the user's application code. The specific requirements that must be met when erasing and writing flash are listed in Table 6. Page 7 of 11

Table 6. Requirements for Calling Flash Utility ROM Routines You cannot erase or program from the same flash sector from which you are executing code. This is not normally a problem since the flash Boot Sector should never be erased during IAP. The watchdog must not be enabled or the watchdog timeout must be set long enough to complete this routine without triggering a reset before the flasherasesector() routine is called. If the watchdog time out occurs before the erase is complete, it will reset the part. Erasing a sector typically takes 0.7 seconds; it can take up to 15 seconds under worst case conditions. Since the System Control Register bit SC.UPA must be set to 0 to access the Utility ROM, a ROM Utility routine cannot be called directly from program memory addresses = 0x8000. If access to a Utility ROM routine is required from a program in upper memory (= 0x8000), the program must indirectly call the ROM routine through a routine residing in lower memory (<0x8000). This effectively limits the boot loader to = 64kB (32kB x 16). The flowchart in Figure 4 shows what the MAXQ does when exiting the reset state. After a diagnostic of the ROM itself and verification that the flash is ready, the ROM initialization code jumps directly to address 0x0000. Read the appropriate data sheet and User's Guide to verify that your MAXQ microcontroller follows this boot sequence. Figure 4. Simplified ROM initialization flowchart. The flowchart in Figure 5 shows what a simple boot-loader application can look like. When using a boot loader for IAP, the entry point for the main application will typically be at address 0x2000 + Header Offset for the 16kB (8K x 16) boot-loader option, and at address 0x4000 + Header Offset for the 32kB (16K x 16) bootloader option. A simple application header will be similar to the following: typedef struct { u16 isize; // The size of the application in words u32 icrc; // The CRC of the application u8 ID[8]; // ID string for current application } APPLICATION_HEADER; Using the information from this header, the boot loader can check the validity of the main application program and report the version identification, if requested. Page 8 of 11

Figure 5. Simplified flash boot-loader flowchart. The programming sequence itself is quite simple. Erase each sector containing the main application code through a call to flasherasesector(). Then write one word at a time by calling flashwrite() for every word to be programmed. You should erase the block containing the application header first, and program the CRC data last to minimize the possibility of an errant CRC match. A simple routine to reflash the microcontroller that gets data through the serial port can look like the following: /* // VerySimpleReFlash() // As simple as it gets. // Step 1. Wait for erase command, then erase flash. // Step 2. Wait for program command, then program flash one word // at a time. */ void VerySimpleReFlash() { u16 istatus; // The status returned from flash utility ROM calls u16 isize; // The size of the main code to program u16 *paddress = 0x2000; // The starting address of the main application InitializeCOMM(); // Can be CAN or UART WaitForEraseCommand(); SlowDownWatchdog(); // If watchdog enabled set update > 15s istatus = flasherasesector(c_address_sector_1); if (istatus == 0) istatus = flasherasesector(c_address_sector_2); UpdateWatchdog(); // Prevent watchdog timeout Page 9 of 11

SendFlashErasedResponse(iStatus); if (istatus) ResetMicro(); } isize = WaitForProgramCommand(); while (isize--) { u16 idata = GetWordFromCOMM(); istatus = flashwrite(paddress, idata); if (istatus) break; ++paddress; UpdateWatchdog(); // Prevent watchdog timeout } SendFlashWriteResponse(iStatus); ResetMicro(); Remember that any program space not used by the boot-loader application can be used for other routines and/or constant data storage. A good example of this would be storing all the routines for indirectly calling Utility ROM routines, such as the ones listed in the Utility ROM Flash Routines section above. There is one restriction to storing other information in the same sector as the boot loader: it cannot be erased without erasing all or part of the boot-loader application itself. IAP Using a RAM-Based Flash Routine A RAM-based flash routine can be used to reflash the MAXQ microcontroller 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. Table 7 shows several restrictions to consider when executing code from RAM. Table 7. 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 & 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. To allow a more robust error-recovery mechanism, it is usually best to receive small packets of data and send some kind of acknowledgement. Figure 6 charts how a reflash routine can flow. Remember, if reprogramming is not successfully completed before loss of power, the microcontroller will need to be reprogrammed through the JTAG port. Page 10 of 11

Figure 6. Simplified RAM reflash routine flowchart. Appendix A. Code Examples Download: Appendix A (PDF) 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 3569: http://www.maximintegrated.com/an3569 APPLICATION NOTE 3569, AN3569, AN 3569, APP3569, Appnote3569, Appnote 3569 Copyright by Maxim Integrated Products Additional Legal Notices: http://www.maximintegrated.com/legal Page 11 of 11