1 /* -----------------------------------------------------------------------------
2 * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
4 * $Date: 2. January 2014
7 * Project: MCI Driver API
8 * -------------------------------------------------------------------------- */
12 \defgroup mci_interface_gr MCI Interface
13 \brief Driver API for Memory Card Interface using SD/MMC interface (%Driver_MCI.h)
16 The <b>Memory Card Interface</b> (MCI) implements the hardware abstraction layer for Secure Digital (SD) and Multi Media Card (MMC)
17 memory that is typically used as file storage. For embedded systems, SD/MMC devices are available as memory cards in several
18 forms (SD, miniSD, microSD, MMC, MMCmicro) or as non-removable devic
19 es that are directly soldered to the PCB (eMMC).
22 - Wikipedia offers more information about the <a href="http://en.wikipedia.org/wiki/SD_card" target="_blank"><b>Secure Digital</b> memory</a>.
23 - Wikipedia offers more information about the <a href="http://en.wikipedia.org/wiki/MultiMediaCard" target="_blank"><b>MultiMediaCard</b></a>.
24 - The SD Association provides detailed documentation under <a href="http://www.sdcard.org">www.sdcard.org</a>.
25 - The MultiMediaCard Association (merged with JEDEC) provides detailed documentation under <a href="http://www.jedec.org">www.jedec.org</a>.
29 The MCI driver allows you to exchange data of the SD/MMC memory via SD/MMC interface.
31 The following modes are supported by SD/MMC memory cards:
33 - SPI bus mode: Serial Peripheral Interface Bus supported by most microcontrollers.
34 - 1-bit SD/MMC Bus mode: proprietary data transfer protocol supported by SD/MMC interfaces.
35 - 4-bit SD/MMC Bus mode: high-speed version of the SD/MMC interface using 4 data I/O pins.
36 - 8-bit SD/MMC Bus mode: high-speed version of the SD/MMC interface using 8 data I/O pins.
38 \image html SPI_BusMode.png "SD memory connected via SPI interface"
40 \image html SD_1BitBusMode.png "SD memory connected via 1-bit SD Bus Mode"
42 \image html SD_4BitBusMode.png "SD memory connected via 4-bit SD Bus Mode"
47 The following header files define the Application Programming Interface (API) for the MCI interface:
48 - \b %Driver_MCI.h : Driver API for Memory Card Interface using SD/MMC interface
50 The driver implementation is a typical part of the Device Family Pack (DFP) that supports the
51 peripherals of the microcontroller family.
54 For parameters, the value marked with (default) is the setting after the driver initialization.
57 <b>Driver Functions</b>
59 The driver functions are published in the access struct as explained in \ref DriverFunctions
60 - \ref ARM_DRIVER_MCI : access struct for MCI driver functions
64 A typical setup sequence for the driver is shown below:
70 #include "Driver_MCI.h"
72 /* Usage example: ARM_MCI_Initialize ----------------------------------------*/
74 // ARM_MCI_SignalEvent callback function prototype
75 void MCI_SignalEvent_Callback (uint32_t event);
77 void init_driver (ARM_DRIVER_MCI *drv) {
80 status = drv->Initialize (&MCI_SignalEvent_Callback);
82 if (status != ARM_DRIVER_OK) {
83 // Initialization and event callback registration failed
87 /* Usage example: ARM_MCI_Uninitialize --------------------------------------*/
89 void uninit_driver (ARM_DRIVER_MCI *drv) {
92 status = drv->Uninitialize ();
94 if (status == ARM_DRIVER_OK) {
95 // Driver successfully uninitialized
99 /* Usage example: ARM_MCI_PowerControl --------------------------------------*/
101 void control_driver_power (ARM_DRIVER_MCI *drv, bool enable) {
104 if (enable == true) {
105 status = drv->PowerControl (ARM_POWER_FULL);
108 status = drv->PowerControl (ARM_POWER_OFF);
111 if (status == ARM_DRIVER_OK) {
112 // Driver power enabled/disabled
116 /* Usage example: ARM_MCI_CardPower -----------------------------------------*/
118 ARM_MCI_CAPABILITIES drv_capabilities;
120 void set_card_vdd_3v3 (ARM_DRIVER_MCI *drv) {
123 if (drv_capabilities.vdd == 1) {
124 // Power switching to 3.3V supported
125 status = drv->CardPower (ARM_MCI_POWER_VDD_3V3);
127 if (status == ARM_DRIVER_OK) {
128 // Card power set to 3.3V
133 /* Usage example: ARM_MCI_ReadCD --------------------------------------------*/
135 void read_card_detect_state (ARM_DRIVER_MCI *drv) {
138 status = drv->ReadCD();
141 // Memory card is detected
145 // Memory card is not detected
148 // Error reading card detect pin state
153 /* Usage example: ARM_MCI_ReadWP --------------------------------------------*/
155 void read_write_protect_state (ARM_DRIVER_MCI *drv) {
158 status = drv->ReadWP();
161 // Memory card write protection is enabled
165 // Memory card write protection is disabled
168 // Error reading write protect pin state
173 /* Usage example: ARM_MCI_SendCommand ---------------------------------------*/
175 volatile uint32_t MCI_Events;
177 void MCI_SignalEvent_Callback (uint32_t event) {
178 // Save current event
182 void send_CMD0 (ARM_DRIVER_MCI *drv) {
186 MCI_Events = 0; //Clear MCI driver event flags
187 cmd = 0; // Set GO_IDLE_STATE command code
189 status = drv->SendCommand (cmd, 0, ARM_MCI_CARD_INITIALIZE | ARM_MCI_RESPONSE_NONE, NULL);
191 if (status == ARM_DRIVER_OK) {
193 while ((MCI_Events & ARM_MCI_EVENT_COMMAND_COMPLETE) == 0U);
194 // Command was successfully sent to memory card
202 /* Usage example: ARM_MCI_SetupTransfer -------------------------------------*/
204 volatile uint32_t MCI_Events;
206 void MCI_SignalEvent_Callback (uint32_t event) {
207 MCI_Events |= event; // Save current event
210 void read_sector (ARM_DRIVER_MCI *drv, uint8_t *buf, uint32_t sz) {
216 // Invalid buffer size, sector consists of 512 bytes
220 status = drv->SetupTransfer (buf, 1, 512, ARM_MCI_TRANSFER_READ | ARM_MCI_TRANSFER_BLOCK);
222 if (status == ARM_DRIVER_OK) {
223 MCI_Events = 0; //Clear MCI driver event flags
225 cmd = 17; // Set READ_SINGLE_BLOCK command
226 arg = 0; // Set sector number
228 status = drv->SendCommand (cmd, arg, ARM_MCI_RESPONSE_SHORT | ARM_MCI_RESPONSE_CRC | ARM_MCI_TRANSFER_DATA, &resp);
230 if (status == ARM_DRIVER_OK) {
232 while ((MCI_Events & ARM_MCI_EVENT_COMMAND_COMPLETE) == 0U);
233 // Command was successfully sent to memory card
234 if ((resp & 0x03) == 0) {
235 // Sector number is valid, wait until data transfer completes
236 while ((MCI_Events & ARM_MCI_EVENT_TRANSFER_COMPLETE) == 0U);
237 // Data was successfully read from memory card
244 /* Usage example: ARM_MCI_AbortTransfer -------------------------------------*/
246 void abort_data_transfer (ARM_DRIVER_MCI *drv) {
247 ARM_MCI_STATUS drv_status;
249 drv_status = drv->GetStatus();
251 if (drv_status.transfer_active == 1U) {
252 // Data transfer is active, abort the transfer
253 if (drv->AbortTransfer() == ARM_DRIVER_OK) {
260 /* Usage example: ARM_MCI_GetStatus -----------------------------------------*/
262 void check_transfer_status (ARM_DRIVER_MCI *drv) {
263 ARM_MCI_STATUS drv_status;
265 drv_status = drv->GetStatus();
267 if (drv_status.transfer_active == 1U) {
268 // Data transfer is active
271 if (drv_status.transfer_timeout == 1U) {
272 // Data not received, timeout expired
275 if (drv_status.transfer_error == 1U) {
276 // Data transfer ended with error
280 /* Usage example: ARM_MCI_SignalEvent ---------------------------------------*/
282 void MCI_SignalEvent_Callback (uint32_t event) {
283 if ((event & ARM_MCI_EVENT_CARD_INSERTED) != 0U) {
284 // Memory card was inserted into socket
286 if ((event & ARM_MCI_EVENT_CARD_REMOVED) != 0U) {
287 // Memory card was removed from socket
290 if ((event & ARM_MCI_EVENT_COMMAND_COMPLETE) != 0U) {
291 // Command was successfully sent to memory card
293 if ((event & ARM_MCI_EVENT_COMMAND_TIMEOUT) != 0U) {
294 // Command response was not received in time
296 if ((event & ARM_MCI_EVENT_COMMAND_ERROR) != 0U) {
297 // Command response was invalid
300 if ((event & ARM_MCI_EVENT_TRANSFER_COMPLETE) != 0U) {
301 // Data successfully transferred from/to memory card
303 if ((event & ARM_MCI_EVENT_TRANSFER_TIMEOUT) != 0U) {
304 // Data not transferred from/to memory card, timeout expired
306 if ((event & ARM_MCI_EVENT_TRANSFER_ERROR) != 0U) {
307 // Data transfer ended with errors
310 if ((event & ARM_MCI_EVENT_SDIO_INTERRUPT) != 0U) {
311 // SD I/O card sent interrupt request
314 if ((event & ARM_MCI_EVENT_CCS) != 0U) {
315 // CE-ATA command completion signal received
317 if ((event & ARM_MCI_EVENT_CCS_TIMEOUT) != 0U) {
318 // CE-ATA command completion signal wait timeout expired
326 /************* Structures ******************************************************************************************************/
328 \struct ARM_DRIVER_MCI
330 The functions of the MCI are accessed by function pointers exposed by this structure. Refer to \ref DriverFunctions for overview information.
332 Each instance of an MCI provides such an access structure.
333 The instance is identified by a postfix number in the symbol name of the access structure, for example:
334 - \b Driver_MCI0 is the name of the access struct of the first instance (no. 0).
335 - \b Driver_MCI1 is the name of the access struct of the second instance (no. 1).
337 A configuration setting in the middleware allows connecting the middleware to a specific driver instance <b>Driver_MCI<i>n</i></b>.
338 The default is \token{0}, which connects a middleware to the first instance of a driver.
339 *******************************************************************************************************************/
342 \struct ARM_MCI_CAPABILITIES
344 A MCI driver can be implemented with different capabilities.
345 The data fields of this struct encode the capabilities implemented by this driver.
348 - \ref ARM_MCI_GetCapabilities
349 *******************************************************************************************************************/
352 \defgroup mci_event_gr MCI Events
353 \brief The MCI driver generates call back events that are notified via the function \ref ARM_MCI_SignalEvent.
355 This section provides the event values for the \ref ARM_MCI_SignalEvent callback function.
357 The following call back notification events are generated:
359 \def ARM_MCI_EVENT_CARD_INSERTED
360 \sa \ref ARM_MCI_SignalEvent
361 \def ARM_MCI_EVENT_CARD_REMOVED
362 \sa \ref ARM_MCI_SignalEvent
363 \def ARM_MCI_EVENT_COMMAND_COMPLETE
364 \sa \ref ARM_MCI_SignalEvent
365 \def ARM_MCI_EVENT_COMMAND_TIMEOUT
366 \sa \ref ARM_MCI_SignalEvent
367 \def ARM_MCI_EVENT_COMMAND_ERROR
368 \sa \ref ARM_MCI_SignalEvent
369 \def ARM_MCI_EVENT_TRANSFER_COMPLETE
370 \sa \ref ARM_MCI_SignalEvent
371 \def ARM_MCI_EVENT_TRANSFER_TIMEOUT
372 \sa \ref ARM_MCI_SignalEvent
373 \def ARM_MCI_EVENT_TRANSFER_ERROR
374 \sa \ref ARM_MCI_SignalEvent
375 \def ARM_MCI_EVENT_SDIO_INTERRUPT
376 \sa \ref ARM_MCI_SignalEvent
377 \def ARM_MCI_EVENT_CCS
378 \sa \ref ARM_MCI_SignalEvent
379 \def ARM_MCI_EVENT_CCS_TIMEOUT
380 \sa \ref ARM_MCI_SignalEvent
382 *******************************************************************************************************************/
384 //open mci_contorl_gr
389 \defgroup mci_control_gr MCI Control Codes
390 \ingroup mci_interface_gr
391 \brief Configure and control the MCI using the \ref ARM_MCI_Control.
394 Many parameters of the MCI driver are configured using the \ref ARM_MCI_Control function.
396 The various MCI control codes define:
397 - \ref mci_mode_ctrls configures and controls the MCI interface
398 - \ref mci_bus_speed_ctrls specifies the bus speed mode
399 - \ref mci_bus_data_width_ctrls specifies the data bus width
400 - \ref mci_cmd_line_ctrls specifies the CMD line mode
401 - \ref mci_driver_strength_ctrls specifies the driver strength
403 Refer to the function \ref ARM_MCI_Control for further details.
405 *******************************************************************************************************************/
409 \defgroup mci_mode_ctrls MCI Controls
410 \ingroup mci_control_gr
411 \brief Configure and control the MCI interface.
413 The following codes are used as values for the parameter \em control of the function \ref ARM_MCI_Control to setup the MCI interface.
415 \def ARM_MCI_BUS_SPEED
416 \def ARM_MCI_BUS_SPEED_MODE
417 \def ARM_MCI_BUS_CMD_MODE
418 \def ARM_MCI_BUS_DATA_WIDTH
419 \def ARM_MCI_DRIVER_STRENGTH
420 \def ARM_MCI_CONTROL_RESET
421 \def ARM_MCI_CONTROL_CLOCK_IDLE
422 \def ARM_MCI_UHS_TUNING_OPERATION
423 \def ARM_MCI_UHS_TUNING_RESULT
424 \def ARM_MCI_DATA_TIMEOUT
425 \def ARM_MCI_CSS_TIMEOUT
426 \def ARM_MCI_MONITOR_SDIO_INTERRUPT
427 \def ARM_MCI_CONTROL_READ_WAIT
428 \def ARM_MCI_SUSPEND_TRANSFER
429 \def ARM_MCI_RESUME_TRANSFER
431 *******************************************************************************************************************/
435 \defgroup mci_bus_speed_ctrls MCI Bus Speed Mode
436 \ingroup mci_control_gr
437 \brief Specify the bus speed mode.
440 The function \ref ARM_MCI_Control with \em control = \ref ARM_MCI_BUS_SPEED configures the bus speed of the MCI to the
441 requested bits/s specified with \em arg.
443 The function \ref ARM_MCI_Control with \em control = \ref ARM_MCI_BUS_SPEED_MODE configures the bus speed mode of the MCI
444 as specified with \em arg listed bellow.
446 The function \ref ARM_MCI_GetCapabilities lists the supported bus speed modes. Initially, all SD cards use a 3.3 volt electrical interface.
447 Some SD cards can switch to 1.8 volt operation. For example, the use of ultra-high-speed (UHS)
448 SD cards requires 1.8 volt operation and a 4-bit bus data width. The data field \em uhs_signaling of the structure ARM_MCI_CAPABILITIES encodes
449 whether the driver supports 1.8 volt UHS signaling.
452 - \ref mci_driver_strength_ctrls
454 The following codes are defined:
456 \def ARM_MCI_BUS_DEFAULT_SPEED
457 \def ARM_MCI_BUS_HIGH_SPEED
458 \def ARM_MCI_BUS_UHS_SDR12
459 \def ARM_MCI_BUS_UHS_SDR25
460 \def ARM_MCI_BUS_UHS_SDR50
461 \def ARM_MCI_BUS_UHS_SDR104
462 \def ARM_MCI_BUS_UHS_DDR50
464 *******************************************************************************************************************/
468 \defgroup mci_bus_data_width_ctrls MCI Bus Data Width
469 \ingroup mci_control_gr
470 \brief Specify the data bus width.
473 The function \ref ARM_MCI_Control with \em control = \ref ARM_MCI_BUS_DATA_WIDTH specifies with \em arg the number of data I/O pins on the SD/MMC interface.
475 For high-speed memory cards, a 4-bit bus data width should be used (or 8-bit for eMMC). The data fields \em data_width_4 and \em data_width_8
476 of the structure ARM_MCI_CAPABILITIES encode whether the driver supports a specific bus data with.
478 The following codes are defined:
480 \def ARM_MCI_BUS_DATA_WIDTH_1
481 \def ARM_MCI_BUS_DATA_WIDTH_4
482 \def ARM_MCI_BUS_DATA_WIDTH_8
483 \def ARM_MCI_BUS_DATA_WIDTH_4_DDR
484 \def ARM_MCI_BUS_DATA_WIDTH_8_DDR
486 *******************************************************************************************************************/
490 \defgroup mci_cmd_line_ctrls MCI CMD Line Mode
491 \ingroup mci_control_gr
492 \brief Specify the CMD line mode (Push-Pull or Open Drain).
495 Set the CMD line type with the function \ref ARM_MCI_Control.
496 The CMD line mode is push-pull (default) or open drain (needed for older MMC).
498 \def ARM_MCI_BUS_CMD_PUSH_PULL
499 \def ARM_MCI_BUS_CMD_OPEN_DRAIN
501 *******************************************************************************************************************/
505 \defgroup mci_driver_strength_ctrls MCI Driver Strength
506 \ingroup mci_control_gr
507 \brief Specify the driver strength.
510 The function \ref ARM_MCI_Control with \em control = \ref ARM_MCI_DRIVER_STRENGTH specifies with \em arg the driver type of the SD interface.
513 - \ref mci_bus_speed_ctrls
515 The following codes are defined:
517 \def ARM_MCI_DRIVER_TYPE_A
518 \def ARM_MCI_DRIVER_TYPE_B
519 \def ARM_MCI_DRIVER_TYPE_C
520 \def ARM_MCI_DRIVER_TYPE_D
522 *******************************************************************************************************************/
526 */ // close group mci_control_gr
529 \defgroup mci_send_command_flags_ctrls MCI Send Command Flags
530 \ingroup mci_interface_gr
531 \brief Specify various options for sending commands to the card and the expected response.
533 \b ARM_MCI_xxx flags are sent with the function \ref ARM_MCI_SendCommand as the parameter \em flag.
534 It controls the behavior of the command sent to the card and provides information about the expected response from the card.
536 The following codes are defined:
538 \def ARM_MCI_RESPONSE_NONE
539 \def ARM_MCI_RESPONSE_SHORT
540 \def ARM_MCI_RESPONSE_SHORT_BUSY
541 \def ARM_MCI_RESPONSE_LONG
542 \def ARM_MCI_RESPONSE_INDEX
543 \def ARM_MCI_RESPONSE_CRC
544 \def ARM_MCI_WAIT_BUSY
545 \def ARM_MCI_TRANSFER_DATA
546 \def ARM_MCI_CARD_INITIALIZE
547 \def ARM_MCI_INTERRUPT_COMMAND
548 \def ARM_MCI_INTERRUPT_RESPONSE
549 \def ARM_MCI_BOOT_OPERATION
550 \def ARM_MCI_BOOT_ALTERNATIVE
551 \def ARM_MCI_BOOT_ACK
555 *******************************************************************************************************************/
558 \defgroup mci_transfer_ctrls MCI Transfer Controls
559 \ingroup mci_interface_gr
560 \brief Specify data transfer mode.
562 Data transfer codes specifies the transfer direction and type and are used with the function \ref ARM_MCI_SetupTransfer as the parameter \em mode.
564 The following codes are defined:
566 \def ARM_MCI_TRANSFER_READ
567 \def ARM_MCI_TRANSFER_WRITE
568 \def ARM_MCI_TRANSFER_BLOCK
569 \def ARM_MCI_TRANSFER_STREAM
571 *******************************************************************************************************************/
574 \defgroup mci_card_power_ctrls MCI Card Power Controls
575 \ingroup mci_interface_gr
576 \brief Specify Memory Card Power supply voltage
578 Specifies the power supply volatge for a memory card. Used with the function \ref ARM_MCI_CardPower as the parameter \em voltage.
580 The following codes are defined:
582 \def ARM_MCI_POWER_VDD_OFF
583 \def ARM_MCI_POWER_VDD_3V3
584 \def ARM_MCI_POWER_VDD_1V8
585 \def ARM_MCI_POWER_VCCQ_OFF
586 \def ARM_MCI_POWER_VCCQ_3V3
587 \def ARM_MCI_POWER_VCCQ_1V8
588 \def ARM_MCI_POWER_VCCQ_1V2
590 *******************************************************************************************************************/
594 \struct ARM_MCI_STATUS
596 Structure with information about the status of the MCI.
599 - \ref ARM_MCI_GetStatus
600 *******************************************************************************************************************/
603 \typedef ARM_MCI_SignalEvent_t
605 Provides the typedef for the callback function \ref ARM_MCI_SignalEvent.
607 <b>Parameter for:</b>
608 - \ref ARM_MCI_Initialize
609 *******************************************************************************************************************/
615 ARM_DRIVER_VERSION ARM_MCI_GetVersion (void) {
619 \fn ARM_DRIVER_VERSION ARM_MCI_GetVersion (void)
621 The function \b ARM_MCI_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
622 - API version is the version of the CMSIS-Driver specification used to implement this driver.
623 - Driver version is source code version of the actual driver implementation.
627 extern ARM_DRIVER_MCI Driver_MCI0;
628 ARM_DRIVER_MCI *drv_info;
630 void setup_mci (void) {
631 ARM_DRIVER_VERSION version;
633 drv_info = &Driver_MCI0;
634 version = drv_info->GetVersion ();
635 if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
641 *******************************************************************************************************************/
643 ARM_MCI_CAPABILITIES ARM_MCI_GetCapabilities (void) {
647 \fn ARM_MCI_CAPABILITIES ARM_MCI_GetCapabilities (void)
649 The function \b ARM_MCI_GetCapabilities returns information about capabilities in this driver implementation.
650 The data fields of the structure \ref ARM_MCI_CAPABILITIES encode various capabilities, for example
651 supported bus modes ...
655 extern ARM_DRIVER_MCI Driver_MCI0;
656 ARM_DRIVER_MCI *drv_info;
658 void read_capabilities (void) {
659 ARM_MCI_CAPABILITIES drv_capabilities;
661 drv_info = &Driver_MCI0;
662 drv_capabilities = drv_info->GetCapabilities ();
663 // interrogate capabilities
667 *******************************************************************************************************************/
669 int32_t ARM_MCI_Initialize (ARM_MCI_SignalEvent_t cb_event) {
670 return ARM_DRIVER_OK;
673 \fn int32_t ARM_MCI_Initialize (ARM_MCI_SignalEvent_t cb_event)
675 The function \b ARM_MCI_Initialize initializes the MCI interface.
676 It is called when the middleware component starts operation.
678 The function performs the following operations:
679 - Initializes the resources needed for the MCI interface.
680 - Registers the \ref ARM_MCI_SignalEvent callback function.
682 The parameter \em cb_event is a pointer to the \ref ARM_MCI_SignalEvent callback function; use a NULL pointer
683 when no callback signals are required.
686 - see \ref mci_interface_gr - Driver Functions
688 *******************************************************************************************************************/
690 int32_t ARM_MCI_Uninitialize (void) {
691 return ARM_DRIVER_OK;
694 \fn int32_t ARM_MCI_Uninitialize (void)
696 The function \b ARM_MCI_Uninitialize de-initializes the resources of I2C interface.
698 It is called when the middleware component stops operation and releases the software resources used by the interface.
699 *******************************************************************************************************************/
701 int32_t ARM_MCI_PowerControl (ARM_POWER_STATE state) {
702 return ARM_DRIVER_OK;
705 \fn int32_t ARM_MCI_PowerControl (ARM_POWER_STATE state)
707 The function \b ARM_MCI_PowerControl operates the power modes of the MCI interface.
709 The parameter \em state can have the following values:
710 - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA. Can be called multiple times.
711 If the peripheral is already in this mode, then the function performs no operation and returns with \ref ARM_DRIVER_OK.
712 - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
713 - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
715 Refer to \ref CallSequence for more information.
716 *******************************************************************************************************************/
718 int32_t ARM_MCI_CardPower (uint32_t voltage) {
719 return ARM_DRIVER_OK;
722 \fn int32_t ARM_MCI_CardPower (uint32_t voltage)
724 The function \b ARM_MCI_CardPower operates the memory card power supply voltage.
726 The parameter \em voltage sets the voltage. Not every voltage might be supported by the driver implementation.
727 The structure \ref ARM_MCI_CAPABILITIES encodes the supported voltage. Retrieve the information with the function \ref ARM_MCI_GetCapabilities and
728 verify the data fields.
730 The following values:
732 Parameter \em voltage | Description | supported when ARM_MCI_CAPABILITIES
733 :-------------------------------------|:------------------------------|-----------------------------------------
734 \ref ARM_MCI_POWER_VDD_OFF | VDD (VCC) turned off | <i>allways supported</i>
735 \ref ARM_MCI_POWER_VDD_3V3 | VDD (VCC) = \token{3.3V} | data field \em vdd = \token{1}
736 \ref ARM_MCI_POWER_VDD_1V8 | VDD (VCC) = \token{1.8V} | data field \em vdd_1v8 = \token{1}
737 \ref ARM_MCI_POWER_VCCQ_OFF | eMMC VCCQ turned off | <i>allways supported</i>
738 \ref ARM_MCI_POWER_VCCQ_3V3 | eMMC VCCQ = \token{3.3V} | data field \em vccq = \token{1}
739 \ref ARM_MCI_POWER_VCCQ_1V8 | eMMC VCCQ = \token{1.8V} | data field \em vccq_1v8 = \token{1}
740 \ref ARM_MCI_POWER_VCCQ_1V2 | eMMC VCCQ = \token{1.2V} | data field \em vccq_1v2 = \token{1}
742 *******************************************************************************************************************/
744 int32_t ARM_MCI_ReadCD (void) {
748 \fn int32_t ARM_MCI_ReadCD (void)
750 The function \b ARM_MCI_ReadCD reads the status of the Card Detect (CD) pin.
751 *******************************************************************************************************************/
753 int32_t ARM_MCI_ReadWP (void) {
757 \fn int32_t ARM_MCI_ReadWP (void)
759 The function \b ARM_MCI_ReadWP reads the status of the Write Protect (WP) pin.
760 *******************************************************************************************************************/
762 int32_t ARM_MCI_SendCommand (uint32_t cmd, uint32_t arg, uint32_t flags, uint32_t *response) {
763 return ARM_DRIVER_OK;
766 \fn int32_t ARM_MCI_SendCommand (uint32_t cmd, uint32_t arg, uint32_t flags, uint32_t *response)
768 The function \b ARM_MCI_SendCommand
769 - sends commands to the memory card
770 - retrieve the response from the card
771 - optionally, start the data transfer.
773 The parameter \em cmd is the command sent to the card. \n
774 The parameter \em arg contains arguments for the command \em cmd. \n
775 The parameter \em flags controls the behavior of the operation and takes predefined values listed in the table below. \n
776 The parameter \em response is a pointer to receive data.
778 The parameter \em flags can have the following values:
780 Parameter \em flags | Description
781 :-------------------------------------|:------------
782 \ref ARM_MCI_RESPONSE_NONE | No response expected (default)
783 \ref ARM_MCI_RESPONSE_SHORT | Short response (\token{48}-bit) expected
784 \ref ARM_MCI_RESPONSE_SHORT_BUSY | Short response with busy signal (\token{48}-bit) expected
785 \ref ARM_MCI_RESPONSE_LONG | Long response (\token{136}-bit) expected
786 \ref ARM_MCI_RESPONSE_INDEX | Check command index in response
787 \ref ARM_MCI_RESPONSE_CRC | Check CRC in response
788 \ref ARM_MCI_WAIT_BUSY | Wait until busy before sending the command
789 \ref ARM_MCI_TRANSFER_DATA | Activate Data transfer
790 \ref ARM_MCI_CARD_INITIALIZE | Execute Memory Card initialization sequence
791 \ref ARM_MCI_INTERRUPT_COMMAND | Send Interrupt command (CMD40 - MMC only)
792 \ref ARM_MCI_INTERRUPT_RESPONSE | Send Interrupt response (CMD40 - MMC only)
793 \ref ARM_MCI_BOOT_OPERATION | Execute Boot operation (MMC only)
794 \ref ARM_MCI_BOOT_ALTERNATIVE | Execute Alternative Boot operation (MMC only)
795 \ref ARM_MCI_BOOT_ACK | Expect Boot Acknowledge (MMC only)
796 \ref ARM_MCI_CCSD | Send Command Completion Signal Disable (CCSD) for CE-ATA device
797 \ref ARM_MCI_CCS | Expect Command Completion Signal (CCS) for CE-ATA device
799 Calling the function <b>ARM_MCI_SendCommand</b> only starts the operation.
800 The function is non-blocking and returns as soon as the driver has started the operation.
801 It is not allowed to call this function again until the operation is in progress.
803 After the command is sent the response is retrieved if specified with <b>ARM_MCI_RESPONSE_xxx</b> flags.
804 When the command completes successfully (requested response is received without errors) the \ref ARM_MCI_EVENT_COMMAND_COMPLETE event is generated.
805 In case that response is requested but not received the \ref ARM_MCI_EVENT_COMMAND_TIMEOUT event is generated instead.
806 In case of invalid response (or CRC error) the \ref ARM_MCI_EVENT_COMMAND_ERROR event is generated instead.
807 Progress of command operation can be monitored by calling the \ref ARM_MCI_GetStatus and checking the \em command_active flag.
809 After the command operation the data transfer operation is started if specified with <b>ARM_MCI_TRANSFER_DATA</b> flag.
810 The data transfer needs to be configured before that by calling the \ref ARM_MCI_SetupTransfer.
811 When the data transfer completes successfully the \ref ARM_MCI_EVENT_TRANSFER_COMPLETE event is generated.
812 In case that data transfer is not completed in-time (specified by \ref ARM_MCI_DATA_TIMEOUT) the \ref ARM_MCI_EVENT_TRANSFER_TIMEOUT event is generated instead.
813 In case of CRC errors the \ref ARM_MCI_EVENT_TRANSFER_ERROR event is generated instead.
814 Progress of data transfer operation can be monitored by calling the \ref ARM_MCI_GetStatus and checking the \em transfer_active flag.
817 - \ref ARM_MCI_SignalEvent
818 *******************************************************************************************************************/
820 int32_t ARM_MCI_SetupTransfer (uint8_t *data, uint32_t block_count, uint32_t block_size, uint32_t mode) {
821 return ARM_DRIVER_OK;
824 \fn int32_t ARM_MCI_SetupTransfer (uint8_t *data, uint32_t block_count, uint32_t block_size, uint32_t mode)
826 The function \b ARM_MCI_SetupTransfer prepares the data transfer operation that is initiated
827 by calling the function \ref ARM_MCI_SendCommand with the parameter \em flags = \ref ARM_MCI_TRANSFER_DATA.
829 The parameter \em data is a pointer to the data to transfer. \n
830 The parameter \em block_count is the number of blocks to transfer. \n
831 The parameter \em block_size is the size of a block. \n
832 The parameter \em mode sets the transfer mode and can have the values liste in the table below:
834 Transfer Directions | Description
835 :-------------------------------------|:------------
836 \ref ARM_MCI_TRANSFER_READ | Read data from MCI
837 \ref ARM_MCI_TRANSFER_WRITE | Write data to MCI
838 \ref ARM_MCI_TRANSFER_BLOCK (default) | Block Data transfer
839 \ref ARM_MCI_TRANSFER_STREAM | Stream Data transfer (MMC only)
841 *******************************************************************************************************************/
843 int32_t ARM_MCI_AbortTransfer (void) {
844 return ARM_DRIVER_OK;
847 \fn int32_t ARM_MCI_AbortTransfer (void)
849 The function \b ARM_MCI_AbortTransfer aborts the active data transfer operation initiated with \ref ARM_MCI_SendCommand.
850 *******************************************************************************************************************/
853 int32_t ARM_MCI_Control (uint32_t control, uint32_t arg) {
854 return ARM_DRIVER_OK;
857 \fn int32_t ARM_MCI_Control (uint32_t control, uint32_t arg)
859 Th function \b ARM_MCI_Control controls the MCI interface and executes various operations.
861 The parameter \em control specifies the operation.
862 Values for \em control cannot be ORed, but must be called separately in the code. \n
863 The parameter \em arg provides, depending on the operation, additional information or sets values.
866 For parameters, the values marked with (default) are the setting after the driver initialization.
868 The table lists values for the parameter \em control.
870 Parameter \em control | Operation
871 :-------------------------------------|:------------
872 \ref ARM_MCI_BUS_SPEED | Set the Bus Speed. The parameter \em arg specifies the speed in bits/s; The function returns the bus speed configured in bits/s.
873 \ref ARM_MCI_BUS_SPEED_MODE | Set the Bus Speed Mode. Predefined values for \em arg are listed in the table <b>Bus Speed Mode</b>.
874 \ref ARM_MCI_BUS_CMD_MODE | Set the CMD Line Mode. Predefined values for \em arg are listed in the table <b>Bus CMD Line Mode</b>.
875 \ref ARM_MCI_BUS_DATA_WIDTH | Set data bus width. Predefined values for \em arg are encoded in <b>Bus Data Width</b>.
876 \ref ARM_MCI_DRIVER_STRENGTH | Set driver strength. Predefined values for \em arg are listed in the table <b>Driver Type</b>
877 \ref ARM_MCI_CONTROL_RESET | Control optional RST_n Pin (eMMC). The parameter \em arg can have the values \token{[0:inactive(default); 1:active]}
878 \ref ARM_MCI_CONTROL_CLOCK_IDLE | Control clock generation on CLK Pin when idle. The parameter \em arg can have the values \token{[0:disabled; 1:enabled]}
879 \ref ARM_MCI_UHS_TUNING_OPERATION | Sampling clock Tuning operation (SD UHS-I). The parameter \em arg can have the values \token{[0:reset; 1:execute]}
880 \ref ARM_MCI_UHS_TUNING_RESULT | Sampling clock Tuning result (SD UHS-I). Returns \token{[0:done; 1:in progress; -1:error]}
881 \ref ARM_MCI_DATA_TIMEOUT | Set Data timeout; The parameter \em arg sets the timeout in bus cycles.
882 \ref ARM_MCI_CSS_TIMEOUT | Set Command Completion Signal (CCS) timeout. The parameter \em arg sets timeout in bus cycles.
883 \ref ARM_MCI_MONITOR_SDIO_INTERRUPT | Monitor SD I/O interrupt. The parameter \em arg can have the values \token{[0:disabled(default); 1:enabled]}. Monitoring is automatically disabled when an interrupt is recognized.
884 \ref ARM_MCI_CONTROL_READ_WAIT | Control Read/Wait states for SD I/O. The parameter \em arg can have the values \token{[0:disabled(default); 1:enabled]}.
885 \ref ARM_MCI_SUSPEND_TRANSFER | Suspend Data transfer (SD I/O). Returns the number of remaining bytes to transfer.
886 \ref ARM_MCI_RESUME_TRANSFER | Resume Data transfer (SD I/O).
889 <b>Bus Speed Mode</b>
891 The function \ref ARM_MCI_GetCapabilities lists the supported bus speed modes. Initially, all SD cards use a 3.3 volt electrical interface.
892 Some SD cards can switch to 1.8 volt operation. For example, the use of ultra-high-speed (UHS)
893 SD cards requires 1.8 volt operation and a 4-bit bus data width. The bit field ARM_MCI_CAPABILITIES.uhs_signaling encodes
894 whether the driver supports 1.8 volt UHS signaling.
896 The \em control operation \b ARM_MCI_BUS_SPEED_MODE sets the bus speed mode using the parameter \em arg.
898 Parameter \em arg | Bus Speed Mode
899 :-------------------------------------------------------------|:------------------------------------------
900 \ref ARM_MCI_BUS_DEFAULT_SPEED (default) | Set the bus speed for SD/MMC cards: Default Speed mode up to \token{[25;26]MHz}
901 \ref ARM_MCI_BUS_HIGH_SPEED | Set the bus speed for SD/MMC: High Speed mode up to \token{[50;52]MHz}
902 \ref ARM_MCI_BUS_UHS_SDR12 | Set the bus speed for SD: SDR12 (Single Data Rate) up to \token{25MHz, 12.5MB/s: UHS-I (Ultra High Speed) 1.8V signalling}
903 \ref ARM_MCI_BUS_UHS_SDR25 | Set the bus speed for SD: SDR25 (Single Data Rate) up to \token{50MHz, 25 MB/s: UHS-I (Ultra High Speed) 1.8V signalling}
904 \ref ARM_MCI_BUS_UHS_SDR50 | Set the bus speed for SD: SDR50 (Single Data Rate) up to \token{100MHz, 50 MB/s: UHS-I (Ultra High Speed) 1.8V signalling}
905 \ref ARM_MCI_BUS_UHS_SDR104 | Set the bus speed for SD: SDR104 (Single Data Rate) up to \token{208MHz, 104 MB/s: UHS-I (Ultra High Speed) 1.8V signalling}
906 \ref ARM_MCI_BUS_UHS_DDR50 | Set the bus speed for SD: DDR50 (Dual Data Rate) up to \token{50MHz, 50 MB/s: UHS-I (Ultra High Speed) 1.8V signalling}
909 <b>Bus CMD Line Mode</b>
911 The \em control operation \b ARM_MCI_BUS_CMD_MODE sets the bus command line mode using the parameter \em arg.
913 Parameter \em arg | Bus CMD Line Mode
914 :-------------------------------------------------------------|:------------------------------------------
915 \ref ARM_MCI_BUS_CMD_PUSH_PULL (default) | Set the Push-Pull CMD line
916 \ref ARM_MCI_BUS_CMD_OPEN_DRAIN | Set the Open Drain CMD line (MMC only)
919 <b>Bus Data Width</b>
921 Specifies the bus data width (the number of data I/O pins on the SD/MMC interface).
923 For high speed memory cards, a 4-bit bus data width should be used (or 8-bit for eMMC). The bit fields ARM_MCI_CAPABILITIES.data_width_4 and
924 ARM_MCI_CAPABILITIES.data_width_8 encode whether the driver supports a specific bus data with.
926 The \em control operation \b ARM_MCI_BUS_DATA_WIDTH sets the bus data width using the parameter \em arg.
928 Parameter \em arg | Bus Data Width
929 :-------------------------------------------------------------|:------------------------------------------
930 \ref ARM_MCI_BUS_DATA_WIDTH_1 (default) | Set the Bus data width to \token{1 bit}
931 \ref ARM_MCI_BUS_DATA_WIDTH_4 | Set the Bus data width to \token{4 bits}
932 \ref ARM_MCI_BUS_DATA_WIDTH_8 | Set the Bus data width to \token{8 bits}
933 \ref ARM_MCI_BUS_DATA_WIDTH_4_DDR | Set the Bus data width to \token{4 bits}, DDR (Dual Data Rate) - MMC only
934 \ref ARM_MCI_BUS_DATA_WIDTH_8_DDR | Set the Bus data width to \token{8 bits}, DDR (Dual Data Rate) - MMC only
939 Specifies the interface driver type.
941 The \em control operation \b ARM_MCI_DRIVER_STRENGTH sets the interface driver type using the parameter \em arg.
943 Parameter \em arg | Driver Type
944 :-------------------------------------------------------------|:------------------------------------------
945 \ref ARM_MCI_DRIVER_TYPE_A | Set the interface to SD UHS-I Driver Type A
946 \ref ARM_MCI_DRIVER_TYPE_B (default) | Set the interface to SD UHS-I Driver Type B
947 \ref ARM_MCI_DRIVER_TYPE_C | Set the interface to SD UHS-I Driver Type C
948 \ref ARM_MCI_DRIVER_TYPE_D | Set the interface to SD UHS-I Driver Type D
952 // Set Bus Speed to 25MHz
953 MCIdrv->Control(ARM_MCI_BUS_SPEED, 25000000);
955 // Set High Speed mode
956 MCIdrv->Control(ARM_MCI_BUS_SPEED_MODE, ARM_MCI_BUS_HIGH_SPEED);
958 // Configure CMD line as Open Drain (MMC only)
959 MCIdrv->Control(ARM_MCI_BUS_CMD_MODE, ARM_MCI_BUS_CMD_OPEN_DRAIN);
961 // Set Bus Data Width = 4bits
962 MCIdrv->Control(ARM_MCI_BUS_DATA_WIDTH, ARM_MCI_BUS_DATA_WIDTH_4);
964 // Set SD UHS-I Driver Type B
965 MCIdrv->Control(ARM_MCI_DRIVER_STRENGTH, ARM_MCI_DRIVER_TYPE_B);
967 // RTS_n Pin is not active by default
968 // Assert RTS_n Pin (eMMC)
969 MCIdrv->Control(ARM_MCI_CONTROL_RESET, 1);
970 // De-assert RTS_n Pin (eMMC)
971 MCIdrv->Control(ARM_MCI_CONTROL_RESET, 0);
973 // Clock generation on CLK when Idle: hardware specific default behavior
974 // Enable Clock generation on CLK when Idle
975 MCIdrv->Control(ARM_MCI_CONTROL_CLOCK_IDLE, 1);
976 // Disable Clock generation on CLK when Idle
977 MCIdrv->Control(ARM_MCI_CONTROL_CLOCK_IDLE, 0);
980 MCIdrv->Control(ARM_MCI_UHS_TUNING_OPERATION, 1); // start tuning
982 status = MCIdrv->Control(ARM_MCI_UHS_TUNING_RESULT, 0/*argument not used*/);
983 if (status == -1) { break; /* tuning failed */ }
984 } while (status == 1);
986 // Set Data Timeout to 12500000 bus cycles (0.5s @25MHz Bus Speed)
987 // Default value is hardware specific (typically 2^32-1)
988 MCIdrv->Control(ARM_MCI_DATA_TIMEOUT, 12500000);
990 // Set CSS Timeout to 1000000 bus cycles
991 // Default value is hardware specific
992 MCIdrv->Control(ARM_MCI_CSS_TIMEOUT, 1000000);
994 // SD I/O Interrupt Monitoring is disabled by default
995 // Enable SD I/O Interrupt Monitoring
996 MCIdrv->Control(ARM_MCI_MONITOR_SDIO_INTERRUPT, 1);
997 // Disable SD I/O Interrupt Monitoring
998 MCIdrv->Control(ARM_MCI_MONITOR_SDIO_INTERRUPT, 0);
1000 // Read/Wait for SD I/O is disabled by default
1001 // Enable Read/Wait for SD I/O
1002 MCIdrv->Control(ARM_MCI_CONTROL_READ_WAIT, 1);
1003 // Disable Read/Wait for SD I/O
1004 MCIdrv->Control(ARM_MCI_CONTROL_READ_WAIT, 0);
1006 // Suspend Data transfer (SD I/O)
1007 MCIdrv->Control(ARM_MCI_SUSPEND_TRANSFER, 0/*argument not used*/);
1009 // Resume Data transfer (SD I/O)
1010 MCIdrv->Control(ARM_MCI_RESUME_TRANSFER, 0/*argument not used*/);
1012 *******************************************************************************************************************/
1014 ARM_MCI_STATUS ARM_MCI_GetStatus (void) {
1015 return ARM_DRIVER_OK;
1018 \fn ARM_MCI_STATUS ARM_MCI_GetStatus (void)
1020 The function \b ARM_MCI_GetStatus returns the current MCI interface status.
1021 *******************************************************************************************************************/
1023 void ARM_MCI_SignalEvent (uint32_t event) {
1027 \fn void ARM_MCI_SignalEvent (uint32_t event)
1029 The function \b ARM_MCI_SignalEvent is a callback function registered by the function \ref ARM_MCI_Initialize.
1031 The parameter \em event indicates one or more events that occurred during driver operation.
1032 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.
1034 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the
1035 data fields of the structure \ref ARM_NAND_CAPABILITIES, which can be retrieved with the function \ref ARM_NAND_GetCapabilities.
1037 The following events can be generated:
1039 Parameter \em event |Bit | Description | supported when \ref ARM_NAND_CAPABILITIES
1040 :------------------------------------------|---:|:----------------------------------------------------------------------|:---------------------------------------------
1041 \ref ARM_MCI_EVENT_CARD_INSERTED | 0 | Occurs after Memory Card inserted | <i>always supported</i>
1042 \ref ARM_MCI_EVENT_CARD_REMOVED | 1 | Occurs after Memory Card removal | <i>always supported</i>
1043 \ref ARM_MCI_EVENT_COMMAND_COMPLETE | 2 | Occurs after command completed successfully | <i>always supported</i>
1044 \ref ARM_MCI_EVENT_COMMAND_TIMEOUT | 3 | Occurs after command timeout | <i>always supported</i>
1045 \ref ARM_MCI_EVENT_COMMAND_ERROR | 4 | Occurs after command response error (CRC error or invalid response) | <i>always supported</i>
1046 \ref ARM_MCI_EVENT_TRANSFER_COMPLETE | 5 | Occurs after data transfer completed successfully | <i>always supported</i>
1047 \ref ARM_MCI_EVENT_TRANSFER_TIMEOUT | 6 | Occurs after data transfer timeout | <i>always supported</i>
1048 \ref ARM_MCI_EVENT_TRANSFER_ERROR | 7 | Occurs after data transfer error (CRC failed) | <i>always supported</i>
1049 \ref ARM_MCI_EVENT_SDIO_INTERRUPT | 8 | Indicates SD I/O Interrupt | data field \em sdio_interrupt = \token{1}
1050 \ref ARM_MCI_EVENT_CCS | 9 | Indicates a Command Completion Signal (CCS) | data field \em ccs = \token{1}
1051 \ref ARM_MCI_EVENT_CCS_TIMEOUT |10 | Indicates a Command Completion Signal (CCS) Timeout | data field \em css_timeout = \token{1}
1054 - \ref ARM_MCI_SendCommand
1056 *******************************************************************************************************************/
1062 // End MCI Interface