1 /* -----------------------------------------------------------------------------
2 * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
4 * $Date: 2. January 2014
7 * Project: NAND Flash Driver API
8 * -------------------------------------------------------------------------- */
12 \defgroup nand_interface_gr NAND Interface
13 \brief Driver API for NAND Flash Device Interface (%Driver_NAND.h).
16 <b>NAND</b> devices are a type of non-volatile storage and do not require power to hold data.
17 Wikipedia offers more information about
18 the <a href="http://en.wikipedia.org/wiki/Flash_memory#ARM_NAND_memories" target="_blank"><b>Flash Memories</b></a>, including NAND.
23 \image html NAND_Schematics.png "Simplified NAND Flash Schematic"
29 The following header files define the Application Programming Interface (API) for the NAND interface:
30 - \b %Driver_NAND.h : Driver API for NAND Flash Device Interface
32 The driver implementation is a typical part of the Device Family Pack (DFP) that supports the
33 peripherals of the microcontroller family.
36 <b>Driver Functions</b>
38 The driver functions are published in the access struct as explained in \ref DriverFunctions
39 - \ref ARM_DRIVER_NAND : access struct for NAND driver functions
44 \todo provide details for the driver implementation text above
46 A typical setup sequence for the driver is shown below:
51 *******************************************************************************************************************/
55 \defgroup nand_execution_status Status Error Codes
56 \ingroup common_drv_gr
57 \brief Negative values indicate errors (NAND has specific codes in addition to common \ref execution_status).
59 The NAND driver has additional status error codes that are listed below.
60 Note that the NAND driver also returns the common \ref execution_status.
63 \def ARM_NAND_ERROR_ECC
64 ECC generation or correction failed during \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData or \ref ARM_NAND_ExecuteSequence.
70 \defgroup NAND_events NAND Events
71 \ingroup nand_interface_gr
72 \brief The NAND driver generates call back events that are notified via the function \ref ARM_NAND_SignalEvent.
74 This section provides the event values for the \ref ARM_NAND_SignalEvent callback function.
76 The following call back notification events are generated:
78 \def ARM_NAND_EVENT_DEVICE_READY
79 \def ARM_NAND_EVENT_DRIVER_READY
80 \def ARM_NAND_EVENT_DRIVER_DONE
81 \def ARM_NAND_EVENT_ECC_ERROR
87 \defgroup nand_driver_flag_codes NAND Flags
88 \ingroup nand_interface_gr
89 \brief Specify Flag codes.
91 The defines can be used in the function \ref ARM_NAND_ReadData and \ref ARM_NAND_WriteData for the parameter \em mode
92 and in the function \ref ARM_NAND_ExecuteSequence for the parameter \em code.
94 \def ARM_NAND_DRIVER_DONE_EVENT
100 \defgroup nand_control_gr NAND Control Codes
101 \ingroup nand_interface_gr
102 \brief Many parameters of the NAND driver are configured using the \ref ARM_NAND_Control function.
105 Refer to the function \ref ARM_NAND_Control for further details.
109 \defgroup nand_control_codes NAND Mode Controls
110 \ingroup nand_control_gr
111 \brief Specify operation modes of the NAND interface.
113 These controls can be used in the function \ref ARM_NAND_Control for the parameter \em control.
115 \def ARM_NAND_BUS_MODE
116 \def ARM_NAND_BUS_DATA_WIDTH
117 \def ARM_NAND_DRIVER_STRENGTH
118 \def ARM_NAND_DEVICE_READY_EVENT
119 \def ARM_NAND_DRIVER_READY_EVENT
124 \defgroup nand_bus_mode_codes NAND Bus Modes
125 \ingroup nand_control_gr
126 \brief Specify bus mode of the NAND interface.
128 The defines can be used in the function \ref ARM_NAND_Control for the parameter \em arg and with the \ref ARM_NAND_BUS_MODE as the \em control code.
130 \def ARM_NAND_BUS_SDR
131 \def ARM_NAND_BUS_DDR
132 \def ARM_NAND_BUS_DDR2
133 \def ARM_NAND_BUS_TIMING_MODE_0
134 \def ARM_NAND_BUS_TIMING_MODE_1
135 \def ARM_NAND_BUS_TIMING_MODE_2
136 \def ARM_NAND_BUS_TIMING_MODE_3
137 \def ARM_NAND_BUS_TIMING_MODE_4
138 \def ARM_NAND_BUS_TIMING_MODE_5
139 \def ARM_NAND_BUS_TIMING_MODE_6
140 \def ARM_NAND_BUS_TIMING_MODE_7
141 \def ARM_NAND_BUS_DDR2_DO_WCYC_0
142 \def ARM_NAND_BUS_DDR2_DO_WCYC_1
143 \def ARM_NAND_BUS_DDR2_DO_WCYC_2
144 \def ARM_NAND_BUS_DDR2_DO_WCYC_4
145 \def ARM_NAND_BUS_DDR2_DI_WCYC_0
146 \def ARM_NAND_BUS_DDR2_DI_WCYC_1
147 \def ARM_NAND_BUS_DDR2_DI_WCYC_2
148 \def ARM_NAND_BUS_DDR2_DI_WCYC_4
149 \def ARM_NAND_BUS_DDR2_VEN
150 \def ARM_NAND_BUS_DDR2_CMPD
151 \def ARM_NAND_BUS_DDR2_CMPR
156 \defgroup nand_data_bus_width_codes NAND Data Bus Width
157 \ingroup nand_control_gr
158 \brief Specify data bus width of the NAND interface.
160 The defines can be used in the function \ref ARM_NAND_Control for the parameter \em arg and with the \ref ARM_NAND_BUS_DATA_WIDTH as the \em control code.
162 \def ARM_NAND_BUS_DATA_WIDTH_8
163 \def ARM_NAND_BUS_DATA_WIDTH_16
168 \defgroup nand_driver_strength_codes NAND Driver Strength
169 \ingroup nand_control_gr
170 \brief Specify driver strength of the NAND interface.
172 The defines can be used in the function \ref ARM_NAND_Control for the parameter \em arg and with the \ref ARM_NAND_DRIVER_STRENGTH as the \em control code.
174 \def ARM_NAND_DRIVER_STRENGTH_18
175 \def ARM_NAND_DRIVER_STRENGTH_25
176 \def ARM_NAND_DRIVER_STRENGTH_35
177 \def ARM_NAND_DRIVER_STRENGTH_50
187 \defgroup nand_driver_ecc_codes NAND ECC Codes
188 \ingroup nand_interface_gr
189 \brief Specify ECC codes.
191 The defines can be used in the function \ref ARM_NAND_ReadData and \ref ARM_NAND_WriteData for the parameter \em mode
192 and in the function \ref ARM_NAND_ExecuteSequence for the parameter \em code.
202 \defgroup nand_driver_seq_exec_codes NAND Sequence Execution Codes
203 \ingroup nand_interface_gr
204 \brief Specify execution codes
206 The defines can be used in the function \ref ARM_NAND_ExecuteSequence for the parameter \em code.
208 \def ARM_NAND_CODE_SEND_CMD1
209 \def ARM_NAND_CODE_SEND_ADDR_COL1
210 \def ARM_NAND_CODE_SEND_ADDR_COL2
211 \def ARM_NAND_CODE_SEND_ADDR_ROW1
212 \def ARM_NAND_CODE_SEND_ADDR_ROW2
213 \def ARM_NAND_CODE_SEND_ADDR_ROW3
214 \def ARM_NAND_CODE_INC_ADDR_ROW
215 \def ARM_NAND_CODE_WRITE_DATA
216 \def ARM_NAND_CODE_SEND_CMD2
217 \def ARM_NAND_CODE_WAIT_BUSY
218 \def ARM_NAND_CODE_READ_DATA
219 \def ARM_NAND_CODE_SEND_CMD3
220 \def ARM_NAND_CODE_READ_STATUS
225 /*------------ Structures --------------------------------------------------------------------------------------*/
227 \struct ARM_NAND_STATUS
229 Structure with information about the status of a NAND. The data fields encode flags for the driver.
232 - \ref ARM_NAND_GetStatus
233 *****************************************************************************************************************/
236 \struct ARM_DRIVER_NAND
238 The functions of the NAND driver are accessed by function pointers exposed by this structure. Refer to \ref DriverFunctions for overview information.
240 Each instance of a NAND interface provides such an access structure.
241 The instance is identified by a postfix number in the symbol name of the access structure, for example:
242 - \b Driver_NAND0 is the name of the access struct of the first instance (no. 0).
243 - \b Driver_NAND1 is the name of the access struct of the second instance (no. 1).
245 A middleware configuration setting allows connecting the middleware to a specific driver instance <b>Driver_NAND<i>n</i></b>.
246 The default is \token{0}, which connects a middleware to the first instance of a driver.
247 *******************************************************************************************************************/
250 \struct ARM_NAND_CAPABILITIES
252 A NAND driver can be implemented with different capabilities. The data fields of this struct encode
253 the capabilities implemented by this driver.
256 - \ref ARM_NAND_GetCapabilities
257 *******************************************************************************************************************/
261 \typedef ARM_NAND_SignalEvent_t
263 Provides the typedef for the callback function \ref ARM_NAND_SignalEvent.
265 <b>Parameter for:</b>
266 - \ref ARM_NAND_Initialize
267 *******************************************************************************************************************/
271 \struct ARM_NAND_ECC_INFO
274 Stores the characteristics of a ECC (Error Correction Code) algorithm and provides the information about necessary
275 application data handling in order to protect stored data from NAND bit errors.
277 ECC algorithms applied on NAND memory typically operate on NAND device page level which is virtually divided to multiple
278 main and spare areas. Data from main and spare area is taken into account when generating ECC data which is also stored
279 into spare area. ECC codeword defines how much data will be protected and how much ECC data will be generated.
281 To describe how application data must be organized, ECC information structure specifies protection \em type which
282 defines the protected part of data. As main and spare are of different size, two different algorithms could be
283 provided, we can describe them as ECC0 and ECC1. Type can then have the following values:
287 0 | ECC algorithm not used
288 1 | ECC0 algorithm protects main data
289 2 | ECC0 algorithm protects main and spare data
290 3 | ECC0 algorithm protects main and ECC1 algorithm protects spare data
292 Virtual page division is described with page layout (\em page_layout), number of pages (\em page_count) and
293 virtual page size (\em page_size or \em virtual_page_size). Virtual page size used by ECC algorithm can be defined
294 by either \em page_size or \em virtual_page_size, depending on the \em page_size values:
296 Value| Main + Spare size
308 15 | Not used, use virtual_page_size
310 Structure member \em virtual_page_size is an array of two 16-bit values. First field of array (i.e. \em virtual_page_size[0])
311 contains main area size while second (i.e. \em virtual_page_size[1]) contains spare area size. Number of virtual pages N
312 is defined with \em page_count and must be calculated as N = 2 ^ page_count.
314 Page layout defines main and spare ordering and two different page layouts are possible. First ordering assumes that
315 spare area follows after every main area, while in second case all main areas build one contiguous region followed by
316 contiguous region of spare areas. This is defined by member \em page_layout:
320 0 | Single spare follows after single main: Main0,Spare0 ... MainN-1,SpareN-1
321 1 | Contiguous spare follows after contiguous main: Main0 ... MainN-1,Spare0 ... SpareN-1
323 ECC codeword size defines the size of data that is protected by ECC algorithm and is different for main and spare
324 area. All structure members that define the codeword are therefore arrays of two 16-bit values. Codeword offset defines
325 where ECC protected data starts in main (\em codeword_offset[0]) or spare (\em codeword_offset[1]) area, codeword
326 size (\em codeword_size) defines the number of data that is protected i.e. data over which ECC is calculated and
327 codeword gap (\em codeword_gap) defines the space between two consecutive codeword regions.
329 Generated ECC data is stored into spare area and is described similar as codeword, with offset from start of spare area
330 (\em ecc_offset), size of generated data (\em ecc_size) and gap (\em ecc_gap) between two consecutive ECC data regions.
332 Number of bits that ECC algorithm can correct per codeword is defined with \em correctable_bits.
334 <b>Parameter for:</b>
335 - \ref ARM_NAND_InquireECC
336 *****************************************************************************************************************/
343 ARM_DRIVER_VERSION ARM_NAND_GetVersion (void) {
347 \fn ARM_DRIVER_VERSION ARM_NAND_GetVersion (void)
349 The function \b ARM_NAND_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
350 - API version is the version of the CMSIS-Driver specification used to implement this driver.
351 - Driver version is source code version of the actual driver implementation.
355 extern ARM_DRIVER_NAND Driver_NAND0;
356 ARM_DRIVER_NAND *drv_info;
358 void setup_nand (void) {
359 ARM_DRIVER_VERSION version;
361 drv_info = &Driver_NAND0;
362 version = drv_info->GetVersion ();
363 if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
369 *******************************************************************************************************************/
371 ARM_NAND_CAPABILITIES ARM_NAND_GetCapabilities (void) {
375 \fn ARM_NAND_CAPABILITIES ARM_NAND_GetCapabilities (void)
377 The function \b ARM_NAND_GetCapabilities retrieves information about capabilities in this driver implementation.
378 The data fields of the structure \ref ARM_NAND_CAPABILITIES encode various capabilities, for example
379 if a hardware is able to create signal events using the \ref ARM_NAND_SignalEvent
384 extern ARM_DRIVER_NAND Driver_NAND0;
385 ARM_DRIVER_NAND *drv_info;
387 void read_capabilities (void) {
388 ARM_NAND_CAPABILITIES drv_capabilities;
390 drv_info = &Driver_NAND0;
391 drv_capabilities = drv_info->GetCapabilities ();
392 // interrogate capabilities
396 *******************************************************************************************************************/
398 int32_t ARM_NAND_Initialize (ARM_NAND_SignalEvent_t cb_event) {
402 \fn int32_t ARM_NAND_Initialize (ARM_NAND_SignalEvent_t cb_event)
404 The function \b ARM_NAND_Initialize initializes the NAND interface.
405 It is called when the middleware component starts operation.
407 The function performs the following operations:
408 - Initializes the resources needed for the NAND interface.
409 - Registers the \ref ARM_NAND_SignalEvent callback function.
411 The parameter \em cb_event is a pointer to the \ref ARM_NAND_SignalEvent callback function; use a NULL pointer
412 when no callback signals are required.
415 - see \ref nand_interface_gr - Driver Functions
417 *******************************************************************************************************************/
419 int32_t ARM_NAND_Uninitialize (void) {
423 \fn int32_t ARM_NAND_Uninitialize (void)
425 The function \b ARM_NAND_Uninitialize de-initializes the resources of NAND interface.
427 It is called when the middleware component stops operation and releases the software resources used by the interface.
428 *******************************************************************************************************************/
430 int32_t ARM_NAND_PowerControl (ARM_POWER_STATE state) {
434 \fn int32_t ARM_NAND_PowerControl (ARM_POWER_STATE state)
436 The function \b ARM_NAND_PowerControl controls the power modes of the NAND interface.
438 The parameter \em state sets the operation and can have the following values:
439 - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA.
440 Can be called multiple times. If the peripheral is already in this mode the function performs
441 no operation and returns with \ref ARM_DRIVER_OK.
442 - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
443 - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
445 Refer to \ref CallSequence for more information.
446 *******************************************************************************************************************/
449 int32_t ARM_NAND_DevicePower (uint32_t voltage) {
453 \fn int32_t ARM_NAND_DevicePower (uint32_t voltage)
455 The function \b ARM_NAND_DevicePower controls the power supply of the NAND device.
457 The parameter \em voltage sets the device supply voltage as defined in the table.
459 \b AMR_NAND_POWER_xxx_xxx specifies power settings.
461 Device Power Bits | Description
462 :--------------------------------|:--------------------------------------------
463 \ref ARM_NAND_POWER_VCC_OFF | Set VCC Power off
464 \ref ARM_NAND_POWER_VCC_3V3 | Set VCC = 3.3V
465 \ref ARM_NAND_POWER_VCC_1V8 | Set VCC = 1.8V
466 \ref ARM_NAND_POWER_VCCQ_OFF | Set VCCQ I/O Power off
467 \ref ARM_NAND_POWER_VCCQ_3V3 | Set VCCQ = 3.3V
468 \ref ARM_NAND_POWER_VCCQ_1V8 | Set VCCQ = 1.8V
469 \ref ARM_NAND_POWER_VPP_OFF | Set VPP off
470 \ref ARM_NAND_POWER_VPP_ON | Set VPP on
472 *******************************************************************************************************************/
474 int32_t ARM_NAND_WriteProtect (uint32_t dev_num, bool enable) {
478 \fn int32_t ARM_NAND_WriteProtect (uint32_t dev_num, bool enable)
480 The function \b ARM_NAND_WriteProtect controls the Write Protect (WPn) pin of a NAND device.
482 The parameter \em dev_num is the device number. \n
483 The parameter \em enable specifies whether to enable or disable write protection.
484 *******************************************************************************************************************/
486 int32_t ARM_NAND_ChipEnable (uint32_t dev_num, bool enable) {
490 \fn int32_t ARM_NAND_ChipEnable (uint32_t dev_num, bool enable)
492 The function \b ARM_NAND_ChipEnable control the Chip Enable (CEn) pin of a NAND device.
494 The parameter \em dev_num is the device number. \n
495 The parameter \em enable specifies whether to enable or disable the device.
497 This function is optional and supported only when the data field \em ce_manual = \token{1} in the structure \ref ARM_NAND_CAPABILITIES.
498 Otherwise, the Chip Enable (CEn) signal is controlled automatically by SendCommand/Address, Read/WriteData and ExecuteSequence
499 (for example when the NAND device is connected to a memory bus).
500 *******************************************************************************************************************/
502 int32_t ARM_NAND_GetDeviceBusy (uint32_t dev_num) {
506 \fn int32_t ARM_NAND_GetDeviceBusy (uint32_t dev_num)
508 The function \b ARM_NAND_GetDeviceBusy returns the status of the Device Busy pin: [\token{1=busy; 0=not busy or error}].
510 The parameter \em dev_num is the device number.
511 *******************************************************************************************************************/
513 int32_t ARM_NAND_SendCommand (uint32_t dev_num, uint8_t cmd) {
517 \fn int32_t ARM_NAND_SendCommand (uint32_t dev_num, uint8_t cmd)
519 The function \b ARM_NAND_SendCommand sends a command to the NAND device.
521 The parameter \em dev_num is the device number. \n
522 The parameter \em cmd is the command sent to the NAND device.
523 *******************************************************************************************************************/
525 int32_t ARM_NAND_SendAddress (uint32_t dev_num, uint8_t addr) {
529 \fn int32_t ARM_NAND_SendAddress (uint32_t dev_num, uint8_t addr)
531 Send an address to the NAND device.
532 The parameter \em dev_num is the device number.
533 The parameter \em addr is the address.
534 *******************************************************************************************************************/
536 int32_t ARM_NAND_ReadData (uint32_t dev_num, void *data, uint32_t cnt, uint32_t mode) {
540 \fn int32_t ARM_NAND_ReadData (uint32_t dev_num, void *data, uint32_t cnt, uint32_t mode)
542 The function \b ARM_NAND_ReadData reads data from a NAND device.
544 The parameter \em dev_num is the device number. \n
545 The parameter \em data is a pointer to the buffer that stores the data read from a NAND device. \n
546 The parameter \em cnt is the number of data items to read. \n
547 The parameter \em mode defines the operation mode as listed in the table below.
549 Read Data Mode | Description
550 :----------------------------------|:--------------------------------------------
551 \ref ARM_NAND_ECC(n) | Select ECC
552 \ref ARM_NAND_ECC0 | Use ECC0 of selected ECC
553 \ref ARM_NAND_ECC1 | Use ECC1 of selected ECC
554 \ref ARM_NAND_DRIVER_DONE_EVENT | Generate \ref ARM_NAND_EVENT_DRIVER_DONE
556 The data item size is defined by the data type, which depends on the configured data bus width.
559 - \em uint8_t for 8-bit data bus
560 - \em uint16_t for 16-bit data bus
562 The function executes in the following ways:
563 - When the operation is blocking (typical for devices connected to memory bus when not using DMA),
564 then the function returns after all data is read and returns the number of data items read.
565 - When the operation is non-blocking (typical for NAND controllers), then the function only starts the operation and returns with zero number of data items read.
566 After the operation is completed, the \ref ARM_NAND_EVENT_DRIVER_DONE event is generated (if enabled by \b ARM_NAND_DRIVER_DONE_EVENT).
567 Progress of the operation can also be monitored by calling the \ref ARM_NAND_GetStatus function and checking the \em busy data field.
568 Operation is automatically aborted if ECC is used and ECC correction fails, which generates the \ref ARM_NAND_EVENT_ECC_ERROR event
569 (together with \ref ARM_NAND_DRIVER_DONE_EVENT if enabled).
571 *******************************************************************************************************************/
573 int32_t ARM_NAND_WriteData (uint32_t dev_num, const void *data, uint32_t cnt, uint32_t mode) {
577 \fn int32_t ARM_NAND_WriteData (uint32_t dev_num, const void *data, uint32_t cnt, uint32_t mode)
579 The function \b ARM_NAND_WriteData writes data to a NAND device.
581 The parameter \em dev_num is the device number. \n
582 The parameter \em data is a pointer to the buffer with data to write. \n
583 The parameter \em cnt is the number of data items to write. \n
584 The parameter \em mode defines the operation mode as listed in the table below.
586 Write Data Mode | Description
587 :----------------------------------|:--------------------------------------------
588 \ref ARM_NAND_ECC(n) | Select ECC
589 \ref ARM_NAND_ECC0 | Use ECC0 of selected ECC
590 \ref ARM_NAND_ECC1 | Use ECC1 of selected ECC
591 \ref ARM_NAND_DRIVER_DONE_EVENT | Generate \ref ARM_NAND_EVENT_DRIVER_DONE
593 The data item size is defined by the data type, which depends on the configured data bus width.
596 - \em uint8_t for 8-bit data bus
597 - \em uint16_t for 16-bit data bus
599 The function executes in the following ways:
600 - When the operation is blocking (typical for devices connected to memory bus when not using DMA),
601 then the function returns after all data is written and returns the number of data items written.
602 - When the operation is non-blocking (typical for NAND controllers), then the function only starts the operation
603 and returns with zero number of data items written. After the operation is completed,
604 the \ref ARM_NAND_EVENT_DRIVER_DONE event is generated (if enabled by \b ARM_NAND_DRIVER_DONE_EVENT).
605 Progress of the operation can also be monitored by calling the \ref ARM_NAND_GetStatus function and checking the \em busy data field.
606 Operation is automatically aborted if ECC is used and ECC generation fails,
607 which generates the \ref ARM_NAND_EVENT_ECC_ERROR event (together with \ref ARM_NAND_DRIVER_DONE_EVENT if enabled).
608 *******************************************************************************************************************/
610 int32_t ARM_NAND_ExecuteSequence (uint32_t dev_num, uint32_t code, uint32_t cmd,
611 uint32_t addr_col, uint32_t addr_row,
612 void *data, uint32_t data_cnt,
613 uint8_t *status, uint32_t *count) {
617 \fn int32_t ARM_NAND_ExecuteSequence (uint32_t dev_num, uint32_t code, uint32_t cmd, uint32_t addr_col, uint32_t addr_row, void *data, uint32_t data_cnt, uint8_t *status, uint32_t *count)
619 The function \b ARM_NAND_ExecuteSequence executes a sequence of operations for a NAND device.
621 The parameter \em dev_num is the device number. \n
622 The parameter \em code is the sequence encoding as defined in the table <b>Sequence execution Code</b>. \n
623 The parameter \em cmd is the command or a series of commands. \n
624 The parameter \em addr_col is the column address. \n
625 The parameter \em addr_row is the row address. \n
626 The parameter \em data is a pointer to the buffer that stores the data to or loads the data from. \n
627 The parameter \em data_cnt is the number of data items to read or write in one iteration. \n
628 The parameter \em status is a pointer to the buffer that stores the status read. \n
629 The parameter \em count is a pointer to the number of iterations. \n
631 \b ARM_NAND_CODE_xxx specifies sequence execution codes.
633 Sequence Execution Code | Description
634 :----------------------------------|:--------------------------------------------
635 \ref ARM_NAND_CODE_SEND_CMD1 | Send Command 1 (cmd[7..0])
636 \ref ARM_NAND_CODE_SEND_ADDR_COL1 | Send Column Address 1 (addr_col[7..0])
637 \ref ARM_NAND_CODE_SEND_ADDR_COL2 | Send Column Address 2 (addr_col[15..8])
638 \ref ARM_NAND_CODE_SEND_ADDR_ROW1 | Send Row Address 1 (addr_row[7..0])
639 \ref ARM_NAND_CODE_SEND_ADDR_ROW2 | Send Row Address 2 (addr_row[15..8])
640 \ref ARM_NAND_CODE_SEND_ADDR_ROW3 | Send Row Address 3 (addr_row[23..16])
641 \ref ARM_NAND_CODE_INC_ADDR_ROW | Auto-increment Row Address
642 \ref ARM_NAND_CODE_WRITE_DATA | Write Data
643 \ref ARM_NAND_CODE_SEND_CMD2 | Send Command 2 (cmd[15..8])
644 \ref ARM_NAND_CODE_WAIT_BUSY | Wait while R/Bn busy
645 \ref ARM_NAND_CODE_READ_DATA | Read Data
646 \ref ARM_NAND_CODE_SEND_CMD3 | Send Command 3 (cmd[23..16])
647 \ref ARM_NAND_CODE_READ_STATUS | Read Status byte and check FAIL bit (bit 0)
648 \ref ARM_NAND_ECC(n) | Select ECC
649 \ref ARM_NAND_ECC0 | Use ECC0 of selected ECC
650 \ref ARM_NAND_ECC1 | Use ECC1 of selected ECC
651 \ref ARM_NAND_DRIVER_DONE_EVENT | Generate \ref ARM_NAND_EVENT_DRIVER_DONE
653 The data item size is defined by the data type, which depends on the configured data bus width.
656 - \em uint8_t for 8-bit data bus
657 - \em uint16_t for 16-bit data bus
659 The function is non-blocking and returns as soon as the driver has started executing the specified sequence.
660 When the operation is completed, the \ref ARM_NAND_EVENT_DRIVER_DONE event is generated (if enabled by \b ARM_NAND_DRIVER_DONE_EVENT).
661 Progress of the operation can also be monitored by calling the \ref ARM_NAND_GetStatus function and checking the \em busy data field.
663 Driver executes the number of specified iterations where in each iteration
664 items specified by \b ARM_NAND_CODE_xxx are executed in the order as listed in the table <b>Sequence execution Code</b>.
665 The parameter \em count is holding the current number of iterations left.
667 Execution is automatically aborted and \ref ARM_NAND_EVENT_DRIVER_DONE event is generated (if enabled by \b ARM_NAND_DRIVER_DONE_EVENT):
668 - if Read Status is enabled and the FAIL bit (bit 0) is set
669 - if ECC is used and ECC fails (also sets \ref ARM_NAND_EVENT_ECC_ERROR event)
672 \ref ARM_NAND_CODE_WAIT_BUSY can only be specified if the Device Ready event can be generated (reported by \em event_device_ready in \ref ARM_NAND_CAPABILITIES).
673 The event \ref ARM_NAND_EVENT_DEVICE_READY is not generated during sequence execution but rather used internally by the driver.
674 *******************************************************************************************************************/
676 int32_t ARM_NAND_AbortSequence (uint32_t dev_num) {
680 \fn int32_t ARM_NAND_AbortSequence (uint32_t dev_num)
682 The function \b ARM_NAND_AbortSequence aborts execution of the current sequence for a NAND device.
684 The parameter \em dev_num is the device number.
685 *******************************************************************************************************************/
687 int32_t ARM_NAND_Control (uint32_t dev_num, uint32_t control, uint32_t arg) {
691 \fn int32_t ARM_NAND_Control (uint32_t dev_num, uint32_t control, uint32_t arg)
693 The function \b ARM_NAND_Control controls the NAND interface and executes operations.
695 The parameter \em dev_num is the device number. \n
696 The parameter \em control specifies the operation. \n
697 The parameter \em arg provides (depending on the \em control) additional information or sets values.
699 The table lists the operations for the parameter \em control.
701 Parameter \em control | Operation
702 :--------------------------------|:--------------------------------------------
703 \ref ARM_NAND_BUS_MODE | Set the bus mode. The parameter \em arg sets the \ref bus_mode_tab "\b Bus Mode".
704 \ref ARM_NAND_BUS_DATA_WIDTH | Set the data bus width. The parameter \em arg sets the \ref bus_data_width_tab "\b Bus Data Width".
705 \ref ARM_NAND_DRIVER_STRENGTH | Set the driver strength. The parameter \em arg sets the \ref driver_strength_tab "\b Driver Strength".
706 \ref ARM_NAND_DRIVER_READY_EVENT | Control generation of callback event \ref ARM_NAND_EVENT_DRIVER_READY. Enable: \em arg = \token{1}. Disable: \em arg = \token{0}.
707 \ref ARM_NAND_DEVICE_READY_EVENT | Control generation of callback event \ref ARM_NAND_EVENT_DEVICE_READY; Enable: \em arg = \token{1}. Disable: \em arg = \token{0}.
710 - \ref ARM_NAND_GetCapabilities returns information about supported operations, which are stored in the structure \ref ARM_NAND_CAPABILITIES.
711 - \ref ARM_NAND_SignalEvent provides information about the callback events \ref ARM_NAND_EVENT_DRIVER_READY and \ref ARM_NAND_EVENT_DEVICE_READY
713 The table lists values for the parameter \em arg used with the \em control operation \ref ARM_NAND_BUS_MODE, \ref ARM_NAND_BUS_DATA_WIDTH, and
714 \ref ARM_NAND_DRIVER_STRENGTH. Values from different categories can be ORed.
717 <table class="cmtable" summary="">
718 <tr><th> Parameter \em arg <br> for <i>control</i> = \ref ARM_NAND_BUS_MODE </th>
721 <th> Description </th>
722 <th width="30%"> Supported when \ref ARM_NAND_CAPABILITIES </th></tr>
723 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_0 (default) </td>
724 <td rowspan="8" style="text-align:right"> 0..3 </td>
725 <td rowspan="8"> \anchor bus_timing_tab Bus Timing Mode </td>
727 <td rowspan="8"> The maximum timing mode that can be applied to a specific \ref bus_data_interface_tab "\b Bus Data Interface"
728 is stored in the data fields: <br><br>
729 <i>sdr_timing_mode</i> - for SDR <br>
730 <i>ddr_timing_mode</i> - for NV-DDR <br>
731 <i>ddr2_timing_mode</i> - for NV_DDR2 </td></tr>
732 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_1 </td><td> \token{1} </td></tr>
733 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_2 </td><td> \token{2} </td></tr>
734 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_3 </td><td> \token{3} </td></tr>
735 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_4 </td><td> \token{4} (SDR EDO capable) </td></tr>
736 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_5 </td><td> \token{5} (SDR EDO capable) </td></tr>
737 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_6 </td><td> \token{6} (NV-DDR2 only) </td></tr>
738 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_7 </td><td> \token{7} (NV-DDR2 only) </td></tr>
739 <tr><td> \ref ARM_NAND_BUS_SDR (default) \anchor bus_data_interface_tab </td>
740 <td rowspan="3" style="text-align:right"> 4..7 </td>
741 <td rowspan="3"> Bus Data Interface </td>
742 <td> SDR (Single Data Rate) - Traditional interface </td>
743 <td> <i>always supported</i> </td></tr>
744 <tr><td> \ref ARM_NAND_BUS_DDR </td><td> NV-DDR (Double Data Rate) </td><td> data field <i>ddr</i> = \token{1} </td></tr>
745 <tr><td> \ref ARM_NAND_BUS_DDR2 </td><td> NV-DDR2 (Double Data Rate) </td><td> data field <i>ddr2</i> = \token{1} </td></tr>
746 <tr><td style="white-space: nowrap"> \ref ARM_NAND_BUS_DDR2_DO_WCYC_0 (default) </td>
747 <td rowspan="4" style="text-align:right"> 8..11 </td>
748 <td rowspan="4" style="white-space: nowrap"> Data Output Warm-up \anchor bus_output_tab </td>
749 <td> Set the DDR2 Data Output Warm-up to \token{0} cycles </td>
750 <td rowspan="4"> <b>Data Output Warm-up</b> cycles are dummy cycles for interface calibration with no incremental data transfer
751 and apply to NV-DDR2 of the \ref bus_data_interface_tab "\b Bus Data Interface".
753 <tr><td> \ref ARM_NAND_BUS_DDR2_DO_WCYC_1 </td><td> Set the DDR2 Data Output Warm-up to \token{1} cycles </td></tr>
754 <tr><td> \ref ARM_NAND_BUS_DDR2_DO_WCYC_2 </td><td> Set the DDR2 Data Output Warm-up to \token{2} cycles </td></tr>
755 <tr><td> \ref ARM_NAND_BUS_DDR2_DO_WCYC_4 </td><td> Set the DDR2 Data Output Warm-up to \token{4} cycles </td></tr>
756 <tr><td style="white-space: nowrap"> \ref ARM_NAND_BUS_DDR2_DI_WCYC_0 (default) \anchor bus_input_tab</td>
757 <td rowspan="4" style="text-align:right"> 12..15 </td>
758 <td rowspan="4" style="white-space: nowrap"> Data Input Warm-up </td>
759 <td> Set the DDR2 Data Input Warm-up to \token{0} cycles </td>
760 <td rowspan="4"> <b>Data Input Warm-up</b> cycles are dummy cycles for interface calibration with no incremental data transfer
761 and apply to NV-DDR2 of the \ref bus_data_interface_tab "\b Bus Data Interface".
763 <tr><td> \ref ARM_NAND_BUS_DDR2_DI_WCYC_1 </td><td> Set the DDR2 Data Input Warm-up to \token{1} cycles </td></tr>
764 <tr><td> \ref ARM_NAND_BUS_DDR2_DI_WCYC_2 </td><td> Set the DDR2 Data Input Warm-up to \token{2} cycles </td></tr>
765 <tr><td> \ref ARM_NAND_BUS_DDR2_DI_WCYC_4 </td><td> Set the DDR2 Data Input Warm-up to \token{4} cycles </td></tr>
766 <tr><td style="white-space: nowrap"> \ref ARM_NAND_BUS_DDR2_VEN \anchor bus_misc_tab </td>
767 <td style="text-align:right"> 16 </td>
768 <td rowspan="3" style="white-space: nowrap"> Miscellaneous </td>
769 <td> Set the DDR2 Enable external VREFQ as reference </td>
770 <td rowspan="3">
772 <tr><td> \ref ARM_NAND_BUS_DDR2_CMPD </td><td style="text-align:right"> 17 </td><td> Set the DDR2 Enable complementary DQS (DQS_c) signal </td></tr>
773 <tr><td> \ref ARM_NAND_BUS_DDR2_CMPR </td><td style="text-align:right"> 18 </td><td> Set the DDR2 Enable complementary RE_n (RE_c) signal </td></tr>
774 <tr><th> Parameter \em arg <br> for <i>control</i> = \ref ARM_NAND_BUS_DATA_WIDTH </th>
776 <th> Category \anchor bus_data_width_tab </th>
777 <th> Description </th>
778 <th width="30%"> Supported when \ref ARM_NAND_CAPABILITIES </th></tr>
779 <tr><td style="white-space: nowrap"> \ref ARM_NAND_BUS_DATA_WIDTH_8 (default) </td>
780 <td rowspan="2" style="text-align:right"> 0..1 </td>
781 <td rowspan="2" style="white-space: nowrap"> Bus Data Width </td>
782 <td> Set to \token{8 bit} </td>
783 <td> <i>always supported</i>
785 <tr><td> \ref ARM_NAND_BUS_DATA_WIDTH_16 </td><td> Set to \token{16 bit} </td><td> data field <i>data_width_16</i> = \token{1} </td></tr>
786 <tr><th style="white-space: nowrap"> Parameter \em arg <br> for <i>control</i> = \ref ARM_NAND_DRIVER_STRENGTH </th>
788 <th> Category \anchor driver_strength_tab </th>
789 <th> Description </th>
790 <th width="30%"> Supported when \ref ARM_NAND_CAPABILITIES </th></tr>
791 <tr><td style="white-space: nowrap"> \ref ARM_NAND_DRIVER_STRENGTH_18 </td>
792 <td rowspan="4" style="text-align:right"> 0..3 </td>
793 <td rowspan="4" style="white-space: nowrap"> Driver Strength </td>
794 <td> Set the Driver Strength 2.0x = 18 Ohms </td>
795 <td> data field <i>driver_strength_18</i> = \token{1}
797 <tr><td> \ref ARM_NAND_DRIVER_STRENGTH_25 </td><td> Set the Driver Strength 1.4x = 25 Ohms </td><td> data field <i>driver_strength_25</i> = \token{1} </td></tr>
798 <tr><td> \ref ARM_NAND_DRIVER_STRENGTH_35 (default) </td><td> Set the Driver Strength 1.0x = 35 Ohms </td><td> <i>always supported</i> </td></tr>
799 <tr><td> \ref ARM_NAND_DRIVER_STRENGTH_50 </td><td> Set the Driver Strength 0.7x = 50 Ohms </td><td> data field <i>driver_strength_50</i> = \token{1} </td></tr>
804 extern ARM_DRIVER_NAND Driver_NAND0;
806 status = Driver_NAND0.Control (0, ARM_NAND_BUS_MODE, ARM_NAND_BUS_TIMING_MODE_5 |
808 ARM_NAND_BUS_DDR2_VEN);
810 status = Driver_NAND0.Control (0, ARM_NAND_BUS_DATA_WIDTH, ARM_NAND_BUS_DATA_WIDTH_16);
812 status = Driver_NAND0.Control (0, ARM_NAND_DRIVER_STRENGTH, ARM_NAND_DRIVER_STRENGTH_50);
815 *******************************************************************************************************************/
817 ARM_NAND_STATUS ARM_NAND_GetStatus (uint32_t dev_num) {
821 \fn ARM_NAND_STATUS ARM_NAND_GetStatus (uint32_t dev_num)
823 The function \b ARM_NAND_GetStatus returns the current NAND device status.
825 The parameter \em dev_num is the device number.
826 *******************************************************************************************************************/
828 int32_t ARM_NAND_InquireECC (int32_t index, ARM_NAND_ECC_INFO *info) {
832 \fn int32_t ARM_NAND_InquireECC (int32_t index, ARM_NAND_ECC_INFO *info)
834 The function \b ARM_NAND_InquireECC reads error correction code information.
836 The parameter \em index is the ECC index and is used to retrieve different ECC configurations. \n
837 The parameter \em info is a pointer of type \ref ARM_NAND_ECC_INFO. The data fields store the information.
839 When multiple different ECC configurations exist, ARM_NAND_ECC_INFO structure exists for each configuration. Parameter
840 \em index denotes which configuration will be retrieved. Value of index should start with zero to retrieve first ECC
841 configuration and should be incremented in order to retrieve next ECC configuration. When index is out of range function
842 ARM_NAND_InquireECC returns with error.
844 Parameter \em index is used by \ref ARM_NAND_ECC(n) in \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData and
845 \ref ARM_NAND_ExecuteSequence to select suitable ECC configuration.
849 extern ARM_DRIVER_NAND Driver_NAND0;
851 ARM_NAND_ECC_INFO ecc;
855 while (Driver_NAND0.InquireECC (idx, &ecc) == ARM_DRIVER_OK) {
856 // Examine retrieved ECC configuration
858 // Algorithm ECC0 protects Main+Spare
864 *******************************************************************************************************************/
866 void ARM_NAND_SignalEvent (uint32_t dev_num, uint32_t event) {
870 \fn void ARM_NAND_SignalEvent (uint32_t dev_num, uint32_t event)
872 The function \b ARM_NAND_SignalEvent is a callback function registered by the function \ref ARM_NAND_Initialize.
874 The parameter \em dev_num is the device number. \n
875 The parameter \em event indicates one or more events that occurred during driver operation.
876 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.
878 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the
879 data fields of the structure \ref ARM_NAND_CAPABILITIES, which can be retrieved with the function \ref ARM_NAND_GetCapabilities.
881 The following events can be generated:
883 Parameter \em event | Bit | Description
884 :---------------------------------|-----|:---------------------------
885 \ref ARM_NAND_EVENT_DEVICE_READY | 0 | Occurs when rising edge is detected on R/Bn (Ready/Busy) pin indicating that the device is ready.
886 \ref ARM_NAND_EVENT_DRIVER_READY | 1 | Occurs to indicate that commands can be executed (after previously being busy and not able to start the requested operation).
887 \ref ARM_NAND_EVENT_DRIVER_DONE | 2 | Occurs after an operation completes. An operation was successfully started before with \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData, \ref ARM_NAND_ExecuteSequence.
888 \ref ARM_NAND_EVENT_ECC_ERROR | 3 | Occurs when ECC generation failed or ECC correction failed. An operation was successfully started before with \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData, \ref ARM_NAND_ExecuteSequence.
890 The event \ref ARM_NAND_EVENT_DEVICE_READY occurs after complete execution of commands
891 (initiated with the functions \ref ARM_NAND_SendCommand, \ref ARM_NAND_SendAddress, \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData, \ref ARM_NAND_ExecuteSequence).
892 It is useful to indicate completion of complex operations (such as erase).
893 The event is only generated when \ref ARM_NAND_GetCapabilities returns data field \em event_device_ready = \token{1}
894 and was enabled by calling \ref ARM_NAND_Control (\ref ARM_NAND_DEVICE_READY_EVENT, 1).
895 If the event is not available, poll the \em busy data field using the function \ref ARM_NAND_GetStatus.
897 The event \ref ARM_NAND_EVENT_DRIVER_READY occurs when previously a function
898 (\ref ARM_NAND_SendCommand, \ref ARM_NAND_SendAddress, \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData, \ref ARM_NAND_ExecuteSequence)
899 returned with \ref ARM_DRIVER_ERROR_BUSY. It is useful when functions are called simultaneously from independent threads
900 (for example to control multiple devices) and the threads have no knowledge about each other (driver rejects reentrant calls with return of \ref ARM_DRIVER_ERROR_BUSY).
901 \em dev_num indicates the device that returned previously busy.
902 *******************************************************************************************************************/
907 // End NAND Interface