Bsp lpc55sxx (#6897)

* [bsp_lpc55sxx] i2c,rtc bsp update

1. add i2c DMA mode
2. enable rtc driver

* [bsp_lpc55sxx] formmat code

using formmating.py for format code

* [lpc55sxx] remove .gitignore

* [bsp][lpc55sxx] update bsp driver

1. update sdif driver, enable DFS, FAT32
2. update rtc driver
This commit is contained in:
杨熙 2023-02-02 16:41:14 +08:00 committed by GitHub
parent 8945e8d9ed
commit 83bd8614ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 2454 additions and 15137 deletions

View File

@ -1,166 +0,0 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_sdmmc_common.h"
/*******************************************************************************
* Variables
******************************************************************************/
#if SDMMCHOST_SUPPORT_DDR50 || SDMMCHOST_SUPPORT_SDR104 || SDMMCHOST_SUPPORT_SDR50 || SDMMCHOST_SUPPORT_HS200 || \
SDMMCHOST_SUPPORT_HS400
/* sdmmc tuning block */
const uint32_t SDMMC_TuningBlockPattern4Bit[16U] = {
0xFF0FFF00U, 0xFFCCC3CCU, 0xC33CCCFFU, 0xFEFFFEEFU, 0xFFDFFFDDU, 0xFFFBFFFBU, 0xBFFF7FFFU, 0x77F7BDEFU,
0xFFF0FFF0U, 0x0FFCCC3CU, 0xCC33CCCFU, 0xFFEFFFEEU, 0xFFFDFFFDU, 0xDFFFBFFFU, 0xBBFFF7FFU, 0xF77F7BDEU,
};
const uint32_t SDMMC_TuningBlockPattern8Bit[32U] = {
0xffff00ffU, 0xffff0000U, 0xffffccccU, 0xcc33ccccU, 0xcc3333ccU, 0xccccffffU, 0xffeeffffU, 0xffeeeeffU,
0xffffddffU, 0xffffddddU, 0xffffffbbU, 0xffffffbbU, 0xbbffffffU, 0x77ffffffU, 0x7777ff77U, 0xbbddeeffU,
0xffffff00U, 0xffffff00U, 0x00ffffccU, 0xcccc33ccU, 0xcccc3333U, 0xccccccffU, 0xffffeeffU, 0xffffeeeeU,
0xffffffddU, 0xffffffddU, 0xddffffffU, 0xbbffffffU, 0xbbbbffffU, 0xff77ffffU, 0xff7777ffU, 0x77bbddeeU,
};
#endif
/*******************************************************************************
* Code
******************************************************************************/
status_t SDMMC_SelectCard(sdmmchost_t *host, uint32_t relativeAddress, bool isSelected)
{
sdmmchost_transfer_t content = {0};
sdmmchost_cmd_t command = {0};
status_t error = kStatus_Success;
command.index = (uint32_t)kSDMMC_SelectCard;
if (isSelected)
{
command.argument = relativeAddress << 16U;
command.responseType = kCARD_ResponseTypeR1;
}
else
{
command.argument = 0U;
command.responseType = kCARD_ResponseTypeNone;
}
content.command = &command;
content.data = NULL;
error = SDMMCHOST_TransferFunction(host, &content);
if ((kStatus_Success != error) || ((command.response[0U] & SDMMC_R1_ALL_ERROR_FLAG) != 0U))
{
return kStatus_SDMMC_TransferFailed;
}
/* Wait until card to transfer state */
return kStatus_Success;
}
status_t SDMMC_SendApplicationCommand(sdmmchost_t *host, uint32_t relativeAddress)
{
sdmmchost_transfer_t content = {0};
sdmmchost_cmd_t command = {0};
status_t error = kStatus_Success;
command.index = (uint32_t)kSDMMC_ApplicationCommand;
command.argument = (relativeAddress << 16U);
command.responseType = kCARD_ResponseTypeR1;
content.command = &command;
content.data = NULL;
error = SDMMCHOST_TransferFunction(host, &content);
if ((kStatus_Success != error) || ((command.response[0U] & SDMMC_R1_ALL_ERROR_FLAG) != 0U))
{
return kStatus_SDMMC_TransferFailed;
}
if (0U == (command.response[0U] & SDMMC_MASK(kSDMMC_R1ApplicationCommandFlag)))
{
return kStatus_SDMMC_CardNotSupport;
}
return kStatus_Success;
}
status_t SDMMC_SetBlockCount(sdmmchost_t *host, uint32_t blockCount)
{
sdmmchost_transfer_t content = {0};
sdmmchost_cmd_t command = {0};
status_t error = kStatus_Success;
command.index = (uint32_t)kSDMMC_SetBlockCount;
command.argument = blockCount;
command.responseType = kCARD_ResponseTypeR1;
content.command = &command;
content.data = NULL;
error = SDMMCHOST_TransferFunction(host, &content);
if ((kStatus_Success != error) || ((command.response[0U] & SDMMC_R1_ALL_ERROR_FLAG) != 0U))
{
return kStatus_SDMMC_TransferFailed;
}
return kStatus_Success;
}
status_t SDMMC_GoIdle(sdmmchost_t *host)
{
sdmmchost_transfer_t content = {0};
sdmmchost_cmd_t command = {0};
status_t error = kStatus_Success;
command.index = (uint32_t)kSDMMC_GoIdleState;
content.command = &command;
content.data = NULL;
error = SDMMCHOST_TransferFunction(host, &content);
if (kStatus_Success != error)
{
return kStatus_SDMMC_TransferFailed;
}
return kStatus_Success;
}
status_t SDMMC_SetBlockSize(sdmmchost_t *host, uint32_t blockSize)
{
sdmmchost_transfer_t content = {0};
sdmmchost_cmd_t command = {0};
status_t error = kStatus_Success;
command.index = (uint32_t)kSDMMC_SetBlockLength;
command.argument = blockSize;
command.responseType = kCARD_ResponseTypeR1;
content.command = &command;
content.data = NULL;
error = SDMMCHOST_TransferFunction(host, &content);
if ((kStatus_Success != error) || ((command.response[0U] & SDMMC_R1_ALL_ERROR_FLAG) != 0U))
{
return kStatus_SDMMC_TransferFailed;
}
return kStatus_Success;
}
status_t SDMMC_SetCardInactive(sdmmchost_t *host)
{
sdmmchost_transfer_t content = {0};
sdmmchost_cmd_t command = {0};
status_t error = kStatus_Success;
command.index = (uint32_t)kSDMMC_GoInactiveState;
command.argument = 0U;
command.responseType = kCARD_ResponseTypeNone;
content.command = &command;
content.data = NULL;
error = SDMMCHOST_TransferFunction(host, &content);
if ((kStatus_Success != error))
{
return kStatus_SDMMC_TransferFailed;
}
return kStatus_Success;
}

View File

@ -1,366 +0,0 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_SDMMC_COMMON_H_
#define _FSL_SDMMC_COMMON_H_
#include "fsl_common.h"
#include "fsl_sdmmc_host.h"
#include "fsl_sdmmc_spec.h"
#include "stdlib.h"
/*!
* @addtogroup sdmmc_common SDMMC Common
* @ingroup card
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief Reverse byte sequence in uint32_t */
#define SWAP_WORD_BYTE_SEQUENCE(x) (__REV(x))
/*! @brief Reverse byte sequence for each half word in uint32_t */
#define SWAP_HALF_WROD_BYTE_SEQUENCE(x) (__REV16(x))
/*! @brief Maximum loop count to check the card operation voltage range */
#define FSL_SDMMC_MAX_VOLTAGE_RETRIES (1000U)
/*! @brief Maximum loop count to send the cmd */
#define FSL_SDMMC_MAX_CMD_RETRIES (10U)
/*! @brief Default block size */
#define FSL_SDMMC_DEFAULT_BLOCK_SIZE (512U)
/*! @brief make sure the internal buffer address is cache align */
#if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
#if defined(FSL_FEATURE_L2DCACHE_LINESIZE_BYTE)
#define SDMMC_DATA_BUFFER_ALIGN_CACHE MAX(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE, FSL_FEATURE_L2DCACHE_LINESIZE_BYTE)
#else
#define SDMMC_DATA_BUFFER_ALIGN_CACHE FSL_FEATURE_L1DCACHE_LINESIZE_BYTE
#endif
#else
#define SDMMC_DATA_BUFFER_ALIGN_CACHE sizeof(uint32_t)
#endif
/*! @brief sdmmc card internal buffer size */
#define FSL_SDMMC_CARD_INTERNAL_BUFFER_SIZE (FSL_SDMMC_DEFAULT_BLOCK_SIZE + SDMMC_DATA_BUFFER_ALIGN_CACHE)
#define FSL_SDMMC_CARD_INTERNAL_BUFFER_ALIGN_ADDR(buffer) \
(uint32_t)((uint32_t)(buffer) + (uint32_t)SDMMC_DATA_BUFFER_ALIGN_CACHE - \
((uint32_t)(buffer) & ((uint32_t)SDMMC_DATA_BUFFER_ALIGN_CACHE - 1U)))
/*! @brief get maximum freq */
#define FSL_SDMMC_CARD_MAX_BUS_FREQ(max, target) ((max) == 0U ? (target) : ((max) > (target) ? (target) : (max)))
/*! @brief SD/MMC error log. */
#if defined SDMMC_ENABLE_LOG_PRINT
#include "fsl_debug_console.h"
#define SDMMC_LOG(...) PRINTF(__VA_ARGS__)
#else
#define SDMMC_LOG(format, ...)
#endif
/*! @brief SD/MMC card API's running status.
* @anchor _sdmmc_status
*/
enum
{
kStatus_SDMMC_NotSupportYet = MAKE_STATUS(kStatusGroup_SDMMC, 0U), /*!< Haven't supported */
kStatus_SDMMC_TransferFailed = MAKE_STATUS(kStatusGroup_SDMMC, 1U), /*!< Send command failed */
kStatus_SDMMC_SetCardBlockSizeFailed = MAKE_STATUS(kStatusGroup_SDMMC, 2U), /*!< Set block size failed */
kStatus_SDMMC_HostNotSupport = MAKE_STATUS(kStatusGroup_SDMMC, 3U), /*!< Host doesn't support */
kStatus_SDMMC_CardNotSupport = MAKE_STATUS(kStatusGroup_SDMMC, 4U), /*!< Card doesn't support */
kStatus_SDMMC_AllSendCidFailed = MAKE_STATUS(kStatusGroup_SDMMC, 5U), /*!< Send CID failed */
kStatus_SDMMC_SendRelativeAddressFailed = MAKE_STATUS(kStatusGroup_SDMMC, 6U), /*!< Send relative address failed */
kStatus_SDMMC_SendCsdFailed = MAKE_STATUS(kStatusGroup_SDMMC, 7U), /*!< Send CSD failed */
kStatus_SDMMC_SelectCardFailed = MAKE_STATUS(kStatusGroup_SDMMC, 8U), /*!< Select card failed */
kStatus_SDMMC_SendScrFailed = MAKE_STATUS(kStatusGroup_SDMMC, 9U), /*!< Send SCR failed */
kStatus_SDMMC_SetDataBusWidthFailed = MAKE_STATUS(kStatusGroup_SDMMC, 10U), /*!< Set bus width failed */
kStatus_SDMMC_GoIdleFailed = MAKE_STATUS(kStatusGroup_SDMMC, 11U), /*!< Go idle failed */
kStatus_SDMMC_HandShakeOperationConditionFailed =
MAKE_STATUS(kStatusGroup_SDMMC, 12U), /*!< Send Operation Condition failed */
kStatus_SDMMC_SendApplicationCommandFailed =
MAKE_STATUS(kStatusGroup_SDMMC, 13U), /*!< Send application command failed */
kStatus_SDMMC_SwitchFailed = MAKE_STATUS(kStatusGroup_SDMMC, 14U), /*!< Switch command failed */
kStatus_SDMMC_StopTransmissionFailed = MAKE_STATUS(kStatusGroup_SDMMC, 15U), /*!< Stop transmission failed */
kStatus_SDMMC_WaitWriteCompleteFailed = MAKE_STATUS(kStatusGroup_SDMMC, 16U), /*!< Wait write complete failed */
kStatus_SDMMC_SetBlockCountFailed = MAKE_STATUS(kStatusGroup_SDMMC, 17U), /*!< Set block count failed */
kStatus_SDMMC_SetRelativeAddressFailed = MAKE_STATUS(kStatusGroup_SDMMC, 18U), /*!< Set relative address failed */
kStatus_SDMMC_SwitchBusTimingFailed = MAKE_STATUS(kStatusGroup_SDMMC, 19U), /*!< Switch high speed failed */
kStatus_SDMMC_SendExtendedCsdFailed = MAKE_STATUS(kStatusGroup_SDMMC, 20U), /*!< Send EXT_CSD failed */
kStatus_SDMMC_ConfigureBootFailed = MAKE_STATUS(kStatusGroup_SDMMC, 21U), /*!< Configure boot failed */
kStatus_SDMMC_ConfigureExtendedCsdFailed = MAKE_STATUS(kStatusGroup_SDMMC, 22U), /*!< Configure EXT_CSD failed */
kStatus_SDMMC_EnableHighCapacityEraseFailed =
MAKE_STATUS(kStatusGroup_SDMMC, 23U), /*!< Enable high capacity erase failed */
kStatus_SDMMC_SendTestPatternFailed = MAKE_STATUS(kStatusGroup_SDMMC, 24U), /*!< Send test pattern failed */
kStatus_SDMMC_ReceiveTestPatternFailed = MAKE_STATUS(kStatusGroup_SDMMC, 25U), /*!< Receive test pattern failed */
kStatus_SDMMC_SDIO_ResponseError = MAKE_STATUS(kStatusGroup_SDMMC, 26U), /*!< sdio response error */
kStatus_SDMMC_SDIO_InvalidArgument =
MAKE_STATUS(kStatusGroup_SDMMC, 27U), /*!< sdio invalid argument response error */
kStatus_SDMMC_SDIO_SendOperationConditionFail =
MAKE_STATUS(kStatusGroup_SDMMC, 28U), /*!< sdio send operation condition fail */
kStatus_SDMMC_InvalidVoltage = MAKE_STATUS(kStatusGroup_SDMMC, 29U), /*!< invaild voltage */
kStatus_SDMMC_SDIO_SwitchHighSpeedFail = MAKE_STATUS(kStatusGroup_SDMMC, 30U), /*!< switch to high speed fail */
kStatus_SDMMC_SDIO_ReadCISFail = MAKE_STATUS(kStatusGroup_SDMMC, 31U), /*!< read CIS fail */
kStatus_SDMMC_SDIO_InvalidCard = MAKE_STATUS(kStatusGroup_SDMMC, 32U), /*!< invaild SDIO card */
kStatus_SDMMC_TuningFail = MAKE_STATUS(kStatusGroup_SDMMC, 33U), /*!< tuning fail */
kStatus_SDMMC_SwitchVoltageFail = MAKE_STATUS(kStatusGroup_SDMMC, 34U), /*!< switch voltage fail*/
kStatus_SDMMC_SwitchVoltage18VFail33VSuccess = MAKE_STATUS(kStatusGroup_SDMMC, 35U), /*!< switch voltage fail*/
kStatus_SDMMC_ReTuningRequest = MAKE_STATUS(kStatusGroup_SDMMC, 36U), /*!< retuning request */
kStatus_SDMMC_SetDriverStrengthFail = MAKE_STATUS(kStatusGroup_SDMMC, 37U), /*!< set driver strength fail */
kStatus_SDMMC_SetPowerClassFail = MAKE_STATUS(kStatusGroup_SDMMC, 38U), /*!< set power class fail */
kStatus_SDMMC_HostNotReady = MAKE_STATUS(kStatusGroup_SDMMC, 39U), /*!< host controller not ready */
kStatus_SDMMC_CardDetectFailed = MAKE_STATUS(kStatusGroup_SDMMC, 40U), /*!< card detect failed */
kStatus_SDMMC_AuSizeNotSetProperly = MAKE_STATUS(kStatusGroup_SDMMC, 41U), /*!< AU size not set properly */
kStatus_SDMMC_PollingCardIdleFailed = MAKE_STATUS(kStatusGroup_SDMMC, 42U), /*!< polling card idle status failed */
kStatus_SDMMC_DeselectCardFailed = MAKE_STATUS(kStatusGroup_SDMMC, 43U), /*!< deselect card failed */
kStatus_SDMMC_CardStatusIdle = MAKE_STATUS(kStatusGroup_SDMMC, 44U), /*!< card idle */
kStatus_SDMMC_CardStatusBusy = MAKE_STATUS(kStatusGroup_SDMMC, 45U), /*!< card busy */
kStatus_SDMMC_CardInitFailed = MAKE_STATUS(kStatusGroup_SDMMC, 46U), /*!< card init failed */
};
/*! @brief sdmmc signal line
* @anchor _sdmmc_signal_line
*/
enum
{
kSDMMC_SignalLineCmd = 1U, /*!< cmd line */
kSDMMC_SignalLineData0 = 2U, /*!< data line */
kSDMMC_SignalLineData1 = 4U, /*!< data line */
kSDMMC_SignalLineData2 = 8U, /*!< data line */
kSDMMC_SignalLineData3 = 16U, /*!< data line */
kSDMMC_SignalLineData4 = 32U, /*!< data line */
kSDMMC_SignalLineData5 = 64U, /*!< data line */
kSDMMC_SignalLineData6 = 128U, /*!< data line */
kSDMMC_SignalLineData7 = 256U, /*!< data line */
};
/*! @brief card operation voltage */
typedef enum _sdmmc_operation_voltage
{
kSDMMC_OperationVoltageNone = 0U, /*!< indicate current voltage setting is not setting by suser*/
kSDMMC_OperationVoltage330V = 1U, /*!< card operation voltage around 3.3v */
kSDMMC_OperationVoltage300V = 2U, /*!< card operation voltage around 3.0v */
kSDMMC_OperationVoltage180V = 3U, /*!< card operation voltage around 1.8v */
} sdmmc_operation_voltage_t;
/*!@brief card bus width
* @anchor _sdmmc_bus_width
*/
enum
{
kSDMMC_BusWdith1Bit = 0U, /*!< card bus 1 width */
kSDMMC_BusWdith4Bit = 1U, /*!< card bus 4 width */
kSDMMC_BusWdith8Bit = 2U, /*!< card bus 8 width */
};
/*!@brief sdmmc capability flag
* @anchor _sdmmc_capability_flag
*/
enum
{
kSDMMC_Support8BitWidth = 1U, /*!< 8 bit data width capability */
};
/*!@ brief sdmmc data packet format
* @anchor _sdmmc_data_packet_format
*/
enum
{
kSDMMC_DataPacketFormatLSBFirst, /*!< usual data packet format LSB first, MSB last */
kSDMMC_DataPacketFormatMSBFirst, /*!< Wide width data packet format MSB first, LSB last */
};
/*! @brief sd card detect type */
typedef enum _sd_detect_card_type
{
kSD_DetectCardByGpioCD, /*!< sd card detect by CD pin through GPIO */
kSD_DetectCardByHostCD, /*!< sd card detect by CD pin through host */
kSD_DetectCardByHostDATA3, /*!< sd card detect by DAT3 pin through host */
} sd_detect_card_type_t;
/*!@ brief SD card detect status
* @anchor _sd_card_cd_status
*/
enum
{
kSD_Inserted = 1U, /*!< card is inserted*/
kSD_Removed = 0U, /*!< card is removed */
};
/*!@ brief SD card detect status
* @anchor _sd_card_dat3_pull_status
*/
enum
{
kSD_DAT3PullDown = 0U, /*!< data3 pull down */
kSD_DAT3PullUp = 1U, /*!< data3 pull up */
};
/*! @brief card detect aoolication callback definition */
typedef void (*sd_cd_t)(bool isInserted, void *userData);
/*! @brief card detect status */
typedef bool (*sd_cd_status_t)(void);
typedef void (*sd_dat3_pull_t)(uint32_t pullStatus);
/*! @brief sd card detect */
typedef struct _sd_detect_card
{
sd_detect_card_type_t type; /*!< card detect type */
uint32_t cdDebounce_ms; /*!< card detect debounce delay ms */
sd_cd_t callback; /*!< card inserted callback which is meaningful for interrupt case */
sd_cd_status_t cardDetected; /*!< used to check sd cd status when card detect through GPIO */
sd_dat3_pull_t dat3PullFunc; /*!< function pointer of DATA3 pull up/down */
void *userData; /*!< user data */
} sd_detect_card_t;
/*!@brief io voltage control type*/
typedef enum _sd_io_voltage_ctrl_type
{
kSD_IOVoltageCtrlNotSupport = 0U, /*!< io voltage control not support */
kSD_IOVoltageCtrlByHost = 1U, /*!< io voltage control by host */
kSD_IOVoltageCtrlByGpio = 2U, /*!< io voltage control by gpio */
} sd_io_voltage_ctrl_type_t;
/*! @brief card switch voltage function pointer */
typedef void (*sd_io_voltage_func_t)(sdmmc_operation_voltage_t voltage);
/*!@brief io voltage control configuration */
typedef struct _sd_io_voltage
{
sd_io_voltage_ctrl_type_t type; /*!< io voltage switch type */
sd_io_voltage_func_t func; /*!< io voltage switch function */
} sd_io_voltage_t;
/*! @brief card power control function pointer */
typedef void (*sd_pwr_t)(bool enable);
/*! @brief card io strength control */
typedef void (*sd_io_strength_t)(uint32_t busFreq);
/*! @brief sdcard user parameter */
typedef struct _sd_usr_param
{
sd_pwr_t pwr; /*!< power control configuration pointer */
uint32_t powerOnDelayMS; /*!< power on delay time */
uint32_t powerOffDelayMS; /*!< power off delay time */
sd_io_strength_t ioStrength; /*!< swicth sd io strength */
sd_io_voltage_t *ioVoltage; /*!< switch io voltage */
sd_detect_card_t *cd; /*!< card detect */
uint32_t maxFreq; /*!< board support maximum frequency */
uint32_t capability; /*!< board capability flag */
} sd_usr_param_t;
/*! @brief card interrupt function pointer */
typedef void (*sdio_int_t)(void *userData);
/*! @brief card interrupt application callback */
typedef struct _sdio_card_int
{
void *userData; /*!< user data */
sdio_int_t cardInterrupt; /*!< card int call back */
} sdio_card_int_t;
/*! @brief sdio user parameter */
typedef struct _sdio_usr_param
{
sd_pwr_t pwr; /*!< power control configuration pointer */
uint32_t powerOnDelayMS; /*!< power on delay time */
uint32_t powerOffDelayMS; /*!< power off delay time */
sd_io_strength_t ioStrength; /*!< swicth sd io strength */
sd_io_voltage_t *ioVoltage; /*!< switch io voltage */
sd_detect_card_t *cd; /*!< card detect */
sdio_card_int_t *sdioInt; /*!< card int */
uint32_t maxFreq; /*!< board support maximum frequency */
uint32_t capability; /*!< board capability flag */
} sdio_usr_param_t;
/*! @brief tuning pattern */
#if SDMMCHOST_SUPPORT_DDR50 || SDMMCHOST_SUPPORT_SDR104 || SDMMCHOST_SUPPORT_SDR50 || SDMMCHOST_SUPPORT_HS200 || \
SDMMCHOST_SUPPORT_HS400
/* sdmmc tuning block */
extern const uint32_t SDMMC_TuningBlockPattern4Bit[16U];
extern const uint32_t SDMMC_TuningBlockPattern8Bit[32U];
#endif
/*************************************************************************************************
* API
************************************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name common function
* @{
*/
/*!
* @brief Selects the card to put it into transfer state.
*
* @param host host handler.
* @param relativeAddress Relative address.
* @param isSelected True to put card into transfer state.
* @retval kStatus_SDMMC_TransferFailed Transfer failed.
* @retval kStatus_Success Operate successfully.
*/
status_t SDMMC_SelectCard(sdmmchost_t *host, uint32_t relativeAddress, bool isSelected);
/*!
* @brief Sends an application command.
*
* @param host host handler.
* @param relativeAddress Card relative address.
* @retval kStatus_SDMMC_TransferFailed Transfer failed.
* @retval kStatus_SDMMC_CardNotSupport Card doesn't support.
* @retval kStatus_Success Operate successfully.
*/
status_t SDMMC_SendApplicationCommand(sdmmchost_t *host, uint32_t relativeAddress);
/*!
* @brief Sets the block count.
*
* @param host host handler.
* @param blockCount Block count.
* @retval kStatus_SDMMC_TransferFailed Transfer failed.
* @retval kStatus_Success Operate successfully.
*/
status_t SDMMC_SetBlockCount(sdmmchost_t *host, uint32_t blockCount);
/*!
* @brief Sets the card to be idle state.
*
* @param host host handler.
* @retval kStatus_SDMMC_TransferFailed Transfer failed.
* @retval kStatus_Success Operate successfully.
*/
status_t SDMMC_GoIdle(sdmmchost_t *host);
/*!
* @brief Sets data block size.
*
* @param host host handler.
* @param blockSize Block size.
* @retval kStatus_SDMMC_TransferFailed Transfer failed.
* @retval kStatus_Success Operate successfully.
*/
status_t SDMMC_SetBlockSize(sdmmchost_t *host, uint32_t blockSize);
/*!
* @brief Sets card to inactive status
*
* @param host host handler.
* @retval kStatus_SDMMC_TransferFailed Transfer failed.
* @retval kStatus_Success Operate successfully.
*/
status_t SDMMC_SetCardInactive(sdmmchost_t *host);
/* @} */
#if defined(__cplusplus)
}
#endif
/* @} */
#endif /* _FSL_SDMMC_COMMON_H_ */

