ChibiOS/HAL 9.0.0
MMC over SPI Driver

Generic MMC driver. More...

Detailed Description

Generic MMC driver.

This module implements a portable MMC/SD driver that uses a SPI driver as physical layer. Hot plugging and removal are supported through kernel events.

Precondition
In order to use the MMC_SPI driver the HAL_USE_MMC_SPI and HAL_USE_SPI options must be enabled in halconf.h.

Driver State Machine

This driver implements a state machine internally, see the Abstract I/O Block Device module documentation for details.

Driver Operations

This driver allows to read or write single or multiple 512 bytes blocks on a SD Card.

Collaboration diagram for MMC over SPI Driver:

MMC_SPI configuration options

#define MMC_IDLE_TIMEOUT_MS   1000
 Timeout before assuming a failure while waiting for card idle.
#define MMC_USE_MUTUAL_EXCLUSION   TRUE
 Mutual exclusion on the SPI bus.

Macro Functions

#define mmcIsCardInserted(mmcp)
 Returns the card insertion status.
#define mmcIsWriteProtected(mmcp)
 Returns the write protect status.

Data Structures

struct  mmc_spi_config_t
 Type of a MMC/SD over SPI driver configuration structure. More...
struct  mmc_spi_driver_vmt
 MMCDriver virtual methods table. More...
struct  mmc_spi_driver_t
 Structure representing a MMC/SD over SPI driver. More...

Macros

#define MMC_CMD0_RETRY   10U
#define MMC_CMD1_RETRY   100U
#define MMC_ACMD41_RETRY   100U
#define MMC_WAIT_DATA   10000U
#define MMC_BUFFER_SIZE   16U
 Size of the buffer to be supplied to the driver.
#define __mmc_driver_methods    _mmcsd_block_device_methods
 MMCDriver specific methods.

Typedefs

typedef mmc_spi_config_t MMCConfig
 Legacy name for compatibility.
typedef mmc_spi_driver_t MMCDriver
 Legacy name for compatibility.

Functions

static bool mmc_is_card_inserted (void *instance)
static bool mmc_is_write_protected (void *instance)
static bool mmc_connect (void *instance)
static bool mmc_disconnect (void *instance)
static bool mmc_read (void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n)
static bool mmc_write (void *instance, uint32_t startblk, const uint8_t *buffer, uint32_t n)
static bool mmc_sync (void *instance)
static bool mmc_get_info (void *instance, BlockDeviceInfo *bdip)
static uint8_t mmc_crc7 (uint8_t crc, const uint8_t *buffer, size_t len)
 Calculate the MMC standard CRC-7 based on a lookup table.
static bool mmc_wait_idle (MMCDriver *mmcp)
 Waits an idle condition.
static bool mmc_send_hdr (MMCDriver *mmcp, uint8_t cmd, uint32_t arg)
 Sends a command header.
static bool mmc_recvr1 (MMCDriver *mmcp, uint8_t *r1p)
 Receives a single byte response.
static bool mmc_recvr3 (MMCDriver *mmcp, uint8_t *r1p)
 Receives a three byte response.
static bool mmc_send_command_R1 (MMCDriver *mmcp, uint8_t cmd, uint32_t arg, uint8_t *r1p)
 Sends a command an returns a single byte response.
static bool mmc_send_command_R3 (MMCDriver *mmcp, uint8_t cmd, uint32_t arg, uint8_t *r1p)
 Sends a command which returns a five bytes response (R3).
static bool mmc_read_CxD (MMCDriver *mmcp, uint8_t cmd, uint32_t cxd[4])
 Reads the CSD.
void mmcInit (void)
 MMC over SPI driver initialization.
void mmcObjectInit (MMCDriver *mmcp, uint8_t *buffer)
 Initializes an instance.
msg_t mmcStart (MMCDriver *mmcp, const MMCConfig *config)
 Configures and activates the MMC peripheral.
void mmcStop (MMCDriver *mmcp)
 Disables the MMC peripheral.
bool mmcConnect (MMCDriver *mmcp)
 Performs the initialization procedure on the inserted card.
bool mmcDisconnect (MMCDriver *mmcp)
 Brings the driver in a state safe for card removal.
bool mmcStartSequentialRead (MMCDriver *mmcp, uint32_t startblk)
 Starts a sequential read.
