NAND Flash Support in AT91SAM9 Microcontrollers
NAND Flash Support in AT91SAM9 Microcontrollers
NAND Flash Support in AT91SAM9 Microcontrollers
Microcontrollers
1. Scope
The purpose of this application note is to introduce the NAND Flash technology and to
describe how to interface NAND Flash memory to Atmel® AT91SAM9 ARM® Thumb®-
based Microcontrollers that do not feature a NAND Flash Controller. The NAND Flash AT91 ARM
logic is driven by the Static Memory Controller on the NCS3 address space.
Sample code is provided the associated zip file, Basic NAND Source Code.zip; the Thumb
source code is based on the product libV3.
Microcontrollers
2. NAND Flash Overview
Application
2.1 General Overview
NAND Flash provides a cost effective alternative to hard drives, especially for portable Note
and handheld systems. The performance, pricing, and memory size options make it
optimal for storage applications (pictures, audio files, etc.).
The NAND Flash used to illustrate this interface is the K9F2G08U0M, manufactured
by Samsung® Electronics. Figure 2-1 shows the memory organization of this device.
6255B–ATARM–26-Jun-09
2.2 NAND Flash vs. NOR Flash
The most important item for memories is the cost per bit which depends on memory cell area per
bit. The cell area of NAND Flash is smaller than that of NOR Flash, making the NAND Flash
more cost effective than NOR Flash.
The first significant difference between NAND and NOR Flash is the hardware interface.
2 Application Note
6255B–ATARM–26-Jun-09
Application Note
NAND Flash typically contains blocks that contain errors and cannot be used. A check must be
done by software to list and maintain a table of bad blocks. Data integrity is achieved by using
hardware or software techniques, such as ECC, that check and correct bad data.
2.2.3 Performances
Further differences between NOR and NAND Flash can be found in read/write performances.
Table 2-1 shows random access time for NOR Flash specified at 0.09 µs, whereas NAND ran-
dom access is significantly slower — 25 µs — for the first byte. Once the initial access has been
made, however, the remaining 2,111 bytes are shifted out of NAND at only 30 ns per byte. This
results in a bandwidth of more than 23 Mb/s for 8-bit I/Os or 37 Mb/s for 16-bit I/Os.
The real benefits for NAND Flash can be found in the faster program and erase times, since
NAND provides over five megabytes per second of sustained write performance. The block
erase times are an impressive 2 ms for NAND versus 200 ms for NOR.
Table 2-1. Differences in Performance
NAND Flash NOR Flash
Characteristics K9F2G08U0M AT49BV16x4-90
25 µs (first byte)
Random access read 30 ns each for remaining 2111 0.09 µs
bytes
Sustained read speed
37 Mbytes/s 11 Mbytes/s
(sector basis)
Random write speed 300 µs/2,112 bytes 20 µs / bytes
Sustained write speed (sector
5 Mbytes/s 0.05 Mbytes/s
basis)
Erase block size 128 Kbytes 64 Kbytes
Erase cycles 100,000 to 1,000,000 10,000 to 100,000
Erase time per block 2 ms 200 ms
2.2.4 Conclusion
Table 2-2 summarizes NAND/NOR advantages and disadvantages.
Table 2-2. NAND/NOR Comparison
NAND NOR
Fast writes
Fast erases Random access
Advantages
Lower bit cost Byte writes possible
Higher density
Slow random access
Byte writes difficult Slow writes
Disadvantages
Bad blocks management and ECC Slow erase
required
File (disk) applications
Execute directly from non volatile
Applications Voice, data, video recorder
memory
Any large sequential data
Clearly, NAND Flash has several significant positive attributes. The one negative attribute is that
it is not well-suited for direct random access.
3
6255B–ATARM–26-Jun-09
NAND is available in large capacities and is the lowest cost Flash memory available today.
NAND is used in virtually all removable cards for cost/density reasons: USB Cards, Memory
Stick, MMC Multimedia Card, SD Secure Digital, CF Compact Flash.
4 Application Note
6255B–ATARM–26-Jun-09
Application Note
Important Note: Any intentional erasure of the original invalid block information is prohibited.
3.3 ECC
NAND devices are subject to data failures that occur during device operation. To ensure data
read/write integrity, system error-checking and correction (ECC) algorithms must be imple-
mented. Depending on the AT91 product, the ECC algorithm must be calculated by software or
can be generated by the embedded hardware ECC controller. The ECC controller is capable of
single bit error correction and 2-bit random detection. When NAND has more than 2 bits of
errors, the data cannot be corrected. This controller allows ECC management without CPU inter-
vention and thus improves the total bandwidth of the system.
5
6255B–ATARM–26-Jun-09
4.4 Address (ALE = 1, CLE = 0)
Addresses are written to the address register on the rising edge of WE# when:
• CE# and CLE are low
• ALE is high
Addresses are input on I/O[7:0] only. For devices with a x16 interface, I/O[15:8] must be written
with zeros when issuing an address. Generally all five ADDRESS cycles are written to the
device.
4.7 Example
The following waveforms shows the successive accesses: COMMAND Latch, ADDRESS Latch
and DATA Output with a “CE don’t Care” NAND. Notice that no command can be sent to the
NAND Flash during tR, because it is busy.
6 Application Note
6255B–ATARM–26-Jun-09
Application Note
7
6255B–ATARM–26-Jun-09
Table 5-2. EBI Signals Example for AT91SAM9260
Name Function Type Active Level
NANDCS NAND Flash Chip Select Line Output Low
NANDOE NAND Flash Output Enable Output Low
NANDWE NAND Flash Write Enable Output Low
A22/CLE Command Latch Enable Output High
A21/ALE Address Latch Enable Output High
PIOx/CE Chip Enable (1)(2) Output Low
PIOy/RDY/BSY Ready/Busy (1) Input Low
Figure 5-1. “CE don’t care” and Standard NAND Flash Application Example
D[7:0] D[7:0]
AD[7:0] AD[7:0]
A[22:21] A[22:21]
ALE ALE
CLE CLE
NCS3/NANDCS NCS3/NANDCS
CE Not Connected
EBI EBI
NCS6/NANDOE NCS6/NANDOE
NOE NOE
NCS7/NANDWE NCS7/NANDWE
NWE NWE
PIO CE
8 Application Note
6255B–ATARM–26-Jun-09
Application Note
6.1 Clocks
The system is running at full speed, this means 198 MHz for the processor and 99 MHz for the
Bus. The EBI NCS3 is to be assigned for NAND Flash usage.
6.2 PIOs
Table 6-3. Peripheral Configuration for “CE don’t Care” NAND on AT91SAM9260
Description Settings AT91 libV3 function
AT91F_PIO_CfgPeriph(AT91C_BASE_PIOC,
NCS3 is CE Output AT91C_PC14_NCS3_NANDCS,0);
PC13 is RDY/BSY (1) Input AT91F_PIO_CfgInput(AT91C_BASE_PIOC, AT91C_PIO_PC13);
9
6255B–ATARM–26-Jun-09
6.3 SMC Timings
The K9F2G08U0M is a 256 MB device connected with an 8-bit data bus width.
An accurate one-to-one comparison is necessary between NandFlash and SMC waveforms for
a complete SMC configuration. Figure 6-1 and Figure 6-2 show two cases that highlight all the
required timings.
ALE/CLE
NCS
NWE
D[31:0]
NWE_CYCLE
NCS
NRD
D[31:0]
NRD_CYCLE
10 Application Note
6255B–ATARM–26-Jun-09
Application Note
As CLE and ALE are address lines (A21, A22), an additional setup timing is required to respect
tAR (10 ns) and tCLR (10 ns) on STATUS or RANDOM DATA READ Cycle.
11
6255B–ATARM–26-Jun-09
To fit these requirements the values to program in SMC are:
• NRD_SETUP = NWE_SETUP = 1
• NRD_CYCLE = NWE_CYCLE = 5
• NRD_PULSE = NWE_PULSE = 3
• Data Float Time = 2
Therefore all the timings are realized:
• NWE_HOLD = NRD_CYCLE - NRD_PULSE - NRD_SETUP = 1
• NRD_CYCLE - NRD_PULSE = 2
• NWE_SETUP + NWE_PULSE = 4
Table 6-5 gives SMC register configurations, other fields keep the reset values.
12 Application Note
6255B–ATARM–26-Jun-09
Application Note
D[0..7]
U1 K9F2G08U0M
CLE 16 29 D0
CLE I/O0 D1
ALE 17 ALE I/O1 30
NANDOE 8 31 D2
RE I/O2 D3
NANDWE 18 WE I/O3 32
(ANY PIO) 9 41 D4
CE I/O4 D5
I/O5 42
7 43 D6
(ANY PIO) R/B I/O6
R1 10K 44 D7
I/O7
3V3 19 WP
R2 10K N.C 48
N.C 47
1 N.C N.C 46
2 N.C N.C 45
3 N.C N.C 40
4 N.C N.C 39
5 N.C PRE 38
6 N.C N.C 35
10 N.C N.C 34
11 N.C N.C 33
14 N.C N.C 28
15 N.C N.C 27 3V3
20 N.C
21 N.C VCC 37
22 N.C VCC 12
23 C2
N.C
24 N.C
25 36 100NF
N.C VSS
26 N.C VSS 13
C1
2 Gb 100NF
TSOP48 PACKAGE
13
6255B–ATARM–26-Jun-09
7.2 16-bit NAND Flash
D[0..15]
U1 MT29F2G16AABWP-ET
16 D0
CLE CLE I/O0 26 D1
ALE 17 ALE I/O1 28
8 D2
NANDOE RE I/O2 30 D3
NANDWE 18 WE I/O3 32
9 D4
(ANY PIO) CE I/O4 40 D5
I/O5 42 D6
(ANY PIO) 7 R/B I/O6 44
R1 10K D7
I/O7 46 D8
3V3 19 WP I/O8 27 D9
R2 10K I/O9 29 D10
I/O10 31 D11
1 N.C I/O11 33
2 D12
N.C I/O12 41 D13
3 N.C I/O13 43
4 D14
N.C I/O14 45 D15
5 N.C I/O15 47
6 N.C
10 N.C N.C 39
11 N.C PRE 38
14 N.C N.C 36
15 3V3
N.C
20 N.C
21 N.C VCC 37
22 N.C VCC 12
23 N.C
24 48 C2
N.C VSS 100NF
34 N.C VSS 25
35 N.C VSS 13
C1
2 Gb 100NF
TSOP48 PACKAGE
14 Application Note
6255B–ATARM–26-Jun-09
Application Note
• Another PIO line must be declared to handle CE# on standard devices (not “CE don’t Care”).
• PC14 PIO line is configured for an NCS3_NANDCS usage.
• The corresponding PIO Clock is started.
• A NAND Flash identification is done on NCS3 memory space.
• A NAND structure is created and filled-in with Flash ID relevant data.
• Data bus width is modified depending on the NAND Flash type.
Once completed, the system is ready to access the NAND Flash with best performances.
A software package that performs this configuration is provided with this Application Note.
15
6255B–ATARM–26-Jun-09
Figure 8-2. CE During Two Page Read on “CE don’t care” NAND
16 Application Note
6255B–ATARM–26-Jun-09
Application Note
Revision History
Change
Doc. Rev Date Comments Request Ref.
6255A 09-Oct-06 First issue
page 1: AT91SAM -> AT91SAM9 3906
6255B 16-Jun-09
Table 6-5 on page 12: NAND Flash support App Note: SMC Timings are not correct 5582
17
6255B–ATARM–26-Jun-09
Headquarters International
Product Contact
Literature Requests
www.atmel.com/literature
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 ATMEL’S TERMS AND CONDI-
TIONS OF SALE LOCATED ON ATMEL’S WEB SITE, 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 INCIDEN-
TAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF 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 product 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’s products are not intended, authorized, or warranted for use
as components in applications intended to support or sustain life.
© 2009 Atmel Corporation. All rights reserved. Atmel®, Atmel logo and combinations thereof, and others are registered trademarks or trade-
marks of Atmel Corporation or its subsidiaries. ARM® and Thumb® are registered trademarks of ARM Ltd. Other terms and product names may
be trademarks of others.
6255B–ATARM–26-Jun-09