View File

@ -1,41 +0,0 @@
/*!
@page middleware_log Middleware Change Log
@section host_sdif Host SDIF driver for MCUXpresso SDK
The current driver version is 2.4.0.
- 2.4.0
- Improvements
- Removed deprecated api in SDIF host driver.
- Added SDMMCHOST_ConvertDataToLittleEndian api.
- Added capability/maxBlockCount/maxBlockSize in host decriptior.
- Added mutual exclusive access for function init/deinit/reset/transfer function.
- Fixed violations of MISRA C-2012 rule 10.1.
- 2.3.1
- Improvements
- Added host instance capability macro.
- Added clear card inserted/removed event when card removed/inserted interrupt generated.
- Increased the reset timeout value to fix the data machine still busy after sdif reset issue.
- Enabled the error recovery function by adding host reset operations.
- Bug Fixes
- Fixed violations of MISRA C-2012 rule 11.9, 15.7, 4.7, 16.4, 10.1, 10.3, 10.4, 11.3, 14.4, 10.6, 17.7, 16.1, 16.3.
- 2.3.0
- Improvements
- Merged the host controller driver from polling/freertos/interrupt to non_blocking/blocking.
- Added SDMMC OSA layer to support muxtex access/event/delay.
- 2.2.14
- Bug Fixes
- Fixed uninitialized value Coverity issue.
- 2.2.13
- Improvements:
- Added host reset after the card being powered on for host controller SDIF to fix the DATA_BUSY issue.
- Removed the SDIF_Reset from SDMMCHOST_Reset.
- 2.0.0
- Initial version
*/

View File

@ -1,238 +0,0 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_sdmmc_host.h"
#include "fsl_sdmmc_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define SDMMCHOST_TRANSFER_COMPLETE_TIMEOUT (~0U)
/*******************************************************************************
* Prototypes
******************************************************************************/
/*!
* @brief SDMMCHOST error recovery.
* @param base host base address.
*/
static void SDMMCHOST_ErrorRecovery(SDIF_Type *base);
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
status_t SDMMCHOST_CardIntInit(sdmmchost_t *host, void *sdioInt)
{
host->cardInt = sdioInt;
return kStatus_Success;
}
status_t SDMMCHOST_CardDetectInit(sdmmchost_t *host, void *cd)
{
if (cd == NULL)
{
return kStatus_Fail;
}
host->cd = cd;
return kStatus_Success;
}
uint32_t SDMMCHOST_CardDetectStatus(sdmmchost_t *host)
{
SDIF_Type *base = host->hostController.base;
sd_detect_card_t *sdCD = (sd_detect_card_t *)host->cd;
#if defined(FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD) && FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD
if (((host->hostPort == 0U) &&
(SDIF_DetectCardInsert(base, sdCD->type == kSD_DetectCardByHostDATA3 ? true : false) == 1U)) ||
((host->hostPort == 1U) &&
(SDIF_DetectCard1Insert(base, sdCD->type == kSD_DetectCardByHostDATA3 ? true : false) == 1U)))
#else
if ((host->hostPort == 0U) &&
(SDIF_DetectCardInsert(base, sdCD->type == kSD_DetectCardByHostDATA3 ? true : false) == 1U))
#endif
{
return kSD_Inserted;
}
return kSD_Removed;
}
status_t SDMMCHOST_PollingCardDetectStatus(sdmmchost_t *host, uint32_t waitCardStatus, uint32_t timeout)
{
assert(host != NULL);
assert(host->cd != NULL);
sd_detect_card_t *cd = host->cd;
uint32_t cardInsertedStatus = kSD_Removed;
/* Wait card inserted. */
do
{
cardInsertedStatus = SDMMCHOST_CardDetectStatus(host);
if ((waitCardStatus == (uint32_t)kSD_Inserted) && (cardInsertedStatus == (uint32_t)kSD_Inserted))
{
SDMMC_OSADelay(cd->cdDebounce_ms);
if (SDMMCHOST_CardDetectStatus(host) == (uint32_t)kSD_Inserted)
{
break;
}
}
if ((cardInsertedStatus == (uint32_t)kSD_Removed) && (waitCardStatus == (uint32_t)kSD_Removed))
{
break;
}
} while (true);
return kStatus_Success;
}
status_t SDMMCHOST_TransferFunction(sdmmchost_t *host, sdmmchost_transfer_t *content)
{
status_t error = kStatus_Success;
sdif_dma_config_t dmaConfig;
(void)memset(&dmaConfig, 0, sizeof(dmaConfig));
/* user DMA mode transfer data */
if (content->data != NULL)
{
dmaConfig.enableFixBurstLen = false;
dmaConfig.mode = kSDIF_ChainDMAMode;
dmaConfig.dmaDesBufferStartAddr = host->dmaDesBuffer;
dmaConfig.dmaDesBufferLen = host->dmaDesBufferWordsNum;
dmaConfig.dmaDesSkipLen = 0U;
}
error = SDIF_TransferBlocking(host->hostController.base, &dmaConfig, content);
if (error != kStatus_Success)
{
error = kStatus_Fail;
/* host error recovery */
SDMMCHOST_ErrorRecovery(host->hostController.base);
}
return error;
}
static void SDMMCHOST_ErrorRecovery(SDIF_Type *base)
{
(void)SDIF_Reset(base, kSDIF_ResetAll, SDMMCHOST_RESET_TIMEOUT_VALUE);
/* the host controller clock will be disabled by the reset operation, so re-send the clock sync command to enable
the output clock */
sdif_command_t clockSync = {
.flags = kSDIF_WaitPreTransferComplete | kSDIF_CmdUpdateClockRegisterOnly, .index = 0U, .argument = 0U};
(void)SDIF_SendCommand(base, &clockSync, 0U);
}
void SDMMCHOST_SetCardPower(sdmmchost_t *host, bool enable)
{
if (host->hostPort == 0U)
{
SDIF_EnableCardPower(host->hostController.base, enable);
}
#if defined(FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD) && FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD
else
{
SDIF_EnableCard1Power(host->hostController.base, enable);
}
#endif
if (enable)
{
/* perform SDIF host controller reset only when DATA BUSY is assert */
if ((SDIF_GetControllerStatus(host->hostController.base) & SDIF_STATUS_DATA_BUSY_MASK) != 0U)
{
(void)SDIF_Reset(host->hostController.base, kSDIF_ResetAll, SDMMCHOST_RESET_TIMEOUT_VALUE);
}
}
}
void SDMMCHOST_ConvertDataToLittleEndian(sdmmchost_t *host, uint32_t *data, uint32_t wordSize, uint32_t format)
{
uint32_t temp = 0U;
if (format == kSDMMC_DataPacketFormatMSBFirst)
{
for (uint32_t i = 0U; i < wordSize; i++)
{
temp = data[i];
data[i] = SWAP_WORD_BYTE_SEQUENCE(temp);
}
}
}
status_t SDMMCHOST_Init(sdmmchost_t *host)
{
assert(host != NULL);
sdif_host_t *sdifHost = &(host->hostController);
/* sdmmc osa init */
SDMMC_OSAInit();
/* host capability flags */
host->capability = (uint32_t)kSDMMCHOST_SupportHighSpeed | (uint32_t)kSDMMCHOST_SupportSuspendResume |
(uint32_t)kSDMMCHOST_SupportVoltage3v3 | (uint32_t)kSDMMCHOST_Support4BitDataWidth |
(uint32_t)kSDMMCHOST_Support8BitDataWidth | (uint32_t)kSDMMCHOST_SupportDetectCardByData3 |
(uint32_t)kSDMMCHOST_SupportDetectCardByCD | (uint32_t)kSDMMCHOST_SupportAutoCmd12;
host->maxBlockCount = SDMMCHOST_SUPPORT_MAX_BLOCK_COUNT;
host->maxBlockSize = SDMMCHOST_SUPPORT_MAX_BLOCK_LENGTH;
/* Initialize SDIF. */
sdifHost->config.responseTimeout = 0xFFU;
sdifHost->config.cardDetDebounce_Clock = 0xFFFFFFU;
sdifHost->config.dataTimeout = 0xFFFFFFU;
SDIF_Init(sdifHost->base, &(sdifHost->config));
return kStatus_Success;
}
void SDMMCHOST_Reset(sdmmchost_t *host)
{
/* disable all the interrupt */
SDIF_DisableInterrupt(host->hostController.base, kSDIF_AllInterruptStatus);
/* make sure host controller release all the bus line. */
(void)SDIF_Reset(host->hostController.base, kSDIF_ResetAll, 100);
/* clear all interrupt/DMA status */
SDIF_ClearInterruptStatus(host->hostController.base, kSDIF_AllInterruptStatus);
SDIF_ClearInternalDMAStatus(host->hostController.base, kSDIF_DMAAllStatus);
}
void SDMMCHOST_SetCardBusWidth(sdmmchost_t *host, uint32_t dataBusWidth)
{
if (host->hostPort == 0U)
{
SDIF_SetCardBusWidth(host->hostController.base, dataBusWidth == (uint32_t)kSDMMC_BusWdith1Bit ?
kSDIF_Bus1BitWidth :
dataBusWidth == (uint32_t)kSDMMC_BusWdith4Bit ?
kSDIF_Bus4BitWidth :
kSDIF_Bus8BitWidth);
}
#if defined(FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD) && FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD
else
{
SDIF_SetCard1BusWidth(host->hostController.base, dataBusWidth == (uint32_t)kSDMMC_BusWdith1Bit ?
kSDIF_Bus1BitWidth :
dataBusWidth == (uint32_t)kSDMMC_BusWdith4Bit ?
kSDIF_Bus4BitWidth :
kSDIF_Bus8BitWidth);
}
#endif
}
void SDMMCHOST_Deinit(sdmmchost_t *host)
{
sdif_host_t *sdifHost = &host->hostController;
SDIF_Deinit(sdifHost->base);
}

View File

@ -1,405 +0,0 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_SDMMC_HOST_H
#define _FSL_SDMMC_HOST_H
#include "fsl_common.h"
#include "fsl_sdif.h"
#include "fsl_sdmmc_osa.h"
/*!
* @addtogroup sdmmchost_sdif SDIF HOST Adapter Driver
* @ingroup sdmmchost
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief Middleware adapter version. */
#define FSL_SDMMC_HOST_ADAPTER_VERSION (MAKE_VERSION(2U, 4U, 0U)) /*2.4.0*/
/*! @brief sdmmc host capability */
enum
{
kSDMMCHOST_SupportHighSpeed = 1U << 0U, /*!< high speed capability */
kSDMMCHOST_SupportSuspendResume = 1U << 1U, /*!< suspend resume capability */
kSDMMCHOST_SupportVoltage3v3 = 1U << 2U, /*!< 3V3 capability */
kSDMMCHOST_SupportVoltage3v0 = 1U << 3U, /*!< 3V0 capability */
kSDMMCHOST_SupportVoltage1v8 = 1U << 4U, /*!< 1V8 capability */
kSDMMCHOST_SupportVoltage1v2 = 1U << 5U, /*!< 1V2 capability */
kSDMMCHOST_Support4BitDataWidth = 1U << 6U, /*!< 4 bit data width capability */
kSDMMCHOST_Support8BitDataWidth = 1U << 7U, /*!< 8 bit data width capability */
kSDMMCHOST_SupportDDRMode = 1U << 8U, /*!< DDR mode capability */
kSDMMCHOST_SupportDetectCardByData3 = 1U << 9U, /*!< data3 detect card capability */
kSDMMCHOST_SupportDetectCardByCD = 1U << 10U, /*!< CD detect card capability */
kSDMMCHOST_SupportAutoCmd12 = 1U << 11U, /*!< auto command 12 capability */
kSDMMCHOST_SupportSDR104 = 1U << 12U, /*!< SDR104 capability */
kSDMMCHOST_SupportSDR50 = 1U << 13U, /*!< SDR50 capability */
kSDMMCHOST_SupportHS200 = 1U << 14U, /*!< HS200 capability */
kSDMMCHOST_SupportHS400 = 1U << 15U, /*!< HS400 capability */
};
/*!@brief host capability */
#define SDMMCHOST_SUPPORT_HIGH_SPEED (1U)
#define SDMMCHOST_SUPPORT_SUSPEND_RESUME (1U)
#define SDMMCHOST_SUPPORT_VOLTAGE_3V3 (1U)
#define SDMMCHOST_SUPPORT_VOLTAGE_3V0 (0U)
#define SDMMCHOST_SUPPORT_VOLTAGE_1V8 (0U)
#define SDMMCHOST_SUPPORT_VOLTAGE_1V2 (0U)
#define SDMMCHOST_SUPPORT_4_BIT_WIDTH (1U)
#define SDMMCHOST_SUPPORT_8_BIT_WIDTH (1U)
#define SDMMCHOST_SUPPORT_DDR50 (0U)
#define SDMMCHOST_SUPPORT_SDR104 (0U)
#define SDMMCHOST_SUPPORT_SDR50 (0U)
#define SDMMCHOST_SUPPORT_HS200 (0U)
#define SDMMCHOST_SUPPORT_HS400 (0U)
#define SDMMCHOST_SUPPORT_DETECT_CARD_BY_DATA3 (1U)
#define SDMMCHOST_SUPPORT_DETECT_CARD_BY_CD (1U)
#define SDMMCHOST_SUPPORT_AUTO_CMD12 (1U)
#define SDMMCHOST_SUPPORT_MAX_BLOCK_LENGTH (SDIF_BLKSIZ_BLOCK_SIZE_MASK)
#define SDMMCHOST_SUPPORT_MAX_BLOCK_COUNT (SDIF_BYTCNT_BYTE_COUNT_MASK / SDIF_BLKSIZ_BLOCK_SIZE_MASK)
/*! @brief sdmmc host instance capability */
#define SDMMCHOST_INSTANCE_SUPPORT_8_BIT_WIDTH(host) 1U
#define SDMMCHOST_INSTANCE_SUPPORT_HS400(host) 0U
#define SDMMCHOST_INSTANCE_SUPPORT_1V8_SIGNAL(host) 0U
#define SDMMCHOST_INSTANCE_SUPPORT_HS200(host) 0U
#define SDMMCHOST_INSTANCE_SUPPORT_SDR104(host) 0U
#define SDMMCHOST_INSTANCE_SUPPORT_SDR50(host) 0U
#define SDMMCHOST_INSTANCE_SUPPORT_DDR50(host) 0U
/*!@brief SDMMC host dma descriptor buffer address align size */
#define SDMMCHOST_DMA_DESCRIPTOR_BUFFER_ALIGN_SIZE (4U)
/*! @brief SDMMC host reset timoue value */
#define SDMMCHOST_RESET_TIMEOUT_VALUE (1000000U)
/*! @brief host Endian mode
* corresponding to driver define
*/
enum _sdmmchost_endian_mode
{
kSDMMCHOST_EndianModeBig = 0U, /*!< Big endian mode */
kSDMMCHOST_EndianModeHalfWordBig = 1U, /*!< Half word big endian mode */
kSDMMCHOST_EndianModeLittle = 2U, /*!< Little endian mode */
};
/*!@brief sdmmc host transfer function */
typedef sdif_transfer_t sdmmchost_transfer_t;
typedef sdif_command_t sdmmchost_cmd_t;
typedef sdif_data_t sdmmchost_data_t;
typedef struct _sdmmchost_ SDMMCHOST_CONFIG;
typedef SDIF_Type SDMMCHOST_TYPE;
typedef void sdmmchost_detect_card_t;
typedef void sdmmchost_boot_config_t;
/*!@brief sdmmc host handler */
typedef struct _sdmmchost_
{
sdif_host_t hostController; /*!< host configuration */
uint8_t hostPort; /*!< host port number, used for one instance support two card */
void *dmaDesBuffer; /*!< DMA descriptor buffer address */
uint32_t dmaDesBufferWordsNum; /*!< DMA descriptor buffer size in byte */
sdif_handle_t handle; /*!< host controller handler */
uint32_t capability; /*!< host controller capability */
uint32_t maxBlockCount; /*!< host controller maximum block count */
uint32_t maxBlockSize; /*!< host controller maximum block size */
sdmmc_osa_event_t hostEvent; /*!< host event handler */
void *cd; /*!< card detect */
void *cardInt; /*!< call back function for card interrupt */
sdmmc_osa_mutex_t lock; /*!< host access lock */
} sdmmchost_t;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name SDIF host controller function
* @{
*/
/*!
* @brief set data bus width.
* @param host host handler
* @param dataBusWidth data bus width
*/
void SDMMCHOST_SetCardBusWidth(sdmmchost_t *host, uint32_t dataBusWidth);
/*!
* @brief Send initilization active 80 clocks to card.
* @param host host handler
*/
static inline void SDMMCHOST_SendCardActive(sdmmchost_t *host)
{
SDIF_SendCardActive(host->hostController.base, 100U);
}
/*!
* @brief Set card bus clock.
* @param host host handler
* @param targetClock target clock frequency
* @retval actual clock frequency can be reach.
*/
static inline uint32_t SDMMCHOST_SetCardClock(sdmmchost_t *host, uint32_t targetClock)
{
return SDIF_SetCardClock(host->hostController.base, host->hostController.sourceClock_Hz, targetClock);
}
/*!
* @brief check card status by DATA0.
* @param host host handler
* @retval true is busy, false is idle.
*/
static inline bool SDMMCHOST_IsCardBusy(sdmmchost_t *host)
{
return (SDIF_GetControllerStatus(host->hostController.base) & SDIF_STATUS_DATA_BUSY_MASK) ==
SDIF_STATUS_DATA_BUSY_MASK ?
true :
false;
}
/*!
* @brief start read boot data.
* @param host host handler
* @param hostConfig boot configuration
* @param cmd boot command
* @param buffer buffer address
*/
static inline status_t SDMMCHOST_StartBoot(sdmmchost_t *host,
sdmmchost_boot_config_t *hostConfig,
sdmmchost_cmd_t *cmd,
uint8_t *buffer)
{
/* host not support */
return kStatus_Fail;
}
/*!
* @brief read boot data.
* @param host host handler
* @param hostConfig boot configuration
* @param buffer buffer address
*/
static inline status_t SDMMCHOST_ReadBootData(sdmmchost_t *host, sdmmchost_boot_config_t *hostConfig, uint8_t *buffer)
{
/* host not support */
return kStatus_Fail;
}
/*!
* @brief enable boot mode.
* @param host host handler
* @param enable true is enable, false is disable
*/
static inline void SDMMCHOST_EnableBoot(sdmmchost_t *host, bool enable)
{
/* not support */
}
/*!
* @brief enable card interrupt.
* @param host host handler
* @param enable true is enable, false is disable.
*/
static inline void SDMMCHOST_EnableCardInt(sdmmchost_t *host, bool enable)
{
if (enable)
{
SDIF_EnableInterrupt(host->hostController.base, kSDIF_SDIOInterrupt);
}
else
{
SDIF_DisableInterrupt(host->hostController.base, kSDIF_SDIOInterrupt);
}
}
/*!
* @brief card interrupt function.
* @param host host handler
* @param sdioInt card interrupt configuration
*/
status_t SDMMCHOST_CardIntInit(sdmmchost_t *host, void *sdioInt);
/*!
* @brief card detect init function.
* @param host host handler
* @param cd card detect configuration
*/
status_t SDMMCHOST_CardDetectInit(sdmmchost_t *host, void *cd);
/*!
* @brief Detect card insert, only need for SD cases.
* @param host host handler
* @param waitCardStatus status which user want to wait
* @param timeout wait time out.
* @retval kStatus_Success detect card insert
* @retval kStatus_Fail card insert event fail
*/
status_t SDMMCHOST_PollingCardDetectStatus(sdmmchost_t *host, uint32_t waitCardStatus, uint32_t timeout);
/*!
* @brief card detect status.
* @param host host handler
* @retval kSD_Inserted, kSD_Removed
*/
uint32_t SDMMCHOST_CardDetectStatus(sdmmchost_t *host);
/*!
* @brief Init host controller.
*
* Thread safe function, please note that the function will create the mutex lock dynamically by default,
* so to avoid the mutex create redundantly, application must follow bellow sequence for card re-initialization
* @code
* SDMMCHOST_Deinit(host);
* SDMMCHOST_Init(host);
* @endcode
*
* @param host host handler
* @retval kStatus_Success host init success
* @retval kStatus_Fail event fail
*/
status_t SDMMCHOST_Init(sdmmchost_t *host);
/*!
* @brief Deinit host controller.
*
* Please note it is a thread safe function.
*
* @param host host handler
*/
void SDMMCHOST_Deinit(sdmmchost_t *host);
/*!
* @brief host power off card function.
* @param host host handler
* @param enable true is power on, false is power down.
*/
void SDMMCHOST_SetCardPower(sdmmchost_t *host, bool enable);
/*!
* @brief host transfer function.
*
* Please note it is a thread safe function.
*
* @param host host handler
* @param content transfer content.
*/
status_t SDMMCHOST_TransferFunction(sdmmchost_t *host, sdmmchost_transfer_t *content);
/*!
* @brief host reset function.
*
* Please note it is a thread safe function.
*
* @param host host handler
*/
void SDMMCHOST_Reset(sdmmchost_t *host);
/*!
* @brief switch to voltage.
* @param host host handler
* @param voltage switch to voltage level.
*/
static inline void SDMMCHOST_SwitchToVoltage(sdmmchost_t *host, uint32_t voltage)
{
/* host not support */
}
/*!
* @brief sdmmc host excute tuning.
*
* @param host host handler
* @param tuningCmd tuning command.
* @param revBuf receive buffer pointer
* @param blockSize tuning data block size.
*/
static inline status_t SDMMCHOST_ExecuteTuning(sdmmchost_t *host,
uint32_t tuningCmd,
uint32_t *revBuf,
uint32_t blockSize)
{
/* host not support */
return kStatus_Fail;
}
/*!
* @brief enable DDR mode.
* @param host host handler
* @param enable true is enable, false is disable.
* @param nibblePos nibble position indictation. 0- the sequence is 'odd high nibble -> even high nibble ->
* odd low nibble -> even low nibble'; 1- the sequence is 'odd high nibble -> odd low nibble -> even high
* nibble -> even low nibble'.
*/
static inline void SDMMCHOST_EnableDDRMode(sdmmchost_t *host, bool enable, uint32_t nibblePos)
{
/* host not support */
}
/*!
* @brief enable HS400 mode.
* @param host host handler
* @param enable true is enable, false is disable.
*/
static inline void SDMMCHOST_EnableHS400Mode(sdmmchost_t *host, bool enable)
{
/* host not support */
}
/*!
* @brief enable STROBE DLL.
* @param host host handler
* @param enable true is enable, false is disable.
*/
static inline void SDMMCHOST_EnableStrobeDll(sdmmchost_t *host, bool enable)
{
/* host not support */
}
/*!
* @brief Get signal line status.
* @param host host handler
* @param signalLine signal line type, reference _sdmmc_signal_line
*/
static inline uint32_t SDMMCHOST_GetSignalLineStatus(sdmmchost_t *host, uint32_t signalLine)
{
/* host not support */
return 0U;
}
/*!
* @brief force card clock on.
* @param host host handler
* @param enable true is enable, false is disable.
*/
static inline void SDMMCHOST_ForceClockOn(sdmmchost_t *host, bool enable)
{
/* host not support */
}
/*!
* @brief sdmmc host convert data sequence to little endian sequence
*
* @param host host handler.
* @param data data buffer address.
* @param wordSize data buffer size in word.
* @param format data packet format.
*/
void SDMMCHOST_ConvertDataToLittleEndian(sdmmchost_t *host, uint32_t *data, uint32_t wordSize, uint32_t format);
/* @} */
#if defined(__cplusplus)
}
#endif
/* @} */
#endif /* _FSL_SDMMC_HOST_H */