bool mmcSequentialRead (MMCDriver *mmcp, uint8_t *buffer)
 Reads a block within a sequential read operation.
bool mmcStopSequentialRead (MMCDriver *mmcp)
 Stops a sequential read gracefully.
bool mmcStartSequentialWrite (MMCDriver *mmcp, uint32_t startblk)
 Starts a sequential write.
bool mmcSequentialWrite (MMCDriver *mmcp, const uint8_t *buffer)
 Writes a block within a sequential write operation.
bool mmcStopSequentialWrite (MMCDriver *mmcp)
 Stops a sequential write gracefully.
bool mmcSync (MMCDriver *mmcp)
 Waits for card idle condition.
bool mmcGetInfo (MMCDriver *mmcp, BlockDeviceInfo *bdip)
 Returns the media info.
bool mmcErase (MMCDriver *mmcp, uint32_t startblk, uint32_t endblk)
 Erases blocks.
bool mmc_lld_is_card_inserted (MMCDriver *mmcp)
bool mmc_lld_is_write_protected (MMCDriver *mmcp)

Variables

static const struct mmc_spi_driver_vmt mmc_vmt
 Virtual methods table.
static const uint8_t mmc_crc7_lookup_table [256]
 Lookup table for CRC-7 ( based on polynomial x^7 + x^3 + 1).

Macro Definition Documentation

◆ MMC_CMD0_RETRY

#define MMC_CMD0_RETRY   10U

Definition at line 34 of file hal_mmc_spi.h.

Referenced by mmcConnect().

◆ MMC_CMD1_RETRY

#define MMC_CMD1_RETRY   100U

Definition at line 35 of file hal_mmc_spi.h.

Referenced by mmcConnect().

◆ MMC_ACMD41_RETRY

#define MMC_ACMD41_RETRY   100U

Definition at line 36 of file hal_mmc_spi.h.

Referenced by mmcConnect().

◆ MMC_WAIT_DATA

#define MMC_WAIT_DATA   10000U

Definition at line 37 of file hal_mmc_spi.h.

Referenced by mmc_read_CxD(), and mmcSequentialRead().

◆ MMC_BUFFER_SIZE

#define MMC_BUFFER_SIZE   16U

Size of the buffer to be supplied to the driver.

Note
The buffer is meant to be non-cacheable on platforms with data cache.

Definition at line 44 of file hal_mmc_spi.h.

◆ MMC_IDLE_TIMEOUT_MS

#define MMC_IDLE_TIMEOUT_MS   1000

Timeout before assuming a failure while waiting for card idle.

Note
Time is in milliseconds.

Definition at line 59 of file hal_mmc_spi.h.

Referenced by mmc_wait_idle().

◆ MMC_USE_MUTUAL_EXCLUSION

#define MMC_USE_MUTUAL_EXCLUSION   TRUE

Mutual exclusion on the SPI bus.

Definition at line 66 of file hal_mmc_spi.h.

◆ __mmc_driver_methods

#define __mmc_driver_methods    _mmcsd_block_device_methods

MMCDriver specific methods.

Definition at line 113 of file hal_mmc_spi.h.

◆ mmcIsCardInserted

#define mmcIsCardInserted ( mmcp)
Value:
bool mmc_lld_is_card_inserted(MMCDriver *mmcp)

Returns the card insertion status.

Note
This macro wraps a low level function named sdc_lld_is_card_inserted(), this function must be provided by the application because it is not part of the SDC driver.
Parameters
[in]mmcppointer to the MMCDriver object
Returns
The card state.
Return values
falsecard not inserted.
truecard inserted.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 178 of file hal_mmc_spi.h.

Referenced by mmc_is_card_inserted().

◆ mmcIsWriteProtected

#define mmcIsWriteProtected ( mmcp)
Value:
bool mmc_lld_is_write_protected(MMCDriver *mmcp)

Returns the write protect status.

Parameters
[in]mmcppointer to the MMCDriver object
Returns
The card state.
Return values
falsecard not inserted.
truecard inserted.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 190 of file hal_mmc_spi.h.

Referenced by mmc_is_write_protected().

Typedef Documentation

◆ MMCConfig

Legacy name for compatibility.

Deprecated

Definition at line 108 of file hal_mmc_spi.h.

