Part Number Hot Search : 
D78C12A SAA5291A XE250 1N4948G VSC7129 BAR3504 TGD40A SC261
Product Description
Full Text Search
 

To Download AN1202 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  1/18 december 2000 AN1202 application note software drivers for the m59bw102 flash memory contents n introduction n the m59bw102 programming model n writing c code for the m59bw102 n c library functions provided n porting the drivers to the target system n limitations of the software n conclusion n c1202_16.h listing n c1202_16.c listing introduction this application note provides library source code in c for the m59bw102 flash memory. the m59bw102 flash memory in- cludes a synchronous burst bus interface, allowing very high data throughput from a small, low-cost device. the c code driv- ers are fully compatible with either the synchronous or the asynchronous modes of operation. listings of the source code can be found at the end of this doc- ument. the source code is also available in file form from the internet site http://www.st.com or from your stmicroelectronics distributor. the c1202_16.c and c1202_16.h files contain librar- ies for accessing the m59bw102. also included in this application note is an overview of the pro- gramming model for the m59bw102. this will familiarize the reader with the operation of the memory devices and provide a basis for understanding and modifying the accompanying source code. the source code is written to be as platform independent as possible and requires minimal changes by the user in order to compile and run. the application note explains how the user should modify the source code for their individual target hard- ware. all of the source code is backed up by comments explain- ing how it is used and why it has been written as it has. this application note does not replace the m59bw102 data sheet. it refers to the data sheet throughout and it is necessary to have a copy in order to follow some of the explanations. the software and accompanying documentation has been fully tested on a target platform. it is small in size and can be applied to any target hardware. the m59bw102 programming model the m59bw102 is a 1 mbit (64kb x16) flash memory which can be electrically erased and programmed through special coded command sequences on most standard microprocessor buses. the m59bw102 is a single voltage device. it differs from first generation devices which require a 12v supply to program or erase. the m59bw102 is therefore easier to use since the hardware does not need to cater for special bus signal levels.
AN1202 - application note 2/18 the voltages needed to erase the device are generated by charge pumps inside the device. included in the device is a program/erase controller. with first generation flash memory devices the soft- ware had to manually program all of the bytes to 00h before erasing to ffh using special programming sequences. the program/erase controller in the m59bw102 allows a simpler programming model to be used, by taking care of all the necessary steps required to erase and program the memory. this has led to improved reliability so that in excess of 100,000 program/erase cycles are guaranteed for the device. bus operations and commands most of the functionality of the m59bw102 is available via the two standard bus operations: read and write. read operations retrieve data or status information from the device. write operations are interpreted by the device as commands, which modify the data stored or the behavior of the device. only certain special sequences of write operations are recognized as commands by the m59bw102. the various commands recognized by the m59bw102 are listed in the commands table of the datasheet and can be grouped as follows: 1. read/reset 2. auto select 3. erase 4. program the read/reset command returns the m59bw102 to its reset state where it behaves as a rom. in this state, a read operation outputs onto the data bus the data stored at the specified address of the device. the auto select command places the device in the auto select mode, which allows the user to read the electronic signature of the device. these (the manufacturer and device codes) are accessed by reading different addresses whilst in the auto select mode. the chip erase command is used to set all the bits to 1 in every memory location in the whole chip. all data previously stored in the memory will be lost. the chip erase command typically takes 1.5s to com- plete on the m59bw102. this is longer than the other commands because the whole device is erased at once. the program command is used to modify the data stored at the specified address of the device. note that programming cannot change bits from 0 to 1. it may therefore be necessary to erase the device before programming it. programming modifies a single word at a time. programming larger amounts of data must be done one word at a time, by issuing a program command, waiting for the command to complete, then issuing the next program command, and so on. each program command requires 4 write operations to issue. the status register while the m59bw102 is programming or erasing, a read from the device will output the status register of the program/erase controller. this provides valuable information about the current program or erase command. the status register bits are described in the status register bits table of the m59bw102 data sheet. their main use is to determine when programming or erasing is complete and whether it is suc- cessful or not. completion of the program or erase operation can be determined either from the polling bit (status reg- ister bit dq7) or from the toggle bit (status register bit dq6), by following the data polling flow chart figure or the data toggle flow chart figure in the datasheet. the library routines described in this appli- cation note use the data toggle flow chart. however, a function based on the data polling flow chart is also provided as an illustration. programming or erasing errors are indicated by the error bit (status register bit dq5) becoming 1 before the command has completed. if a failure occurs, the command will not complete and read operations will continue to output the status register bits until a read/reset command is issued to the device.
3/18 AN1202 - application note a detailed example the commands table of the m59bw102 data sheet describes the sequences of write operations that will be recognized by the program/erase controller as valid commands. for example programming 65h to the address 03e2h requires the user to write the following sequence (in c): *(unsigned int*)(0x0555) = 0x00aa; *(unsigned int*)(0x02aa) = 0x0055; *(unsigned int*)(0x0555) = 0x00a0; *(unsigned int*)(0x03e2) = 0x9465; this example assumes that address 0000h of the m59bw102 is mapped to address 0000h in the micro- processor address space. in practice it is likely that the flash will have a base offset which needs to be added to the address. while the device is programming the specified address, read operations will access the status register bits. status register bit dq5 will be 1 if an error has occurred. bit dq6 will toggle while programming is on-going. bit dq7 will be the complement of the data being programmed. there are only two possible outcomes to this programming command: success or failure. success will be indicated by the toggle bit dq6 no longer toggling but being constant at its programmed value (of 1 in our example) and the polling bit dq7 also being at its programmed value (of 0 in our example). failure will be indicated by the error bit dq5 becoming 1 while the toggle bit dq6 still toggles and the polling bit dq7 remains the complement (1 in our example) of the data being programmed. note that failure of the device itself is extremely unlikely. if the command fails it will normally be because the user is attempting to change a 0 to a 1 by programming. it is only possible to change a 0 to a 1 by erasing. writing c code for the m59bw102 the low-level functions (drivers) described in this application note have been provided to simplify the pro- cess of developing application code in c for the stmicroelectronics flash memories. this enables users to concentrate on writing the high level functions required for their particular applications. these high level functions can access the flash memories by calling the low level drivers, hence keeping details of special command sequences away from the users' high level code: this will result in source code both simpler and easier to maintain. code developed using the drivers provided can be decomposed into three layers: 1. the hardware specific bus operations 2. the low-level drivers 3. the high level functions written by the user the implementation in c of the hardware specific read and write bus operations is required by the low- level drivers in order to communicate with the m59bw102. this implementation is hardware platform de- pendent as it is affected by which microprocessor the c code runs on and by where in the microproces- sor's address space the memory device is located. the user will have to write the c functions appropriate to his hardware platform (see flashread() and flashwrite() in the next section). the low-level drivers take care of issuing the correct sequences of write operations for each command and of interpreting the information received from the device during programming or erasing. these drivers encode all the specific details of how to issue commands and how to interpret the status register bits. the high level functions written by the user will access the memory device by calling the low-level func- tions. by keeping the specific details of how to access the m59bw102 away from the high level functions, the user is left with code which is simple and easier to maintain. it also makes the user's high level func- tions easier to apply to other stmicroelectronics flash memories. when developing an application, the user is advised to proceed as follows: C first write a simple program to test the low level drivers provided and verify that these operate as ex- pected on the user's target hardware and software environments.
AN1202 - application note 4/18 C then the user should write the high level code for his application, which will access the flash memories by calling the low level drivers provided. C finally test the complete application source code thoroughly. c library functions provided the software library provided with this application note provides the user with source code for the following functions: flashreadreset() is used to reset the device into the read mode. note that there should be no need to call this function under normal operation as all of the other software library functions leave the device in this mode. flashautoselect() is used to identify the manufacturer code and the device code of the device. flashchiperase() is used to erase the entire chip. flashprogram() is used to program data arrays into the flash. only previously erased words can be programmed reliably. the functions provided in the software library rely on the user implementing the hardware specific bus op- erations as well as a suitable timing function. this is to be done by writing three functions as follows: C flashread() must be written to read a value from the flash. C flashwrite() must be written to write a value to the flash. C flashpause() must be written to provide a timer with microsecond resolution. this is used to wait while the flash recovers from some conditions. an example of these functions is provided in the source code. in many instances these functions can be written as macros and therefore will not incur the function call time overhead. the two functions which perform the basic i/o to the device have been provided for users who have awkward systems. for example where the addressing system is peculiar or the data bus has d0..d7 of the device on d8..d15 of the microprocessor. they allow any user to quickly adapt the code to virtually any target system. throughout the functions assumptions have been made on the data types. these are: a char is 8 bits (1 byte). this is not the case in all microcontrollers. where it is not it will be necessary to mask the unused bits of the word (particularly in the user's flashread() function). an int is 16 bits (2 bytes). again, like the char , if this is not the case it will be necessary to use a variable type which is 16 bits or longer and mask bits above 16 bits. a long is 32 bits (4 bytes). it is necessary to have arithmetic greater than 16 bits in order to address the entire device. two approaches to the addressing are available: the desired address in the flash can be specified by a 32 bit linear pointer or a 32 bit offset into the device could be provided by the user. the flashread( ) functions in each case would declared as: unsigned char flashread( unsigned char *addr); unsigned char flashread( unsigned long uloff); the pointer option has the advantage that it runs faster. the 32 bit offset needs to be changed to an ad- dress for each access and this involves 32 bit arithmetic. using a 32 bit offset is, however, more portable since the resulting software can easily be changed to run on microprocessors with segmented memory spaces (such as the 8086). for maximum portability all the functions in this application note use a 32 bit unsigned long offset, rather than a pointer.
5/18 AN1202 - application note porting the drivers to the target system before using the software in the target system the user needs to write flashread() , flashwrite() and flashpause() functions appropriate to the target hardware. the example flashread() and flashwrite() functions provided in the source code should give the user a good idea of what is required and can be used in many instances without much modification. to test the source code in the target system start by simply reading from the m59bw102. if it is erased then only ffh data should be read. next read the manufacturer and device codes and check they are correct. if these functions work then it is likely that all of the functions will work but they should all be tested thoroughly. the programmer needs to take extra care when the device is accessed during an interrupt service routine. two situations exist which must be considered: 1. when the device is in read mode interrupts can freely read from the device. 2. interrupts which do not access the device may be used during the program, autoselect and chip erase functions. the programmer should also take care when a reset is applied during program or erase operations. the flash will be left in an indeterminate state and data could be lost. limitations of the software care should be taken in some of the while() loops. no time-outs have been implemented. software ex- ecution may stop in one of the loops due to a hardware error. a /* timeout! */ comment has been put at these places and the user can add a timer to them to prevent the software failing. the software only caters for one device in the system. to add software for more devices a mechanism for selecting the devices will be required. when an error occurs the software simply returns the error message. it is left to the user to decide what to do. either the command can be tried again or, if necessary the device may need to be replaced. conclusion the m59bw102 single voltage flash memory is an ideal product for embedded and other computer sys- tems, able to be easily interfaced to microprocessors and driven with simple software drivers written in the c language.
AN1202 - application note 6/18 /**** c1202_16.h header file for c1202_16.c ************************************ filename: c1202_16.h description: header file for c1202_16.c. consult the c file for details version: v1.00 for use with c file v1.00 copyright (c) 2000 stmicroelectronics. this program is provided as is without warranty of any kind,either expressed or implied, including but not limited to, the implied warranty of merchantability and fitness for a particular purpose. the entire risk as to the quality and performance of the program is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction. ******************************************************************************** commands for the various functions *******************************************************************************/ #define flash_read_manufacturer (-2) #define flash_read_device_code (-1) /******************************************************************************* error conditions and return values. see end of c file for explanations and help *******************************************************************************/ #define flash_success (-1) #define flash_poll_fail (-2) #define flash_too_many_blocks (-3) #define flash_mpu_too_slow (-4) #define flash_block_invalid (-5) #define flash_program_fail (-6) #define flash_offset_out_of_range (-7) #define flash_wrong_type (-8) #define flash_block_failed_erase (-9) #define flash_function_not_supported (-12) #define flash_erase_fail (-14) #define flash_toggle_fail (-15) /******************************************************************************* function prototypes *******************************************************************************/ extern unsigned int flashwrite( unsigned long uloff, unsigned int uval ); extern unsigned int flashread( unsigned long uloff ); extern void flashreadreset( void ); extern int flashautoselect( int ifunc ); extern int flasherase( void ); extern int flashprogram( unsigned long uloff, size_t numbytes, void *array ); extern int flashdatatoggle( void ); static int flashdatapoll( unsigned long uloff, unsigned int uval ); extern char *flasherrorstr( int ierrnum );
7/18 AN1202 - application note /**** 1202_16.c flash memory *************************************************** filename: 1202_16.c description: library routines for the m59bw102 flash memory. version: 1.00 initial release, fully tested on target platform. date: 14/09/2000 author: tim webster, oxford technical solutions (www.ots.ndirect.co.uk) copyright (c) 1999 stmicroelectronics. this program is provided as is without warranty of any kind, either expressed or implied, including but not limited to, the implied warranty of merchantability and fitness for a particular purpose. the entire risk as to the quality and performance of the program is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction. ******************************************************************************** version history. ver. date comments 0.00 14/09/2000 initial creation 1.00 15/09/2000 first release after testing ******************************************************************************** this source file provides library c code for using the m59bw102 device. the following devices are supported in the code: m59bw102 the following functions are available in this library: flashreadreset() to reset the flash for normal memory access flashautoselect() to get information about the device flasherase() to erase the flash flashprogram() to program a word or an array flasherrorstr() to return the error string of an error for further information consult the data sheet and the application note. the application note gives information about how to modify this code for a specific application. the hardware specific functions which need to be modified by the user are: flashwrite() for writing a word to the flash flashread() for reading a word from the flash a list of the error conditions is at the end of the code. there are no timeouts implemented in the loops in the code. at each point where an infinite loop is implemented a comment /# timeout! #/ has been placed. it is up to the user to implement these to avoid the code hanging instead of timing out. the source code assumes that the compiler implements the numerical types as unsigned char 8 bits
AN1202 - application note 8/18 unsigned int 16 bits unsigned long 32 bits additional changes to the code will be necessary if these are not correct. *******************************************************************************/ #include #include 1202_16.h /* header file with global prototypes */ #define use_m59bw102 /******************************************************************************* constants *******************************************************************************/ #define manufacturer_st (0x0020) #define base_addr ((volatile unsigned int*)0x0000) /* base_addr is the base address of the flash, see the functions flashread and flashwrite(). some applications which require a more complicated flashread() or flashwrite() may not use base_addr */ #define any_addr (0x0000l) /* any address offset within the flash memory will do */ /* bulk device not block */ #ifdef use_m59bw102 #define expected_device (0x00c1) /* device code for the m59bw102 */ #define flash_size (0x10000) /* 64k */ #endif /******************************************************************************* static prototypes the following function is only needed in this module. *******************************************************************************/ static unsigned int flashwrite( unsigned long uloff, unsigned int uval ); /******************************************************************************* function: unsigned int flashwrite( unsigned long uloff, unsigned int uval ) arguments: uloff is word offset in the flash to write to. uval is the value to be written returns: uval description: this function is used to write a word to the flash. on many microprocessor systems a macro can be used instead, increasing the speed of the flash routines. for example: #define flashwrite( uloff, uval ) ( base_addr[uloff] = (unsigned int) uval ) a function is used here instead to allow the user to expand it if necessary. the function is made to return uval so that it is compatible with the macro. pseudo code: step 1: write uval to the word offset in the flash step 2: return uval *******************************************************************************/ static unsigned int flashwrite( unsigned long uloff, unsigned int uval ) { /* step1, 2: write uval to the word offset in the flash and return it */
9/18 AN1202 - application note return base_addr[uloff] = uval; } /******************************************************************************* function: unsigned int flashread( unsigned long uloff ) arguments: uloff is the word offset into the flash to read from. returns: the unsigned int at the word offset. description: this function is used to read a word from the flash. on many microprocessor systems a macro can be used instead, increasing the speed of the flash routines. for example: #define flashread( uloff ) ( base_addr[uloff] ) a function is used here instead to allow the user to expand it if necessary. pseudo code: step 1: return the value at word offset uloff *******************************************************************************/ unsigned int flashread( unsigned long uloff ) { /* step 1 return the value at word offset uloff */ return base_addr[uloff]; } /******************************************************************************* function: void flashreadreset( void ) arguments: none return value: none description: this function places the flash in the read array mode described in the data sheet. in this mode the flash can be read as normal memory. all of the other functions leave the flash in the read array mode so this is not strictly necessary.it is provided for completeness. pseudo code: step 1: write command sequence *******************************************************************************/ void flashreadreset( void ) { /* step 1: write command sequence */ flashwrite( 0x0555l, 0x00aa ); /* 1st cycle */ flashwrite( 0x02aal, 0x0055 ); /* 2nd cycle */ flashwrite( any_addr, 0x00f0 ); /* 3rd cycle */ } /******************************************************************************* function: int flashautoselect( int ifunc ) arguments: ifunc should be set to one of the read signature values. the header file defines the values for reading the signature. return value: when ifunc is flash_read_manufacturer (-2) the function returns the manufacturers code. the manufacturer code for st is 0020h. when ifunc is flash_read_device_code (-1) the function returns the device code. the device codes for the parts are: m59bw102 00c1h when ifunc is invalid the function returns flash_function_not_supported (-12)
AN1202 - application note 10/18 description: this function can be used to read the electronic signature of the device or the manufacturer code. pseudo code: step 1: send the auto select instruction to the device instruction step 2: read the required function from the device step 3: return the device to read array mode *******************************************************************************/ int flashautoselect( int ifunc ) { int iretval; /* holds the return value */ /* step 1: send the read electronic signature instruction */ flashwrite( 0x5555l, 0x00aa ); /* 1st cycle */ flashwrite( 0x2aaal, 0x0055 ); /* 2nd cycle */ flashwrite( 0x5555l, 0x0090 ); /* 3rd cycle */ /* step 2: read the required function */ if( ifunc == flash_read_manufacturer ) iretval = flashread( 0x0000l ); /* a0 = a1 = 0 */ else if( ifunc == flash_read_device_code ) iretval = flashread( 0x0001l ); /* a0 = 1, a1 = 0 */ else iretval = flash_function_not_supported; /* step 3: return to read array mode */ flashreadreset(); return iretval; } /******************************************************************************* function: int flasherase(void) arguments: void return value: the function returns the following conditions: flash_success (-1) flash_wrong_type (-8) flash_erase_fail (-14) description: this function erases the entire flash memory. during the erase cycle the data toggle flow chart of the data sheet is followed. the polling bit, dq7, is not used. pseudo code: step 1: check for correct flash type step 2: write flash erase command step 3: follow data toggle flow chart until program/erase controller has completed step 4: return to read mode (if an error occurs) *******************************************************************************/ int flasherase( void ) { int iretval = flash_success; /* holds return value: optimistic initially! */ /* step 1: check for correct flash type */ if( !(flashautoselect( flash_read_manufacturer ) == manufacturer_st) || !(flashautoselect( flash_read_device_code ) == expected_device ) )
11/18 AN1202 - application note return flash_wrong_type; /* step 2: write flash erase command */ flashwrite( 0x0555l, 0xaa ); flashwrite( 0x02aal, 0x55 ); flashwrite( 0x0555l, 0x80 ); flashwrite( 0x0555l, 0xaa ); flashwrite( 0x02aal, 0x55 ); flashwrite( 0x0555l, 0x10 ); /* step 3: follow data toggle flow chart until program/erase controller completes */ if( flashdatatoggle() != flash_success ) { iretval = flash_erase_fail; /* step 4: return to read mode */ flashreadreset(); } return iretval; } /******************************************************************************* function: int flashprogram( unsigned long uloff, size_t numbytes, void *array ) arguments: uloff is the byte offset into the flash to be programmed numbytes holds the number of bytes in the array. array is a pointer to the array to be programmed. return value: the function returns the following conditions: flash_success (-1) flash_program_fail (-6) flash_offset_out_of_range (-7) flash_wrong_type (-8) on success the function returns flash_success (-1). the function returns flash_program_fail (-6) if a programming failure occurs. if the address range to be programmed exceeds the address range of the flash device the function returns flash_offset_out_of_range (-7) and nothing is programmed. if the wrong type of flash is detected then flash_wrong_type (-8) is returned and nothing is programmed. description: this function is used to program an array into the flash. it does not erase the flash first. pseudo code: step 1: check for correct flash type step 2: check the offset range is valid step 3: while more words are to be programed step 4: check for changes from 0 to 1 step 5: program the next word step 6: follow data toggle flow chart until program/erase controller has completed step 7: return to read mode step 8: update pointers *******************************************************************************/ int flashprogram( unsigned long uloff, size_t numbytes, void *array ) { unsigned int *uarraypointer; /* use an unsigned char to access the array */ unsigned long ullastoff; /* holds the last offset to be programmed */
AN1202 - application note 12/18 /* step 1: check for correct flash type */ if( !(flashautoselect( flash_read_manufacturer ) == manufacturer_st) || !(flashautoselect( flash_read_device_code ) == expected_device ) ) return flash_wrong_type; /* step 2: check the offset and range are valid */ ullastoff = uloff+numbytes-1; if( ullastoff >= flash_size ) return flash_offset_out_of_range; /* step 3: while there is more to be programmed */ uarraypointer = (unsigned int *)array; while( uloff <= ullastoff ) { /* step 4: check for changes from 0 to 1 */ if( ~flashread( uloff ) & *uarraypointer ) /* indicate failure as it is not possible to change a 0 to a 1 using a program command. this must be done using an erase command */ return flash_program_fail; /* step 5: program the next word */ flashwrite( 0x0555l, 0xaa ); /* 1st cycle */ flashwrite( 0x02aal, 0x55 ); /* 2nd cycle */ flashwrite( 0x0555l, 0xa0 ); /* program command */ flashwrite( uloff, *uarraypointer ); /* program value */ /* step 6: follow data toggle flow chart until program/erase controller has completed */ /* see data toggle flow chart of the data sheet */ if( flashdatatoggle() == flash_toggle_fail ) { /* step 7: return to read mode (if an error occurred) */ flashreadreset(); return flash_program_fail; } /* step 8: update pointers */ uloff++; uarraypointer++; } return flash_success; } /******************************************************************************* function: static int flashdatatoggle( void ) arguments: none return value: the function returns flash_success if the program/erase controller is successful or flash_toggle_fail if there is a problem. description: the function is used to monitor the program/erase controller during erase or program operations. it returns when the program/erase controller has completed. in them59bw102 data sheet the data toggle flow chart shows the operation of the function. pseudo code: step 1: read dq6 (into a byte) step 2: read dq5 and dq6 (into another byte) step 3: if dq6 did not toggle between the two reads then
13/18 AN1202 - application note return flash_success step 4: else if dq5 is zero then operation is not yet complete, goto 1 step 5: else (dq5 != 0), read dq6 again step 6: if dq6 did not toggle between the last two reads then return flash_success step 7: else return flash_toggle_fail *******************************************************************************/ static int flashdatatoggle( void ) { unsigned int u1, u2; /* hold values read from any address offset within the flash memory */ while( 1 ) /* timeout!: if, for some reason, the hardware fails then this loop may not exit. use a timer function to implement a timeout from the loop. */ { /* step 1: read dq6 (into a word) */ u1 = flashread( any_addr ); /* read dq6 from the flash (any address) */ /* step 2: read dq5 and dq6 (into another word) */ u2 = flashread( any_addr ); /* read dq5 and dq6 from the flash (any address) */ /* step 3: if dq6 did not toggle between the two reads then return flash_success */ if( (u1&0x0040) == (u2&0x0040) ) /* dq6 == no toggle */ return flash_success; /* step 4: else if dq5 is zero then operation is not yet complete */ if( (u2&0x0020) == 0x0000 ) continue; /* step 5: else (dq5 == 1), read dq6 again */ u1 = flashread( any_addr ); /* read dq6 from the flash (any address) */ /* step 6: if dq6 did not toggle between the last two reads then return flash_success */ if( (u2&0x0040) == (u1&0x0040) ) /* dq6 == no toggle */ return flash_success; /* step 7: else return flash_toggle_fail */ else /* dq6 == toggle here means fail */ return flash_toggle_fail; } /* end of while loop */ } #ifndef illustration_only /******************************************************************************* function: static int flashdatapoll( unsigned long uloff, unsigned int uval ) arguments: uloff should hold a valid offset to be polled. for programming this will be the offset of the word being programmed. for erasing this can be any offset in the block(s) being erased. uval should hold the value being programmed. a value of ffh should be used when erasing. return value: the function returns flash_success if the program/erase controller is successful or flash_poll_fail if there is a problem. description: the function is used to monitor the program/erase controller during erase or program operations. it returns when the program/erase controller has
AN1202 - application note 14/18 completed. in the m59bw102 data sheet the data polling flow chart shows the operation of the function. note: this library does not use the data polling flow chart to assess the correct operation of program/erase controller, but uses the data toggle flow chart instead. the flashdatapoll() function is only provided here as an illustration of the data polling flow chart in the data sheet. the code uses the function flashdatatoggle() instead. pseudo code: step 1: read dq5 and dq7 (into a word) step 2: if dq7 is the same as uval(bit 7) then return flash_success step 3: else if dq5 is zero then operation is not yet complete, goto 1 step 4: else (dq5 != 0), read dq7 step 5: if dq7 is now the same as uval(bit 7) then return flash_success step 6: else return flash_poll_fail *******************************************************************************/ static int flashdatapoll( unsigned long uloff, unsigned int uval ) { unsigned int u; /* holds value read from valid address */ while( 1 ) /* timeout!: if, for some reason, the hardware fails then this loop may not exit. use a timer function to implement a timeout from the loop. */ { /* step 1: read dq5 and dq7 (into a word) */ u = flashread( uloff ); /* read dq5, dq7 at valid addr */ /* step 2: if dq7 is the same as value(bit 7) then return flash_success */ if( (u&0x0080) == (uval&0x0080) ) /* dq7 == data */ return flash_success; /* step 3: else if dq5 is zero then operation is not yet complete */ if( (u&0x0020) == 0x0000 ) continue; /* step 4: else (dq5 == 1) */ u = flashread( uloff ); /* read dq7 at valid addr */ /* step 5: if dq7 is now the same as uval(bit 7) then return flash_success */ if( (u&0x0080) == (uval&0x0080) ) /* dq7 == data */ return flash_success; /* step 6: else return flash_poll_fail */ else /* dq7 != data here means fail */ return flash_poll_fail; } /* end of while loop */ } #endif /* !illustration_only */ /******************************************************************************* function: char *flasherrorstr( int ierrnum ); arguments: ierrnum is the error number returned from another flash routine return value: a pointer to a string with the error message description: this function is used to generate a text string describing the error from the flash. call with the return value from another
15/18 AN1202 - application note flash routine. pseudo code: step 1: check the error message range. step 2: return the correct string. *******************************************************************************/ char *flasherrorstr( int ierrnum ) { static char *str[] = { flash success, flash poll failure, flash too many blocks, mpu is too slow to erase all the blocks, flash block selected is invalid, flash program failure, flash address offset out of range, flash is of wrong type, flash block failed erase, flash is unprotected, flash is protected, flash function not supported, flash vpp invalid, flash erase fail, flash toggle flow chart failure}; /* step 1: check the error message range */ ierrnum = -ierrnum - 1; /* all errors are negative: make +ve & adjust */ if( ierrnum < 0 || ierrnum >= sizeof(str)/sizeof(str[0])) /* check range */ return unknown error\n; /* step 2: return the correct string */ else return str[ierrnum]; } /******************************************************************************* list of errors and return values, explanations and help. ******************************************************************************** return name: flash_success return value: -1 description: this value indicates that the flash command has executed correctly. ******************************************************************************** error name: flash_poll_fail notes: the data polling flow chart, which applies to m29 series flash only, is not used in this library. the function flashdatapoll() is only provided as an illustration of the data polling flow chart. this error condition should not occur when using this library. return value: -2 description: the program/erase controller algorithm has not managed to complete the command operation successfully. this may be because the device is damaged solution: try the command again. if it fails a second time then it is likely that the device will need to be replaced. ******************************************************************************** error name: flash_too_many_blocks notes: applies to m29 series flash only. return value: -3
AN1202 - application note 16/18 description: the user has chosen to erase more blocks than the device has. this may be because the array of blocks to erase contains the same block more than once. solutions: check that the program is trying to erase valid blocks. the device will only have num_blocks blocks (defined at the top of the file). also check that the same block has not been added twice or more to the array. ******************************************************************************** error name: flash_mpu_too_slow notes: applies to m29 series flash only. return value: -4 description: the mpu has not managed to write all of the selected blocks to the device before the timeout period expired. see block erase command section of the data sheet for details. solutions: if this occurs occasionally then it may be because an interrupt is occuring between writing the blocks to be erased. search for dsi! in the code and disable interrupts during the time critical sections. if this error condition always occurs then it may be time for a faster microprocessor, a better optimising c compiler or, worse still, learn assembly. the immediate solution is to only erase one block at a time. disable the test (by #defineing out the code) and always call the function with one block at a time. ******************************************************************************** error name: flash_block_invalid notes: does not apply to m59bw102 return value: -5 description: a request for an invalid block has been made. valid blocks number from 0 to num_blocks-1. solution: check that the block is in the valid range. ******************************************************************************** error name: flash_program_fail return value: -6 description: the programmed value has not been programmed correctly. solutions: make sure that the block containing the value was erased before programming. try erasing the block and re-programming the value. if it fails again then the device may need to be changed. ******************************************************************************** error name: flash_offset_out_of_range return value: -7 description: the address offset given is out of the range of the device. solution: check that the address offset is in the valid range. ******************************************************************************** error name: flash_wrong_type return value: -8 description: the source code has been used to access the wrong type of flash. solutions: use a different flash chip with the target hardware or contact stmicroelectronics for a different source code library. ******************************************************************************** error name: flash_block_failed_erase notes: does not apply to m59bw102 return value: -9 description: the previous erase to this block has not managed to successfully erase the block. solution: sadly the flash needs replacing.
17/18 AN1202 - application note ******************************************************************************** return name: flash_unprotected notes: applies to some m29 series flash only. this condition should not occur when using this library. return value: -10 description: the user has requested to unprotect a flash that is already unprotected or the user has requested to re-protect a flash that has no protected blocks. this is just a warning to the user that their operation did not make any changes and was not necessary. ******************************************************************************** return name: flash_protected notes: this condition should not occur when using this library. return value: -11 description: the user has requested to protect a flash that is already protected. this is just a warning to the user that their operation did not make any changes and was not necessary. ******************************************************************************** return name: flash_function_not_supported notes: this condition should not occur when using this library. return value: -12 description: the user has attempted to make use of functionality not available on this flash device (and thus not provided by the software drivers). this is simply a warning to the user. ******************************************************************************** error name: flash_vpp_invalid notes: applies to m28 series flash only. this error condition should not occur when using this library. return value: -13 description: a program or a block erase has been attempted with the vpp supply voltage outside the allowed ranges. this command had no effect since an invalid vpp has the effect of protecting the whole of the flash device. solution: the (hardware) configuration of vpp will need to be modified to make programming or erasing the device possible. ******************************************************************************** error name: flash_erase_fail return value: -14 description: this indicates that the previous erasure of one block, many blocks or of the whole device has failed. solution: investigate this failure further by attempting to erase each block individually. if erasing a single block still causes failure, then the flash sadly needs replacing. ******************************************************************************* error name: flash_toggle_fail return value: -15 notes: this applies to m29 series flash only. description: the program/erase controller algorithm has not managed to complete the command operation successfully. this may be because the device is damaged. solution: try the command again. if it fails a second time then it is likely that the device will need to be replaced. *******************************************************************************/
AN1202 - application note 18/18 if you have any questions or suggestion concerning the matters raised in this document please send them to the following electronic mail address: ask.memory@st.com (for general enquiries) please remember to include your name, company, location, telephone number and fax number. information furnished is believed to be accurate and reliable. however, stmicroelectronics assumes no responsibility for the co nsequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of stmicroelectronics. specifications mentioned in this publicati on are subject to change without notice. this publication supersedes and replaces all information previously supplied. stmicroelectronics prod ucts are not authorized for use as critical components in life support devices or systems without express written approval of stmicroelectro nics. the st logo is registered trademark of stmicroelectronics all other names are the property of their respective owners ? 2000 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - brazil - china - finland - france - germany - hong kong - india - italy - japan - malaysia - malta - morocco - singapore - spain - sweden - switzerland - united kingdom - u.s.a. www.st.com


▲Up To Search▲   

 
Price & Availability of AN1202

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X