View File

@ -1,457 +0,0 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_sdmmc_host.h"
#include "fsl_sdmmc_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define SDMMCHOST_TRANSFER_COMPLETE_TIMEOUT (~0U)
/*******************************************************************************
* Prototypes
******************************************************************************/
/*!
* @brief SDMMCHOST detect card insert status by host controller.
* @param base host base address.
* @param userData user can register a application card insert callback through userData.
*/
static void SDMMCHOST_DetectCardInsertByHost(SDIF_Type *base, void *userData);
/*!
* @brief SDMMCHOST detect card remove status by host controller.
* @param base host base address.
* @param userData user can register a application card insert callback through userData.
*/
static void SDMMCHOST_DetectCardRemoveByHost(SDIF_Type *base, void *userData);
/*!
* @brief SDMMCHOST transfer complete callback.
* @param base host base address.
* @param handle host handle.
* @param status interrupt status.
* @param userData user data.
*/
static void SDMMCHOST_TransferCompleteCallback(SDIF_Type *base, void *handle, status_t status, void *userData);
/*!
* @brief SDMMCHOST error recovery.
* @param base host base address.
*/
static void SDMMCHOST_ErrorRecovery(SDIF_Type *base);
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
static void SDMMCHOST_DetectCardInsertByHost(SDIF_Type *base, void *userData)
{
sd_detect_card_t *cd = NULL;
(void)SDMMC_OSAEventSet(&(((sdmmchost_t *)userData)->hostEvent), SDMMC_OSA_EVENT_CARD_INSERTED);
(void)SDMMC_OSAEventClear(&(((sdmmchost_t *)userData)->hostEvent), SDMMC_OSA_EVENT_CARD_REMOVED);
if (userData != NULL)
{
cd = (sd_detect_card_t *)(((sdmmchost_t *)userData)->cd);
if (cd != NULL)
{
if (cd->callback != NULL)
{
cd->callback(true, cd->userData);
}
}
}
}
static void SDMMCHOST_DetectCardRemoveByHost(SDIF_Type *base, void *userData)
{
sd_detect_card_t *cd = NULL;
(void)SDMMC_OSAEventSet(&(((sdmmchost_t *)userData)->hostEvent), SDMMC_OSA_EVENT_CARD_REMOVED);
(void)SDMMC_OSAEventClear(&(((sdmmchost_t *)userData)->hostEvent), SDMMC_OSA_EVENT_CARD_INSERTED);
if (userData != NULL)
{
cd = (sd_detect_card_t *)(((sdmmchost_t *)userData)->cd);
if (cd != NULL)
{
if (cd->callback != NULL)
{
cd->callback(false, cd->userData);
}
}
}
}
static void SDMMCHOST_CardInterrupt(SDIF_Type *base, void *userData)
{
sdio_card_int_t *cardInt = NULL;
/* application callback */
if (userData != NULL)
{
cardInt = ((sdmmchost_t *)userData)->cardInt;
if ((cardInt != NULL) && (cardInt->cardInterrupt != NULL))
{
cardInt->cardInterrupt(cardInt->userData);
}
}
}
status_t SDMMCHOST_CardIntInit(sdmmchost_t *host, void *sdioInt)
{
host->cardInt = sdioInt;
host->handle.callback.SDIOInterrupt = SDMMCHOST_CardInterrupt;
SDMMCHOST_EnableCardInt(host, true);
return kStatus_Success;
}
status_t SDMMCHOST_CardDetectInit(sdmmchost_t *host, void *cd)
{
SDIF_Type *base = host->hostController.base;
sd_detect_card_t *sdCD = (sd_detect_card_t *)cd;
if (cd == NULL)
{
return kStatus_Fail;
}
host->cd = cd;
/* enable card detect interrupt */
SDIF_EnableInterrupt(base, kSDIF_CardDetect);
if (SDMMCHOST_CardDetectStatus(host) == (uint32_t)kSD_Inserted)
{
(void)SDMMC_OSAEventSet(&(host->hostEvent), SDMMC_OSA_EVENT_CARD_INSERTED);
/* notify application about the card insertion status */
if (sdCD->callback != NULL)
{
sdCD->callback(true, sdCD->userData);
}
}
else
{
(void)SDMMC_OSAEventSet(&(host->hostEvent), SDMMC_OSA_EVENT_CARD_REMOVED);
}
return kStatus_Success;
}
uint32_t SDMMCHOST_CardDetectStatus(sdmmchost_t *host)
{
SDIF_Type *base = host->hostController.base;
sd_detect_card_t *sdCD = (sd_detect_card_t *)host->cd;
#if defined(FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD) && FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD
if (((host->hostPort == 0U) &&
(SDIF_DetectCardInsert(base, sdCD->type == kSD_DetectCardByHostDATA3 ? true : false) == 1U)) ||
((host->hostPort == 1U) &&
(SDIF_DetectCard1Insert(base, sdCD->type == kSD_DetectCardByHostDATA3 ? true : false) == 1U)))
#else
if ((host->hostPort == 0U) &&
(SDIF_DetectCardInsert(base, sdCD->type == kSD_DetectCardByHostDATA3 ? true : false) == 1U))
#endif
{
return kSD_Inserted;
}
return kSD_Removed;
}
status_t SDMMCHOST_PollingCardDetectStatus(sdmmchost_t *host, uint32_t waitCardStatus, uint32_t timeout)
{
assert(host != NULL);
assert(host->cd != NULL);
sd_detect_card_t *cd = host->cd;
uint32_t event = 0U;
(void)SDMMC_OSAEventGet(&(host->hostEvent), SDMMC_OSA_EVENT_CARD_INSERTED | SDMMC_OSA_EVENT_CARD_REMOVED, &event);
if ((((event & SDMMC_OSA_EVENT_CARD_INSERTED) == SDMMC_OSA_EVENT_CARD_INSERTED) &&
(waitCardStatus == (uint32_t)kSD_Inserted)) ||
(((event & SDMMC_OSA_EVENT_CARD_REMOVED) == SDMMC_OSA_EVENT_CARD_REMOVED) &&
(waitCardStatus == (uint32_t)kSD_Removed)))
{
return kStatus_Success;
}
/* Wait card inserted. */
do
{
if (SDMMC_OSAEventWait(&(host->hostEvent), SDMMC_OSA_EVENT_CARD_INSERTED | SDMMC_OSA_EVENT_CARD_REMOVED,
timeout, &event) != kStatus_Success)
{
return kStatus_Fail;
}
else
{
if ((waitCardStatus == (uint32_t)kSD_Inserted) &&
((event & SDMMC_OSA_EVENT_CARD_INSERTED) == SDMMC_OSA_EVENT_CARD_INSERTED))
{
SDMMC_OSADelay(cd->cdDebounce_ms);
if (SDMMCHOST_CardDetectStatus(host) == (uint32_t)kSD_Inserted)
{
break;
}
}
if (((event & SDMMC_OSA_EVENT_CARD_REMOVED) == SDMMC_OSA_EVENT_CARD_REMOVED) &&
(waitCardStatus == (uint32_t)kSD_Removed))
{
break;
}
}
} while (true);
return kStatus_Success;
}
static void SDMMCHOST_TransferCompleteCallback(SDIF_Type *base, void *handle, status_t status, void *userData)
{
uint32_t eventStatus = 0U;
if (status == kStatus_SDIF_DataTransferFail)
{
eventStatus = SDMMC_OSA_EVENT_TRANSFER_DATA_FAIL;
}
else if (status == kStatus_SDIF_DataTransferSuccess)
{
eventStatus = SDMMC_OSA_EVENT_TRANSFER_DATA_SUCCESS;
}
else if (status == kStatus_SDIF_SendCmdFail)
{
eventStatus = SDMMC_OSA_EVENT_TRANSFER_CMD_FAIL;
}
else
{
eventStatus = SDMMC_OSA_EVENT_TRANSFER_CMD_SUCCESS;
}
(void)SDMMC_OSAEventSet(&(((sdmmchost_t *)userData)->hostEvent), eventStatus);
}
status_t SDMMCHOST_TransferFunction(sdmmchost_t *host, sdmmchost_transfer_t *content)
{
status_t error = kStatus_Success;
uint32_t event = 0U;
sdif_dma_config_t dmaConfig;
SDMMC_OSAMutexLock(&host->lock, osaWaitForever_c);
/* clear redundant transfer event flag */
(void)SDMMC_OSAEventClear(&(host->hostEvent),
SDMMC_OSA_EVENT_TRANSFER_CMD_SUCCESS | SDMMC_OSA_EVENT_TRANSFER_CMD_FAIL |
SDMMC_OSA_EVENT_TRANSFER_DATA_SUCCESS | SDMMC_OSA_EVENT_TRANSFER_DATA_FAIL);
/* user DMA mode transfer data */
if (content->data != NULL)
{
(void)memset(&dmaConfig, 0, sizeof(dmaConfig));
dmaConfig.enableFixBurstLen = false;
dmaConfig.mode = kSDIF_DualDMAMode;
dmaConfig.dmaDesBufferStartAddr = host->dmaDesBuffer;
dmaConfig.dmaDesBufferLen = host->dmaDesBufferWordsNum;
dmaConfig.dmaDesSkipLen = 0U;
}
do
{
error = SDIF_TransferNonBlocking(host->hostController.base, &host->handle, &dmaConfig, content);
} while (error == kStatus_SDIF_SyncCmdTimeout);
if (error == kStatus_Success)
{
/* wait command event */
if ((kStatus_Fail ==
SDMMC_OSAEventWait(&(host->hostEvent),
SDMMC_OSA_EVENT_TRANSFER_CMD_SUCCESS | SDMMC_OSA_EVENT_TRANSFER_CMD_FAIL |
SDMMC_OSA_EVENT_TRANSFER_DATA_SUCCESS | SDMMC_OSA_EVENT_TRANSFER_DATA_FAIL,
SDMMCHOST_TRANSFER_COMPLETE_TIMEOUT, &event)) ||
((event & SDMMC_OSA_EVENT_TRANSFER_CMD_FAIL) != 0U))
{
error = kStatus_Fail;
}
else
{
if (content->data != NULL)
{
if ((event & SDMMC_OSA_EVENT_TRANSFER_DATA_SUCCESS) == 0U)
{
if (((event & SDMMC_OSA_EVENT_TRANSFER_DATA_FAIL) != 0U) ||
(kStatus_Fail == SDMMC_OSAEventWait(
&(host->hostEvent),
SDMMC_OSA_EVENT_TRANSFER_DATA_SUCCESS | SDMMC_OSA_EVENT_TRANSFER_DATA_FAIL,
SDMMCHOST_TRANSFER_COMPLETE_TIMEOUT, &event) ||
((event & SDMMC_OSA_EVENT_TRANSFER_DATA_FAIL) != 0U)))
{
error = kStatus_Fail;
}
}
}
}
}
/*
* error = kStatus_SDIF_DescriptorBufferLenError means that the DMA descriptor buffer not len enough for current
* transfer, application should assign a bigger descriptor memory space.
*/
if (error != kStatus_Success)
{
error = kStatus_Fail;
/* host error recovery */
SDMMCHOST_ErrorRecovery(host->hostController.base);
}
SDMMC_OSAMutexUnlock(&host->lock);
return error;
}
static void SDMMCHOST_ErrorRecovery(SDIF_Type *base)
{
(void)SDIF_Reset(base, kSDIF_ResetAll, SDMMCHOST_RESET_TIMEOUT_VALUE);
/* the host controller clock will be disabled by the reset operation, so re-send the clock sync command to enable
the output clock */
sdif_command_t clockSync = {
.flags = kSDIF_WaitPreTransferComplete | kSDIF_CmdUpdateClockRegisterOnly, .index = 0U, .argument = 0U};
(void)SDIF_SendCommand(base, &clockSync, 0U);
}
void SDMMCHOST_SetCardPower(sdmmchost_t *host, bool enable)
{
if (host->hostPort == 0U)
{
SDIF_EnableCardPower(host->hostController.base, enable);
}
#if defined(FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD) && FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD
else
{
SDIF_EnableCard1Power(host->hostController.base, enable);
}
#endif
if (enable)
{
/* perform SDIF host controller reset only when DATA BUSY is assert */
if ((SDIF_GetControllerStatus(host->hostController.base) & SDIF_STATUS_DATA_BUSY_MASK) != 0U)
{
(void)SDIF_Reset(host->hostController.base, kSDIF_ResetAll, SDMMCHOST_RESET_TIMEOUT_VALUE);
}
}
}
void SDMMCHOST_ConvertDataToLittleEndian(sdmmchost_t *host, uint32_t *data, uint32_t wordSize, uint32_t format)
{
uint32_t temp = 0U;
if (format == kSDMMC_DataPacketFormatMSBFirst)
{
for (uint32_t i = 0U; i < wordSize; i++)
{
temp = data[i];
data[i] = SWAP_WORD_BYTE_SEQUENCE(temp);
}
}
}
status_t SDMMCHOST_Init(sdmmchost_t *host)
{
assert(host != NULL);
sdif_transfer_callback_t sdifCallback = {0};
sdif_host_t *sdifHost = &(host->hostController);
status_t error = kStatus_Success;
/* host capability flags */
host->capability = (uint32_t)kSDMMCHOST_SupportHighSpeed | (uint32_t)kSDMMCHOST_SupportSuspendResume |
(uint32_t)kSDMMCHOST_SupportVoltage3v3 | (uint32_t)kSDMMCHOST_Support4BitDataWidth |
(uint32_t)kSDMMCHOST_Support8BitDataWidth | (uint32_t)kSDMMCHOST_SupportDetectCardByData3 |
(uint32_t)kSDMMCHOST_SupportDetectCardByCD | (uint32_t)kSDMMCHOST_SupportAutoCmd12;
host->maxBlockCount = SDMMCHOST_SUPPORT_MAX_BLOCK_COUNT;
host->maxBlockSize = SDMMCHOST_SUPPORT_MAX_BLOCK_LENGTH;
/* sdmmc osa init */
SDMMC_OSAInit();
SDMMC_OSAMutexCreate(&host->lock);
SDMMC_OSAMutexLock(&host->lock, osaWaitForever_c);
/* Initialize SDIF. */
sdifHost->config.responseTimeout = 0xFFU;
sdifHost->config.cardDetDebounce_Clock = 0xFFFFFFU;
sdifHost->config.dataTimeout = 0xFFFFFFU;
SDIF_Init(sdifHost->base, &(sdifHost->config));
/* Create handle for SDIF driver */
sdifCallback.TransferComplete = SDMMCHOST_TransferCompleteCallback;
sdifCallback.cardInserted = SDMMCHOST_DetectCardInsertByHost;
sdifCallback.cardRemoved = SDMMCHOST_DetectCardRemoveByHost;
SDIF_TransferCreateHandle(sdifHost->base, &host->handle, &sdifCallback, host);
/* Create transfer event. */
if (kStatus_Success != SDMMC_OSAEventCreate(&(host->hostEvent)))
{
error = kStatus_Fail;
}
SDMMC_OSAMutexUnlock(&host->lock);
return error;
}
void SDMMCHOST_Reset(sdmmchost_t *host)
{
SDMMC_OSAMutexLock(&host->lock, osaWaitForever_c);
/* disable all the interrupt */
SDIF_DisableInterrupt(host->hostController.base, kSDIF_AllInterruptStatus);
/* make sure host controller release all the bus line. */
(void)SDIF_Reset(host->hostController.base, kSDIF_ResetAll, SDMMCHOST_RESET_TIMEOUT_VALUE);
/* clear all interrupt/DMA status */
SDIF_ClearInterruptStatus(host->hostController.base, kSDIF_AllInterruptStatus);
SDIF_ClearInternalDMAStatus(host->hostController.base, kSDIF_DMAAllStatus);
SDMMC_OSAMutexUnlock(&host->lock);
}
void SDMMCHOST_SetCardBusWidth(sdmmchost_t *host, uint32_t dataBusWidth)
{
if (host->hostPort == 0U)
{
SDIF_SetCardBusWidth(host->hostController.base, dataBusWidth == (uint32_t)kSDMMC_BusWdith1Bit ?
kSDIF_Bus1BitWidth :
dataBusWidth == (uint32_t)kSDMMC_BusWdith4Bit ?
kSDIF_Bus4BitWidth :
kSDIF_Bus8BitWidth);
}
#if defined(FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD) && FSL_FEATURE_SDIF_ONE_INSTANCE_SUPPORT_TWO_CARD
else
{
SDIF_SetCard1BusWidth(host->hostController.base, dataBusWidth == (uint32_t)kSDMMC_BusWdith1Bit ?
kSDIF_Bus1BitWidth :
dataBusWidth == (uint32_t)kSDMMC_BusWdith4Bit ?
kSDIF_Bus4BitWidth :
kSDIF_Bus8BitWidth);
}
#endif
}
void SDMMCHOST_Deinit(sdmmchost_t *host)
{
SDMMC_OSAMutexLock(&host->lock, osaWaitForever_c);
sdif_host_t *sdifHost = &host->hostController;
SDIF_Deinit(sdifHost->base);
(void)SDMMC_OSAEventDestroy(&(host->hostEvent));
SDMMC_OSAMutexDestroy(&host->lock);
}

View File