◆ MMCDriver

Legacy name for compatibility.

Deprecated

Definition at line 154 of file hal_mmc_spi.h.

Function Documentation

◆ mmc_is_card_inserted()

bool mmc_is_card_inserted ( void * instance)
static

Definition at line 105 of file hal_mmc_spi.c.

References mmcIsCardInserted.

◆ mmc_is_write_protected()

bool mmc_is_write_protected ( void * instance)
static

Definition at line 114 of file hal_mmc_spi.c.

References mmcIsWriteProtected.

◆ mmc_connect()

bool mmc_connect ( void * instance)
static

Definition at line 123 of file hal_mmc_spi.c.

References mmc_spi_driver_t::config, mmcConnect(), spiAcquireBus(), mmc_spi_config_t::spip, and spiReleaseBus().

Here is the call graph for this function:

◆ mmc_disconnect()

bool mmc_disconnect ( void * instance)
static

Definition at line 140 of file hal_mmc_spi.c.

References mmc_spi_driver_t::config, mmcDisconnect(), spiAcquireBus(), mmc_spi_config_t::spip, and spiReleaseBus().

Here is the call graph for this function:

◆ mmc_read()

bool mmc_read ( void * instance,
uint32_t startblk,
uint8_t * buffer,
uint32_t n )
static

◆ mmc_write()

bool mmc_write ( void * instance,
uint32_t startblk,
const uint8_t * buffer,
uint32_t n )
static

◆ mmc_sync()

bool mmc_sync ( void * instance)
static

Definition at line 229 of file hal_mmc_spi.c.

References mmc_spi_driver_t::config, mmcSync(), spiAcquireBus(), mmc_spi_config_t::spip, and spiReleaseBus().

Here is the call graph for this function:

◆ mmc_get_info()

bool mmc_get_info ( void * instance,
BlockDeviceInfo * bdip )
static

Definition at line 246 of file hal_mmc_spi.c.

References mmcGetInfo().

Here is the call graph for this function:

◆ mmc_crc7()

uint8_t mmc_crc7 ( uint8_t crc,
const uint8_t * buffer,
size_t len )
static

Calculate the MMC standard CRC-7 based on a lookup table.

Parameters
[in]crcstart value for CRC
[in]bufferpointer to data buffer
[in]lenlength of data
Returns
Calculated CRC

Definition at line 263 of file hal_mmc_spi.c.

References mmc_crc7_lookup_table.

Referenced by mmc_send_hdr().

◆ mmc_wait_idle()

bool mmc_wait_idle ( MMCDriver * mmcp)
static

Waits an idle condition.

Parameters
[in]mmcppointer to the MMCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Not an API, this function is for internal use only.

Definition at line 282 of file hal_mmc_spi.c.

References mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, MMC_IDLE_TIMEOUT_MS, osalThreadSleepMilliseconds, mmc_spi_config_t::spip, and spiReceive().

Referenced by mmc_send_hdr(), mmcDisconnect(), mmcSequentialWrite(), and mmcSync().

Here is the call graph for this function:

◆ mmc_send_hdr()

bool mmc_send_hdr ( MMCDriver * mmcp,
uint8_t cmd,
uint32_t arg )
static

Sends a command header.

Parameters
[in]mmcppointer to the MMCDriver object
[in]cmdthe command id
[in]argthe command argument
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Not an API, this function is for internal use only.

Definition at line 319 of file hal_mmc_spi.c.

References mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, mmc_crc7(), mmc_wait_idle(), mmc_spi_config_t::spip, and spiSend().

Referenced by mmc_read_CxD(), mmc_send_command_R1(), mmc_send_command_R3(), mmcStartSequentialRead(), and mmcStartSequentialWrite().

Here is the call graph for this function:

◆ mmc_recvr1()

bool mmc_recvr1 ( MMCDriver * mmcp,
uint8_t * r1p )
static

Receives a single byte response.

Parameters
[in]mmcppointer to the MMCDriver object
[out]r1ppointer to buffer for R1 answer
Returns
Operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Not an API, this function is for internal use only.

Definition at line 350 of file hal_mmc_spi.c.

References mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, mmc_spi_config_t::spip, and spiReceive().

