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.
35 NAND Flash is organized in pages, grouped into blocks as the smallest erasable unit. The addressing
36 of data is archieved by `byte_address = block * block_size + page_in_block * page_size + offset_in_page`.
37 In terms of this NAND API blocks and pages are referrd to as `row` and the byte offset within the page as `col`.
38 Thus one can calculate the `byte_address = row * page_size + col`. The parameters `page_size` and `block_size`
39 are device specific and must be handled by the driver user appropriately.
41 <b>Driver Functions</b>
42 <b>Driver Functions</b>
44 The driver functions are published in the access struct as explained in \ref DriverFunctions
45 - \ref ARM_DRIVER_NAND : access struct for NAND driver functions
48 \anchor example <b>Example Code:</b>
52 /*******************************************************************************************************************/
56 \defgroup nand_execution_status Status Error Codes
57 \ingroup common_drv_gr
58 \brief Negative values indicate errors (NAND has specific codes in addition to common \ref execution_status).
60 The NAND driver has additional status error codes that are listed below.
61 Note that the NAND driver also returns the common \ref execution_status.
64 \def ARM_NAND_ERROR_ECC
65 ECC generation or correction failed during \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData or \ref ARM_NAND_ExecuteSequence.
71 \defgroup NAND_events NAND Events
72 \ingroup nand_interface_gr
73 \brief The NAND driver generates call back events that are notified via the function \ref ARM_NAND_SignalEvent.
75 This section provides the event values for the \ref ARM_NAND_SignalEvent callback function.
77 The following call back notification events are generated:
79 \def ARM_NAND_EVENT_DEVICE_READY
80 \def ARM_NAND_EVENT_DRIVER_READY
81 \def ARM_NAND_EVENT_DRIVER_DONE
82 \def ARM_NAND_EVENT_ECC_ERROR
88 \defgroup nand_driver_flag_codes NAND Flags
89 \ingroup nand_interface_gr
90 \brief Specify Flag codes.
92 The defines can be used in the function \ref ARM_NAND_ReadData and \ref ARM_NAND_WriteData for the parameter \em mode
93 and in the function \ref ARM_NAND_ExecuteSequence for the parameter \em code.
95 \def ARM_NAND_DRIVER_DONE_EVENT
101 \defgroup nand_control_gr NAND Control Codes
102 \ingroup nand_interface_gr
103 \brief Many parameters of the NAND driver are configured using the \ref ARM_NAND_Control function.
106 Refer to the function \ref ARM_NAND_Control for further details.
110 \defgroup nand_control_codes NAND Mode Controls
111 \ingroup nand_control_gr
112 \brief Specify operation modes of the NAND interface.
114 These controls can be used in the function \ref ARM_NAND_Control for the parameter \em control.
116 \def ARM_NAND_BUS_MODE
117 \def ARM_NAND_BUS_DATA_WIDTH
118 \def ARM_NAND_DRIVER_STRENGTH
119 \def ARM_NAND_DEVICE_READY_EVENT
120 \def ARM_NAND_DRIVER_READY_EVENT
125 \defgroup nand_bus_mode_codes NAND Bus Modes
126 \ingroup nand_control_gr
127 \brief Specify bus mode of the NAND interface.
129 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.
131 \def ARM_NAND_BUS_SDR
132 \def ARM_NAND_BUS_DDR
133 \def ARM_NAND_BUS_DDR2
134 \def ARM_NAND_BUS_TIMING_MODE_0
135 \def ARM_NAND_BUS_TIMING_MODE_1
136 \def ARM_NAND_BUS_TIMING_MODE_2
137 \def ARM_NAND_BUS_TIMING_MODE_3
138 \def ARM_NAND_BUS_TIMING_MODE_4
139 \def ARM_NAND_BUS_TIMING_MODE_5
140 \def ARM_NAND_BUS_TIMING_MODE_6
141 \def ARM_NAND_BUS_TIMING_MODE_7
142 \def ARM_NAND_BUS_DDR2_DO_WCYC_0
143 \def ARM_NAND_BUS_DDR2_DO_WCYC_1
144 \def ARM_NAND_BUS_DDR2_DO_WCYC_2
145 \def ARM_NAND_BUS_DDR2_DO_WCYC_4
146 \def ARM_NAND_BUS_DDR2_DI_WCYC_0
147 \def ARM_NAND_BUS_DDR2_DI_WCYC_1
148 \def ARM_NAND_BUS_DDR2_DI_WCYC_2
149 \def ARM_NAND_BUS_DDR2_DI_WCYC_4
150 \def ARM_NAND_BUS_DDR2_VEN
151 \def ARM_NAND_BUS_DDR2_CMPD
152 \def ARM_NAND_BUS_DDR2_CMPR
157 \defgroup nand_data_bus_width_codes NAND Data Bus Width
158 \ingroup nand_control_gr
159 \brief Specify data bus width of the NAND interface.
161 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.
163 \def ARM_NAND_BUS_DATA_WIDTH_8
164 \def ARM_NAND_BUS_DATA_WIDTH_16
169 \defgroup nand_driver_strength_codes NAND Driver Strength
170 \ingroup nand_control_gr
171 \brief Specify driver strength of the NAND interface.
173 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.
175 \def ARM_NAND_DRIVER_STRENGTH_18
176 \def ARM_NAND_DRIVER_STRENGTH_25
177 \def ARM_NAND_DRIVER_STRENGTH_35
178 \def ARM_NAND_DRIVER_STRENGTH_50
188 \defgroup nand_driver_ecc_codes NAND ECC Codes
189 \ingroup nand_interface_gr
190 \brief Specify ECC codes.
192 The defines can be used in the function \ref ARM_NAND_ReadData and \ref ARM_NAND_WriteData for the parameter \em mode
193 and in the function \ref ARM_NAND_ExecuteSequence for the parameter \em code.
203 \defgroup nand_driver_seq_exec_codes NAND Sequence Execution Codes
204 \ingroup nand_interface_gr
205 \brief Specify execution codes
207 The defines can be used in the function \ref ARM_NAND_ExecuteSequence for the parameter \em code.
209 \def ARM_NAND_CODE_SEND_CMD1
210 \def ARM_NAND_CODE_SEND_ADDR_COL1
211 \def ARM_NAND_CODE_SEND_ADDR_COL2
212 \def ARM_NAND_CODE_SEND_ADDR_ROW1
213 \def ARM_NAND_CODE_SEND_ADDR_ROW2
214 \def ARM_NAND_CODE_SEND_ADDR_ROW3
215 \def ARM_NAND_CODE_INC_ADDR_ROW
216 \def ARM_NAND_CODE_WRITE_DATA
217 \def ARM_NAND_CODE_SEND_CMD2
218 \def ARM_NAND_CODE_WAIT_BUSY
219 \def ARM_NAND_CODE_READ_DATA
220 \def ARM_NAND_CODE_SEND_CMD3
221 \def ARM_NAND_CODE_READ_STATUS
226 /*------------ Structures --------------------------------------------------------------------------------------*/
228 \struct ARM_NAND_STATUS
230 Structure with information about the status of a NAND. The data fields encode flags for the driver.
233 - \ref ARM_NAND_GetStatus
234 *****************************************************************************************************************/
237 \struct ARM_DRIVER_NAND
239 The functions of the NAND driver are accessed by function pointers exposed by this structure. Refer to \ref DriverFunctions for overview information.
241 Each instance of a NAND interface provides such an access structure.
242 The instance is identified by a postfix number in the symbol name of the access structure, for example:
243 - \b Driver_NAND0 is the name of the access struct of the first instance (no. 0).
244 - \b Driver_NAND1 is the name of the access struct of the second instance (no. 1).
246 A middleware configuration setting allows connecting the middleware to a specific driver instance <b>Driver_NAND<i>n</i></b>.
247 The default is \token{0}, which connects a middleware to the first instance of a driver.
248 *******************************************************************************************************************/
251 \struct ARM_NAND_CAPABILITIES
253 A NAND driver can be implemented with different capabilities. The data fields of this struct encode
254 the capabilities implemented by this driver.
257 - \ref ARM_NAND_GetCapabilities
258 *******************************************************************************************************************/
262 \typedef ARM_NAND_SignalEvent_t
264 Provides the typedef for the callback function \ref ARM_NAND_SignalEvent.
266 <b>Parameter for:</b>
267 - \ref ARM_NAND_Initialize
268 *******************************************************************************************************************/
272 \struct ARM_NAND_ECC_INFO
275 Stores the characteristics of a ECC (Error Correction Code) algorithm and provides the information about necessary
276 application data handling in order to protect stored data from NAND bit errors.
278 ECC algorithms applied on NAND memory typically operate on NAND device page level which is virtually divided to multiple
279 main and spare areas. Data from main and spare area is taken into account when generating ECC data which is also stored
280 into spare area. ECC codeword defines how much data will be protected and how much ECC data will be generated.
282 To describe how application data must be organized, ECC information structure specifies protection \em type which
283 defines the protected part of data. As main and spare are of different size, two different algorithms could be
284 provided, we can describe them as ECC0 and ECC1. Type can then have the following values:
288 0 | ECC algorithm not used
289 1 | ECC0 algorithm protects main data
290 2 | ECC0 algorithm protects main and spare data
291 3 | ECC0 algorithm protects main and ECC1 algorithm protects spare data
293 Virtual page division is described with page layout (\em page_layout), number of pages (\em page_count) and
294 virtual page size (\em page_size or \em virtual_page_size). Virtual page size used by ECC algorithm can be defined
295 by either \em page_size or \em virtual_page_size, depending on the \em page_size values:
297 Value| Main + Spare size
309 15 | Not used, use virtual_page_size
311 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])
312 contains main area size while second (i.e. \em virtual_page_size[1]) contains spare area size. Number of virtual pages N
313 is defined with \em page_count and must be calculated as N = 2 ^ page_count.
315 Page layout defines main and spare ordering and two different page layouts are possible. First ordering assumes that
316 spare area follows after every main area, while in second case all main areas build one contiguous region followed by
317 contiguous region of spare areas. This is defined by member \em page_layout:
321 0 | Single spare follows after single main: Main0,Spare0 ... MainN-1,SpareN-1
322 1 | Contiguous spare follows after contiguous main: Main0 ... MainN-1,Spare0 ... SpareN-1
324 ECC codeword size defines the size of data that is protected by ECC algorithm and is different for main and spare
325 area. All structure members that define the codeword are therefore arrays of two 16-bit values. Codeword offset defines
326 where ECC protected data starts in main (\em codeword_offset[0]) or spare (\em codeword_offset[1]) area, codeword
327 size (\em codeword_size) defines the number of data that is protected i.e. data over which ECC is calculated and
328 codeword gap (\em codeword_gap) defines the space between two consecutive codeword regions.
330 Generated ECC data is stored into spare area and is described similar as codeword, with offset from start of spare area
331 (\em ecc_offset), size of generated data (\em ecc_size) and gap (\em ecc_gap) between two consecutive ECC data regions.
333 Number of bits that ECC algorithm can correct per codeword is defined with \em correctable_bits.
335 <b>Parameter for:</b>
336 - \ref ARM_NAND_InquireECC
337 *****************************************************************************************************************/
344 ARM_DRIVER_VERSION ARM_NAND_GetVersion (void) {
348 \fn ARM_DRIVER_VERSION ARM_NAND_GetVersion (void)
350 The function \b ARM_NAND_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
351 - API version is the version of the CMSIS-Driver specification used to implement this driver.
352 - Driver version is source code version of the actual driver implementation.
356 extern ARM_DRIVER_NAND Driver_NAND0;
357 ARM_DRIVER_NAND *drv_info;
359 void setup_nand (void) {
360 ARM_DRIVER_VERSION version;
362 drv_info = &Driver_NAND0;
363 version = drv_info->GetVersion ();
364 if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
370 *******************************************************************************************************************/
372 ARM_NAND_CAPABILITIES ARM_NAND_GetCapabilities (void) {
376 \fn ARM_NAND_CAPABILITIES ARM_NAND_GetCapabilities (void)
378 The function \b ARM_NAND_GetCapabilities retrieves information about capabilities in this driver implementation.
379 The data fields of the structure \ref ARM_NAND_CAPABILITIES encode various capabilities, for example
380 if a hardware is able to create signal events using the \ref ARM_NAND_SignalEvent
385 extern ARM_DRIVER_NAND Driver_NAND0;
386 ARM_DRIVER_NAND *drv_info;
388 void read_capabilities (void) {
389 ARM_NAND_CAPABILITIES drv_capabilities;
391 drv_info = &Driver_NAND0;
392 drv_capabilities = drv_info->GetCapabilities ();
393 // interrogate capabilities
397 *******************************************************************************************************************/
399 int32_t ARM_NAND_Initialize (ARM_NAND_SignalEvent_t cb_event) {
403 \fn int32_t ARM_NAND_Initialize (ARM_NAND_SignalEvent_t cb_event)
405 The function \b ARM_NAND_Initialize initializes the NAND interface.
406 It is called when the middleware component starts operation.
408 The function performs the following operations:
409 - Initializes the resources needed for the NAND interface.
410 - Registers the \ref ARM_NAND_SignalEvent callback function.
412 The parameter \em cb_event is a pointer to the \ref ARM_NAND_SignalEvent callback function; use a NULL pointer
413 when no callback signals are required.
416 - see \ref nand_interface_gr - Driver Functions
418 *******************************************************************************************************************/
420 int32_t ARM_NAND_Uninitialize (void) {
424 \fn int32_t ARM_NAND_Uninitialize (void)
426 The function \b ARM_NAND_Uninitialize de-initializes the resources of NAND interface.
428 It is called when the middleware component stops operation and releases the software resources used by the interface.
429 *******************************************************************************************************************/
431 int32_t ARM_NAND_PowerControl (ARM_POWER_STATE state) {
435 \fn int32_t ARM_NAND_PowerControl (ARM_POWER_STATE state)
437 The function \b ARM_NAND_PowerControl controls the power modes of the NAND interface.
439 The parameter \em state sets the operation and can have the following values:
440 - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA.
441 Can be called multiple times. If the peripheral is already in this mode the function performs
442 no operation and returns with \ref ARM_DRIVER_OK.
443 - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
444 - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
446 Refer to \ref CallSequence for more information.
447 *******************************************************************************************************************/
450 int32_t ARM_NAND_DevicePower (uint32_t voltage) {
454 \fn int32_t ARM_NAND_DevicePower (uint32_t voltage)
456 The function \b ARM_NAND_DevicePower controls the power supply of the NAND device.
458 The parameter \em voltage sets the device supply voltage as defined in the table.
460 \b AMR_NAND_POWER_xxx_xxx specifies power settings.
462 Device Power Bits | Description
463 :--------------------------------|:--------------------------------------------
464 \ref ARM_NAND_POWER_VCC_OFF | Set VCC Power off
465 \ref ARM_NAND_POWER_VCC_3V3 | Set VCC = 3.3V
466 \ref ARM_NAND_POWER_VCC_1V8 | Set VCC = 1.8V
467 \ref ARM_NAND_POWER_VCCQ_OFF | Set VCCQ I/O Power off
468 \ref ARM_NAND_POWER_VCCQ_3V3 | Set VCCQ = 3.3V
469 \ref ARM_NAND_POWER_VCCQ_1V8 | Set VCCQ = 1.8V
470 \ref ARM_NAND_POWER_VPP_OFF | Set VPP off
471 \ref ARM_NAND_POWER_VPP_ON | Set VPP on
473 *******************************************************************************************************************/
475 int32_t ARM_NAND_WriteProtect (uint32_t dev_num, bool enable) {
479 \fn int32_t ARM_NAND_WriteProtect (uint32_t dev_num, bool enable)
481 The function \b ARM_NAND_WriteProtect controls the Write Protect (WPn) pin of a NAND device.
483 The parameter \em dev_num is the device number. \n
484 The parameter \em enable specifies whether to enable or disable write protection.
485 *******************************************************************************************************************/
487 int32_t ARM_NAND_ChipEnable (uint32_t dev_num, bool enable) {
491 \fn int32_t ARM_NAND_ChipEnable (uint32_t dev_num, bool enable)
493 The function \b ARM_NAND_ChipEnable control the Chip Enable (CEn) pin of a NAND device.
495 The parameter \em dev_num is the device number. \n
496 The parameter \em enable specifies whether to enable or disable the device.
498 This function is optional and supported only when the data field \em ce_manual = \token{1} in the structure \ref ARM_NAND_CAPABILITIES.
499 Otherwise, the Chip Enable (CEn) signal is controlled automatically by SendCommand/Address, Read/WriteData and ExecuteSequence
500 (for example when the NAND device is connected to a memory bus).
501 *******************************************************************************************************************/
503 int32_t ARM_NAND_GetDeviceBusy (uint32_t dev_num) {
507 \fn int32_t ARM_NAND_GetDeviceBusy (uint32_t dev_num)
509 The function \b ARM_NAND_GetDeviceBusy returns the status of the Device Busy pin: [\token{1=busy; 0=not busy or error}].
511 The parameter \em dev_num is the device number.
512 *******************************************************************************************************************/
514 int32_t ARM_NAND_SendCommand (uint32_t dev_num, uint8_t cmd) {
518 \fn int32_t ARM_NAND_SendCommand (uint32_t dev_num, uint8_t cmd)
520 The function \b ARM_NAND_SendCommand sends a command to the NAND device.
522 The parameter \em dev_num is the device number. \n
523 The parameter \em cmd is the command sent to the NAND device.
524 *******************************************************************************************************************/
526 int32_t ARM_NAND_SendAddress (uint32_t dev_num, uint8_t addr) {
530 \fn int32_t ARM_NAND_SendAddress (uint32_t dev_num, uint8_t addr)
532 Send an address to the NAND device.
533 The parameter \em dev_num is the device number.
534 The parameter \em addr is the address.
535 *******************************************************************************************************************/
537 int32_t ARM_NAND_ReadData (uint32_t dev_num, void *data, uint32_t cnt, uint32_t mode) {
541 \fn int32_t ARM_NAND_ReadData (uint32_t dev_num, void *data, uint32_t cnt, uint32_t mode)
543 The function \b ARM_NAND_ReadData reads data from a NAND device.
545 The parameter \em dev_num is the device number. \n
546 The parameter \em data is a pointer to the buffer that stores the data read from a NAND device. \n
547 The parameter \em cnt is the number of data items to read. \n
548 The parameter \em mode defines the operation mode as listed in the table below.
550 Read Data Mode | Description
551 :----------------------------------|:--------------------------------------------
552 \ref ARM_NAND_ECC(n) | Select ECC
553 \ref ARM_NAND_ECC0 | Use ECC0 of selected ECC
554 \ref ARM_NAND_ECC1 | Use ECC1 of selected ECC
555 \ref ARM_NAND_DRIVER_DONE_EVENT | Generate \ref ARM_NAND_EVENT_DRIVER_DONE
557 The data item size is defined by the data type, which depends on the configured data bus width.
560 - \em uint8_t for 8-bit data bus
561 - \em uint16_t for 16-bit data bus
563 The function executes in the following ways:
564 - When the operation is blocking (typical for devices connected to memory bus when not using DMA),
565 then the function returns after all data is read and returns the number of data items read.
566 - 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.
567 After the operation is completed, the \ref ARM_NAND_EVENT_DRIVER_DONE event is generated (if enabled by \b ARM_NAND_DRIVER_DONE_EVENT).
568 Progress of the operation can also be monitored by calling the \ref ARM_NAND_GetStatus function and checking the \em busy data field.
569 Operation is automatically aborted if ECC is used and ECC correction fails, which generates the \ref ARM_NAND_EVENT_ECC_ERROR event
570 (together with \ref ARM_NAND_DRIVER_DONE_EVENT if enabled).
572 *******************************************************************************************************************/
574 int32_t ARM_NAND_WriteData (uint32_t dev_num, const void *data, uint32_t cnt, uint32_t mode) {
578 \fn int32_t ARM_NAND_WriteData (uint32_t dev_num, const void *data, uint32_t cnt, uint32_t mode)
580 The function \b ARM_NAND_WriteData writes data to a NAND device.
582 The parameter \em dev_num is the device number. \n
583 The parameter \em data is a pointer to the buffer with data to write. \n
584 The parameter \em cnt is the number of data items to write. \n
585 The parameter \em mode defines the operation mode as listed in the table below.
587 Write Data Mode | Description
588 :----------------------------------|:--------------------------------------------
589 \ref ARM_NAND_ECC(n) | Select ECC
590 \ref ARM_NAND_ECC0 | Use ECC0 of selected ECC
591 \ref ARM_NAND_ECC1 | Use ECC1 of selected ECC
592 \ref ARM_NAND_DRIVER_DONE_EVENT | Generate \ref ARM_NAND_EVENT_DRIVER_DONE
594 The data item size is defined by the data type, which depends on the configured data bus width.
597 - \em uint8_t for 8-bit data bus
598 - \em uint16_t for 16-bit data bus
600 The function executes in the following ways:
601 - When the operation is blocking (typical for devices connected to memory bus when not using DMA),
602 then the function returns after all data is written and returns the number of data items written.
603 - When the operation is non-blocking (typical for NAND controllers), then the function only starts the operation
604 and returns with zero number of data items written. After the operation is completed,
605 the \ref ARM_NAND_EVENT_DRIVER_DONE event is generated (if enabled by \b ARM_NAND_DRIVER_DONE_EVENT).
606 Progress of the operation can also be monitored by calling the \ref ARM_NAND_GetStatus function and checking the \em busy data field.
607 Operation is automatically aborted if ECC is used and ECC generation fails,
608 which generates the \ref ARM_NAND_EVENT_ECC_ERROR event (together with \ref ARM_NAND_DRIVER_DONE_EVENT if enabled).
609 *******************************************************************************************************************/
611 int32_t ARM_NAND_ExecuteSequence (uint32_t dev_num, uint32_t code, uint32_t cmd,
612 uint32_t addr_col, uint32_t addr_row,
613 void *data, uint32_t data_cnt,
614 uint8_t *status, uint32_t *count) {
618 \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)
620 The function \b ARM_NAND_ExecuteSequence executes a sequence of operations for a NAND device.
622 The parameter \em dev_num is the device number. \n
623 The parameter \em code is the sequence encoding as defined in the table <b>Sequence execution Code</b>. \n
624 The parameter \em cmd is the command or a series of commands. \n
625 The parameter \em addr_col is the column address. \n
626 The parameter \em addr_row is the row address. \n
627 The parameter \em data is a pointer to the buffer that stores the data to or loads the data from. \n
628 The parameter \em data_cnt is the number of data items to read or write in one iteration. \n
629 The parameter \em status is a pointer to the buffer that stores the status read. \n
630 The parameter \em count is a pointer to the number of iterations. \n
632 \b ARM_NAND_CODE_xxx specifies sequence execution codes.
634 Sequence Execution Code | Description
635 :----------------------------------|:--------------------------------------------
636 \ref ARM_NAND_CODE_SEND_CMD1 | Send Command 1 (cmd[7..0])
637 \ref ARM_NAND_CODE_SEND_ADDR_COL1 | Send Column Address 1 (addr_col[7..0])
638 \ref ARM_NAND_CODE_SEND_ADDR_COL2 | Send Column Address 2 (addr_col[15..8])
639 \ref ARM_NAND_CODE_SEND_ADDR_ROW1 | Send Row Address 1 (addr_row[7..0])
640 \ref ARM_NAND_CODE_SEND_ADDR_ROW2 | Send Row Address 2 (addr_row[15..8])
641 \ref ARM_NAND_CODE_SEND_ADDR_ROW3 | Send Row Address 3 (addr_row[23..16])
642 \ref ARM_NAND_CODE_INC_ADDR_ROW | Auto-increment Row Address
643 \ref ARM_NAND_CODE_WRITE_DATA | Write Data
644 \ref ARM_NAND_CODE_SEND_CMD2 | Send Command 2 (cmd[15..8])
645 \ref ARM_NAND_CODE_WAIT_BUSY | Wait while R/Bn busy
646 \ref ARM_NAND_CODE_READ_DATA | Read Data
647 \ref ARM_NAND_CODE_SEND_CMD3 | Send Command 3 (cmd[23..16])
648 \ref ARM_NAND_CODE_READ_STATUS | Read Status byte and check FAIL bit (bit 0)
649 \ref ARM_NAND_ECC(n) | Select ECC
650 \ref ARM_NAND_ECC0 | Use ECC0 of selected ECC
651 \ref ARM_NAND_ECC1 | Use ECC1 of selected ECC
652 \ref ARM_NAND_DRIVER_DONE_EVENT | Generate \ref ARM_NAND_EVENT_DRIVER_DONE
654 The data item size is defined by the data type, which depends on the configured data bus width.
657 - \em uint8_t for 8-bit data bus
658 - \em uint16_t for 16-bit data bus
660 The function is non-blocking and returns as soon as the driver has started executing the specified sequence.
661 When the operation is completed, the \ref ARM_NAND_EVENT_DRIVER_DONE event is generated (if enabled by \b ARM_NAND_DRIVER_DONE_EVENT).
662 Progress of the operation can also be monitored by calling the \ref ARM_NAND_GetStatus function and checking the \em busy data field.
664 Driver executes the number of specified iterations where in each iteration
665 items specified by \b ARM_NAND_CODE_xxx are executed in the order as listed in the table <b>Sequence execution Code</b>.
666 The parameter \em count is holding the current number of iterations left.
668 Execution is automatically aborted and \ref ARM_NAND_EVENT_DRIVER_DONE event is generated (if enabled by \b ARM_NAND_DRIVER_DONE_EVENT):
669 - if Read Status is enabled and the FAIL bit (bit 0) is set
670 - if ECC is used and ECC fails (also sets \ref ARM_NAND_EVENT_ECC_ERROR event)
673 \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).
674 The event \ref ARM_NAND_EVENT_DEVICE_READY is not generated during sequence execution but rather used internally by the driver.
675 *******************************************************************************************************************/
677 int32_t ARM_NAND_AbortSequence (uint32_t dev_num) {
681 \fn int32_t ARM_NAND_AbortSequence (uint32_t dev_num)
683 The function \b ARM_NAND_AbortSequence aborts execution of the current sequence for a NAND device.
685 The parameter \em dev_num is the device number.
686 *******************************************************************************************************************/
688 int32_t ARM_NAND_Control (uint32_t dev_num, uint32_t control, uint32_t arg) {
692 \fn int32_t ARM_NAND_Control (uint32_t dev_num, uint32_t control, uint32_t arg)
694 The function \b ARM_NAND_Control controls the NAND interface and executes operations.
696 The parameter \em dev_num is the device number. \n
697 The parameter \em control specifies the operation. \n
698 The parameter \em arg provides (depending on the \em control) additional information or sets values.
700 The table lists the operations for the parameter \em control.
702 Parameter \em control | Operation
703 :--------------------------------|:--------------------------------------------
704 \ref ARM_NAND_BUS_MODE | Set the bus mode. The parameter \em arg sets the \ref bus_mode_tab "\b Bus Mode".
705 \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".
706 \ref ARM_NAND_DRIVER_STRENGTH | Set the driver strength. The parameter \em arg sets the \ref driver_strength_tab "\b Driver Strength".
707 \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}.
708 \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}.
711 - \ref ARM_NAND_GetCapabilities returns information about supported operations, which are stored in the structure \ref ARM_NAND_CAPABILITIES.
712 - \ref ARM_NAND_SignalEvent provides information about the callback events \ref ARM_NAND_EVENT_DRIVER_READY and \ref ARM_NAND_EVENT_DEVICE_READY
714 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
715 \ref ARM_NAND_DRIVER_STRENGTH. Values from different categories can be ORed.
718 <table class="cmtable" summary="">
719 <tr><th> Parameter \em arg <br> for <i>control</i> = \ref ARM_NAND_BUS_MODE </th>
722 <th> Description </th>
723 <th width="30%"> Supported when \ref ARM_NAND_CAPABILITIES </th></tr>
724 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_0 (default) </td>
725 <td rowspan="8" style="text-align:right"> 0..3 </td>
726 <td rowspan="8"> \anchor bus_timing_tab Bus Timing Mode </td>
728 <td rowspan="8"> The maximum timing mode that can be applied to a specific \ref bus_data_interface_tab "\b Bus Data Interface"
729 is stored in the data fields: <br><br>
730 <i>sdr_timing_mode</i> - for SDR <br>
731 <i>ddr_timing_mode</i> - for NV-DDR <br>
732 <i>ddr2_timing_mode</i> - for NV_DDR2 </td></tr>
733 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_1 </td><td> \token{1} </td></tr>
734 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_2 </td><td> \token{2} </td></tr>
735 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_3 </td><td> \token{3} </td></tr>
736 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_4 </td><td> \token{4} (SDR EDO capable) </td></tr>
737 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_5 </td><td> \token{5} (SDR EDO capable) </td></tr>
738 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_6 </td><td> \token{6} (NV-DDR2 only) </td></tr>
739 <tr><td> \ref ARM_NAND_BUS_TIMING_MODE_7 </td><td> \token{7} (NV-DDR2 only) </td></tr>
740 <tr><td> \ref ARM_NAND_BUS_SDR (default) \anchor bus_data_interface_tab </td>
741 <td rowspan="3" style="text-align:right"> 4..7 </td>
742 <td rowspan="3"> Bus Data Interface </td>
743 <td> SDR (Single Data Rate) - Traditional interface </td>
744 <td> <i>always supported</i> </td></tr>
745 <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>
746 <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>
747 <tr><td style="white-space: nowrap"> \ref ARM_NAND_BUS_DDR2_DO_WCYC_0 (default) </td>
748 <td rowspan="4" style="text-align:right"> 8..11 </td>
749 <td rowspan="4" style="white-space: nowrap"> Data Output Warm-up \anchor bus_output_tab </td>
750 <td> Set the DDR2 Data Output Warm-up to \token{0} cycles </td>
751 <td rowspan="4"> <b>Data Output Warm-up</b> cycles are dummy cycles for interface calibration with no incremental data transfer
752 and apply to NV-DDR2 of the \ref bus_data_interface_tab "\b Bus Data Interface".
754 <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>
755 <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>
756 <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>
757 <tr><td style="white-space: nowrap"> \ref ARM_NAND_BUS_DDR2_DI_WCYC_0 (default) \anchor bus_input_tab</td>
758 <td rowspan="4" style="text-align:right"> 12..15 </td>
759 <td rowspan="4" style="white-space: nowrap"> Data Input Warm-up </td>
760 <td> Set the DDR2 Data Input Warm-up to \token{0} cycles </td>
761 <td rowspan="4"> <b>Data Input Warm-up</b> cycles are dummy cycles for interface calibration with no incremental data transfer
762 and apply to NV-DDR2 of the \ref bus_data_interface_tab "\b Bus Data Interface".
764 <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>
765 <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>
766 <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>
767 <tr><td style="white-space: nowrap"> \ref ARM_NAND_BUS_DDR2_VEN \anchor bus_misc_tab </td>
768 <td style="text-align:right"> 16 </td>
769 <td rowspan="3" style="white-space: nowrap"> Miscellaneous </td>
770 <td> Set the DDR2 Enable external VREFQ as reference </td>
771 <td rowspan="3">
773 <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>
774 <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>
775 <tr><th> Parameter \em arg <br> for <i>control</i> = \ref ARM_NAND_BUS_DATA_WIDTH </th>
777 <th> Category \anchor bus_data_width_tab </th>
778 <th> Description </th>
779 <th width="30%"> Supported when \ref ARM_NAND_CAPABILITIES </th></tr>
780 <tr><td style="white-space: nowrap"> \ref ARM_NAND_BUS_DATA_WIDTH_8 (default) </td>
781 <td rowspan="2" style="text-align:right"> 0..1 </td>
782 <td rowspan="2" style="white-space: nowrap"> Bus Data Width </td>
783 <td> Set to \token{8 bit} </td>
784 <td> <i>always supported</i>
786 <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>
787 <tr><th style="white-space: nowrap"> Parameter \em arg <br> for <i>control</i> = \ref ARM_NAND_DRIVER_STRENGTH </th>
789 <th> Category \anchor driver_strength_tab </th>
790 <th> Description </th>
791 <th width="30%"> Supported when \ref ARM_NAND_CAPABILITIES </th></tr>
792 <tr><td style="white-space: nowrap"> \ref ARM_NAND_DRIVER_STRENGTH_18 </td>
793 <td rowspan="4" style="text-align:right"> 0..3 </td>
794 <td rowspan="4" style="white-space: nowrap"> Driver Strength </td>
795 <td> Set the Driver Strength 2.0x = 18 Ohms </td>
796 <td> data field <i>driver_strength_18</i> = \token{1}
798 <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>
799 <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>
800 <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>
805 extern ARM_DRIVER_NAND Driver_NAND0;
807 status = Driver_NAND0.Control (0, ARM_NAND_BUS_MODE, ARM_NAND_BUS_TIMING_MODE_5 |
809 ARM_NAND_BUS_DDR2_VEN);
811 status = Driver_NAND0.Control (0, ARM_NAND_BUS_DATA_WIDTH, ARM_NAND_BUS_DATA_WIDTH_16);
813 status = Driver_NAND0.Control (0, ARM_NAND_DRIVER_STRENGTH, ARM_NAND_DRIVER_STRENGTH_50);
816 *******************************************************************************************************************/
818 ARM_NAND_STATUS ARM_NAND_GetStatus (uint32_t dev_num) {
822 \fn ARM_NAND_STATUS ARM_NAND_GetStatus (uint32_t dev_num)
824 The function \b ARM_NAND_GetStatus returns the current NAND device status.
826 The parameter \em dev_num is the device number.
827 *******************************************************************************************************************/
829 int32_t ARM_NAND_InquireECC (int32_t index, ARM_NAND_ECC_INFO *info) {
833 \fn int32_t ARM_NAND_InquireECC (int32_t index, ARM_NAND_ECC_INFO *info)
835 The function \b ARM_NAND_InquireECC reads error correction code information.
837 The parameter \em index is the ECC index and is used to retrieve different ECC configurations. \n
838 The parameter \em info is a pointer of type \ref ARM_NAND_ECC_INFO. The data fields store the information.
840 When multiple different ECC configurations exist, ARM_NAND_ECC_INFO structure exists for each configuration. Parameter
841 \em index denotes which configuration will be retrieved. Value of index should start with zero to retrieve first ECC
842 configuration and should be incremented in order to retrieve next ECC configuration. When index is out of range function
843 ARM_NAND_InquireECC returns with error.
845 Parameter \em index is used by \ref ARM_NAND_ECC(n) in \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData and
846 \ref ARM_NAND_ExecuteSequence to select suitable ECC configuration.
850 extern ARM_DRIVER_NAND Driver_NAND0;
852 ARM_NAND_ECC_INFO ecc;
856 while (Driver_NAND0.InquireECC (idx, &ecc) == ARM_DRIVER_OK) {
857 // Examine retrieved ECC configuration
859 // Algorithm ECC0 protects Main+Spare
865 *******************************************************************************************************************/
867 void ARM_NAND_SignalEvent (uint32_t dev_num, uint32_t event) {
871 \fn void ARM_NAND_SignalEvent (uint32_t dev_num, uint32_t event)
873 The function \b ARM_NAND_SignalEvent is a callback function registered by the function \ref ARM_NAND_Initialize.
875 The parameter \em dev_num is the device number. \n
876 The parameter \em event indicates one or more events that occurred during driver operation.
877 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.
879 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the
880 data fields of the structure \ref ARM_NAND_CAPABILITIES, which can be retrieved with the function \ref ARM_NAND_GetCapabilities.
882 The following events can be generated:
884 Parameter \em event | Bit | Description
885 :---------------------------------|-----|:---------------------------
886 \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.
887 \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).
888 \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.
889 \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.
891 The event \ref ARM_NAND_EVENT_DEVICE_READY occurs after complete execution of commands
892 (initiated with the functions \ref ARM_NAND_SendCommand, \ref ARM_NAND_SendAddress, \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData, \ref ARM_NAND_ExecuteSequence).
893 It is useful to indicate completion of complex operations (such as erase).
894 The event is only generated when \ref ARM_NAND_GetCapabilities returns data field \em event_device_ready = \token{1}
895 and was enabled by calling \ref ARM_NAND_Control (\ref ARM_NAND_DEVICE_READY_EVENT, 1).
896 If the event is not available, poll the \em busy data field using the function \ref ARM_NAND_GetStatus.
898 The event \ref ARM_NAND_EVENT_DRIVER_READY occurs when previously a function
899 (\ref ARM_NAND_SendCommand, \ref ARM_NAND_SendAddress, \ref ARM_NAND_ReadData, \ref ARM_NAND_WriteData, \ref ARM_NAND_ExecuteSequence)
900 returned with \ref ARM_DRIVER_ERROR_BUSY. It is useful when functions are called simultaneously from independent threads
901 (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).
902 \em dev_num indicates the device that returned previously busy.
903 *******************************************************************************************************************/
908 // End NAND Interface