@ -1,113 +0,0 @@
/*!
@page middleware_log Middleware Change Log
@section mmc MMC Card driver for MCUXpresso SDK
The current driver version is 2.5.0.
- 2.5.0
- Improvements
- Added api MMC_SetSleepAwake to support enter/exit sleep state.
- Added new api MMC_PollingCardStatusBusy for application polling card status.
- Removed deprecated api in mmc driver and mark MMC_HostReset as deprecated.
- Improved the read/write/erase function flow.
- Added mutual exclusive access for init/deinit/read/write/erase function.
- Fixed violations of MISRA C-2012 rule 4.7, 17.7, 10.7, 10.4, 13.5, 14.4, 10.6.
- 2.4.1
- Improvements
- Improved the voltage window argument of CMD1 according to host capabilty instead of use card ocr directly.
- Added host HS200/HS400/8bit bus width capability validation during card initialization.
- Used cache line size align buffer for MMC relate api.
- Increased the CMD13 timeout count to avoid polling CMD13 time out issue.
- Bug Fixes
- Fixed violations of MISRA C-2012 rule 11.9, 15.7, 4.7, 16.4, 10.1, 10.3, 10.4, 11.3, 14.4, 10.6, 17.7, 16.1, 16.3.
- 2.4.0
- Improvements
- Added new apis MMC_EnableCacheControl/MMC_FlushCache to support cache feature.
- 2.3.1
- Improvements
- Removed the dead loop while polling DAT0 and CMD13 instead of using timeout mechanism.
- Added card state check before switching to HS400 to improve the emmc initialization stability.
- Removed the redundant operation of memset internal buffer in MMC_WrtiteBlocks function.
- Bug Fixes
- Fixed the sandisk emmc always busy while sending CMD1 without supported voltage provide in argument.
- 2.3.0
- Improvements
- Deprecated api MMC_PowerOnCard/MMC_PowerOffCard by api MMC_SetCardPower.
- Added internalBuffer in mmc_card_t and removed rawCid/rawCsd/rawExtendedCsd.
- Added retuning support during data transfer under HS200 mode.
- Increased the read/write blocks failed retry times for stability.
- Added delay while retry the CMD1 for stability.
- Added legacy card support, the card not support CMD6, CMD8.
- 2.2.13
- Improvements
- Used the boot mode value instead of boot mode mask value as the parameter of MMC_SetBootConfig to improve user experience.
- Removed dynamic voltage switch feature for mmc, according to JEDEC standard, the voltage should be fixed after power up.
- 2.2.12
- Improvement
- Increased the CMD1 retry times in the MMC card driver to improve driver compatibility.
- Bug Fixes
- Fixed the build warning by changing the old style function declaration static
status_t inline to static inline status_t(found by adding -Wold-style-declaration in armgcc build flag).
- Fixed the fall through build warning by adding SUPPRESS_FALL_THROUGH_WARNING() in mmc driver.
- 2.2.7
- Bug Fixes
- Fixed MDK 66-D warning.
- 2.2.6
- Improvements
- Saved MMC OCR registers while sending CMD1 with argument 0.
- Bug Fixes
- Added MMC_PowerOn function in which there is delay function after powerup sdcard. Otherwise, the
card initialization by fail.
- 2.2.5
- Improvements
- Added SDMMC_ENABLE_SOFTWARE_TUNING to enable/disable software tuning and it is disabled by default.
- 2.2.4
- Bug Fixes
- Fixed DDR mode data sequence miss issue, which is caused by NIBBLE_POS.
- Improvements
- Increased g_sdmmc 512byte to improve the performance when application use a non-word align data buffer address.
- Used OCR access mode bits to determine the mmccard high capacity flag.
- 2.2.3
- Bug Fixes
- Added response check for send operation condition command. If not checked, the card may occasionally init fail.
- 2.2.1
- Improvements
- Improved MMC Boot feature.
- 2.2.0
- Improvements
- Optimized tuning/mmc switch voltage/mmc select power class/mmc select timing function.
- Added strobe dll for mmc HS400 mode.
- Added write complete wait operation for MMC_Write to fix command timeout issue.
- 2.1.2
- Improvements
- Improved SDMMC to support eMMC v5.0.
- Bug Fixes
- Fixed incorrect comparison between count and length in MMC_ReadBlocks/MMC_WriteBlocks.
- 2.1.1
- Bug Fixes
- Fixed the block range boundary error when transferring data to MMC card.
- 2.1.0
- Improvements
- Optimized the function of setting maximum data bus width for MMC card.
- 2.0.0
- Initial version
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,445 +0,0 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_MMC_H_
#define _FSL_MMC_H_
#include "fsl_sdmmc_common.h"
/*!
* @addtogroup mmccard MMC Card Driver
* @ingroup card
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief Middleware mmc version. */
#define FSL_MMC_DRIVER_VERSION (MAKE_VERSION(2U, 5U, 0U)) /*2.5.0*/
/*! @brief MMC card flags
* @anchor _mmc_card_flag
*/
enum
{
kMMC_SupportHighSpeed26MHZFlag = (1U << 0U), /*!< Support high speed 26MHZ */
kMMC_SupportHighSpeed52MHZFlag = (1U << 1U), /*!< Support high speed 52MHZ */
kMMC_SupportHighSpeedDDR52MHZ180V300VFlag = (1 << 2U), /*!< ddr 52MHZ 1.8V or 3.0V */
kMMC_SupportHighSpeedDDR52MHZ120VFlag = (1 << 3U), /*!< DDR 52MHZ 1.2V */
kMMC_SupportHS200200MHZ180VFlag = (1 << 4U), /*!< HS200 ,200MHZ,1.8V */
kMMC_SupportHS200200MHZ120VFlag = (1 << 5U), /*!< HS200, 200MHZ, 1.2V */
kMMC_SupportHS400DDR200MHZ180VFlag = (1 << 6U), /*!< HS400, DDR, 200MHZ,1.8V */
kMMC_SupportHS400DDR200MHZ120VFlag = (1 << 7U), /*!< HS400, DDR, 200MHZ,1.2V */
kMMC_SupportHighCapacityFlag = (1U << 8U), /*!< Support high capacity */
kMMC_SupportAlternateBootFlag = (1U << 9U), /*!< Support alternate boot */
kMMC_SupportDDRBootFlag = (1U << 10U), /*!< support DDR boot flag*/
kMMC_SupportHighSpeedBootFlag = (1U << 11U), /*!< support high speed boot flag */
kMMC_SupportEnhanceHS400StrobeFlag = (1U << 12U), /*!< support enhance HS400 strobe */
};
/*! @brief mmccard sleep/awake state */
typedef enum _mmc_sleep_awake
{
kMMC_Sleep = 1U, /*!< MMC card sleep */
kMMC_Awake = 0U, /*!< MMC card awake */
} mmc_sleep_awake_t;
/*! @brief card io strength control */
typedef void (*mmc_io_strength_t)(uint32_t busFreq);
/*! @brief card user parameter */
typedef struct _mmc_usr_param
{
mmc_io_strength_t ioStrength; /*!< switch sd io strength */
uint32_t maxFreq; /*!< board support maximum frequency */
uint32_t capability; /*!< board capability flag */
} mmc_usr_param_t;
/*!
* @brief mmc card state
*
* Defines the card structure including the necessary fields to identify and describe the card.
*/
typedef struct _mmc_card
{
sdmmchost_t *host; /*!< Host information */
mmc_usr_param_t usrParam; /*!< user parameter */
bool isHostReady; /*!< Use this flag to indicate if host re-init needed or not*/
bool noInteralAlign; /*!< Use this flag to disable sdmmc align. If disabled, sdmmc will not make sure the
data buffer address is word align, otherwise all the transfer are aligned to low level driver. */
uint32_t busClock_Hz; /*!< MMC bus clock united in Hz */
uint32_t relativeAddress; /*!< Relative address of the card */
bool enablePreDefinedBlockCount; /*!< Enable PRE-DEFINED block count when read/write */
uint32_t flags; /*!< Capability flag in @ref _mmc_card_flag */
uint8_t internalBuffer[FSL_SDMMC_CARD_INTERNAL_BUFFER_SIZE]; /*!< raw buffer used for mmc driver internal */
uint32_t ocr; /*!< Raw OCR content */
mmc_cid_t cid; /*!< CID */
mmc_csd_t csd; /*!< CSD */
mmc_extended_csd_t extendedCsd; /*!< Extended CSD */
uint32_t blockSize; /*!< Card block size */
uint32_t userPartitionBlocks; /*!< Card total block number in user partition */
uint32_t bootPartitionBlocks; /*!< Boot partition size united as block size */
uint32_t eraseGroupBlocks; /*!< Erase group size united as block size */
mmc_access_partition_t currentPartition; /*!< Current access partition */
mmc_voltage_window_t hostVoltageWindowVCCQ; /*!< application must set this value according to board specific */
mmc_voltage_window_t hostVoltageWindowVCC; /*!< application must set this value according to board specific */
mmc_high_speed_timing_t busTiming; /*!< indicates the current work timing mode*/
mmc_data_bus_width_t busWidth; /*!< indicates the current work bus width */
sdmmc_osa_mutex_t lock; /*!< card access lock */
} mmc_card_t;
/*************************************************************************************************
* API
************************************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name MMCCARD Function
* @{
*/
/*!
* @brief Initializes the MMC card and host.
*
* @param card Card descriptor.
*
* Thread safe function, please note that the function will create the mutex lock dynamically by default,
* so to avoid the mutex to be created redundantly, application must follow bellow sequence for card re-initialization:
* @code
MMC_Deinit(card);
MMC_Init(card);
* @endcode
*
* @retval #kStatus_SDMMC_HostNotReady Host is not ready.
* @retval #kStatus_SDMMC_GoIdleFailed Going idle failed.
* @retval #kStatus_SDMMC_HandShakeOperationConditionFailed Sending operation condition failed.
* @retval #kStatus_SDMMC_AllSendCidFailed Sending CID failed.
* @retval #kStatus_SDMMC_SetRelativeAddressFailed Setging relative address failed.
* @retval #kStatus_SDMMC_SendCsdFailed Sending CSD failed.
* @retval #kStatus_SDMMC_CardNotSupport Card not support.
* @retval #kStatus_SDMMC_SelectCardFailed Sending SELECT_CARD command failed.
* @retval #kStatus_SDMMC_SendExtendedCsdFailed Sending EXT_CSD failed.
* @retval #kStatus_SDMMC_SetDataBusWidthFailed Setting bus width failed.
* @retval #kStatus_SDMMC_SwitchBusTimingFailed Switching high speed failed.
* @retval #kStatus_SDMMC_SetCardBlockSizeFailed Setting card block size failed.
* @retval #kStatus_SDMMC_SetPowerClassFail Setting card power class failed.
* @retval #kStatus_Success Operation succeeded.
*/
status_t MMC_Init(mmc_card_t *card);
/*!
* @brief Deinitializes the card and host.
*
* @note It is a thread safe function.
*
* @param card Card descriptor.
*/
void MMC_Deinit(mmc_card_t *card);
/*!
* @brief Initializes the card.
*
* Thread safe function, please note that the function will create the mutex lock dynamically by default,
* so to avoid the mutex to be created redundantly, application must follow bellow sequence for card re-initialization:
* @code
MMC_CardDeinit(card);
MMC_CardInit(card);
* @endcode
*
* @param card Card descriptor.
*
* @retval #kStatus_SDMMC_HostNotReady Host is not ready.
* @retval #kStatus_SDMMC_GoIdleFailed Going idle failed.
* @retval #kStatus_SDMMC_HandShakeOperationConditionFailed Sending operation condition failed.
* @retval #kStatus_SDMMC_AllSendCidFailed Sending CID failed.
* @retval #kStatus_SDMMC_SetRelativeAddressFailed Setting relative address failed.
* @retval #kStatus_SDMMC_SendCsdFailed Sending CSD failed.
* @retval #kStatus_SDMMC_CardNotSupport Card not support.
* @retval #kStatus_SDMMC_SelectCardFailed Sending SELECT_CARD command failed.
* @retval #kStatus_SDMMC_SendExtendedCsdFailed Sending EXT_CSD failed.
* @retval #kStatus_SDMMC_SetDataBusWidthFailed Setting bus width failed.
* @retval #kStatus_SDMMC_SwitchBusTimingFailed Switching high speed failed.
* @retval #kStatus_SDMMC_SetCardBlockSizeFailed Setting card block size failed.
* @retval #kStatus_SDMMC_SetPowerClassFail Setting card power class failed.
* @retval #kStatus_Success Operation succeeded.
*/
status_t MMC_CardInit(mmc_card_t *card);
/*!
* @brief Deinitializes the card.
*
* @note It is a thread safe function.
*
* @param card Card descriptor.
*/
void MMC_CardDeinit(mmc_card_t *card);
/*!
* @brief initialize the host.
*
* This function deinitializes the specific host.
*
* @param card Card descriptor.
*/
status_t MMC_HostInit(mmc_card_t *card);
/*!
* @brief Deinitializes the host.
*
* This function deinitializes the host.
*
* @param card Card descriptor.
*/
void MMC_HostDeinit(mmc_card_t *card);
/*!
* @brief Resets the host.
*
* This function resets the specific host.
*
* @param card Card descriptor.
*/
void MMC_HostDoReset(mmc_card_t *card);
/*!
* @brief Resets the host.
*
* @deprecated Do not use this function. It has been superceded by @ref MMC_HostDoReset.
* This function resets the specific host.
*
* @param host Host descriptor.
*/
void MMC_HostReset(SDMMCHOST_CONFIG *host);
/*!
* @brief Sets card power.
*
* @param card Card descriptor.
* @param enable True is powering on, false is powering off.
*/
void MMC_SetCardPower(mmc_card_t *card, bool enable);
/*!
* @brief Checks if the card is read-only.
*
* @param card Card descriptor.
* @retval true Card is read only.
* @retval false Card isn't read only.
*/
bool MMC_CheckReadOnly(mmc_card_t *card);
/*!
* @brief Reads data blocks from the card.
*
* @note It is a thread safe function.
*
* @param card Card descriptor.
* @param buffer The buffer to save data.
* @param startBlock The start block index.
* @param blockCount The number of blocks to read.
* @retval #kStatus_InvalidArgument Invalid argument.
* @retval #kStatus_SDMMC_CardNotSupport Card not support.
* @retval #kStatus_SDMMC_SetBlockCountFailed Setting block count failed.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_SDMMC_StopTransmissionFailed Stopping transmission failed.
* @retval #kStatus_Success Operation succeeded.
*/
status_t MMC_ReadBlocks(mmc_card_t *card, uint8_t *buffer, uint32_t startBlock, uint32_t blockCount);
/*!
* @brief Writes data blocks to the card.
*
* @note
* 1. It is a thread safe function.
* 2. It is an async write function which means that the card status may still be busy after the function returns.
* Application can call function MMC_PollingCardStatusBusy to wait for the card status to be idle after the write
* operation.
*
* @param card Card descriptor.
* @param buffer The buffer to save data blocks.
* @param startBlock Start block number to write.
* @param blockCount Block count.
* @retval #kStatus_InvalidArgument Invalid argument.
* @retval #kStatus_SDMMC_NotSupportYet Not support now.
* @retval #kStatus_SDMMC_SetBlockCountFailed Setting block count failed.
* @retval #kStatus_SDMMC_WaitWriteCompleteFailed Sending status failed.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_SDMMC_StopTransmissionFailed Stop transmission failed.
* @retval #kStatus_Success Operation succeeded.
*/
status_t MMC_WriteBlocks(mmc_card_t *card, const uint8_t *buffer, uint32_t startBlock, uint32_t blockCount);
/*!
* @brief Erases groups of the card.
*
* The erase command is best used to erase the entire device or a partition.
* Erase group is the smallest erase unit in MMC card. The erase range is [startGroup, endGroup].
*
* @note
* 1. It is a thread safe function.
* 2. This function always polls card busy status according to the timeout value defined in the card register after
* all the erase command sent out.
*
* @param card Card descriptor.
* @param startGroup Start group number.
* @param endGroup End group number.
* @retval #kStatus_InvalidArgument Invalid argument.
* @retval #kStatus_SDMMC_WaitWriteCompleteFailed Send status failed.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_Success Operation succeeded.
*/
status_t MMC_EraseGroups(mmc_card_t *card, uint32_t startGroup, uint32_t endGroup);
/*!
* @brief Selects the partition to access.
*
* @note It is a thread safe function.
*
* @param card Card descriptor.
* @param partitionNumber The partition number.
* @retval #kStatus_SDMMC_ConfigureExtendedCsdFailed Configuring EXT_CSD failed.
* @retval #kStatus_Success Operation succeeded.
*/
status_t MMC_SelectPartition(mmc_card_t *card, mmc_access_partition_t partitionNumber);
/*!
* @brief Configures the boot activity of the card.
*
* @param card Card descriptor.
* @param config Boot configuration structure.
* @retval #kStatus_SDMMC_NotSupportYet Not support now.
* @retval #kStatus_SDMMC_ConfigureExtendedCsdFailed Configuring EXT_CSD failed.
* @retval #kStatus_SDMMC_ConfigureBootFailed Configuring boot failed.
* @retval #kStatus_Success Operation succeeded.
*/
status_t MMC_SetBootConfig(mmc_card_t *card, const mmc_boot_config_t *config);
/*!
* @brief MMC card start boot.
*
* @param card Card descriptor.
* @param mmcConfig The mmc Boot configuration structure.
* @param buffer Address to receive data.
* @param hostConfig Host boot configurations.
* @retval #kStatus_Fail Failed.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_SDMMC_GoIdleFailed Resetting card failed.
* @retval #kStatus_Success Operation succeeded.
*/
status_t MMC_StartBoot(mmc_card_t *card,
const mmc_boot_config_t *mmcConfig,
uint8_t *buffer,
sdmmchost_boot_config_t *hostConfig);
/*!
* @brief MMC card set boot configuration write protect.
*
* @param card Card descriptor.
* @param wp Write protect value.
*/
status_t MMC_SetBootConfigWP(mmc_card_t *card, uint8_t wp);
/*!
* @brief MMC card continuous read boot data.
*
* @param card Card descriptor.
* @param buffer Buffer address.
* @param hostConfig Host boot configurations.
*/
status_t MMC_ReadBootData(mmc_card_t *card, uint8_t *buffer, sdmmchost_boot_config_t *hostConfig);
/*!
* @brief MMC card stop boot mode.
*
* @param card Card descriptor.
* @param bootMode Boot mode.
*/
status_t MMC_StopBoot(mmc_card_t *card, uint32_t bootMode);
/*!
* @brief MMC card set boot partition write protect.
*
* @param card Card descriptor.
* @param bootPartitionWP Boot partition write protect value.
*/
status_t MMC_SetBootPartitionWP(mmc_card_t *card, mmc_boot_partition_wp_t bootPartitionWP);
/*!
* @brief MMC card cache control function.
*
* The mmc device's cache is enabled by the driver by default.
* The cache should in typical case reduce the access time (compared to an access to the main nonvolatile storage) for
* both write and read.
*
* @param card Card descriptor.
* @param enable True is enabling the cache, false is disabling the cache.
*/
status_t MMC_EnableCacheControl(mmc_card_t *card, bool enable);
/*!
* @brief MMC card cache flush function.
*
* A Flush operation refers to the requirement, from the host to the device, to write the cached data to the nonvolatile
* memory. Prior to a flush, the device may autonomously write data to the nonvolatile memory, but after the flush
* operation all data in the volatile area must be written to nonvolatile memory. There is no requirement for flush due
* to switching between the partitions. (Note: This also implies that the cache data shall not be lost when switching
* between partitions). Cached data may be lost in SLEEP state, so host should flush the cache before placing the device
* into SLEEP state.
*
* @param card Card descriptor.
*/
status_t MMC_FlushCache(mmc_card_t *card);
/*!
* @brief MMC sets card sleep awake state.
*
* The Sleep/Awake command is used to initiate the state transition between Standby state and Sleep state.
* The memory device indicates the transition phase busy by pulling down the DAT0 line.
* The Sleep/Standby state is reached when the memory device stops pulling down the DAT0 line, then the function
* returns.
*
* @param card Card descriptor.
* @param state The sleep/awake command argument, refer to @ref mmc_sleep_awake_t.
*
* @retval kStatus_SDMMC_NotSupportYet Indicates the memory device doesn't support the Sleep/Awake command.
* @retval kStatus_SDMMC_TransferFailed Indicates command transferred fail.
* @retval kStatus_SDMMC_PollingCardIdleFailed Indicates polling DAT0 busy timeout.
* @retval kStatus_SDMMC_DeselectCardFailed Indicates deselect card command failed.
* @retval kStatus_SDMMC_SelectCardFailed Indicates select card command failed.
* @retval kStatus_Success Indicates the card state switched successfully.
*/
status_t MMC_SetSleepAwake(mmc_card_t *card, mmc_sleep_awake_t state);
/*!
* @brief Polling card idle status.
*
* This function can be used to poll the status from busy to idle, the function will return with the card
* status being idle or timeout or command failed.
*
* @param card Card descriptor.
* @param checkStatus True is send CMD and read DAT0 status to check card status, false is read DAT0 status only.
* @param timeoutMs Polling card status timeout value.
*
* @retval kStatus_SDMMC_CardStatusIdle Card is idle.
* @retval kStatus_SDMMC_CardStatusBusy Card is busy.
* @retval kStatus_SDMMC_TransferFailed Command tranfer failed.
* @retval kStatus_SDMMC_SwitchFailed Status command reports switch error.
*/
status_t MMC_PollingCardStatusBusy(mmc_card_t *card, bool checkStatus, uint32_t timeoutMs);
/* @} */
#if defined(__cplusplus)
}
#endif
/*! @} */
#endif /* _FSL_MMC_H_*/

View File