Referenced by mmc_read_CxD(), mmc_recvr3(), mmc_send_command_R1(), mmcStartSequentialRead(), mmcStartSequentialWrite(), and mmcStopSequentialRead().

Here is the call graph for this function:

◆ mmc_recvr3()

bool mmc_recvr3 ( MMCDriver * mmcp,
uint8_t * r1p )
static

Receives a three byte response.

Parameters
[in]mmcppointer to the MMCDriver object
[out]r1ppointer to buffer for R1 answer
Returns
Operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Not an API, this function is for internal use only.

Definition at line 374 of file hal_mmc_spi.c.

References mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, mmc_recvr1(), mmc_spi_config_t::spip, and spiReceive().

Referenced by mmc_send_command_R3().

Here is the call graph for this function:

◆ mmc_send_command_R1()

bool mmc_send_command_R1 ( MMCDriver * mmcp,
uint8_t cmd,
uint32_t arg,
uint8_t * r1p )
static

Sends a command an returns a single byte response.

Parameters
[in]mmcppointer to the MMCDriver object
[in]cmdthe command id
[in]argthe command argument
[out]r1ppointer to buffer for R1 answer
Returns
Operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Not an API, this function is for internal use only.

Definition at line 396 of file hal_mmc_spi.c.

References mmc_spi_driver_t::config, mmc_recvr1(), mmc_send_hdr(), mmc_spi_config_t::spip, spiSelect(), and spiUnselect().

Referenced by mmcConnect(), and mmcErase().

Here is the call graph for this function:

◆ mmc_send_command_R3()

bool mmc_send_command_R3 ( MMCDriver * mmcp,
uint8_t cmd,
uint32_t arg,
uint8_t * r1p )
static

Sends a command which returns a five bytes response (R3).

Parameters
[in]mmcppointer to the MMCDriver object
[in]cmdthe command id
[in]argthe command argument
[out]r1ppointer to buffer for R1 answer
Returns
The first byte of the response (R1) as an uint8_t value.
Return values
0xFFtimed out.
Function Class:
Not an API, this function is for internal use only.

Definition at line 423 of file hal_mmc_spi.c.

References mmc_spi_driver_t::config, mmc_recvr3(), mmc_send_hdr(), mmc_spi_config_t::spip, spiSelect(), and spiUnselect().

Referenced by mmcConnect().

Here is the call graph for this function:

◆ mmc_read_CxD()

bool mmc_read_CxD ( MMCDriver * mmcp,
uint8_t cmd,
uint32_t cxd[4] )
static

Reads the CSD.

Parameters
[in]mmcppointer to the MMCDriver object
[out]cmdcommand
[out]cxdpointer to the CSD/CID buffer
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Not an API, this function is for internal use only.

Definition at line 450 of file hal_mmc_spi.c.

References mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, mmc_recvr1(), mmc_send_hdr(), MMC_WAIT_DATA, spiIgnore(), mmc_spi_config_t::spip, spiReceive(), spiSelect(), and spiUnselect().

Referenced by mmcConnect().

Here is the call graph for this function:

◆ mmcInit()

void mmcInit ( void )

MMC over SPI driver initialization.

Note
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:
Object or module nitializer function.

Definition at line 504 of file hal_mmc_spi.c.

Referenced by halInit().

◆ mmcObjectInit()

void mmcObjectInit ( MMCDriver * mmcp,
uint8_t * buffer )

Initializes an instance.

Parameters
[out]mmcppointer to the MMCDriver object
[in]bufferoperations buffer
Function Class:
Object or module nitializer function.

Definition at line 516 of file hal_mmc_spi.c.

References BLK_STOP, mmc_spi_driver_t::block_addresses, mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, mmc_vmt, and mmc_spi_driver_t::vmt.

◆ mmcStart()

msg_t mmcStart ( MMCDriver * mmcp,
const MMCConfig * config )

Configures and activates the MMC peripheral.

Parameters
[in]mmcppointer to the MMCDriver object
[in]configpointer to the MMCConfig object.
Returns
The operation status.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 534 of file hal_mmc_spi.c.

References BLK_ACTIVE, BLK_STOP, mmc_spi_driver_t::config, HAL_RET_SUCCESS, osalDbgAssert, and osalDbgCheck.

◆ mmcStop()

void mmcStop ( MMCDriver * mmcp)

