Application Note: Features
Application Note: Features
Features
• Wear leveling
• Average the program/erase operations in different blocks
• Write not need be preceded by an erase operation
• Redirect logical address from host system to physical address in flash memory
• Power loss recovery
• Support FAT file system
Description
Flash memory has a limited program/erase cycle, program and erase in a same block
many times will result in bad blocks and decrease the flash memory life cycle
dramatically.
Flash memory is not fit for sector-based file systems (fat, etc.). Flash memory has
several characteristics that make difficult straightforward replacement of magnetic
disks. First, a write in flash memory should be preceded by an erase operation, which
takes an order of magnitude longer than a write operation. Second, erase operations
can only be performed in a much larger unit than the write operation. This implies
that, for an update of even a single byte, an erase operation as well as restoration of
a large amount of data would be required. This not only degrades the potential
performance significantly, but also gives rise to an integrity problem since data may
be lost if the power goes down unexpectedly during the restoration process.
An intermediate software layer called flash translation layer (FTL) addresses the
above mentioned issues. It enables the file systems access flash memory as access
magnetic disks and prolong the flash memory life cycle.
This application note will help the user to use the FTL interface.
32194A−AVR−07/12
Table of contents
2. Related parts
FTL library can be applied to the following parts:
3. FTL library
3.1 Introduction
FTL redirects the logical address from uplayer to physical address in flash memory, and average the program/erase
operation in different blocks.
FTL features the function of wear leveling, bad block management, garbage collection, defrag and power loss recovery.
It fully supports FAT file system.
Due to different features of the AT25DFx series and AT45DBx series DataFlash, two libraries have been implemented
respectively. Most of the two libraries are the same; the only difference for user is the hal layer interface. This will be
detailed in Section 3.3.3.
The footprint of FTL library is about 6Kbyte. The RAM usage depends on the block number.
3.2 Architecture
FTL is divided into three parts, up layer, ftl and hal. Figure 3-1 illustrates the architecture. Figure 3-2 shows briefly the
redirection of the logical address from uplayer to physical address in flash.
1 2 3 4 5 6 7 8 9 10 11 12 …...
Logical Sector
FTL
3 5 1 6 2 9 8 12 11 4 7 10 …... Physical Sector
Physical Sector
Data Flash 1 2 3 4 5 6 7 8 9 10 11 12 …... Address
3.3 Interface
3.3.1 Up layer
This layer provides the interface for FAT file system.
• uplayer_status_t test_unit_ready(void)
y This function is used to check memory state
Argument Type Comment
None - -
• bool test_unit_removal(void)
y This function is used to check memory if be removed
Argument Type Comment
None - -
3.3.2 FTL
This layer provides interfaces for uplayer, and can also be called directly when you don’t want to use FAT.
• ftl_status_t ftl_init(void)
y This function is used to initialize ftl structure
Argument Type Comment
None - -
• ftl_status_t ftl_test_unit_ready(void)
y This function is used to test memory state
Argument Type Comment
None - -
• ftl_status_t ftl_test_unit_wr_protect(void)
y This function is used to test memory write protect state
Argument Type Comment
None - -
• ftl_status_t ftl_test_unit_removal(void)
y This function is used to test memory if be removed
Argument Type Comment
None - -
• ftl_status_t hal_test_unit_wr_protect(void)
y This function is used to test memory if write protect
Argument Type Comment
None - -
• ftl_status_t hal_test_unit_removal(void)
y This function is used to test if memory be removed
Argument Type Comment
None - -
• ftl_status_t hal_test_unit_wr_protect(void)
y This function is used to test memory if write protect
Argument Type Comment
None - -
• ftl_status_t hal_test_unit_removal(void)
y This function is used to test if memory be removed
Argument Type Comment
None - -
2. Add the FTL library files to this folder. Here we create a new folder ftl under drivers.
3. Set the search path for toolchains and enable FTL_SUPPORT. Right click on the project, select Properties.
6. Add test routine in the at45dbx_example.c file and include asf.h in this file.
while(index--) {
//Write file data1, data2, data3, each file 1Mbytes
for(i = 0; i < 3; i++) {
printf("File: %s created\r\n", name[i]);
if(!nav_file_create((const FS_STRING)name[i])) {
printf("Create file: %s fail\r\n", name[i]);
return false;
}
if(!file_open(FOPEN_MODE_W)) {
printf("Open file: %s for write fail\r\n", name[i]);
return false;
}
for(cnt = 0; cnt < NB_WRITE; cnt++) {
if(!file_write_buf(page_buf, BUF_SIZE)) {
file_close();
printf("File write fail: %s\r\n", name[i]);
return false;
}
}
file_close();
//Read back to verify it
if(!file_open(FOPEN_MODE_R)) {
printf("Open file: %s for read fail\r\n", name[i]);
return false;
}
while (file_eof()==false) {
file_read_buf(read_buf, BUF_SIZE);
if(compare_buf(0xa5, read_buf)) {
printf("Verify file %s fail!\r\n", name[i]);
file_close();
return false;
}
}
file_close();
printf("File: %s write OK, file size: %dMByte\r\n\n", name[i],1);
}
// Delete file data1, data2, data3, then we can write them in next loop
if(!file_delete()) {
printf(“File delete fail!\r\n”);
return false;
}
}
return true;
}
Figure 5-1. Wear leveling on the Atmel AT45DB642D using FTL interface.
55
54
53
52
Erase Count
51
50
49
48
47
46
45
1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 121 127
Block
Figure 5-2 shows the wear leveling on the DataFlash AT45DB642D after about 400MByte data write through FAT
interfaces.
X-axis value is block number and Y-axis value is erase count in different blocks.
300
295
290
285
Erase Count
280
275
270
265
260
255
1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 121 127
Block
FTL divides DataFlash lifecycle to four levels (for example, AT45DB642D 100,000 times program/erase life cycles, each
level has 25,000 program/erase cycles). The block will not be used when its erase count gets up to the first level while
other blocks’ erase counts are still below 25,000. Free blocks are allocated by round robin scheduling again when all
the blocks get up to the first level. This process is going on till the blocks get its end life cycle.
Atmel®, Atmel logo and combinations thereof, AVR®, DataFlash®, Enabling Unlimited Possibilities®, and others are registered trademarks or trademarks of Atmel
Corporation or its subsidiaries. Other terms and product names may be trademarks of others.
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this
document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES
NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF
INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no
representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time
without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in,
automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.