@ -1,275 +0,0 @@
/*
* Copyright 2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_sdmmc_osa.h"
/*******************************************************************************
* Definitons
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
/*!
* brief Initialize OSA.
*/
void SDMMC_OSAInit(void)
{
/* Intentional empty */
}
/*!
* brief OSA Create event.
* param event handle.
* retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventCreate(void *eventHandle)
{
assert(eventHandle != NULL);
#if defined(SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE) && SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
(void)OSA_SemaphoreCreate(&(((sdmmc_osa_event_t *)eventHandle)->handle), 0U);
#else
(void)OSA_EventCreate(&(((sdmmc_osa_event_t *)eventHandle)->handle), true);
#endif
return kStatus_Success;
}
/*!
* brief Wait event.
*
* param eventHandle The event type
* param eventType Timeout time in milliseconds.
* param timeoutMilliseconds timeout value in ms.
* param event event flags.
* retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventWait(void *eventHandle, uint32_t eventType, uint32_t timeoutMilliseconds, uint32_t *event)
{
assert(eventHandle != NULL);
osa_status_t status = KOSA_StatusError;
#if defined(SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE) && SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
while (true)
{
status = OSA_SemaphoreWait(&(((sdmmc_osa_event_t *)eventHandle)->handle), timeoutMilliseconds);
if (KOSA_StatusTimeout == status)
{
break;
}
if (KOSA_StatusSuccess == status)
{
(void)SDMMC_OSAEventGet(eventHandle, eventType, event);
if ((*event & eventType) != 0U)
{
return kStatus_Success;
}
}
}
#else
while (true)
{
status = OSA_EventWait(&(((sdmmc_osa_event_t *)eventHandle)->handle), eventType, 0, timeoutMilliseconds, event);
if ((KOSA_StatusSuccess == status) || (KOSA_StatusTimeout == status))
{
break;
}
}
if (KOSA_StatusSuccess == status)
{
return kStatus_Success;
}
#endif
return kStatus_Fail;
}
/*!
* brief set event.
* param event event handle.
* param eventType The event type
* retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventSet(void *eventHandle, uint32_t eventType)
{
assert(eventHandle != NULL);
#if defined(SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE) && SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
OSA_SR_ALLOC();
OSA_ENTER_CRITICAL();
((sdmmc_osa_event_t *)eventHandle)->eventFlag |= eventType;
OSA_EXIT_CRITICAL();
(void)OSA_SemaphorePost(&(((sdmmc_osa_event_t *)eventHandle)->handle));
#else
(void)OSA_EventSet(&(((sdmmc_osa_event_t *)eventHandle)->handle), eventType);
#endif
return kStatus_Success;
}
/*!
* brief Get event flag.
* param eventHandle event handle.
* param eventType The event type
* param flag pointer to store event value.
* retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventGet(void *eventHandle, uint32_t eventType, uint32_t *flag)
{
assert(eventHandle != NULL);
assert(flag != NULL);
#if defined(SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE) && SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
*flag = ((sdmmc_osa_event_t *)eventHandle)->eventFlag;
#else
(void)OSA_EventGet(&(((sdmmc_osa_event_t *)eventHandle)->handle), eventType, flag);
#endif
return kStatus_Success;
}
/*!
* brief clear event flag.
* param eventHandle event handle.
* param eventType The event type
* retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventClear(void *eventHandle, uint32_t eventType)
{
assert(eventHandle != NULL);
#if defined(SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE) && SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
OSA_SR_ALLOC();
OSA_ENTER_CRITICAL();
((sdmmc_osa_event_t *)eventHandle)->eventFlag &= ~eventType;
OSA_EXIT_CRITICAL();
#else
(void)OSA_EventClear(&(((sdmmc_osa_event_t *)eventHandle)->handle), eventType);
#endif
return kStatus_Success;
}
/*!
* brief Delete event.
* param event The event handle.
*/
status_t SDMMC_OSAEventDestroy(void *eventHandle)
{
assert(eventHandle != NULL);
#if defined(SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE) && SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
(void)OSA_SemaphoreDestroy(&(((sdmmc_osa_event_t *)eventHandle)->handle));
#else
(void)OSA_EventDestroy(&(((sdmmc_osa_event_t *)eventHandle)->handle));
#endif
return kStatus_Success;
}
/*!
* brief Create a mutex.
* param mutexHandle mutex handle.
* retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAMutexCreate(void *mutexHandle)
{
assert(mutexHandle != NULL);
(void)OSA_MutexCreate(&((sdmmc_osa_mutex_t *)mutexHandle)->handle);
return kStatus_Success;
}
/*!
* brief set event.
* param mutexHandle mutex handle.
* param millisec The maximum number of milliseconds to wait for the mutex.
* If the mutex is locked, Pass the value osaWaitForever_c will
* wait indefinitely, pass 0 will return KOSA_StatusTimeout
* immediately.
* retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAMutexLock(void *mutexHandle, uint32_t millisec)
{
assert(mutexHandle != NULL);
(void)OSA_MutexLock(&((sdmmc_osa_mutex_t *)mutexHandle)->handle, millisec);
return kStatus_Success;
}
/*!
* brief Get event flag.
* param mutexHandle mutex handle.
* retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAMutexUnlock(void *mutexHandle)
{
assert(mutexHandle != NULL);
(void)OSA_MutexUnlock(&((sdmmc_osa_mutex_t *)mutexHandle)->handle);
return kStatus_Success;
}
/*!
* brief Delete mutex.
* param mutexHandle The mutex handle.
*/
status_t SDMMC_OSAMutexDestroy(void *mutexHandle)
{
assert(mutexHandle != NULL);
(void)OSA_MutexDestroy(&((sdmmc_osa_mutex_t *)mutexHandle)->handle);
return kStatus_Success;
}
/*!
* brief sdmmc delay.
* param milliseconds time to delay
*/
void SDMMC_OSADelay(uint32_t milliseconds)
{
#if (defined FSL_OSA_BM_TIMER_CONFIG) && (FSL_OSA_BM_TIMER_CONFIG == FSL_OSA_BM_TIMER_NONE)
SDK_DelayAtLeastUs(milliseconds * 1000U, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
#else
OSA_TimeDelay(milliseconds);
#endif
}
/*!
* brief sdmmc delay us.
* param microseconds time to delay
* return actual delayed microseconds
*/
uint32_t SDMMC_OSADelayUs(uint32_t microseconds)
{
#if (defined FSL_OSA_BM_TIMER_CONFIG) && (FSL_OSA_BM_TIMER_CONFIG == FSL_OSA_BM_TIMER_NONE)
SDK_DelayAtLeastUs(microseconds, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
return microseconds;
#else
uint32_t milliseconds = microseconds / 1000U + ((microseconds % 1000U) == 0U ? 0U : 1U);
OSA_TimeDelay(milliseconds);
return milliseconds * 1000U;
#endif
}

View File

@ -1,170 +0,0 @@
/*
* Copyright 2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_SDMMC_OSA_H_
#define _FSL_SDMMC_OSA_H_
#include "fsl_common.h"
#include "fsl_os_abstraction.h"
/*!
* @addtogroup sdmmc_osa SDMMC OSA
* @ingroup card
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*!@brief transfer event */
#define SDMMC_OSA_EVENT_TRANSFER_CMD_SUCCESS (1UL << 0U)
#define SDMMC_OSA_EVENT_TRANSFER_CMD_FAIL (1UL << 1U)
#define SDMMC_OSA_EVENT_TRANSFER_DATA_SUCCESS (1UL << 2U)
#define SDMMC_OSA_EVENT_TRANSFER_DATA_FAIL (1UL << 3U)
#define SDMMC_OSA_EVENT_TRANSFER_DMA_COMPLETE (1UL << 4U)
/*!@brief card detect event, start from index 8 */
#define SDMMC_OSA_EVENT_CARD_INSERTED (1UL << 8U)
#define SDMMC_OSA_EVENT_CARD_REMOVED (1UL << 9U)
/*!@brief enable semphore by default */
#ifndef SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
#define SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE 1
#endif
/*!@brief sdmmc osa event */
typedef struct _sdmmc_osa_event
{
#if defined(SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE) && SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
volatile uint32_t eventFlag;
OSA_SEMAPHORE_HANDLE_DEFINE(handle);
#else
OSA_EVENT_HANDLE_DEFINE(handle);
#endif
} sdmmc_osa_event_t;
/*!@brief sdmmc osa mutex */
typedef struct _sdmmc_osa_mutex
{
OSA_MUTEX_HANDLE_DEFINE(handle);
} sdmmc_osa_mutex_t;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name sdmmc osa Function
* @{
*/
/*!
* @brief Initialize OSA.
*/
void SDMMC_OSAInit(void);
/*!
* @brief OSA Create event.
* @param eventHandle event handle.
* @retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventCreate(void *eventHandle);
/*!
* @brief Wait event.
*
* @param eventHandle The event type
* @param eventType Timeout time in milliseconds.
* @param timeoutMilliseconds timeout value in ms.
* @param event event flags.
* @retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventWait(void *eventHandle, uint32_t eventType, uint32_t timeoutMilliseconds, uint32_t *event);
/*!
* @brief set event.
* @param eventHandle event handle.
* @param eventType The event type
* @retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventSet(void *eventHandle, uint32_t eventType);
/*!
* @brief Get event flag.
* @param eventHandle event handle.
* @param eventType event type.
* @param flag pointer to store event value.
* @retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventGet(void *eventHandle, uint32_t eventType, uint32_t *flag);
/*!
* @brief clear event flag.
* @param eventHandle event handle.
* @param eventType The event type
* @retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAEventClear(void *eventHandle, uint32_t eventType);
/*!
* @brief Delete event.
* @param eventHandle The event handle.
*/
status_t SDMMC_OSAEventDestroy(void *eventHandle);
/*!
* @brief Create a mutex.
* @param mutexHandle mutex handle.
* @retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAMutexCreate(void *mutexHandle);
/*!
* @brief set event.
* @param mutexHandle mutex handle.
* @param millisec The maximum number of milliseconds to wait for the mutex.
* If the mutex is locked, Pass the value osaWaitForever_c will
* wait indefinitely, pass 0 will return KOSA_StatusTimeout
* immediately.
* @retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAMutexLock(void *mutexHandle, uint32_t millisec);
/*!
* @brief Get event flag.
* @param mutexHandle mutex handle.
* @retval kStatus_Fail or kStatus_Success.
*/
status_t SDMMC_OSAMutexUnlock(void *mutexHandle);
/*!
* @brief Delete mutex.
* @param mutexHandle The mutex handle.
*/
status_t SDMMC_OSAMutexDestroy(void *mutexHandle);
/*!
* @brief sdmmc delay.
* @param milliseconds time to delay
*/
void SDMMC_OSADelay(uint32_t milliseconds);
/*!
* @brief sdmmc delay us.
* @param microseconds time to delay
* @return actual delayed microseconds
*/
uint32_t SDMMC_OSADelayUs(uint32_t microseconds);
/* @} */
#if defined(__cplusplus)
}
#endif
/* @} */
#endif /* _FSL_SDMMC_OSA_H_*/

View File

@ -1,123 +0,0 @@
/*!
@page middleware_log Middleware Change Log
@section sd SD Card driver for MCUXpresso SDK
The current driver version is 2.4.0.
- 2.4.0
- Improvements
- Removed deprecated api in sd driver.
- Added new api SD_PollingCardStatusBusy for application polling card status.
- Improved the read/write/erase function flow.
- Improved the signal line voltage switch flow.
- Added powerOnDelayMS/powerOffDelayMS in sd_usr_param_t to allow redefine the default power on/off delay.
- Added mutual exclusive access for init/deinit/read/write/erase function.
- Fixed the driver strength configurations missed when timing mode switch to non SDR50/SDR104 mode.
- Fixed violations of MISRA C-2012 rule 4.7, 17.7, 10.7, 10.4, 13.5, 14.4.
- 2.3.3
- Improvements
- Added host SDR timing mode capability validation during card initialization.
- Added plling card ready for data status when transfer data failed.
- Used cache line size align buffer for SD initialization api.
- Bug Fixes
- Fixed violations of MISRA C-2012 rule 11.9, 15.7, 4.7, 16.4, 10.1, 10.3, 10.4, 11.3, 14.4, 10.6, 17.7, 16.1, 16.3.
- 2.3.2
- Improvements
- Moved power off function after card detect in SD_Init for DAT3 detect card feature.
- 2.3.1
- Improvements
- Removed the dead loop while polling DAT0 and CMD13 instead of using timeout mechanism.
- 2.3.0
- Improvements
- Marked api SD_HostReset/SD_PowerOnCard/SD_PowerOffCard/SD_WaitCardDetectStatus as deprecated.
- Added new api SD_SetCardPower/SD_PollingCardDetectStatus/SD_HostDoReset.
- Added internalBuffer in sd_card_t and removed rawCid/rawCsd/rawScr.
- Added retuning support during data transfer under SDR50/SDR104 mode.
- Increased the read/write blocks failed retry times for stability.
- Added delay while retry the ACMD41 for stability.
- 2.2.12
- Improvements
- Increased the sd io driver strength for SD2.0 card.
- Bug Fixes
- Fixed the build warning by changing the old style function declaration static
status_t inline to static inline status_t(found by adding
-Wold-style-declaration in armgcc build flag).
- 2.2.10
- Bug Fixes
- Added event value check for all the FreeRTOS events to fix program hangs
when a card event occurs before create.
- 2.2.7
- Bug Fixes
- Fixed MDK 66-D warning.
- 2.2.5
- Improvements
- Added SD_ReadStatus api to get 512bit SD status.
- Added error log support in sdcard functions.
- Added SDMMC_ENABLE_SOFTWARE_TUNING to enable/disable software tuning and it is disabled by default.
- 2.2.4
- Bug Fixes
- Fixed DDR mode data sequence miss issue, which is caused by NIBBLE_POS.
- Improvements
- Increased g_sdmmc 512byte to improve the performance when application use a non-word align data buffer address.
- Enabled auto cmd12 for SD read/write.
- 2.2.3
- Bug Fixes
- Added response check for send operation condition command. If not checked, the card may occasionally init fail.
- 2.2.1
- Improvements
- Kept SD_Init function for forward compatibility.
- 2.2.0
- Improvements
- Separated the SD/MMC/SDIO init API to xxx_CardInit/xxx_HostInit.
- SD_Init/SDIO_Init will be deprecated in the next version.
- 2.1.6
- Improvements
- Enhanced SD IO default driver strength.
- 2.1.5
- Bug Fixes
- Fixed Coverity issue.
- Fixed SD v1.x card write fail issue. It was caused by the block length set error.
- Fixed card cannot detect dynamically.
- 2.1.3
- Bug Fixes
- Fixed Non high-speed sdcard init fail at switch to high speed.
- Improvements
- Added Delay for SDCard power up.
- 2.1.2
- Improvements
- Improved SDMMC to support SD v3.0.
- 2.1.1
- Bug Fixes
- Fixed the bit mask error in the SD card switch to high speed function.
- Improvements
- Optimized the SD card initialization function.
- 2.1.0
- Bug Fixes
- Changed the callback mechanism when sending a command.
- Fixed the performance low issue when transferring data.
- Improvements
- Changed the name of some error codes returned by internal function.
- Merged all host related attributes to one structure.
- 2.0.0
- Initial version.
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,349 +0,0 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2019 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_SD_H_
#define _FSL_SD_H_
#include "fsl_sdmmc_common.h"
/*!
* @addtogroup sdcard SD Card Driver
* @ingroup card
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief Driver version. */
#define FSL_SD_DRIVER_VERSION (MAKE_VERSION(2U, 4U, 0U)) /*2.4.0*/
/*! @brief SD card flags
* @anchor _sd_card_flag
*/
enum
{
kSD_SupportHighCapacityFlag = (1U << 1U), /*!< Support high capacity */
kSD_Support4BitWidthFlag = (1U << 2U), /*!< Support 4-bit data width */
kSD_SupportSdhcFlag = (1U << 3U), /*!< Card is SDHC */
kSD_SupportSdxcFlag = (1U << 4U), /*!< Card is SDXC */
kSD_SupportVoltage180v = (1U << 5U), /*!< card support 1.8v voltage*/
kSD_SupportSetBlockCountCmd = (1U << 6U), /*!< card support cmd23 flag*/
kSD_SupportSpeedClassControlCmd = (1U << 7U), /*!< card support speed class control flag */
};
/*!
* @brief SD card state
*
* Define the card structure including the necessary fields to identify and describe the card.
*/
typedef struct _sd_card
{
sdmmchost_t *host; /*!< Host configuration */
sd_usr_param_t usrParam; /*!< user parameter */
bool isHostReady; /*!< use this flag to indicate if need host re-init or not*/
bool noInteralAlign; /*!< used to enable/disable the functionality of the exchange buffer */
uint32_t busClock_Hz; /*!< SD bus clock frequency united in Hz */
uint32_t relativeAddress; /*!< Relative address of the card */
uint32_t version; /*!< Card version */
uint32_t flags; /*!< Flags in _sd_card_flag */
uint8_t internalBuffer[FSL_SDMMC_CARD_INTERNAL_BUFFER_SIZE]; /*!< internal buffer */
uint32_t ocr; /*!< Raw OCR content */
sd_cid_t cid; /*!< CID */
sd_csd_t csd; /*!< CSD */
sd_scr_t scr; /*!< SCR */
sd_status_t stat; /*!< sd 512 bit status */
uint32_t blockCount; /*!< Card total block number */
uint32_t blockSize; /*!< Card block size */
sd_timing_mode_t currentTiming; /*!< current timing mode */
sd_driver_strength_t driverStrength; /*!< driver strength */
sd_max_current_t maxCurrent; /*!< card current limit */
sdmmc_operation_voltage_t operationVoltage; /*!< card operation voltage */
sdmmc_osa_mutex_t lock; /*!< card access lock */
} sd_card_t;
/*************************************************************************************************
* API
************************************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name SDCARD Function
* @{
*/
/*!
* @brief Initializes the card on a specific host controller.
* This function initializes the card on a specific host controller, it is consist of
* host init, card detect, card init function, however user can ignore this high level function,
* instead of use the low level function, such as SD_CardInit, SD_HostInit, SD_CardDetect.
*
* Thread safe function, please note that the function will create the mutex lock dynamically by default,
* so to avoid the mutex create redundantly, application must follow bellow sequence for card re-initialization
* @code
* SD_Deinit(card);
* SD_Init(card);
* @endcode
*
* @param card Card descriptor.
* @retval #kStatus_SDMMC_HostNotReady host is not ready.
* @retval #kStatus_SDMMC_GoIdleFailed Go idle failed.
* @retval #kStatus_SDMMC_NotSupportYet Card not support.
* @retval #kStatus_SDMMC_HandShakeOperationConditionFailed Send operation condition failed.
* @retval #kStatus_SDMMC_AllSendCidFailed Send CID failed.
* @retval #kStatus_SDMMC_SendRelativeAddressFailed Send relative address failed.
* @retval #kStatus_SDMMC_SendCsdFailed Send CSD failed.
* @retval #kStatus_SDMMC_SelectCardFailed Send SELECT_CARD command failed.
* @retval #kStatus_SDMMC_SendScrFailed Send SCR failed.
* @retval #kStatus_SDMMC_SetDataBusWidthFailed Set bus width failed.
* @retval #kStatus_SDMMC_SwitchBusTimingFailed Switch high speed failed.
* @retval #kStatus_SDMMC_SetCardBlockSizeFailed Set card block size failed.
* @retval #kStatus_Success Operate successfully.
*/
status_t SD_Init(sd_card_t *card);
/*!
* @brief Deinitializes the card.
* This function deinitializes the specific card and host.
* Please note it is a thread safe function.
*
* @param card Card descriptor.
*/
void SD_Deinit(sd_card_t *card);
/*!
* @brief Initializes the card.
*
* This function initializes the card only, make sure the host is ready when call this function,
* otherwise it will return kStatus_SDMMC_HostNotReady.
*
* Thread safe function, please note that the function will create the mutex lock dynamically by default,
* so to avoid the mutex create redundantly, application must follow bellow sequence for card re-initialization
* @code
* SD_CardDeinit(card);
* SD_CardInit(card);
* @endcode
*
* @param card Card descriptor.
* @retval #kStatus_SDMMC_HostNotReady host is not ready.
* @retval #kStatus_SDMMC_GoIdleFailed Go idle failed.
* @retval #kStatus_SDMMC_NotSupportYet Card not support.
* @retval #kStatus_SDMMC_HandShakeOperationConditionFailed Send operation condition failed.
* @retval #kStatus_SDMMC_AllSendCidFailed Send CID failed.
* @retval #kStatus_SDMMC_SendRelativeAddressFailed Send relative address failed.
* @retval #kStatus_SDMMC_SendCsdFailed Send CSD failed.
* @retval #kStatus_SDMMC_SelectCardFailed Send SELECT_CARD command failed.
* @retval #kStatus_SDMMC_SendScrFailed Send SCR failed.
* @retval #kStatus_SDMMC_SetDataBusWidthFailed Set bus width failed.
* @retval #kStatus_SDMMC_SwitchBusTimingFailed Switch high speed failed.
* @retval #kStatus_SDMMC_SetCardBlockSizeFailed Set card block size failed.
* @retval #kStatus_Success Operate successfully.
*/
status_t SD_CardInit(sd_card_t *card);
/*!
* @brief Deinitializes the card.
*
* This function deinitializes the specific card.
* Please note it is a thread safe function.
*
*
* @param card Card descriptor.
*/
void SD_CardDeinit(sd_card_t *card);
/*!
* @brief initialize the host.
*
* This function deinitializes the specific host.
*
* @param card Card descriptor.
*/
status_t SD_HostInit(sd_card_t *card);
/*!
* @brief Deinitializes the host.
*
* This function deinitializes the host.
*
* @param card Card descriptor.
*/
void SD_HostDeinit(sd_card_t *card);
/*!
* @brief reset the host.
*
* This function reset the specific host.
*
* @param card Card descriptor.
*/
void SD_HostDoReset(sd_card_t *card);
/*!
* @brief set card power.
*
* The power off operation depend on host or the user define power on function.
* @param card card descriptor.
* @param enable true is power on, false is power off.
*/
void SD_SetCardPower(sd_card_t *card, bool enable);
/*!
* @brief sd wait card detect function.
*
* Detect card through GPIO, CD, DATA3.
* @param card card descriptor.
* @param status detect status, kSD_Inserted or kSD_Removed.
*/
status_t SD_PollingCardInsert(sd_card_t *card, uint32_t status);
/*!
* @brief sd card present check function.
*
* @param card card descriptor.
*/
bool SD_IsCardPresent(sd_card_t *card);
/*!
* @brief Checks whether the card is write-protected.
*
* This function checks if the card is write-protected via the CSD register.
*
* @param card The specific card.
* @retval true Card is read only.
* @retval false Card isn't read only.
*/
bool SD_CheckReadOnly(sd_card_t *card);
/*!
* @brief Send SELECT_CARD command to set the card to be transfer state or not.
*
* @param card Card descriptor.
* @param isSelected True to set the card into transfer state, false to disselect.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_Success Operate successfully.
*/
status_t SD_SelectCard(sd_card_t *card, bool isSelected);
/*!
* @brief Send ACMD13 to get the card current status.
*
* @param card Card descriptor.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_SDMMC_SendApplicationCommandFailed send application command failed.
* @retval #kStatus_Success Operate successfully.
*/
status_t SD_ReadStatus(sd_card_t *card);
/*!
* @brief Reads blocks from the specific card.
*
* This function reads blocks from the specific card with default block size defined by the
* SDHC_CARD_DEFAULT_BLOCK_SIZE.
*
* Please note it is a thread safe function.
*
* @param card Card descriptor.
* @param buffer The buffer to save the data read from card.
* @param startBlock The start block index.
* @param blockCount The number of blocks to read.
* @retval #kStatus_InvalidArgument Invalid argument.
* @retval #kStatus_SDMMC_CardNotSupport Card not support.
* @retval #kStatus_SDMMC_NotSupportYet Not support now.
* @retval #kStatus_SDMMC_WaitWriteCompleteFailed Send status failed.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_SDMMC_StopTransmissionFailed Stop transmission failed.
* @retval #kStatus_Success Operate successfully.
*/
status_t SD_ReadBlocks(sd_card_t *card, uint8_t *buffer, uint32_t startBlock, uint32_t blockCount);
/*!
* @brief Writes blocks of data to the specific card.
*
* This function writes blocks to the specific card with default block size 512 bytes.
*
* Please note,
* 1. It is a thread safe function.
* 2. It is a async write function which means that the card status may still busy after the function return.
* Application can call function SD_PollingCardStatusBusy to wait card status idle after the write operation.
*
* @param card Card descriptor.
* @param buffer The buffer holding the data to be written to the card.
* @param startBlock The start block index.
* @param blockCount The number of blocks to write.
* @retval #kStatus_InvalidArgument Invalid argument.
* @retval #kStatus_SDMMC_NotSupportYet Not support now.
* @retval #kStatus_SDMMC_CardNotSupport Card not support.
* @retval #kStatus_SDMMC_WaitWriteCompleteFailed Send status failed.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_SDMMC_StopTransmissionFailed Stop transmission failed.
* @retval #kStatus_Success Operate successfully.
*/
status_t SD_WriteBlocks(sd_card_t *card, const uint8_t *buffer, uint32_t startBlock, uint32_t blockCount);
/*!
* @brief Erases blocks of the specific card.
*
* This function erases blocks of the specific card with default block size 512 bytes.
*
* Please note,
* 1. It is a thread safe function.
* 2. It is a async erase function which means that the card status may still busy after the function return.
* Application can call function SD_PollingCardStatusBusy to wait card status idle after the erase operation.
*
* @param card Card descriptor.
* @param startBlock The start block index.
* @param blockCount The number of blocks to erase.
* @retval #kStatus_InvalidArgument Invalid argument.
* @retval #kStatus_SDMMC_WaitWriteCompleteFailed Send status failed.
* @retval #kStatus_SDMMC_TransferFailed Transfer failed.
* @retval #kStatus_SDMMC_WaitWriteCompleteFailed Send status failed.
* @retval #kStatus_Success Operate successfully.
*/
status_t SD_EraseBlocks(sd_card_t *card, uint32_t startBlock, uint32_t blockCount);
/*!
* @brief select card driver strength
* select card driver strength
* @param card Card descriptor.
* @param driverStrength Driver strength
*/
status_t SD_SetDriverStrength(sd_card_t *card, sd_driver_strength_t driverStrength);
/*!
* @brief select max current
* select max operation current
* @param card Card descriptor.
* @param maxCurrent Max current
*/
status_t SD_SetMaxCurrent(sd_card_t *card, sd_max_current_t maxCurrent);
/*!
* @brief Polling card idle status.
*
* This function can be used to polling the status from busy to Idle, the function will return if the card
* status idle or timeout.
*
* @param card Card descriptor.
* @param timeoutMs polling card status timeout value.
* @retval kStatus_Success Operate successfully.
* @retval kStatus_SDMMC_WaitWriteCompleteFailed CMD13 transfer failed.
* @retval kStatus_SDMMC_PollingCardIdleFailed, polling card DAT0 idle failed.
*/
status_t SD_PollingCardStatusBusy(sd_card_t *card, uint32_t timeoutMs);
/* @} */
#if defined(__cplusplus)
}
#endif
/*! @} */
#endif /* _FSL_SD_H_*/

View File

@ -1,98 +0,0 @@
/*!
@page middleware_log Middleware Change Log
@section sdio SDIO Card driver for MCUXpresso SDK
The current driver version is 2.4.0.
- 2.4.0
- Improvements
- Removed deprecated api in sdio driver.
- Improved the signal line voltage switch flow.
- Added powerOnDelayMS/powerOffDelayMS in sdio_usr_param_t to allow redefine the default power on/off delay.
- Added mutual exclusive access for init/deinit/direct/extend function.
- Fixed violations of MISRA C-2012 rule 4.7, 17.7, 10.1, 12.2.
- 2.3.3
- Bug Fixes
- Fixed logical dead code coverity issue.
- Improvements
- Removed deprecated api in sdio driver.
- 2.3.2
- Improvements
- Added host SDR timing mode capability validation during card initialization.
- Used cache line size align buffer for SDIO initialization api.
- Bug Fixes
- Fixed violations of MISRA C-2012 rule 11.9, 15.7, 4.7, 16.4, 10.1, 10.3, 10.4, 11.3, 14.4, 10.6, 17.7, 16.1, 16.3.
- 2.3.1
- Improvements
- Moved power off function after card detect in SD_Init for DAT3 detect card feature.
- 2.3.0
- Improvements
- Marked api SDIO_HostReset/SDIO_PowerOnCard/SDIO_PowerOffCard/SDIO_WaitCardDetectStatus as deprecated.
- Added new api SDIO_SetCardPower/SDIO_PollingCardDetectStatus/SDIO_HostDoReset.
- Added internalBuffer in sdio_card_t for card register content extract and improve the data access efficiency.
- Added retry function after switch to target timing failed in SDIO_SelectBusTiming.
- Changed defalut bus clock from 400KHZ to 25MHZ.
- 2.2.13
- Improvements
- Removed the sdio card interrupt from sdio host initialization, since the card interrupt enablement should be determined by application.
- Bug Fixes
- Fixed Out-of-bounds write Coverity issue.
- 2.2.12
- Improvements
- Added manual tuning function for looking for the tuning window automatically.
- Fixed the build warning by changing the old style function declaration static
status_t inline to static inline status_t(found by adding
-Wold-style-declaration in armgcc build flag).
- Fixed the fall through build warning by adding SUPPRESS_FALL_THROUGH_WARNING() in sdio driver.
- 2.2.11
- Bug Fixes
- Added check card async interrupt capability in function
SDIO_GetCardCapability.
- Fixed OUT OF BOUNDS access in function SDIO_IO_Transfer.
- 2.2.10
- Bug Fixes
- Fixed SDIO card driver get an incorrect io number when the card io number is
bigger than 2.
- Improvements
- Added SDIO 3.0 support.
- Added API SDIO_IO_RW_Direct for direct read/write card register access.
- 2.2.9
- Improvements
- Added API SDIO_SetIOIRQHandler/SDIO_HandlePendingIOInterrupt to handle multi io pending IRQ.
- 2.2.8
- Improvements
- Updated sdmmc to support SDIO interrupt.
- Added API SDIO_GetPendingInterrupt to get the pending io interrupt.
- 2.2.7
- Bug Fixes
- Fixed MDK 66-D warning.
- 2.2.6
- Improvements
- Added an unify transfer interface for SDIO.
- Bug Fixes
- Fixed Wrong pointer address used by SDMMCHOST_Init.
- 2.1.5
- Improvements
- Improved SDIO card init sequence and add retry option for SDIO_SwitchToHighSpeed function.
- 2.1.4
- Improvements
- Added Go_Idle function for SDIO card.
- 2.0.0
- Initial version.
*/

View File

@ -1,529 +0,0 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_SDIO_H_
#define _FSL_SDIO_H_
#include "fsl_sdmmc_common.h"
/*!
* @addtogroup sdiocard SDIO Card Driver
* @ingroup card
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief Middleware version. */
#define FSL_SDIO_DRIVER_VERSION (MAKE_VERSION(2U, 4U, 0U)) /*2.4.0*/
/*!@brief sdio device support maximum IO number */
#ifndef FSL_SDIO_MAX_IO_NUMS
#define FSL_SDIO_MAX_IO_NUMS (7U)
#endif
/*!@brief sdio card descriptor */
typedef struct _sdio_card sdio_card_t;
/*!@brief sdio io handler */
typedef void (*sdio_io_irq_handler_t)(sdio_card_t *card, uint32_t func);
/*! @brief sdio io read/write direction */
typedef enum _sdio_io_direction
{
kSDIO_IORead = 0U, /*!< io read */
kSDIO_IOWrite = 1U, /*!< io write */
} sdio_io_direction_t;
/*!
* @brief SDIO card state
*
* Define the card structure including the necessary fields to identify and describe the card.
*/
struct _sdio_card
{
sdmmchost_t *host; /*!< Host information */
sdio_usr_param_t usrParam; /*!< user parameter */
bool noInternalAlign; /*!< use this flag to disable sdmmc align. If disable, sdmmc will not make sure the
data buffer address is word align, otherwise all the transfer are align to low level driver */
uint8_t internalBuffer[FSL_SDMMC_CARD_INTERNAL_BUFFER_SIZE]; /*!< internal buffer */
bool isHostReady; /*!< use this flag to indicate if need host re-init or not*/
bool memPresentFlag; /*!< indicate if memory present */
uint32_t busClock_Hz; /*!< SD bus clock frequency united in Hz */
uint32_t relativeAddress; /*!< Relative address of the card */
uint8_t sdVersion; /*!< SD version */
sd_timing_mode_t currentTiming; /*!< current timing mode */
sd_driver_strength_t driverStrength; /*!< driver strength */
sd_max_current_t maxCurrent; /*!< card current limit */
sdmmc_operation_voltage_t operationVoltage; /*!< card operation voltage */
uint8_t sdioVersion; /*!< SDIO version */
uint8_t cccrVersioin; /*!< CCCR version */
uint8_t ioTotalNumber; /*!< total number of IO function */
uint32_t cccrflags; /*!< Flags in _sd_card_flag */
uint32_t io0blockSize; /*!< record the io0 block size*/
uint32_t ocr; /*!< Raw OCR content, only 24bit avalible for SDIO card */
uint32_t commonCISPointer; /*!< point to common CIS */
sdio_common_cis_t commonCIS; /*!< CIS table */
/* io registers/IRQ handler */
sdio_fbr_t ioFBR[FSL_SDIO_MAX_IO_NUMS]; /*!< FBR table */
sdio_func_cis_t funcCIS[FSL_SDIO_MAX_IO_NUMS]; /*!< function CIS table*/
sdio_io_irq_handler_t ioIRQHandler[FSL_SDIO_MAX_IO_NUMS]; /*!< io IRQ handler */
uint8_t ioIntIndex; /*!< used to record current enabled io interrupt index */
uint8_t ioIntNums; /*!< used to record total enabled io interrupt numbers */
sdmmc_osa_mutex_t lock; /*!< card access lock */
};
/*************************************************************************************************
* API
************************************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name Initialization and deinitialization
* @{
*/
/*!
* @brief SDIO card init function
*
*
* Thread safe function, please note that the function will create the mutex lock dynamically by default,
* so to avoid the mutex create redundantly, application must follow bellow sequence for card re-initialization
* @code
* SDIO_Deinit(card);
* SDIO_Init(card);
* @endcode
*
* @param card Card descriptor.
* @retval kStatus_SDMMC_GoIdleFailed
* @retval kStatus_SDMMC_HandShakeOperationConditionFailed
* @retval kStatus_SDMMC_SDIO_InvalidCard
* @retval kStatus_SDMMC_SDIO_InvalidVoltage
* @retval kStatus_SDMMC_SendRelativeAddressFailed
* @retval kStatus_SDMMC_SelectCardFailed
* @retval kStatus_SDMMC_SDIO_SwitchHighSpeedFail
* @retval kStatus_SDMMC_SDIO_ReadCISFail
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_Init(sdio_card_t *card);
/*!
* @brief SDIO card deinit, include card and host deinit.
*
* Please note it is a thread safe function.
*
* @param card Card descriptor.
*/
void SDIO_Deinit(sdio_card_t *card);
/*!
* @brief Initializes the card.
*
* This function initializes the card only, make sure the host is ready when call this function,
* otherwise it will return kStatus_SDMMC_HostNotReady.
*
* Thread safe function, please note that the function will create the mutex lock dynamically by default,
* so to avoid the mutex create redundantly, application must follow bellow sequence for card re-initialization
* @code
* SDIO_CardDeinit(card);
* SDIO_CardInit(card);
* @endcode
*
* @param card Card descriptor.
* @retval kStatus_SDMMC_HostNotReady host is not ready.
* @retval kStatus_SDMMC_GoIdleFailed Go idle failed.
* @retval kStatus_SDMMC_NotSupportYet Card not support.
* @retval kStatus_SDMMC_SendOperationConditionFailed Send operation condition failed.
* @retval kStatus_SDMMC_AllSendCidFailed Send CID failed.
* @retval kStatus_SDMMC_SendRelativeAddressFailed Send relative address failed.
* @retval kStatus_SDMMC_SendCsdFailed Send CSD failed.
* @retval kStatus_SDMMC_SelectCardFailed Send SELECT_CARD command failed.
* @retval kStatus_SDMMC_SendScrFailed Send SCR failed.
* @retval kStatus_SDMMC_SetBusWidthFailed Set bus width failed.
* @retval kStatus_SDMMC_SwitchHighSpeedFailed Switch high speed failed.
* @retval kStatus_SDMMC_SetCardBlockSizeFailed Set card block size failed.
* @retval kStatus_Success Operate successfully.
*/
status_t SDIO_CardInit(sdio_card_t *card);
/*!
* @brief Deinitializes the card.
*
* This function deinitializes the specific card.
*
* Please note it is a thread safe function.
*
* @param card Card descriptor.
*/
void SDIO_CardDeinit(sdio_card_t *card);
/*!
* @brief initialize the host.
*
* This function deinitializes the specific host.
*
* @param card Card descriptor.
*/
status_t SDIO_HostInit(sdio_card_t *card);
/*!
* @brief Deinitializes the host.
*
* This function deinitializes the host.
*
* @param card Card descriptor.
*/
void SDIO_HostDeinit(sdio_card_t *card);
/*!
* @brief reset the host.
*
* This function reset the specific host.
*
* @param card Card descriptor.
*/
void SDIO_HostDoReset(sdio_card_t *card);
/*!
* @brief set card power.
*
* The power off operation depend on host or the user define power on function.
* @param card card descriptor.
* @param enable true is power on, false is power off.
*/
void SDIO_SetCardPower(sdio_card_t *card, bool enable);
/*!
* @brief set SDIO card to inactive state
*
* @param card Card descriptor.
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_CardInActive(sdio_card_t *card);
/*!
* @brief get SDIO card capability
*
* @param card Card descriptor.
* @param func IO number
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_GetCardCapability(sdio_card_t *card, sdio_func_num_t func);
/*!
* @brief set SDIO card block size
*
* @param card Card descriptor.
* @param func io number
* @param blockSize block size
* @retval kStatus_SDMMC_SetCardBlockSizeFailed
* @retval kStatus_SDMMC_SDIO_InvalidArgument
* @retval kStatus_Success
*/
status_t SDIO_SetBlockSize(sdio_card_t *card, sdio_func_num_t func, uint32_t blockSize);
/*!
* @brief set SDIO card reset
*
* @param card Card descriptor.
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_CardReset(sdio_card_t *card);
/*!
* @brief set SDIO card data bus width
*
* @param card Card descriptor.
* @param busWidth bus width
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_SetDataBusWidth(sdio_card_t *card, sdio_bus_width_t busWidth);
/*!
* @brief switch the card to high speed
*
* @param card Card descriptor.
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_SDMMC_SDIO_SwitchHighSpeedFail
* @retval kStatus_Success
*/
status_t SDIO_SwitchToHighSpeed(sdio_card_t *card);
/*!
* @brief read SDIO card CIS for each function
*
* @param card Card descriptor.
* @param func io number
* @param tupleList code list
* @param tupleNum code number
* @retval kStatus_SDMMC_SDIO_ReadCISFail
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_ReadCIS(sdio_card_t *card, sdio_func_num_t func, const uint32_t *tupleList, uint32_t tupleNum);
/*!
* @brief sdio wait card detect function.
*
* Detect card through GPIO, CD, DATA3.
* @param card card descriptor.
* @param status detect status, kSD_Inserted or kSD_Removed.
*/
status_t SDIO_PollingCardInsert(sdio_card_t *card, uint32_t status);
/*!
* @brief sdio card present check function.
*
* @param card card descriptor.
*/
bool SDIO_IsCardPresent(sdio_card_t *card);
/* @} */
/*!
* @name IO operations
* @{
*/
/*!
* @brief IO direct write transfer function
*
* Please note it is a thread safe function.
*
* @param card Card descriptor.
* @param func IO numner
* @param regAddr register address
* @param data the data pinter to write
* @param raw flag, indicate read after write or write only
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_IO_Write_Direct(sdio_card_t *card, sdio_func_num_t func, uint32_t regAddr, uint8_t *data, bool raw);
/*!
* @brief IO direct read transfer function
*
* Please note it is a thread safe function.
*
* @param card Card descriptor.
* @param func IO number
* @param regAddr register address
* @param data pointer to read
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_IO_Read_Direct(sdio_card_t *card, sdio_func_num_t func, uint32_t regAddr, uint8_t *data);
/*!
* @brief IO direct read/write transfer function
*
* Please note it is a thread safe function.
*
* @param card Card descriptor.
* @param direction io access direction, please reference sdio_io_direction_t.
* @param func IO number
* @param regAddr register address
* @param dataIn data to write
* @param dataOut data pointer for readback data, support both for read and write, when application want readback
* the data after write command, dataOut should not be NULL.
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_IO_RW_Direct(sdio_card_t *card,
sdio_io_direction_t direction,
sdio_func_num_t func,
uint32_t regAddr,
uint8_t dataIn,
uint8_t *dataOut);
/*!
* @brief IO extended write transfer function
*
* Please note it is a thread safe function.
*
* @param card Card descriptor.
* @param func IO number
* @param regAddr register address
* @param buffer data buffer to write
* @param count data count
* @param flags write flags
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_SDMMC_SDIO_InvalidArgument
* @retval kStatus_Success
*/
status_t SDIO_IO_Write_Extended(
sdio_card_t *card, sdio_func_num_t func, uint32_t regAddr, uint8_t *buffer, uint32_t count, uint32_t flags);
/*!
* @brief IO extended read transfer function
*
* Please note it is a thread safe function.
*
* @param card Card descriptor.
* @param func IO number
* @param regAddr register address
* @param buffer data buffer to read
* @param count data count
* @param flags write flags
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_SDMMC_SDIO_InvalidArgument
* @retval kStatus_Success
*/
status_t SDIO_IO_Read_Extended(
sdio_card_t *card, sdio_func_num_t func, uint32_t regAddr, uint8_t *buffer, uint32_t count, uint32_t flags);
/*!
* @brief enable IO interrupt
*
* @param card Card descriptor.
* @param func IO number
* @param enable enable/disable flag
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_EnableIOInterrupt(sdio_card_t *card, sdio_func_num_t func, bool enable);
/*!
* @brief enable IO and wait IO ready
*
* @param card Card descriptor.
* @param func IO number
* @param enable enable/disable flag
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_EnableIO(sdio_card_t *card, sdio_func_num_t func, bool enable);
/*!
* @brief select IO
*
* @param card Card descriptor.
* @param func IO number
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_SelectIO(sdio_card_t *card, sdio_func_num_t func);
/*!
* @brief Abort IO transfer
*
* @param card Card descriptor.
* @param func IO number
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_AbortIO(sdio_card_t *card, sdio_func_num_t func);
/*!
* @brief Set driver strength.
*
* @param card Card descriptor.
* @param driverStrength target driver strength.
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_SetDriverStrength(sdio_card_t *card, sd_driver_strength_t driverStrength);
/*!
* @brief Enable/Disable Async interrupt.
*
* @param card Card descriptor.
* @param enable true is enable, false is disable.
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_EnableAsyncInterrupt(sdio_card_t *card, bool enable);
/*!
* @brief Get pending interrupt.
*
* @param card Card descriptor.
* @param pendingInt pointer store pending interrupt
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_GetPendingInterrupt(sdio_card_t *card, uint8_t *pendingInt);
/*!
* @brief sdio card io transfer function.
* This function can be used for trnansfer direct/extend command.
* Please pay attention to the non-align data buffer address transfer,
* if data buffer address can not meet host controller internal DMA requirement, sdio driver will try to use
* internal align buffer if data size is not bigger than internal buffer size,
* Align address transfer always can get a better performance, so if application want sdio driver make sure buffer
* address align,
*
* Please note it is a thread safe function.
*
* @param card card descriptor.
* @param cmd command to transfer
* @param argument argument to transfer
* @param blockSize used for block mode.
* @param txData tx buffer pointer or NULL
* @param rxData rx buffer pointer or NULL
* @param dataSize transfer data size
* @param response reponse pointer, if application want read response back, please set it to a NON-NULL pointer.
*/
status_t SDIO_IO_Transfer(sdio_card_t *card,
sdio_command_t cmd,
uint32_t argument,
uint32_t blockSize,
uint8_t *txData,
uint8_t *rxData,
uint16_t dataSize,
uint32_t *response);
/*!
* @brief sdio set io IRQ handler.
*
* @param card card descriptor.
* @param func function io number.
* @param handler io IRQ handler.
*/
void SDIO_SetIOIRQHandler(sdio_card_t *card, sdio_func_num_t func, sdio_io_irq_handler_t handler);
/*!
* @brief sdio card io pending interrupt handle function.
* This function is used to handle the pending io interrupt.
* To reigster a IO IRQ handler,
* @code
* SDIO_EnableIOInterrupt(card, 0, true);
* SDIO_SetIOIRQHandler(card, 0, func0_handler);
* @endcode
* call it in interrupt callback
* @code
* SDIO_HandlePendingIOInterrupt(card);
* @endcode
* To releae a IO IRQ handler,
* @code
* SDIO_EnableIOInterrupt(card, 0, false);
* SDIO_SetIOIRQHandler(card, 0, NULL);
* @endcode
* @param card card descriptor.
*
* @retval kStatus_SDMMC_TransferFailed
* @retval kStatus_Success
*/
status_t SDIO_HandlePendingIOInterrupt(sdio_card_t *card);
/* @} */
#if defined(__cplusplus)
}
#endif
/* @} */
#endif /* _FSL_SDIO_H_*/