Disables the MMC peripheral.

Parameters
[in]mmcppointer to the MMCDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 553 of file hal_mmc_spi.c.

References BLK_ACTIVE, BLK_STOP, mmc_spi_driver_t::config, osalDbgAssert, osalDbgCheck, mmc_spi_config_t::spip, and spiStop().

Here is the call graph for this function:

◆ mmcConnect()

bool mmcConnect ( MMCDriver * mmcp)

Performs the initialization procedure on the inserted card.

This function should be invoked when a card is inserted and brings the driver in the MMC_READY state where it is possible to perform read and write operations.

Note
It is possible to invoke this function from the insertion event handler.
Parameters
[in]mmcppointer to the MMCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 581 of file hal_mmc_spi.c.

References _mmcsd_get_capacity(), BLK_ACTIVE, BLK_CONNECTING, BLK_READY, mmc_spi_driver_t::block_addresses, mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, mmc_spi_config_t::hscfg, mmc_spi_config_t::lscfg, MMC_ACMD41_RETRY, MMC_CMD0_RETRY, MMC_CMD1_RETRY, mmc_read_CxD(), mmc_send_command_R1(), mmc_send_command_R3(), MMCSD_BLOCK_SIZE, MMCSD_CMD8_PATTERN, MMCSD_CMD_APP_CMD, MMCSD_CMD_APP_OP_COND, MMCSD_CMD_GO_IDLE_STATE, MMCSD_CMD_INIT, MMCSD_CMD_READ_OCR, MMCSD_CMD_SEND_CID, MMCSD_CMD_SEND_CSD, MMCSD_CMD_SEND_IF_COND, MMCSD_CMD_SET_BLOCKLEN, osalDbgAssert, osalDbgCheck, osalThreadSleepMilliseconds, spiIgnore(), mmc_spi_config_t::spip, spiStart(), and spiStop().

Referenced by mmc_connect().

Here is the call graph for this function:

◆ mmcDisconnect()

bool mmcDisconnect ( MMCDriver * mmcp)

Brings the driver in a state safe for card removal.

Parameters
[in]mmcppointer to the MMCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 719 of file hal_mmc_spi.c.

References BLK_ACTIVE, BLK_DISCONNECTING, BLK_READY, mmc_spi_driver_t::config, HAL_SUCCESS, mmc_spi_config_t::hscfg, mmc_wait_idle(), osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), mmc_spi_config_t::spip, spiSelect(), spiStart(), spiStop(), and spiUnselect().

Referenced by mmc_disconnect().

Here is the call graph for this function:

◆ mmcStartSequentialRead()

bool mmcStartSequentialRead ( MMCDriver * mmcp,
uint32_t startblk )

Starts a sequential read.

Parameters
[in]mmcppointer to the MMCDriver object
[in]startblkfirst block to read
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 764 of file hal_mmc_spi.c.

References BLK_READING, BLK_READY, mmc_spi_driver_t::block_addresses, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, mmc_spi_config_t::hscfg, mmc_recvr1(), mmc_send_hdr(), MMCSD_BLOCK_SIZE, MMCSD_CMD_READ_MULTIPLE_BLOCK, osalDbgAssert, osalDbgCheck, mmc_spi_config_t::spip, spiSelect(), spiStart(), and spiUnselect().

Referenced by mmc_read().

Here is the call graph for this function:

◆ mmcSequentialRead()

bool mmcSequentialRead ( MMCDriver * mmcp,
uint8_t * buffer )

Reads a block within a sequential read operation.

Parameters
[in]mmcppointer to the MMCDriver object
[out]bufferpointer to the read buffer
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 817 of file hal_mmc_spi.c.

References BLK_READING, BLK_READY, mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, MMC_WAIT_DATA, MMCSD_BLOCK_SIZE, osalDbgCheck, spiIgnore(), mmc_spi_config_t::spip, spiReceive(), and spiUnselect().

Referenced by mmc_read().

Here is the call graph for this function:

◆ mmcStopSequentialRead()

bool mmcStopSequentialRead ( MMCDriver * mmcp)

Stops a sequential read gracefully.

Parameters
[in]mmcppointer to the MMCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 855 of file hal_mmc_spi.c.