View File

@ -1,58 +0,0 @@
/*
* Copyright 2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "sdmmc_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/*!brief sdmmc dma buffer */
SDK_ALIGN(uint32_t s_sdmmcHostDmaBuffer[BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE],
SDMMCHOST_DMA_DESCRIPTOR_BUFFER_ALIGN_SIZE);
#if defined(SDIO_ENABLED) || defined(SD_ENABLED)
static sd_detect_card_t s_cd;
#endif
sdmmchost_t s_host;
/*******************************************************************************
* Code
******************************************************************************/
#ifdef SD_ENABLED
void BOARD_SD_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, void *userData)
{
assert(card);
s_host.dmaDesBuffer = s_sdmmcHostDmaBuffer;
s_host.dmaDesBufferWordsNum = BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE;
((sd_card_t *)card)->host = &s_host;
((sd_card_t *)card)->host->hostController.base = BOARD_SDMMC_SD_HOST_BASEADDR;
((sd_card_t *)card)->host->hostController.sourceClock_Hz = CLOCK_GetFreq(kCLOCK_CoreSysClk);
((sd_card_t *)card)->usrParam.cd = &s_cd;
NVIC_SetPriority(BOARD_SDMMC_SD_HOST_IRQ, hostIRQPriority);
}
#endif
#ifdef MMC_ENABLED
void BOARD_MMC_Config(void *card, uint32_t hostIRQPriority)
{
assert(card);
s_host.dmaDesBuffer = s_sdmmcHostDmaBuffer;
s_host.dmaDesBufferWordsNum = BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE;
((mmc_card_t *)card)->host = &s_host;
((mmc_card_t *)card)->host->hostController.base = BOARD_SDMMC_MMC_HOST_BASEADDR;
((mmc_card_t *)card)->host->hostController.sourceClock_Hz = CLOCK_GetFreq(kCLOCK_CoreSysClk);
((mmc_card_t *)card)->hostVoltageWindowVCC = BOARD_SDMMC_MMC_VCC_SUPPLY;
((mmc_card_t *)card)->hostVoltageWindowVCCQ = BOARD_SDMMC_MMC_VCCQ_SUPPLY;
NVIC_SetPriority(BOARD_SDMMC_MMC_HOST_IRQ, hostIRQPriority);
}
#endif

View File

@ -1,101 +0,0 @@
/*
* Copyright 2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SDMMC_CONFIG_H_
#define _SDMMC_CONFIG_H_
#ifdef SD_ENABLED
#include "fsl_sd.h"
#endif
#ifdef MMC_ENABLED
#include "fsl_mmc.h"
#endif
#include "clock_config.h"
#include "fsl_sdmmc_host.h"
#include "fsl_sdmmc_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* @brief host basic configuration */
#define BOARD_SDMMC_SD_HOST_BASEADDR SDHC
#define BOARD_SDMMC_MMC_HOST_BASEADDR SDHC
#define BOARD_SDMMC_SD_HOST_IRQ SDHC_IRQn
#define BOARD_SDMMC_MMC_HOST_IRQ SDHC_IRQn
/* @brief card detect configuration */
#define BOARD_SDMMC_SD_CD_GPIO_BASE GPIOB
#define BOARD_SDMMC_SD_CD_GPIO_PIN 20U
#define BOARD_SDMMC_SD_CD_PORT_BASE PORTB
#define BOARD_SDMMC_SD_CD_PORT_IRQ PORTB_IRQn
#define BOARD_SDMMC_SD_CD_IRQ_PRIORITY 6U
#define BOARD_SDMMC_SD_CD_INTTERUPT_TYPE kPORT_InterruptEitherEdge
#define BOARD_SDMMC_SD_CD_INSERT_LEVEL (0U)
#define BOARD_SDMMC_SD_CD_PORT_IRQ_HANDLER PORTB_IRQHandler
/* @brief card detect type
*
* Note: if you want to use DAT3 as card detect pin, please pay attention, DAT3 card detection cannot works during the
* card access, since the DAT3 will be used for data transfer, thus the functionality of card detect interrupt will be
* disabled as soon as card is detected. So If application would like to re-detect sdcard/sdiocard, please calling
* SD_PollingCardInsert/SDIO_PollingCardInsert The function will polling the card detect status and could yield CPU
* while RTOS and non-blocking adapter is using.
*
* Using card detect pin for card detection is recommended.
*/
#define BOARD_SDMMC_SD_CD_TYPE kSD_DetectCardByGpioCD
#define BOARD_SDMMC_SD_CARD_DETECT_DEBOUNCE_DELAY_MS (100U)
#define BOARD_SDMMC_DATA_BUFFER_ALIGN_SIZE (4U)
/* @brief mmc configuration */
#define BOARD_SDMMC_MMC_VCC_SUPPLY kMMC_VoltageWindows270to360
#define BOARD_SDMMC_MMC_VCCQ_SUPPLY kMMC_VoltageWindows270to360
/* @brief The SDSPI configuration. */
#define BOARD_SDSPI_HOST_BASE SPI1_BASE /*!< SPI base address for SDSPI */
#define BOARD_SDSPI_HOST_CD_GPIO_BASE GPIOB /*!< Port related to card detect pin for SDSPI */
#define BOARD_SDSPI_HOST_CD_PIN 20U /*!< Card detect pin for SDSPI */
/*!@ brief host interrupt priority*/
#define BOARD_SDMMC_SD_HOST_IRQ_PRIORITY (5U)
#define BOARD_SDMMC_MMC_HOST_IRQ_PRIORITY (5U)
/*!@brief dma descriptor buffer size */
#define BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE (32U)
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*******************************************************************************
* API
******************************************************************************/
/*!
* @brief BOARD SD configurations.
* @param card card descriptor
* @param cd card detect callback
* @param userData user data for callback
*/
#ifdef SD_ENABLED
void BOARD_SD_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, void *userData);
#endif
/*!
* @brief BOARD MMC configurations.
* @param card card descriptor
* @param cd card detect callback
* @param userData user data for callback
*/
#ifdef MMC_ENABLED
void BOARD_MMC_Config(void *card, uint32_t hostIRQPriority);
#endif
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* _BOARD_H_ */

View File

@ -1,115 +0,0 @@
/*
* Copyright 2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "sdmmc_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/*!brief sdmmc dma buffer */
SDK_ALIGN(uint32_t s_sdmmcHostDmaBuffer[BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE],
SDMMCHOST_DMA_DESCRIPTOR_BUFFER_ALIGN_SIZE);
#if defined(SDIO_ENABLED) || defined(SD_ENABLED)
static sd_detect_card_t s_cd;
#endif
static sdmmchost_t s_host;
#ifdef SDIO_ENABLED
sdio_card_int_t s_sdioInt;
#endif
/*******************************************************************************
* Code
******************************************************************************/
void Board_InitSdifUnusedDataPin(void)
{
}
uint32_t BOARD_SDIF0ClockConfiguration(void)
{
return 0;
}
#ifdef SD_ENABLED
void BOARD_SD_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, void *userData)
{
assert(card);
s_host.dmaDesBuffer = s_sdmmcHostDmaBuffer;
s_host.dmaDesBufferWordsNum = BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE;
((sd_card_t *)card)->host = &s_host;
((sd_card_t *)card)->host->hostController.base = BOARD_SDMMC_SD_HOST_BASEADDR;
((sd_card_t *)card)->host->hostController.sourceClock_Hz = BOARD_SDIF0ClockConfiguration();
((sd_card_t *)card)->usrParam.cd = &s_cd;
/* This function is used to init the SDIF unused data pin, DATA4 - DATA7, these pin should be configured
* ,otherswise the SDIF will not work, please check the corresponding errata.
*/
Board_InitSdifUnusedDataPin();
NVIC_SetPriority(BOARD_SDMMC_SD_HOST_IRQ, hostIRQPriority);
}
#endif
#ifdef SDIO_ENABLED
void BOARD_SDIO_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, sdio_int_t cardInt)
{
assert(card);
s_host.dmaDesBuffer = s_sdmmcHostDmaBuffer;
s_host.dmaDesBufferWordsNum = BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE;
((sdio_card_t *)card)->host = &s_host;
((sdio_card_t *)card)->host->hostController.base = BOARD_SDMMC_SDIO_HOST_BASEADDR;
((sdio_card_t *)card)->host->hostController.sourceClock_Hz = BOARD_SDIF0ClockConfiguration();
((sdio_card_t *)card)->usrParam.cd = &s_cd;
if (cardInt != NULL)
{
s_sdioInt.cardInterrupt = cardInt;
((sdio_card_t *)card)->usrParam.sdioInt = &s_sdioInt;
}
/* This function is used to init the SDIF unused data pin, DATA4 - DATA7, these pin should be configured
* ,otherswise the SDIF will not work, please check the corresponding errata.
*/
Board_InitSdifUnusedDataPin();
BOARD_SDCardDetectInit(cd, NULL);
NVIC_SetPriority(BOARD_SDMMC_SDIO_HOST_IRQ, hostIRQPriority);
}
#endif
#ifdef MMC_ENABLED
void BOARD_MMC_Config(void *card, uint32_t hostIRQPriority)
{
assert(card);
s_host.dmaDesBuffer = s_sdmmcHostDmaBuffer;
s_host.dmaDesBufferWordsNum = BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE;
((mmc_card_t *)card)->host = &s_host;
((mmc_card_t *)card)->host->hostController.base = BOARD_SDMMC_MMC_HOST_BASEADDR;
((mmc_card_t *)card)->host->hostController.sourceClock_Hz = BOARD_SDIF0ClockConfiguration();
((mmc_card_t *)card)->hostVoltageWindowVCC = BOARD_SDMMC_MMC_VCC_SUPPLY;
((mmc_card_t *)card)->hostVoltageWindowVCCQ = BOARD_SDMMC_MMC_VCCQ_SUPPLY;
/* This function is used to init the SDIF unused data pin, DATA4 - DATA7, these pin should be configured
* ,otherswise the SDIF will not work, please check the corresponding errata.
*/
Board_InitSdifUnusedDataPin();
NVIC_SetPriority(BOARD_SDMMC_MMC_HOST_IRQ, hostIRQPriority);
}
#endif

View File

@ -1,92 +0,0 @@
/*
* Copyright 2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SDMMC_CONFIG_H_
#define _SDMMC_CONFIG_H_
#ifdef SD_ENABLED
#include "fsl_sd.h"
#endif
#ifdef MMC_ENABLED
#include "fsl_mmc.h"
#endif
#ifdef SDIO_ENABLED
#include "fsl_sdio.h"
#endif
#include "clock_config.h"
#include "fsl_sdmmc_host.h"
#include "fsl_sdmmc_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* @brief host basic configuration */
#define BOARD_SDMMC_SD_HOST_BASEADDR SDIF
#define BOARD_SDMMC_SD_HOST_IRQ SDIO_IRQn
#define BOARD_SDMMC_MMC_HOST_BASEADDR SDIF
#define BOARD_SDMMC_MMC_HOST_IRQ SDIO_IRQn
#define BOARD_SDMMC_SDIO_HOST_BASEADDR SDIF
#define BOARD_SDMMC_SDIO_HOST_IRQ SDIO_IRQn
/* @brief card detect configuration */
#define BOARD_SDMMC_SD_CD_TYPE kSD_DetectCardByHostCD
#define BOARD_SDMMC_SD_CARD_DETECT_DEBOUNCE_DELAY_MS (100U)
/* @brief mmc configuration */
#define BOARD_SDMMC_MMC_VCC_SUPPLY kMMC_VoltageWindows270to360
#define BOARD_SDMMC_MMC_VCCQ_SUPPLY kMMC_VoltageWindows270to360
#define BOARD_SDMMC_DATA_BUFFER_ALIGN_SIZE (4U)
/*!@ brief host interrupt priority*/
#define BOARD_SDMMC_SD_HOST_IRQ_PRIORITY (5U)
#define BOARD_SDMMC_MMC_HOST_IRQ_PRIORITY (5U)
#define BOARD_SDMMC_SDIO_HOST_IRQ_PRIORITY (5U)
/*!@brief dma descriptor buffer size */
#define BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE (0x40U)
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*******************************************************************************
* API
******************************************************************************/
/*!
* @brief BOARD SD configurations.
* @param card card descriptor
* @param cd card detect callback
* @param userData user data for callback
*/
#ifdef SD_ENABLED
void BOARD_SD_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, void *userData);
#endif
/*!
* @brief BOARD SDIO configurations.
* @param card card descriptor
* @param cd card detect callback
* @param cardInt card interrupt
*/
#ifdef SDIO_ENABLED
void BOARD_SDIO_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, sdio_int_t cardInt);
#endif
/*!
* @brief BOARD MMC configurations.
* @param card card descriptor
* @param cd card detect callback
* @param userData user data for callback
*/
#ifdef MMC_ENABLED
void BOARD_MMC_Config(void *card, uint32_t hostIRQPriority);
#endif
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* _BOARD_H_ */