References BLK_READING, BLK_READY, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, mmc_recvr1(), MMCSD_CMD_STOP_TRANSMISSION, osalDbgCheck, mmc_spi_config_t::spip, spiSend(), and spiUnselect().

Referenced by mmc_read().

Here is the call graph for this function:

◆ mmcStartSequentialWrite()

bool mmcStartSequentialWrite ( MMCDriver * mmcp,
uint32_t startblk )

Starts a sequential write.

Parameters
[in]mmcppointer to the MMCDriver object
[in]startblkfirst block to write
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 893 of file hal_mmc_spi.c.

References BLK_READY, BLK_WRITING, mmc_spi_driver_t::block_addresses, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, mmc_spi_config_t::hscfg, mmc_recvr1(), mmc_send_hdr(), MMCSD_BLOCK_SIZE, MMCSD_CMD_WRITE_MULTIPLE_BLOCK, osalDbgAssert, osalDbgCheck, mmc_spi_config_t::spip, spiSelect(), spiStart(), and spiUnselect().

Referenced by mmc_write().

Here is the call graph for this function:

◆ mmcSequentialWrite()

bool mmcSequentialWrite ( MMCDriver * mmcp,
const uint8_t * buffer )

Writes a block within a sequential write operation.

Parameters
[in]mmcppointer to the MMCDriver object
[out]bufferpointer to the write buffer
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 942 of file hal_mmc_spi.c.

References BLK_READY, BLK_WRITING, mmc_spi_driver_t::buffer, mmc_spi_driver_t::config, HAL_FAILED, mmc_wait_idle(), MMCSD_BLOCK_SIZE, osalDbgCheck, spiIgnore(), mmc_spi_config_t::spip, spiReceive(), spiSend(), and spiUnselect().

Referenced by mmc_write().

Here is the call graph for this function:

◆ mmcStopSequentialWrite()

bool mmcStopSequentialWrite ( MMCDriver * mmcp)

Stops a sequential write gracefully.

Parameters
[in]mmcppointer to the MMCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 978 of file hal_mmc_spi.c.

References BLK_READY, BLK_WRITING, mmc_spi_driver_t::config, HAL_FAILED, HAL_SUCCESS, osalDbgCheck, mmc_spi_config_t::spip, spiSend(), and spiUnselect().

Referenced by mmc_write().

Here is the call graph for this function:

◆ mmcSync()

bool mmcSync ( MMCDriver * mmcp)

Waits for card idle condition.

Parameters
[in]mmcppointer to the MMCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 1007 of file hal_mmc_spi.c.

References BLK_READY, BLK_SYNCING, mmc_spi_driver_t::config, HAL_FAILED, mmc_spi_config_t::hscfg, mmc_wait_idle(), osalDbgCheck, mmc_spi_config_t::spip, spiSelect(), spiStart(), and spiUnselect().

Referenced by mmc_sync().

Here is the call graph for this function:

◆ mmcGetInfo()

bool mmcGetInfo ( MMCDriver * mmcp,
BlockDeviceInfo * bdip )

Returns the media info.

Parameters
[in]mmcppointer to the MMCDriver object
[out]bdippointer to a BlockDeviceInfo structure
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 1044 of file hal_mmc_spi.c.

References BlockDeviceInfo::blk_num, BLK_READY, BlockDeviceInfo::blk_size, HAL_FAILED, HAL_SUCCESS, MMCSD_BLOCK_SIZE, and osalDbgCheck.

Referenced by mmc_get_info().

◆ mmcErase()

bool mmcErase ( MMCDriver * mmcp,
uint32_t startblk,
uint32_t endblk )

Erases blocks.

Parameters
[in]mmcppointer to the MMCDriver object
[in]startblkstarting block number
[in]endblkending block number
Returns
The operation status.
Return values
HAL_SUCCESSif the operation succeeded.
HAL_FAILEDif the operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 1071 of file hal_mmc_spi.c.

References BLK_READY, BLK_WRITING, mmc_spi_driver_t::block_addresses, HAL_FAILED, HAL_SUCCESS, mmc_send_command_R1(), MMCSD_BLOCK_SIZE, MMCSD_CMD_ERASE, MMCSD_CMD_ERASE_RW_BLK_END, MMCSD_CMD_ERASE_RW_BLK_START, and osalDbgCheck.

Here is the call graph for this function:

◆ mmc_lld_is_card_inserted()

bool mmc_lld_is_card_inserted ( MMCDriver * mmcp)

◆ mmc_lld_is_write_protected()

bool mmc_lld_is_write_protected ( MMCDriver * mmcp)

Variable Documentation

◆ mmc_vmt

const struct mmc_spi_driver_vmt mmc_vmt
static
Initial value:
= {
(size_t)0,
}
static bool mmc_read(void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n)
static bool mmc_write(void *instance, uint32_t startblk, const uint8_t *buffer, uint32_t n)
static bool mmc_is_write_protected(void *instance)
static bool mmc_get_info(void *instance, BlockDeviceInfo *bdip)
static bool mmc_sync(void *instance)
static bool mmc_connect(void *instance)
static bool mmc_disconnect(void *instance)
static bool mmc_is_card_inserted(void *instance)

Virtual methods table.

Definition at line 61 of file hal_mmc_spi.c.

Referenced by mmcObjectInit().

◆ mmc_crc7_lookup_table

const uint8_t mmc_crc7_lookup_table[256]
static
Initial value:
= {
0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53,
0x6c, 0x65, 0x7e, 0x77, 0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26,
0x51, 0x58, 0x43, 0x4a, 0x75, 0x7c, 0x67, 0x6e, 0x32, 0x3b, 0x20, 0x29,
0x16, 0x1f, 0x04, 0x0d, 0x7a, 0x73, 0x68, 0x61, 0x5e, 0x57, 0x4c, 0x45,
0x2b, 0x22, 0x39, 0x30, 0x0f, 0x06, 0x1d, 0x14, 0x63, 0x6a, 0x71, 0x78,
0x47, 0x4e, 0x55, 0x5c, 0x64, 0x6d, 0x76, 0x7f, 0x40, 0x49, 0x52, 0x5b,
0x2c, 0x25, 0x3e, 0x37, 0x08, 0x01, 0x1a, 0x13, 0x7d, 0x74, 0x6f, 0x66,
0x59, 0x50, 0x4b, 0x42, 0x35, 0x3c, 0x27, 0x2e, 0x11, 0x18, 0x03, 0x0a,
0x56, 0x5f, 0x44, 0x4d, 0x72, 0x7b, 0x60, 0x69, 0x1e, 0x17, 0x0c, 0x05,
0x3a, 0x33, 0x28, 0x21, 0x4f, 0x46, 0x5d, 0x54, 0x6b, 0x62, 0x79, 0x70,
0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31, 0x38, 0x41, 0x48, 0x53, 0x5a,
0x65, 0x6c, 0x77, 0x7e, 0x09, 0x00, 0x1b, 0x12, 0x2d, 0x24, 0x3f, 0x36,
0x58, 0x51, 0x4a, 0x43, 0x7c, 0x75, 0x6e, 0x67, 0x10, 0x19, 0x02, 0x0b,
0x34, 0x3d, 0x26, 0x2f, 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c,
0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, 0x0d, 0x04, 0x6a, 0x63, 0x78, 0x71,
0x4e, 0x47, 0x5c, 0x55, 0x22, 0x2b, 0x30, 0x39, 0x06, 0x0f, 0x14, 0x1d,
0x25, 0x2c, 0x37, 0x3e, 0x01, 0x08, 0x13, 0x1a, 0x6d, 0x64, 0x7f, 0x76,
0x49, 0x40, 0x5b, 0x52, 0x3c, 0x35, 0x2e, 0x27, 0x18, 0x11, 0x0a, 0x03,
0x74, 0x7d, 0x66, 0x6f, 0x50, 0x59, 0x42, 0x4b, 0x17, 0x1e, 0x05, 0x0c,
0x33, 0x3a, 0x21, 0x28, 0x5f, 0x56, 0x4d, 0x44, 0x7b, 0x72, 0x69, 0x60,
0x0e, 0x07, 0x1c, 0x15, 0x2a, 0x23, 0x38, 0x31, 0x46, 0x4f, 0x54, 0x5d,
0x62, 0x6b, 0x70, 0x79
}

Lookup table for CRC-7 ( based on polynomial x^7 + x^3 + 1).

Definition at line 76 of file hal_mmc_spi.c.

Referenced by mmc_crc7().