View File

@ -1,149 +0,0 @@
/*
* Copyright 2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "sdmmc_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
void BOARD_SDCardPowerControl(bool enable);
/*******************************************************************************
* Variables
******************************************************************************/
/*!brief sdmmc dma buffer */
AT_NONCACHEABLE_SECTION_ALIGN(uint32_t s_sdmmcHostDmaBuffer[BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE],
SDMMCHOST_DMA_DESCRIPTOR_BUFFER_ALIGN_SIZE);
#if defined SDMMCHOST_ENABLE_CACHE_LINE_ALIGN_TRANSFER && SDMMCHOST_ENABLE_CACHE_LINE_ALIGN_TRANSFER
/* two cache line length for sdmmc host driver maintain unalign transfer */
SDK_ALIGN(static uint8_t s_sdmmcCacheLineAlignBuffer[BOARD_SDMMC_DATA_BUFFER_ALIGN_SIZE * 2U],
BOARD_SDMMC_DATA_BUFFER_ALIGN_SIZE);
#endif
#if defined(SDIO_ENABLED) || defined(SD_ENABLED)
static sd_detect_card_t s_cd;
static sd_io_voltage_t s_ioVoltage = {
.type = BOARD_SDMMC_SD_IO_VOLTAGE_CONTROL_TYPE,
.func = NULL,
};
#endif
sdmmchost_t s_host;
#ifdef SDIO_ENABLED
static sdio_card_int_t s_sdioInt;
#endif
/*******************************************************************************
* Code
******************************************************************************/
uint32_t BOARD_USDHC1ClockConfiguration(void)
{
return 0;
}
#if defined(SDIO_ENABLED) || defined(SD_ENABLED)
void BOARD_SDCardPowerControl(bool enable)
{
}
void BOARD_SD_Pin_Config(uint32_t freq)
{
}
#endif
#ifdef SD_ENABLED
void BOARD_SD_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, void *userData)
{
assert(card);
s_host.dmaDesBuffer = s_sdmmcHostDmaBuffer;
s_host.dmaDesBufferWordsNum = BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE;
s_host.enableCacheControl = BOARD_SDMMC_HOST_CACHE_CONTROL;
#if defined SDMMCHOST_ENABLE_CACHE_LINE_ALIGN_TRANSFER && SDMMCHOST_ENABLE_CACHE_LINE_ALIGN_TRANSFER
s_host.cacheAlignBuffer = s_sdmmcCacheLineAlignBuffer;
s_host.cacheAlignBufferSize = BOARD_SDMMC_DATA_BUFFER_ALIGN_SIZE * 2U;
#endif
((sd_card_t *)card)->host = &s_host;
((sd_card_t *)card)->host->hostController.base = BOARD_SDMMC_SD_HOST_BASEADDR;
((sd_card_t *)card)->host->hostController.sourceClock_Hz = BOARD_USDHC1ClockConfiguration();
((sd_card_t *)card)->usrParam.cd = &s_cd;
((sd_card_t *)card)->usrParam.pwr = BOARD_SDCardPowerControl;
((sd_card_t *)card)->usrParam.ioStrength = BOARD_SD_Pin_Config;
((sd_card_t *)card)->usrParam.ioVoltage = &s_ioVoltage;
((sd_card_t *)card)->usrParam.maxFreq = BOARD_SDMMC_SD_HOST_SUPPORT_SDR104_FREQ;
NVIC_SetPriority(BOARD_SDMMC_SD_HOST_IRQ, hostIRQPriority);
}
#endif
#ifdef SDIO_ENABLED
void BOARD_SDIO_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, sdio_int_t cardInt)
{
assert(card);
s_host.dmaDesBuffer = s_sdmmcHostDmaBuffer;
s_host.dmaDesBufferWordsNum = BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE;
s_host.enableCacheControl = BOARD_SDMMC_HOST_CACHE_CONTROL;
#if defined SDMMCHOST_ENABLE_CACHE_LINE_ALIGN_TRANSFER && SDMMCHOST_ENABLE_CACHE_LINE_ALIGN_TRANSFER
s_host.cacheAlignBuffer = s_sdmmcCacheLineAlignBuffer;
s_host.cacheAlignBufferSize = BOARD_SDMMC_DATA_BUFFER_ALIGN_SIZE * 2U;
#endif
((sdio_card_t *)card)->host = &s_host;
((sdio_card_t *)card)->host->hostController.base = BOARD_SDMMC_SDIO_HOST_BASEADDR;
((sdio_card_t *)card)->host->hostController.sourceClock_Hz = BOARD_USDHC1ClockConfiguration();
((sdio_card_t *)card)->usrParam.cd = &s_cd;
((sdio_card_t *)card)->usrParam.pwr = BOARD_SDCardPowerControl;
((sdio_card_t *)card)->usrParam.ioStrength = BOARD_SD_Pin_Config;
((sdio_card_t *)card)->usrParam.ioVoltage = &s_ioVoltage;
((sdio_card_t *)card)->usrParam.maxFreq = BOARD_SDMMC_SD_HOST_SUPPORT_SDR104_FREQ;
if (cardInt != NULL)
{
s_sdioInt.cardInterrupt = cardInt;
((sdio_card_t *)card)->usrParam.sdioInt = &s_sdioInt;
}
BOARD_SDCardPowerResetInit();
BOARD_SDCardDetectInit(cd, NULL);
NVIC_SetPriority(BOARD_SDMMC_SDIO_HOST_IRQ, hostIRQPriority);
}
#endif
#ifdef MMC_ENABLED
static void BOARD_MMC_Pin_Config(uint32_t freq)
{
}
void BOARD_MMC_Config(void *card, uint32_t hostIRQPriority)
{
assert(card);
s_host.dmaDesBuffer = s_sdmmcHostDmaBuffer;
s_host.dmaDesBufferWordsNum = BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE;
s_host.enableCacheControl = BOARD_SDMMC_HOST_CACHE_CONTROL;
#if defined SDMMCHOST_ENABLE_CACHE_LINE_ALIGN_TRANSFER && SDMMCHOST_ENABLE_CACHE_LINE_ALIGN_TRANSFER
s_host.cacheAlignBuffer = s_sdmmcCacheLineAlignBuffer;
s_host.cacheAlignBufferSize = BOARD_SDMMC_DATA_BUFFER_ALIGN_SIZE * 2U;
#endif
((mmc_card_t *)card)->host = &s_host;
((mmc_card_t *)card)->host->hostController.base = BOARD_SDMMC_MMC_HOST_BASEADDR;
((mmc_card_t *)card)->host->hostController.sourceClock_Hz = BOARD_USDHC1ClockConfiguration();
((mmc_card_t *)card)->usrParam.ioStrength = BOARD_MMC_Pin_Config;
((mmc_card_t *)card)->usrParam.maxFreq = BOARD_SDMMC_MMC_HOST_SUPPORT_HS200_FREQ;
((mmc_card_t *)card)->hostVoltageWindowVCC = BOARD_SDMMC_MMC_VCC_SUPPLY;
((mmc_card_t *)card)->hostVoltageWindowVCCQ = BOARD_SDMMC_MMC_VCCQ_SUPPLY;
NVIC_SetPriority(BOARD_SDMMC_MMC_HOST_IRQ, hostIRQPriority);
}
#endif

View File

@ -1,115 +0,0 @@
/*
* Copyright 2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SDMMC_CONFIG_H_
#define _SDMMC_CONFIG_H_
#ifdef SD_ENABLED
#include "fsl_sd.h"
#endif
#ifdef MMC_ENABLED
#include "fsl_mmc.h"
#endif
#ifdef SDIO_ENABLED
#include "fsl_sdio.h"
#endif
#include "clock_config.h"
#include "fsl_sdmmc_host.h"
#include "fsl_sdmmc_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* @brief host basic configuration */
#define BOARD_SDMMC_SD_HOST_BASEADDR USDHC1
#define BOARD_SDMMC_SD_HOST_IRQ USDHC1_IRQn
#define BOARD_SDMMC_MMC_HOST_BASEADDR USDHC1
#define BOARD_SDMMC_MMC_HOST_IRQ USDHC1_IRQn
#define BOARD_SDMMC_SDIO_HOST_BASEADDR USDHC1
#define BOARD_SDMMC_SDIO_HOST_IRQ USDHC1_IRQn
/* @brief card detect configuration */
#define BOARD_SDMMC_SD_CD_GPIO_BASE GPIO2
#define BOARD_SDMMC_SD_CD_GPIO_PIN 28u
#define BOARD_SDMMC_SD_CD_IRQ_PRIORITY 6U
#define BOARD_SDMMC_SD_CD_IRQ GPIO2_Combined_16_31_IRQn
#define BOARD_SDMMC_SD_CD_INTTERUPT_TYPE kGPIO_IntRisingOrFallingEdge
#define BOARD_SDMMC_SD_CD_INSERT_LEVEL (0U)
#define BOARD_SDMMC_SD_CD_PORT_IRQ_HANDLER GPIO2_Combined_16_31_IRQHandler
/* @brief card detect type
*
* Note: Please pay attention, DAT3 card detection cannot works during the card access,
* since the DAT3 will be used for data transfer, thus the functionality of card detect will be disabled. Using card
* detect pin for card detection is recommended.
*/
#define BOARD_SDMMC_SD_CD_TYPE kSD_DetectCardByGpioCD
#define BOARD_SDMMC_SD_CARD_DETECT_DEBOUNCE_DELAY_MS (100U)
/*! @brief SD power reset */
#define BOARD_SDMMC_SD_POWER_RESET_GPIO_BASE GPIO1
#define BOARD_SDMMC_SD_POWER_RESET_GPIO_PIN 5U
/*! @brief SD IO voltage */
#define BOARD_SDMMC_SD_IO_VOLTAGE_CONTROL_TYPE kSD_IOVoltageCtrlByHost
#define BOARD_SDMMC_SD_HOST_SUPPORT_SDR104_FREQ (200000000U)
#define BOARD_SDMMC_MMC_HOST_SUPPORT_HS200_FREQ (180000000U)
/*! @brief mmc configuration */
#define BOARD_SDMMC_MMC_VCC_SUPPLY kMMC_VoltageWindows270to360
#define BOARD_SDMMC_MMC_VCCQ_SUPPLY kMMC_VoltageWindows270to360
/*! @brief align with cache line size */
#define BOARD_SDMMC_DATA_BUFFER_ALIGN_SIZE (32U)
/*!@ brief host interrupt priority*/
#define BOARD_SDMMC_SD_HOST_IRQ_PRIORITY (5U)
#define BOARD_SDMMC_MMC_HOST_IRQ_PRIORITY (5U)
#define BOARD_SDMMC_SDIO_HOST_IRQ_PRIORITY (5U)
/*!@brief dma descriptor buffer size */
#define BOARD_SDMMC_HOST_DMA_DESCRIPTOR_BUFFER_SIZE (32U)
/*! @brief cache maintain function enabled for RW buffer */
#define BOARD_SDMMC_HOST_CACHE_CONTROL kSDMMCHOST_CacheControlRWBuffer
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*******************************************************************************
* API
******************************************************************************/
/*!
* @brief BOARD SD configurations.
* @param card card descriptor
* @param cd card detect callback
* @param userData user data for callback
*/
#ifdef SD_ENABLED
void BOARD_SD_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, void *userData);
#endif
/*!
* @brief BOARD SDIO configurations.
* @param card card descriptor
* @param cd card detect callback
* @param cardInt card interrupt
*/
#ifdef SDIO_ENABLED
void BOARD_SDIO_Config(void *card, sd_cd_t cd, uint32_t hostIRQPriority, sdio_int_t cardInt);
#endif
/*!
* @brief BOARD MMC configurations.
* @param card card descriptor
* @param cd card detect callback
* @param userData user data for callback
*/
#ifdef MMC_ENABLED
void BOARD_MMC_Config(void *card, uint32_t hostIRQPriority);
#endif
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* _BOARD_H_ */

View File

@ -23,7 +23,7 @@ if GetDepend('BSP_USING_SPI'):
src += ['drv_spi.c']
if GetDepend('BSP_USING_SDIO'):
src += ['drv_sd.c']
src += ['drv_sdif.c']
if GetDepend('BSP_USING_I2C'):
src += ['drv_i2c.c']

View File

@ -1,265 +0,0 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-08-08 Yang the first version
* 2019-07-19 Magicoe The first version for LPC55S6x
*/
#include <string.h>
#include <board.h>
#include "fsl_common.h"
#include "fsl_iocon.h"
#include "fsl_sdif.h"
#include "fsl_sd.h"
#include "drv_sd.h"
#include <finsh.h>
#include <dfs.h>
#include <dfs_fs.h>
#include "board.h"
static struct mci_device *_mci_device;
static uint8_t sdio_buffer[1024];
#ifdef RT_USING_SDIO
static rt_err_t rt_mci_init(rt_device_t dev)
{
rt_err_t result = RT_EOK;
return result;
}
static rt_err_t rt_mci_open(rt_device_t dev, rt_uint16_t oflag)
{
return RT_EOK;
}
static rt_err_t rt_mci_close(rt_device_t dev)
{
return RT_EOK;
}
static rt_size_t rt_mci_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
{
rt_uint8_t status = kStatus_Success;
struct mci_device *mci = (struct mci_device *)dev;
int ret;
ret = rt_mutex_take(&mci->lock, RT_WAITING_FOREVER);
if (ret == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return ret;
}
else if (ret == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return ret;
}
{
/* non-aligned. */
uint32_t i;
rt_size_t sector_adr;
uint8_t* copy_buffer;
sector_adr = pos;
copy_buffer = (uint8_t*)buffer;
for(i=0; i<size; i++)
{
status = SD_ReadBlocks(&mci->card, sdio_buffer, sector_adr, 1);
memcpy(copy_buffer, sdio_buffer, mci->card.blockSize);
sector_adr ++;
copy_buffer += mci->card.blockSize;
}
}
rt_mutex_release(&_mci_device->lock);
if (status == kStatus_Success) return size;
return 0;
}
static rt_size_t rt_mci_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
rt_uint8_t status = kStatus_Success;
struct mci_device *mci = (struct mci_device *)dev;
int ret;
ret = rt_mutex_take(&mci->lock, RT_WAITING_FOREVER);
if (ret == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return ret;
}
else if (ret == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return ret;
}
{
/* non-aligned. */
uint32_t i;
rt_size_t sector_adr;
uint8_t* copy_buffer;
sector_adr = pos;
copy_buffer = (uint8_t*)buffer;
for(i = 0; i < size; i++)
{
memcpy(sdio_buffer, copy_buffer, mci->card.blockSize);
status = SD_WriteBlocks(&mci->card, sdio_buffer, sector_adr, 1);
sector_adr ++;
copy_buffer += mci->card.blockSize;
}
}
/* release and exit */
rt_mutex_release(&_mci_device->lock);
if (status == kStatus_Success) return size;
return 0;
}
static rt_err_t rt_mci_control(rt_device_t dev, int cmd, void *args)
{
struct mci_device *mci = (struct mci_device *)dev;
RT_ASSERT(dev != RT_NULL);
if (cmd == RT_DEVICE_CTRL_BLK_GETGEOME)
{
struct rt_device_blk_geometry *geometry;
geometry = (struct rt_device_blk_geometry *)args;
if (geometry == RT_NULL) return -RT_ERROR;
geometry->bytes_per_sector = mci->card.blockSize;
geometry->block_size = mci->card.csd.eraseSectorSize;
geometry->sector_count = mci->card.blockCount;
}
return RT_EOK;
}
/*! @brief SDMMC host detect card configuration */
static const sdmmchost_detect_card_t s_sdCardDetect = {
.cdType = BOARD_SD_DETECT_TYPE,
.cdTimeOut_ms = (~0U),
};
/*! @brief Card descriptor. */
sd_card_t g_sd;
int rt_hw_mci_init(void)
{
_mci_device = (struct mci_device *)rt_malloc(sizeof(struct mci_device));
if (_mci_device == RT_NULL)
{
rt_kprintf("mci_hw_init _mci_device rt_malloc failed!\n");
return -RT_ERROR;
}
rt_memset(_mci_device, 0, sizeof(struct mci_device));
/* attach main clock to SDIF */
CLOCK_AttachClk(kMAIN_CLK_to_SDIO_CLK);
/* need call this function to clear the halt bit in clock divider register */
CLOCK_SetClkDiv(kCLOCK_DivSdioClk, (uint32_t)(SystemCoreClock / FSL_FEATURE_SDIF_MAX_SOURCE_CLOCK + 1U), true);
_mci_device->card = g_sd;
/* Save host information. */
_mci_device->card.host.base = SDIF;
_mci_device->card.host.sourceClock_Hz = CLOCK_GetFreq(kCLOCK_SDio);
_mci_device->card.usrParam.cd = &s_sdCardDetect;
#if 1
rt_kprintf("\r\nNeed wait a few seconds to SD init, Better Set SystemTick as 1000\r\n");
rt_kprintf("SDCard Freq %d\r\n", _mci_device->card.host.sourceClock_Hz);
#endif
if (kStatus_Success != SD_HostInit(&_mci_device->card))
{
memset(&_mci_device->card, 0U, sizeof(_mci_device->card));
rt_kprintf("SD_Init failed!\n");
return -RT_ERROR;
}
/* power off card */
SD_PowerOffCard(_mci_device->card.host.base, _mci_device->card.usrParam.pwr);
/* check SD card insert */
if(BOARD_SDIF_CD_STATUS() == true)
{
rt_kprintf("\r\nCard detect fail.\r\n");
return kStatus_Fail;
}
/* wait card insert */
if (SD_WaitCardDetectStatus(_mci_device->card.host.base, &s_sdCardDetect, true) == kStatus_Success)
{
/* reset host once card re-plug in */
SD_HostReset(&(_mci_device->card.host));
/* power on the card */
SD_PowerOnCard(_mci_device->card.host.base, _mci_device->card.usrParam.pwr);
}
else
{
rt_kprintf("\r\nCard detect fail.\r\n");
return kStatus_Fail;
}
/* Init card. */
if (SD_CardInit(&_mci_device->card))
{
rt_kprintf("\r\nSD card init failed.\r\n");
return kStatus_Fail;
}
/* initialize mutex lock */
rt_mutex_init(&_mci_device->lock, "sdcard0", RT_IPC_FLAG_PRIO);
/* create finish event */
_mci_device->finish_event = rt_event_create("sdcard0", RT_IPC_FLAG_FIFO);
/* register sdcard device */
_mci_device->parent.type = RT_Device_Class_Block;
_mci_device->geometry.bytes_per_sector = 0;
_mci_device->geometry.sector_count = 0;
_mci_device->geometry.block_size = 0;
_mci_device->parent.init = rt_mci_init;
_mci_device->parent.open = rt_mci_open;
_mci_device->parent.close = rt_mci_close;
_mci_device->parent.read = rt_mci_read;
_mci_device->parent.write = rt_mci_write;
_mci_device->parent.control = rt_mci_control;
/* no private, no callback */
_mci_device->parent.user_data = RT_NULL;
_mci_device->parent.rx_indicate = RT_NULL;
_mci_device->parent.tx_complete = RT_NULL;
rt_device_register(&_mci_device->parent, "sdcard0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE );
return 0;
}
INIT_DEVICE_EXPORT(rt_hw_mci_init);
#endif /* endif RT_USING_SDIO */

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-07-19 Magicoe The first version for LPC55S6x
*/
#ifndef __DRV_SD_H__
#define __DRV_SD_H__
#include <rtthread.h>
#include "rtdef.h"
struct mci_device
{
struct rt_device parent; /**< RT-Thread device struct */
struct rt_device_blk_geometry geometry; /**< sector size, sector count */
sd_card_t card; /**< Card descriptor */
rt_event_t finish_event; /**< data send finish event*/
rt_bool_t data_error; /**< data send error*/
struct rt_mutex lock;
};
extern int rt_hw_mci_init(void);
#endif // __DRV_SD_H__

View File

@ -0,0 +1,326 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-08-08 Yang the first version
* 2019-07-19 Magicoe The first version for LPC55S6x
* 2023-02-0 Alex Yang update driver
*/
#include "board.h"
#include <rtdevice.h>
#include "fsl_sdif.h"
#ifdef RT_USING_SDIO
//#define MMCSD_DEBUG
#ifdef MMCSD_DEBUG
#define MMCSD_DGB rt_kprintf
#else
#define MMCSD_DGB(fmt, ...)
#endif
#define SDMMCHOST_RESET_TIMEOUT_VALUE (1000000U)
struct lpc_mmcsd
{
struct rt_mmcsd_host *host;
SDIF_Type *SDIFx;
uint32_t sdmmcHostDmaBuffer[0x40];
};
static void SDMMCHOST_ErrorRecovery(SDIF_Type *base)
{
(void)SDIF_Reset(base, kSDIF_ResetAll, SDMMCHOST_RESET_TIMEOUT_VALUE);
/* the host controller clock will be disabled by the reset operation, so re-send the clock sync command to enable
the output clock */
sdif_command_t clockSync = {
.flags = kSDIF_WaitPreTransferComplete | kSDIF_CmdUpdateClockRegisterOnly, .index = 0U, .argument = 0U};
(void)SDIF_SendCommand(base, &clockSync, 0U);
}
static void lpc_sdmmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
{
struct lpc_mmcsd *mmcsd;
struct rt_mmcsd_cmd *cmd;
struct rt_mmcsd_data *data;
rt_uint32_t *buf = NULL;
status_t error;
mmcsd = (struct lpc_mmcsd *) host->private_data;
cmd = req->cmd;
data = cmd->data;
sdif_dma_config_t dmaConfig;
dmaConfig.enableFixBurstLen = false;
dmaConfig.mode = kSDIF_ChainDMAMode;
dmaConfig.dmaDesBufferStartAddr = mmcsd->sdmmcHostDmaBuffer;
dmaConfig.dmaDesBufferLen = 0x40;
dmaConfig.dmaDesSkipLen = 0U;
sdif_transfer_t fsl_content = {0};
sdif_command_t fsl_command = {0};
sdif_data_t fsl_data = {0};
fsl_content.command = &fsl_command;
fsl_content.data = &fsl_data;
// MMCSD_DGB("ARG:0x%X, CODE:0x%X\r\n", cmd->arg, cmd->cmd_code);
fsl_command.index = cmd->cmd_code;
fsl_command.argument = cmd->arg;
if (cmd->cmd_code == STOP_TRANSMISSION)
fsl_command.type = kCARD_CommandTypeAbort;
else
fsl_command.type = kCARD_CommandTypeNormal;
switch (cmd->flags & RESP_MASK)
{
case RESP_NONE:
fsl_command.responseType = kCARD_ResponseTypeNone;
break;
case RESP_R1:
fsl_command.responseType = kCARD_ResponseTypeR1;
break;
case RESP_R1B:
fsl_command.responseType = kCARD_ResponseTypeR1b;
break;
case RESP_R2:
fsl_command.responseType = kCARD_ResponseTypeR2;
break;
case RESP_R3:
fsl_command.responseType = kCARD_ResponseTypeR3;
break;
case RESP_R4:
fsl_command.responseType = kCARD_ResponseTypeR4;
break;
case RESP_R6:
fsl_command.responseType = kCARD_ResponseTypeR6;
break;
case RESP_R7:
fsl_command.responseType = kCARD_ResponseTypeR7;
break;
case RESP_R5:
fsl_command.responseType = kCARD_ResponseTypeR5;
break;
default:
RT_ASSERT(NULL);
}
fsl_command.flags = 0;
fsl_content.command = &fsl_command;
if (data)
{
if (req->stop != NULL)
fsl_data.enableAutoCommand12 = true;
else
fsl_data.enableAutoCommand12 = false;
fsl_data.enableIgnoreError = false;
fsl_data.blockSize = data->blksize;
fsl_data.blockCount = data->blks;
if ((cmd->cmd_code == WRITE_BLOCK) || (cmd->cmd_code == WRITE_MULTIPLE_BLOCK))
{
if (buf)
{
MMCSD_DGB(" write(data->buf to buf) ");
rt_memcpy(buf, data->buf, fsl_data.blockSize * fsl_data.blockCount);
fsl_data.txData = (uint32_t const *)buf;
}
else
{
fsl_data.txData = (uint32_t const *)data->buf;
}
fsl_data.rxData = NULL;
}
else
{
if (buf)
{
fsl_data.rxData = (uint32_t *)buf;
}
else
{
fsl_data.rxData = (uint32_t *)data->buf;
}
fsl_data.txData = NULL;
}
fsl_content.data = &fsl_data;
}
else
{
fsl_content.data = NULL;
}
error = SDIF_TransferBlocking(mmcsd->SDIFx, &dmaConfig, &fsl_content);
if (error != kStatus_Success)
{
SDMMCHOST_ErrorRecovery(mmcsd->SDIFx);
MMCSD_DGB(" ***SDIF_TransferBlocking error: %d*** --> \n", error);
cmd->err = -RT_ERROR;
}
if (buf)
{
if (fsl_data.rxData)
{
MMCSD_DGB("read copy buf to data->buf ");
rt_memcpy(data->buf, buf, fsl_data.blockSize * fsl_data.blockCount);
}
rt_free_align(buf);
}
if ((cmd->flags & RESP_MASK) == RESP_R2)
{
cmd->resp[3] = fsl_command.response[0];
cmd->resp[2] = fsl_command.response[1];
cmd->resp[1] = fsl_command.response[2];
cmd->resp[0] = fsl_command.response[3];
// MMCSD_DGB(" resp 0x%08X 0x%08X 0x%08X 0x%08X\n", cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
}
else
{
cmd->resp[0] = fsl_command.response[0];
// MMCSD_DGB(" resp 0x%08X\n", cmd->resp[0]);
}
mmcsd_req_complete(host);
}
static void lpc_sdmmc_set_iocfg(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg)
{
//rt_kprintf("%s\r\n", __FUNCTION__);
struct lpc_mmcsd *mmcsd;
mmcsd = (struct lpc_mmcsd *) host->private_data;
uint32_t sdxc_clock = io_cfg->clock;
MMCSD_DGB("sdxc_clock:%d\r\n", sdxc_clock);
MMCSD_DGB("bus_width:%d\r\n", io_cfg->bus_width);
if (sdxc_clock != 0U)
{
SDIF_SetCardClock(mmcsd->SDIFx, CLOCK_GetSdioClkFreq(), sdxc_clock);
switch (io_cfg->bus_width)
{
case MMCSD_BUS_WIDTH_4:
SDIF_SetCardBusWidth(mmcsd->SDIFx, kSDIF_Bus4BitWidth);
break;
case MMCSD_BUS_WIDTH_8:
SDIF_SetCardBusWidth(mmcsd->SDIFx, kSDIF_Bus8BitWidth);
break;
default:
SDIF_SetCardBusWidth(mmcsd->SDIFx, kSDIF_Bus1BitWidth);
break;
}
}
rt_thread_mdelay(20);
}
static const struct rt_mmcsd_host_ops lpc_mmcsd_host_ops =
{
.request = lpc_sdmmc_request,
.set_iocfg = lpc_sdmmc_set_iocfg,
.get_card_status = NULL,
.enable_sdio_irq = NULL, // Do not use the interrupt mode, use DMA instead
};
int rt_hw_sdio_init(void)
{
struct rt_mmcsd_host *host = NULL;
struct lpc_mmcsd *mmcsd = NULL;
host = mmcsd_alloc_host();
if (!host)
{
return -RT_ERROR;
}
mmcsd = rt_malloc(sizeof(struct lpc_mmcsd));
if (!mmcsd)
{
rt_kprintf("alloc mci failed\n");
goto err;
}
rt_memset(mmcsd, 0, sizeof(struct lpc_mmcsd));
mmcsd->SDIFx = SDIF;
host->ops = &lpc_mmcsd_host_ops;
host->freq_min = 375000;
host->freq_max = 50000000;
host->valid_ocr = VDD_30_31 | VDD_31_32 | VDD_32_33 | VDD_33_34;
host->flags = MMCSD_MUTBLKWRITE | MMCSD_BUSWIDTH_4 | MMCSD_SUP_HIGHSPEED | MMCSD_SUP_SDIO_IRQ;
host->max_seg_size = 65535;
host->max_dma_segs = 2;
host->max_blk_size = 512;
host->max_blk_count = 4096;
mmcsd->host = host;
/* Perform necessary initialization */
CLOCK_AttachClk(kMAIN_CLK_to_SDIO_CLK);
CLOCK_SetClkDiv(kCLOCK_DivSdioClk, (uint32_t)(SystemCoreClock / FSL_FEATURE_SDIF_MAX_SOURCE_CLOCK + 1U), true);
MMCSD_DGB("SDIO clock:%dHz\r\n", CLOCK_GetSdioClkFreq());
sdif_config_t sdif_config = {0};
sdif_config.responseTimeout = 0xFFU;
sdif_config.cardDetDebounce_Clock = 0xFFFFFFU;
sdif_config.dataTimeout = 0xFFFFFFU;
SDIF_Init(mmcsd->SDIFx, &sdif_config);
SDIF_EnableCardPower(mmcsd->SDIFx, false);
SDIF_EnableCardPower(mmcsd->SDIFx, true);
host->private_data = mmcsd;
mmcsd_change(host);
return 0;
err:
mmcsd_free_host(host);
return -RT_ENOMEM;
}
INIT_DEVICE_EXPORT(rt_hw_sdio_init);
#endif /* endif RT_USING_SDIO */

View File

@ -60,6 +60,7 @@ CONFIG_RT_USING_MESSAGEQUEUE=y
#
# Memory Management
#
CONFIG_RT_PAGE_MAX_ORDER=11
CONFIG_RT_USING_MEMPOOL=y
CONFIG_RT_USING_SMALL_MEM=y
# CONFIG_RT_USING_SLAB is not set
@ -107,8 +108,7 @@ CONFIG_FINSH_USING_MSH=y
CONFIG_FINSH_THREAD_NAME="tshell"
CONFIG_FINSH_THREAD_PRIORITY=20
CONFIG_FINSH_THREAD_STACK_SIZE=4096
CONFIG_FINSH_USING_HISTORY=y
CONFIG_FINSH_HISTORY_LINES=5
# CONFIG_FINSH_USING_HISTORY is not set
CONFIG_FINSH_USING_SYMTAB=y
CONFIG_FINSH_CMD_SIZE=80
CONFIG_MSH_USING_BUILT_IN_COMMANDS=y
@ -116,7 +116,41 @@ CONFIG_FINSH_USING_DESCRIPTION=y
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
# CONFIG_FINSH_USING_AUTH is not set
CONFIG_FINSH_ARG_MAX=10
# CONFIG_RT_USING_DFS is not set
CONFIG_RT_USING_DFS=y
CONFIG_DFS_USING_POSIX=y
CONFIG_DFS_USING_WORKDIR=y
CONFIG_DFS_FILESYSTEMS_MAX=4
CONFIG_DFS_FILESYSTEM_TYPES_MAX=4
CONFIG_DFS_FD_MAX=16
# CONFIG_RT_USING_DFS_MNTTABLE is not set
CONFIG_RT_USING_DFS_ELMFAT=y
#
# elm-chan's FatFs, Generic FAT Filesystem Module
#
CONFIG_RT_DFS_ELM_CODE_PAGE=437
CONFIG_RT_DFS_ELM_WORD_ACCESS=y
# CONFIG_RT_DFS_ELM_USE_LFN_0 is not set
# CONFIG_RT_DFS_ELM_USE_LFN_1 is not set
# CONFIG_RT_DFS_ELM_USE_LFN_2 is not set
CONFIG_RT_DFS_ELM_USE_LFN_3=y
CONFIG_RT_DFS_ELM_USE_LFN=3
CONFIG_RT_DFS_ELM_LFN_UNICODE_0=y
# CONFIG_RT_DFS_ELM_LFN_UNICODE_1 is not set
# CONFIG_RT_DFS_ELM_LFN_UNICODE_2 is not set
# CONFIG_RT_DFS_ELM_LFN_UNICODE_3 is not set
CONFIG_RT_DFS_ELM_LFN_UNICODE=0
CONFIG_RT_DFS_ELM_MAX_LFN=255
CONFIG_RT_DFS_ELM_DRIVES=2
CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512
# CONFIG_RT_DFS_ELM_USE_ERASE is not set
CONFIG_RT_DFS_ELM_REENTRANT=y
CONFIG_RT_DFS_ELM_MUTEX_TIMEOUT=3000
CONFIG_RT_USING_DFS_DEVFS=y
# CONFIG_RT_USING_DFS_ROMFS is not set
# CONFIG_RT_USING_DFS_CROMFS is not set
# CONFIG_RT_USING_DFS_RAMFS is not set
# CONFIG_RT_USING_DFS_TMPFS is not set
# CONFIG_RT_USING_FAL is not set
#
@ -148,8 +182,16 @@ CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_MTD_NAND is not set
# CONFIG_RT_USING_PM is not set
# CONFIG_RT_USING_FDT is not set
# CONFIG_RT_USING_RTC is not set
# CONFIG_RT_USING_SDIO is not set
CONFIG_RT_USING_RTC=y
# CONFIG_RT_USING_ALARM is not set
# CONFIG_RT_USING_SOFT_RTC is not set
CONFIG_RT_USING_SDIO=y
CONFIG_RT_SDIO_STACK_SIZE=512
CONFIG_RT_SDIO_THREAD_PRIORITY=15
CONFIG_RT_MMCSD_STACK_SIZE=1024
CONFIG_RT_MMCSD_THREAD_PREORITY=22
CONFIG_RT_MMCSD_MAX_PARTITION=16
# CONFIG_RT_SDIO_DEBUG is not set
# CONFIG_RT_USING_SPI is not set
# CONFIG_RT_USING_WDT is not set
# CONFIG_RT_USING_AUDIO is not set
@ -511,6 +553,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
# CONFIG_PKG_USING_TFDB is not set
# CONFIG_PKG_USING_QPC is not set
# CONFIG_PKG_USING_AGILE_UPGRADE is not set
# CONFIG_PKG_USING_FLASH_BLOB is not set
#
# peripheral libraries and drivers
@ -753,7 +796,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
# CONFIG_PKG_USING_SOEM is not set
# CONFIG_PKG_USING_QPARAM is not set
# CONFIG_PKG_USING_CorevMCU_CLI is not set
# CONFIG_PKG_USING_GET_IRQ_PRIORITY is not set
#
# Arduino libraries
@ -982,8 +1024,8 @@ CONFIG_HW_I2C4_BAUDRATE_100kHZ=y
# CONFIG_HW_I2C4_BAUDRATE_400kHZ is not set
# CONFIG_BSP_USING_SPI is not set
# CONFIG_BSP_USING_ADC is not set
# CONFIG_BSP_USING_SDIO is not set
# CONFIG_BSP_USING_RTC is not set
CONFIG_BSP_USING_SDIO=y
CONFIG_BSP_USING_RTC=y
# CONFIG_BSP_USING_WDT is not set
# CONFIG_BSP_USING_HWTIMER is not set
# CONFIG_BSP_USING_PWM is not set

View File

@ -11,8 +11,6 @@ if rtconfig.PLATFORM in ['gcc']:
else:
CPPDEFINES = []
if GetDepend('BSP_USING_SDIO'):
src += ['mnt.c']
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
@ -13,6 +13,7 @@
*/
#include <rtdevice.h>
#include "dfs_fs.h"
#include "drv_pin.h"
/* defined the LED pin: GPIO1_IO4 */
@ -33,6 +34,18 @@ int main(void)
#endif
rt_pin_mode(LEDB_PIN, PIN_MODE_OUTPUT); /* Set GPIO as Output */
#ifdef RT_USING_SDIO
rt_thread_mdelay(2000);
if (dfs_mount("sd", "/", "elm", 0, NULL) == 0)
{
rt_kprintf("sd mounted to /\n");
}
else
{
rt_kprintf("sd mount to / failed\n");
}
#endif
while (1)
{
rt_pin_write(LEDB_PIN, PIN_HIGH); /* Set GPIO output 1 */

View File

@ -1,32 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* sdio filesystem support
* Change Logs:
* Date Author Notes
* 2021-10-10 supperthomas first version
*/
#include "dfs_fs.h"
#include <rtthread.h>
#include <rtdevice.h>
#ifdef BSP_USING_SDIO
/**
* @brief SDIO filesystem init
* @param void
* @retval 0: filesystem init success, -1: filesystem init failed
*/
static int sdio_fs_init(void)
{
int result = 0;
dfs_mount("sdcard0", "/", "elm", 0, 0);
return result;
}
INIT_ENV_EXPORT(sdio_fs_init);
#endif /* BSP_USING_SDIO */

View File

@ -1,110 +0,0 @@
/*
* Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-01-10 Kevin/Karl Add PS demo
*
*/
#include <rtdevice.h>
#include <string.h>
#include "tfm_ns_lock.h"
#include "psa_protected_storage.h"
#define TEST_UID_A 2U
#define ASSET_A "THEQUICKBROWNFOXJUMPSOVERALAZYDOG"
#define ASSET_A_SIZE (sizeof( ASSET_A ) - 1)
#define RESETDATA "THISIS"
#define RESETDATA_SIZE (sizeof( RESETDATA ) - 1)
#define READ_LENGTH (ASSET_A_SIZE > RESETDATA_SIZE ? \
ASSET_A_SIZE : RESETDATA_SIZE)
void protected_storage_demo_thread(void * parameters)
{
psa_ps_status_t status;
const psa_ps_uid_t uid = TEST_UID_A;
const psa_ps_create_flags_t flags = PSA_PS_FLAG_NONE;
uint8_t write_data[] = ASSET_A;
const uint32_t data_length = ASSET_A_SIZE;
uint8_t rewrite_data[] = RESETDATA;
const uint32_t reset_data_length = RESETDATA_SIZE;
uint8_t get_data[READ_LENGTH];
uint32_t counter = 0;
tfm_ns_lock_init();
for ( ; ; )
{
/* Call TF-M protected storage service and set the asset. */
status = psa_ps_set(uid, data_length, write_data, flags);
if (status != PSA_PS_SUCCESS)
{
rt_kprintf("[Protected Storage Asset A Set Round %ld] Fail\r\n", counter);
for( ; ; );
}
rt_kprintf("[Protected Storage Asset A Set Round %ld] Success\r\n", counter);
/* Read the asset. */
status = psa_ps_get(uid, 0, data_length, get_data);
if (status != PSA_PS_SUCCESS)
{
rt_kprintf("[Protected Storage Asset A Get Round %ld] Fail\r\n", counter);
for ( ; ; );
}
rt_kprintf("[Protected Storage Asset A Get Round %ld] Success\r\n", counter);
/* Check the read data. */
if (memcmp(write_data, get_data, sizeof(write_data) - 1) != 0)
{
rt_kprintf("[Protected Storage Asset A Get Round %ld] Get the wrong data\r\n", counter);
for ( ; ; );
}
/* Change the asset. */
status = psa_ps_set(uid, reset_data_length, rewrite_data, flags);
if (status != PSA_PS_SUCCESS)
{
rt_kprintf("[Protected Storage Asset A Reset Round %ld] Fail\r\n", counter);
}
rt_kprintf("[Protected Storage Asset A Reset Round %ld] Success\r\n", counter);
/* Read the asset. */
status = psa_ps_get(uid, 0, reset_data_length, get_data);
if (status != PSA_PS_SUCCESS)
{
rt_kprintf("[Protected Storage Asset A Get Round %ld] Fail\r\n", counter);
for ( ; ; );
}
rt_kprintf("[Protected Storage Asset A Get Round %ld] Success\r\n", counter);
/* Check the read data. */
if (memcmp(rewrite_data, get_data, sizeof(rewrite_data) - 1) != 0)
{
rt_kprintf("[Protected Storage Asset A Get Round %ld] Get the wrong data\r\n", counter);
for ( ; ; );
}
/* Remove the asset. */
status = psa_ps_remove(uid);
if (status != PSA_PS_SUCCESS)
{
rt_kprintf("[Protected Storage Asset A Remove Round %ld] Fail\r\n", counter);
for ( ; ; );
}
rt_kprintf("[Protected Storage Asset A Remove Round %ld] Success\r\n\n", counter);
/* Wait for a second. */
rt_thread_mdelay(1000);
counter++;
}
}
// end file

View File

@ -437,7 +437,7 @@
</option>
<option>
<name>CMSISDAPSelectedCPUBehaviour</name>
<state>0</state>
<state></state>
</option>
<option>
<name>ICpuName</name>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -340,7 +340,7 @@
<MiscControls>--target=arm-arm-none-eabi</MiscControls>
<Define>__STDC_LIMIT_MACROS, RT_USING_ARMLIBC, RT_USING_LIBC, __CLK_TCK=RT_TICK_PER_SECOND, __RTTHREAD__, DEBUG</Define>
<Undefine></Undefine>
<IncludePath>..\..\..\components\libc\posix\ipc;board;..\..\..\components\drivers\include;board\MCUX_Config\board;..\..\..\components\libc\compilers\common\extension\fcntl\octal;..\Libraries\LPC55S6X\middleware\sdmmc\port;..\Libraries\drivers;..\..\..\components\libc\posix\io\poll;..\Libraries\drivers\config;..\..\..\components\finsh;..\..\..\components\libc\compilers\common\include;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m33;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\Libraries\LPC55S6X\middleware\sdmmc\inc;..\..\..\components\libc\posix\io\stdio;applications;..\Libraries\CMSIS\Core\Include;..\Libraries\LPC55S6X\components\codec;.;..\..\..\components\libc\compilers\common\extension;..\Libraries\LPC55S6X\LPC55S6X;..\Libraries\LPC55S6X\LPC55S6X\drivers;..\..\..\components\drivers\include;..\..\..\include</IncludePath>
<IncludePath>..\..\..\components\libc\posix\ipc;board;..\..\..\components\drivers\include;..\..\..\components\drivers\include;board\MCUX_Config\board;..\..\..\components\libc\compilers\common\extension\fcntl\octal;..\Libraries\LPC55S6X\middleware\sdmmc\port;..\..\..\components\drivers\include;..\Libraries\drivers;..\..\..\components\dfs\include;..\..\..\components\libc\posix\io\poll;..\Libraries\drivers\config;..\..\..\components\dfs\filesystems\devfs;..\..\..\components\finsh;..\..\..\components\dfs\filesystems\elmfat;..\..\..\components\libc\compilers\common\include;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m33;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\Libraries\LPC55S6X\middleware\sdmmc\inc;..\..\..\components\libc\posix\io\stdio;..\..\..\components\utilities\libadt;applications;..\Libraries\CMSIS\Core\Include;..\Libraries\LPC55S6X\components\codec;.;..\..\..\components\libc\compilers\common\extension;..\Libraries\LPC55S6X\LPC55S6X;..\Libraries\LPC55S6X\LPC55S6X\drivers;..\..\..\components\drivers\include;..\..\..\include</IncludePath>
</VariousControls>
</Cads>
<Aads>
@ -381,6 +381,16 @@
</TargetArmAds>
</TargetOption>
<Groups>
<Group>
<GroupName>ADT</GroupName>
<Files>
<File>
<FileName>avl.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\utilities\libadt\avl.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Applications</GroupName>
<Files>
@ -524,6 +534,41 @@
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\misc\pin.c</FilePath>
</File>
<File>
<FileName>rtc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\rtc\rtc.c</FilePath>
</File>
<File>
<FileName>block_dev.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\sdio\block_dev.c</FilePath>
</File>
<File>
<FileName>gpt.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\sdio\gpt.c</FilePath>
</File>
<File>
<FileName>mmc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\sdio\mmc.c</FilePath>
</File>
<File>
<FileName>mmcsd_core.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\sdio\mmcsd_core.c</FilePath>
</File>
<File>
<FileName>sd.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\sdio\sd.c</FilePath>
</File>
<File>
<FileName>sdio.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\sdio\sdio.c</FilePath>
</File>
<File>
<FileName>serial.c</FileName>
<FileType>1</FileType>
@ -574,6 +619,16 @@
<FileType>1</FileType>
<FilePath>..\Libraries\drivers\drv_pin.c</FilePath>
</File>
<File>
<FileName>drv_rtc.c</FileName>
<FileType>1</FileType>
<FilePath>..\Libraries\drivers\drv_rtc.c</FilePath>
</File>
<File>
<FileName>drv_sdif.c</FileName>
<FileType>1</FileType>
<FilePath>..\Libraries\drivers\drv_sdif.c</FilePath>
</File>
<File>
<FileName>drv_uart.c</FileName>
<FileType>1</FileType>
@ -581,6 +636,51 @@
</File>
</Files>
</Group>
<Group>
<GroupName>Filesystem</GroupName>
<Files>
<File>
<FileName>devfs.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\dfs\filesystems\devfs\devfs.c</FilePath>
</File>
<File>
<FileName>dfs_elm.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\dfs\filesystems\elmfat\dfs_elm.c</FilePath>
</File>
<File>
<FileName>ff.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\dfs\filesystems\elmfat\ff.c</FilePath>
</File>
<File>
<FileName>ffunicode.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\dfs\filesystems\elmfat\ffunicode.c</FilePath>
</File>
<File>
<FileName>dfs.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\dfs\src\dfs.c</FilePath>
</File>
<File>
<FileName>dfs_file.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\dfs\src\dfs_file.c</FilePath>
</File>
<File>
<FileName>dfs_fs.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\dfs\src\dfs_fs.c</FilePath>
</File>
<File>
<FileName>dfs_posix.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\dfs\src\dfs_posix.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Finsh</GroupName>
<Files>
@ -604,6 +704,11 @@
<FileType>1</FileType>
<FilePath>..\..\..\components\finsh\cmd.c</FilePath>
</File>
<File>
<FileName>msh_file.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\finsh\msh_file.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -896,13 +1001,4 @@
<files/>
</RTE>
<LayerInfo>
<Layers>
<Layer>
<LayName>project</LayName>
<LayPrjMark>1</LayPrjMark>
</Layer>
</Layers>
</LayerInfo>
</Project>

View File

@ -37,6 +37,7 @@
/* Memory Management */
#define RT_PAGE_MAX_ORDER 11
#define RT_USING_MEMPOOL
#define RT_USING_SMALL_MEM
#define RT_USING_SMALL_MEM_AS_HEAP
@ -67,13 +68,33 @@
#define FINSH_THREAD_NAME "tshell"
#define FINSH_THREAD_PRIORITY 20
#define FINSH_THREAD_STACK_SIZE 4096
#define FINSH_USING_HISTORY
#define FINSH_HISTORY_LINES 5
#define FINSH_USING_SYMTAB
#define FINSH_CMD_SIZE 80
#define MSH_USING_BUILT_IN_COMMANDS
#define FINSH_USING_DESCRIPTION
#define FINSH_ARG_MAX 10
#define RT_USING_DFS
#define DFS_USING_POSIX
#define DFS_USING_WORKDIR
#define DFS_FILESYSTEMS_MAX 4
#define DFS_FILESYSTEM_TYPES_MAX 4
#define DFS_FD_MAX 16
#define RT_USING_DFS_ELMFAT
/* elm-chan's FatFs, Generic FAT Filesystem Module */
#define RT_DFS_ELM_CODE_PAGE 437
#define RT_DFS_ELM_WORD_ACCESS
#define RT_DFS_ELM_USE_LFN_3
#define RT_DFS_ELM_USE_LFN 3
#define RT_DFS_ELM_LFN_UNICODE_0
#define RT_DFS_ELM_LFN_UNICODE 0
#define RT_DFS_ELM_MAX_LFN 255
#define RT_DFS_ELM_DRIVES 2
#define RT_DFS_ELM_MAX_SECTOR_SIZE 512
#define RT_DFS_ELM_REENTRANT
#define RT_DFS_ELM_MUTEX_TIMEOUT 3000
#define RT_USING_DFS_DEVFS
/* Device Drivers */
@ -85,6 +106,13 @@
#define RT_SERIAL_RB_BUFSZ 64
#define RT_USING_I2C
#define RT_USING_PIN
#define RT_USING_RTC
#define RT_USING_SDIO
#define RT_SDIO_STACK_SIZE 512
#define RT_SDIO_THREAD_PRIORITY 15
#define RT_MMCSD_STACK_SIZE 1024
#define RT_MMCSD_THREAD_PREORITY 22
#define RT_MMCSD_MAX_PARTITION 16
/* Using USB */
@ -239,6 +267,8 @@
#define BSP_USING_I2C
#define BSP_USING_I2C4
#define HW_I2C4_BAUDRATE_100kHZ
#define BSP_USING_SDIO
#define BSP_USING_RTC
/* Onboard Peripheral Drivers */