mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 09:22:11 +00:00
update version to v2.0.5
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32_sdio.h
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief this file contains all the functions prototypes for the sd/mmc
|
||||
* card at32_sdio driver firmware library.
|
||||
**************************************************************************
|
||||
@@ -73,8 +73,8 @@ typedef enum
|
||||
typedef enum
|
||||
{
|
||||
/* sdio specific error defines ------------------------------------------*/
|
||||
SD_CMD_FAIL = 1, /*!< command response received (but crc check failed) */
|
||||
SD_DATA_FAIL = 2, /*!< data bock sent/received (crc check failed) */
|
||||
SD_CMD_FAIL = 1, /*!< command response received (but crc check error) */
|
||||
SD_DATA_FAIL = 2, /*!< data bock sent/received (crc check error) */
|
||||
SD_CMD_RSP_TIMEOUT = 3, /*!< command response timeout */
|
||||
SD_DATA_TIMEOUT = 4, /*!< data time out */
|
||||
SD_TX_UNDERRUN = 5, /*!< transmit fifo under-run */
|
||||
@@ -86,10 +86,10 @@ typedef enum
|
||||
SD_ERASE_SEQ_ERR = 11, /*!< an error in the sequence of erase command occurs. */
|
||||
SD_INVALID_ERASE_PARAM = 12, /*!< an invalid selection for erase groups */
|
||||
SD_WR_PROTECT_VIOLATION = 13, /*!< attempt to program a write protect block */
|
||||
SD_LOCK_UNLOCK_FAILED = 14, /*!< sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
|
||||
SD_CMD_CRC_FAILED = 15, /*!< crc check of the previous command failed */
|
||||
SD_LOCK_UNLOCK_ERROR = 14, /*!< sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
|
||||
SD_CMD_CRC_ERROR = 15, /*!< crc check of the previous command error */
|
||||
SD_ILLEGAL_CMD = 16, /*!< command is not legal for the card state */
|
||||
SD_CARD_ECC_FAILED = 17, /*!< card internal ecc was applied but failed to correct the data */
|
||||
SD_CARD_ECC_ERROR = 17, /*!< card internal ecc was applied but error to correct the data */
|
||||
SD_CARD_CONTROLLER_ERR = 18, /*!< internal card controller error */
|
||||
SD_GENERAL_UNKNOWN_ERROR = 19, /*!< general or unknown error */
|
||||
SD_STREAM_RD_UNDERRUN = 20, /*!< the card could not sustain data transfer in stream read operation. */
|
||||
@@ -104,7 +104,7 @@ typedef enum
|
||||
SD_SWITCH_ERROR = 29, /*!< switch error */
|
||||
SD_SDIO_DISABLED = 30, /*!< sdio disabled */
|
||||
SD_SDIO_FUNC_BUSY = 31, /*!< function busy */
|
||||
SD_SDIO_FUNC_FAILED = 32, /*!< function failed */
|
||||
SD_SDIO_FUNC_ERROR = 32, /*!< function error */
|
||||
SD_SDIO_UNKNOWN_FUNC = 33, /*!< unknown function */
|
||||
|
||||
/* standard error defines --------------------------------------------*/
|
||||
@@ -359,10 +359,10 @@ typedef struct
|
||||
#define SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000)
|
||||
#define SD_OCR_INVALID_ERASE_PARAM ((uint32_t)0x08000000)
|
||||
#define SD_OCR_WR_PROTECT_VIOLATION ((uint32_t)0x04000000)
|
||||
#define SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000)
|
||||
#define SD_OCR_CMD_CRC_FAILED ((uint32_t)0x00800000)
|
||||
#define SD_OCR_LOCK_UNLOCK_ERROR ((uint32_t)0x01000000)
|
||||
#define SD_OCR_CMD_CRC_ERROR ((uint32_t)0x00800000)
|
||||
#define SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000)
|
||||
#define SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000)
|
||||
#define SD_OCR_CARD_ECC_ERROR ((uint32_t)0x00200000)
|
||||
#define SD_OCR_CARD_CONTROLLER_ERR ((uint32_t)0x00100000)
|
||||
#define SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000)
|
||||
#define SD_OCR_STREAM_RD_UNDERRUN ((uint32_t)0x00040000)
|
||||
@@ -387,13 +387,13 @@ typedef struct
|
||||
*/
|
||||
#define SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000)
|
||||
#define SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000)
|
||||
#define SD_R6_CMD_CRC_FAILED ((uint32_t)0x00008000)
|
||||
#define SD_R6_CMD_CRC_ERROR ((uint32_t)0x00008000)
|
||||
#define SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000)
|
||||
#define SD_HIGH_CAPACITY ((uint32_t)0x40000000)
|
||||
#define SD_STD_CAPACITY ((uint32_t)0x00000000)
|
||||
#define SD_CHECK_PATTERN ((uint32_t)0x000001AA)
|
||||
#define SD_VOLTAGE_WINDOW_MMC ((uint32_t)0x80FF8000)
|
||||
#define SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF)
|
||||
#define SD_MAX_VOLT_TRIAL ((uint32_t)0x000000FF)
|
||||
#define SD_ALLZERO ((uint32_t)0x00000000)
|
||||
#define SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000)
|
||||
#define SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_clock.h
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief header file of clock program
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_conf.h
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief at32f415 config header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_int.h
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief header file of main interrupt service routines.
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file readme.txt
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief readme
|
||||
**************************************************************************
|
||||
*/
|
||||
@@ -17,4 +17,5 @@
|
||||
- sdio1_d2 pc10 ---> dat2
|
||||
- sdio1_d3 pc11 ---> dat3
|
||||
- sdio1_ck pc12 ---> clk
|
||||
- sdio1_cmd pd2 ---> cmd
|
||||
- sdio1_cmd pd2 ---> cmd
|
||||
for more detailed information. please refer to the application note document AN0105.
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32_sdio.c
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief this file provides a set of functions needed to manage the
|
||||
* sdio/mmc card memory.
|
||||
**************************************************************************
|
||||
@@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "at32_sdio.h"
|
||||
#include "at32f415_board.h"
|
||||
|
||||
/** @addtogroup AT32F415_periph_examples
|
||||
* @{
|
||||
@@ -73,6 +74,7 @@ sd_error_status_type sd_init(void)
|
||||
uint16_t clkdiv = 0;
|
||||
sd_error_status_type status = SD_OK;
|
||||
gpio_init_type gpio_init_struct = {0};
|
||||
uint8_t retry = 0;
|
||||
|
||||
/* gpioc and gpiod periph clock enable */
|
||||
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
|
||||
@@ -93,12 +95,17 @@ sd_error_status_type sd_init(void)
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_2;
|
||||
gpio_init(GPIOD, &gpio_init_struct);
|
||||
|
||||
/* reset sdio */
|
||||
sdio_reset(SDIOx);
|
||||
|
||||
/* power on */
|
||||
status = sd_power_on();
|
||||
|
||||
retry = 3;
|
||||
while(retry--){
|
||||
/* reset sdio */
|
||||
sdio_reset(SDIOx);
|
||||
/* power on */
|
||||
status = sd_power_on();
|
||||
|
||||
if(status == SD_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
if(status == SD_OK)
|
||||
{
|
||||
/* sdio card initialize */
|
||||
@@ -138,8 +145,8 @@ sd_error_status_type sd_init(void)
|
||||
{
|
||||
if(sd_card_info.card_type == SDIO_STD_CAPACITY_SD_CARD_V1_1 || sd_card_info.card_type == SDIO_STD_CAPACITY_SD_CARD_V2_0)
|
||||
{
|
||||
/* set sdio_ck to 4MHz */
|
||||
clkdiv = system_core_clock / 4000000;
|
||||
/* set sdio_ck to 12mhz */
|
||||
clkdiv = system_core_clock / 12000000;
|
||||
|
||||
if(clkdiv >= 2)
|
||||
{
|
||||
@@ -148,8 +155,8 @@ sd_error_status_type sd_init(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set sdio_ck to 4MHz */
|
||||
clkdiv = system_core_clock / 4000000;
|
||||
/* set sdio_ck to 48mhz */
|
||||
clkdiv = system_core_clock / 48000000;
|
||||
|
||||
if(clkdiv >= 2)
|
||||
{
|
||||
@@ -217,7 +224,7 @@ sd_error_status_type sd_power_on(void)
|
||||
/* enable to output sdio_ck */
|
||||
sdio_clock_enable(SDIOx, TRUE);
|
||||
|
||||
for(retry = 0; retry < 10; retry++)
|
||||
for(retry = 0; retry < 5; retry++)
|
||||
{
|
||||
/* send cmd0, get in idle stage */
|
||||
sdio_command_init_struct.argument = 0x0;
|
||||
@@ -227,21 +234,11 @@ sd_error_status_type sd_power_on(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
/* get command status */
|
||||
status = command_error();
|
||||
|
||||
if(status == SD_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if any errors occured, return status */
|
||||
if(status != SD_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* send cmd8, check card interface feature */
|
||||
@@ -252,7 +249,7 @@ sd_error_status_type sd_power_on(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
/* waiting R7 */
|
||||
@@ -273,7 +270,7 @@ sd_error_status_type sd_power_on(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
/* waiting R1 */
|
||||
@@ -285,6 +282,8 @@ sd_error_status_type sd_power_on(void)
|
||||
/* send acmd41, check voltage operation range */
|
||||
while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL))
|
||||
{
|
||||
delay_ms(10);
|
||||
|
||||
/* send cmd55 before acmd41 */
|
||||
sdio_command_init_struct.argument = 0x00;
|
||||
sdio_command_init_struct.cmd_index = SD_CMD_APP_CMD;
|
||||
@@ -293,7 +292,7 @@ sd_error_status_type sd_power_on(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
/* waiting R1 */
|
||||
@@ -313,7 +312,7 @@ sd_error_status_type sd_power_on(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
/* waiting R3 */
|
||||
@@ -350,6 +349,8 @@ sd_error_status_type sd_power_on(void)
|
||||
/* send cmd1 */
|
||||
while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL))
|
||||
{
|
||||
delay_ms(10);
|
||||
|
||||
sdio_command_init_struct.argument = SD_VOLTAGE_WINDOW_MMC;
|
||||
sdio_command_init_struct.cmd_index = SD_CMD_SEND_OP_COND;
|
||||
sdio_command_init_struct.rsp_type = SDIO_RESPONSE_SHORT;
|
||||
@@ -357,7 +358,7 @@ sd_error_status_type sd_power_on(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
/* waiting R3 */
|
||||
@@ -428,7 +429,7 @@ sd_error_status_type sd_card_init(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp2_error();
|
||||
@@ -455,7 +456,7 @@ sd_error_status_type sd_card_init(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp6_error(SD_CMD_SET_REL_ADDR, &rca_temp);
|
||||
@@ -476,7 +477,7 @@ sd_error_status_type sd_card_init(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp2_error();
|
||||
@@ -497,7 +498,7 @@ sd_error_status_type sd_card_init(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp2_error();
|
||||
@@ -806,7 +807,7 @@ sd_error_status_type sd_deselect_select(uint32_t addr)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
return command_rsp1_error(SD_CMD_SEL_DESEL_CARD);
|
||||
@@ -836,7 +837,7 @@ sd_error_status_type sdio_command_data_send(sdio_command_struct_type *sdio_cmd_i
|
||||
|
||||
/* sdio command config */
|
||||
sdio_data_config(SDIOx, sdio_data_init_t);
|
||||
/* enable DCSM */
|
||||
/* enable dcsm */
|
||||
sdio_data_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
length = sdio_data_init_t->data_length;
|
||||
@@ -855,7 +856,7 @@ sd_error_status_type sdio_command_data_send(sdio_command_struct_type *sdio_cmd_i
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, sdio_cmd_init_t);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(sdio_cmd_init_t->cmd_index);
|
||||
@@ -964,7 +965,7 @@ sd_error_status_type sdio_command_data_send(sdio_command_struct_type *sdio_cmd_i
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, sdio_cmd_init_t);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_STOP_TRANSMISSION);
|
||||
@@ -1037,7 +1038,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
end_addr = start_addr + (nblks - 1) * 512;
|
||||
}
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = SDIO_DATA_BLOCK_SIZE_1B;
|
||||
sdio_data_init_struct.data_length = 0 ;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT ;
|
||||
@@ -1052,7 +1053,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if(card_type == SDIO_MULTIMEDIA_CARD || card_type == SDIO_HIGH_SPEED_MULTIMEDIA_CARD)
|
||||
@@ -1065,7 +1066,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_ERASE_GRP_START);
|
||||
@@ -1081,7 +1082,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_ERASE_GRP_END);
|
||||
@@ -1097,7 +1098,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_ERASE);
|
||||
@@ -1117,7 +1118,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SD_ERASE_GRP_START);
|
||||
@@ -1133,7 +1134,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
if(status != SD_OK)
|
||||
@@ -1147,7 +1148,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_ERASE);
|
||||
@@ -1196,7 +1197,7 @@ sd_error_status_type sd_block_read(uint8_t *buf, long long addr, uint16_t blk_si
|
||||
addr >>= 9;
|
||||
}
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = SDIO_DATA_BLOCK_SIZE_1B;
|
||||
sdio_data_init_struct.data_length = 0;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT;
|
||||
@@ -1211,7 +1212,7 @@ sd_error_status_type sd_block_read(uint8_t *buf, long long addr, uint16_t blk_si
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if((blk_size > 0) && (blk_size <= 2048) && ((blk_size & (blk_size - 1)) == 0))
|
||||
@@ -1226,7 +1227,7 @@ sd_error_status_type sd_block_read(uint8_t *buf, long long addr, uint16_t blk_si
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SET_BLOCKLEN);
|
||||
@@ -1266,7 +1267,6 @@ sd_error_status_type sd_block_read(uint8_t *buf, long long addr, uint16_t blk_si
|
||||
* @param nblks: number of blocks to be read.
|
||||
* @retval sd_error_status_type: sd card error code.
|
||||
*/
|
||||
__align(4) uint32_t *tempbuff;
|
||||
sd_error_status_type sd_mult_blocks_read(uint8_t *buf, long long addr, uint16_t blk_size, uint32_t nblks)
|
||||
{
|
||||
sd_error_status_type status = SD_OK;
|
||||
@@ -1281,7 +1281,7 @@ sd_error_status_type sd_mult_blocks_read(uint8_t *buf, long long addr, uint16_t
|
||||
addr >>= 9;
|
||||
}
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = (sdio_block_size_type)0;
|
||||
sdio_data_init_struct.data_length = 0;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT;
|
||||
@@ -1296,7 +1296,7 @@ sd_error_status_type sd_mult_blocks_read(uint8_t *buf, long long addr, uint16_t
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if((blk_size > 0) && (blk_size <= 2048) && ((blk_size & (blk_size - 1)) == 0))
|
||||
@@ -1311,7 +1311,7 @@ sd_error_status_type sd_mult_blocks_read(uint8_t *buf, long long addr, uint16_t
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SET_BLOCKLEN);
|
||||
@@ -1370,7 +1370,7 @@ sd_error_status_type sd_block_write(const uint8_t *buf, long long addr, uint16_t
|
||||
|
||||
SDIOx->dtctrl = 0x0;
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = (sdio_block_size_type)0;
|
||||
sdio_data_init_struct.data_length = 0;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT;
|
||||
@@ -1385,7 +1385,7 @@ sd_error_status_type sd_block_write(const uint8_t *buf, long long addr, uint16_t
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if(card_type == SDIO_HIGH_CAPACITY_SD_CARD)
|
||||
@@ -1406,7 +1406,7 @@ sd_error_status_type sd_block_write(const uint8_t *buf, long long addr, uint16_t
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SET_BLOCKLEN);
|
||||
@@ -1492,7 +1492,7 @@ sd_error_status_type sd_mult_blocks_write(const uint8_t *buf, long long addr, ui
|
||||
|
||||
SDIOx->dtctrl = 0x0;
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = (sdio_block_size_type)0;
|
||||
sdio_data_init_struct.data_length = 0;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT;
|
||||
@@ -1507,7 +1507,7 @@ sd_error_status_type sd_mult_blocks_write(const uint8_t *buf, long long addr, ui
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if(card_type == SDIO_HIGH_CAPACITY_SD_CARD)
|
||||
@@ -1528,7 +1528,7 @@ sd_error_status_type sd_mult_blocks_write(const uint8_t *buf, long long addr, ui
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SET_BLOCKLEN);
|
||||
@@ -1574,7 +1574,7 @@ sd_error_status_type sd_mult_blocks_write(const uint8_t *buf, long long addr, ui
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_APP_CMD);
|
||||
@@ -1592,7 +1592,7 @@ sd_error_status_type sd_mult_blocks_write(const uint8_t *buf, long long addr, ui
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SET_BLOCK_COUNT);
|
||||
@@ -1649,7 +1649,7 @@ sd_error_status_type mmc_stream_read(uint8_t *buf, long long addr, uint32_t len)
|
||||
|
||||
SDIOx->dtctrl = 0x0;
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = SDIO_DATA_BLOCK_SIZE_1B;
|
||||
sdio_data_init_struct.data_length = 0 ;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT ;
|
||||
@@ -1664,7 +1664,7 @@ sd_error_status_type mmc_stream_read(uint8_t *buf, long long addr, uint32_t len)
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
/* send cmd11, read data */
|
||||
sdio_command_init_struct.argument = addr;
|
||||
@@ -1703,7 +1703,7 @@ sd_error_status_type mmc_stream_write(uint8_t *buf, long long addr, uint32_t len
|
||||
|
||||
SDIOx->dtctrl = 0x0;
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = SDIO_DATA_BLOCK_SIZE_1B;
|
||||
sdio_data_init_struct.data_length = 0;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT;
|
||||
@@ -1718,7 +1718,7 @@ sd_error_status_type mmc_stream_write(uint8_t *buf, long long addr, uint32_t len
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
/* send cmd20, write data */
|
||||
sdio_command_init_struct.argument = addr;
|
||||
@@ -1792,7 +1792,7 @@ sd_error_status_type sd_irq_service(void)
|
||||
sdio_command_init_struct.wait_type = SDIO_WAIT_FOR_NO;
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
transfer_error = command_rsp1_error(SD_CMD_STOP_TRANSMISSION);
|
||||
}
|
||||
@@ -2183,7 +2183,7 @@ sd_error_status_type command_rsp6_error(uint8_t cmd, uint16_t *prca)
|
||||
|
||||
response = sdio_response_get(SDIOx, SDIO_RSP1_INDEX);
|
||||
|
||||
if(SD_ALLZERO == (response & (SD_R6_GENERAL_UNKNOWN_ERROR | SD_R6_ILLEGAL_CMD | SD_R6_CMD_CRC_FAILED)))
|
||||
if(SD_ALLZERO == (response & (SD_R6_GENERAL_UNKNOWN_ERROR | SD_R6_ILLEGAL_CMD | SD_R6_CMD_CRC_ERROR)))
|
||||
{
|
||||
*prca = (uint16_t)(response >> 16);
|
||||
return status;
|
||||
@@ -2199,9 +2199,9 @@ sd_error_status_type command_rsp6_error(uint8_t cmd, uint16_t *prca)
|
||||
return SD_ILLEGAL_CMD;
|
||||
}
|
||||
|
||||
if(response & SD_R6_CMD_CRC_FAILED)
|
||||
if(response & SD_R6_CMD_CRC_ERROR)
|
||||
{
|
||||
return SD_CMD_CRC_FAILED;
|
||||
return SD_CMD_CRC_ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -2233,7 +2233,7 @@ sd_error_status_type sd_bus_wide_enable(confirm_state new_state)
|
||||
/* check card locked or not */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if(sd_card_info.sd_scr_reg.sd_bus_width)
|
||||
@@ -2245,7 +2245,7 @@ sd_error_status_type sd_bus_wide_enable(confirm_state new_state)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_APP_CMD);
|
||||
@@ -2262,7 +2262,7 @@ sd_error_status_type sd_bus_wide_enable(confirm_state new_state)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_APP_SD_SET_BUSWIDTH);
|
||||
@@ -2293,7 +2293,7 @@ sd_error_status_type mmc_switch(uint8_t set, uint8_t index, uint8_t value)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_HS_SWITCH);
|
||||
@@ -2355,7 +2355,7 @@ sd_error_status_type sd_switch(uint32_t mode, uint32_t group, uint8_t value, uin
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SET_BLOCKLEN);
|
||||
@@ -2400,7 +2400,7 @@ sd_error_status_type check_card_programming(uint8_t *p_status)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
sts_reg = SDIOx->sts;
|
||||
@@ -2459,7 +2459,7 @@ sd_error_status_type sd_status_send(uint32_t *p_card_status)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SEND_STATUS);
|
||||
@@ -2513,7 +2513,7 @@ sd_error_status_type scr_find(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SET_BLOCKLEN);
|
||||
@@ -2531,7 +2531,7 @@ sd_error_status_type scr_find(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_APP_CMD);
|
||||
@@ -2558,7 +2558,7 @@ sd_error_status_type scr_find(void)
|
||||
|
||||
/* sdio command config */
|
||||
sdio_command_config(SDIOx, &sdio_command_init_struct);
|
||||
/* enable CCSM */
|
||||
/* enable ccsm */
|
||||
sdio_command_state_machine_enable(SDIOx, TRUE);
|
||||
|
||||
status = command_rsp1_error(SD_CMD_SD_APP_SEND_SCR);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_clock.c
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief system clock config program
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_int.c
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief main interrupt service routines.
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file main.c
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief main program
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32_sdio.h
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief this file contains all the functions prototypes for the sd/mmc
|
||||
* card at32_sdio driver firmware library.
|
||||
**************************************************************************
|
||||
@@ -73,8 +73,8 @@ typedef enum
|
||||
typedef enum
|
||||
{
|
||||
/* sdio specific error defines ------------------------------------------*/
|
||||
SD_CMD_FAIL = 1, /*!< command response received (but crc check failed) */
|
||||
SD_DATA_FAIL = 2, /*!< data bock sent/received (crc check failed) */
|
||||
SD_CMD_FAIL = 1, /*!< command response received (but crc check error) */
|
||||
SD_DATA_FAIL = 2, /*!< data bock sent/received (crc check error) */
|
||||
SD_CMD_RSP_TIMEOUT = 3, /*!< command response timeout */
|
||||
SD_DATA_TIMEOUT = 4, /*!< data time out */
|
||||
SD_TX_UNDERRUN = 5, /*!< transmit fifo under-run */
|
||||
@@ -86,10 +86,10 @@ typedef enum
|
||||
SD_ERASE_SEQ_ERR = 11, /*!< an error in the sequence of erase command occurs. */
|
||||
SD_INVALID_ERASE_PARAM = 12, /*!< an invalid selection for erase groups */
|
||||
SD_WR_PROTECT_VIOLATION = 13, /*!< attempt to program a write protect block */
|
||||
SD_LOCK_UNLOCK_FAILED = 14, /*!< sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
|
||||
SD_CMD_CRC_FAILED = 15, /*!< crc check of the previous command failed */
|
||||
SD_LOCK_UNLOCK_ERROR = 14, /*!< sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
|
||||
SD_CMD_CRC_ERROR = 15, /*!< crc check of the previous command error */
|
||||
SD_ILLEGAL_CMD = 16, /*!< command is not legal for the card state */
|
||||
SD_CARD_ECC_FAILED = 17, /*!< card internal ecc was applied but failed to correct the data */
|
||||
SD_CARD_ECC_ERROR = 17, /*!< card internal ecc was applied but error to correct the data */
|
||||
SD_CARD_CONTROLLER_ERR = 18, /*!< internal card controller error */
|
||||
SD_GENERAL_UNKNOWN_ERROR = 19, /*!< general or unknown error */
|
||||
SD_STREAM_RD_UNDERRUN = 20, /*!< the card could not sustain data transfer in stream read operation. */
|
||||
@@ -104,7 +104,7 @@ typedef enum
|
||||
SD_SWITCH_ERROR = 29, /*!< switch error */
|
||||
SD_SDIO_DISABLED = 30, /*!< sdio disabled */
|
||||
SD_SDIO_FUNC_BUSY = 31, /*!< function busy */
|
||||
SD_SDIO_FUNC_FAILED = 32, /*!< function failed */
|
||||
SD_SDIO_FUNC_ERROR = 32, /*!< function error */
|
||||
SD_SDIO_UNKNOWN_FUNC = 33, /*!< unknown function */
|
||||
|
||||
/* standard error defines --------------------------------------------*/
|
||||
@@ -359,10 +359,10 @@ typedef struct
|
||||
#define SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000)
|
||||
#define SD_OCR_INVALID_ERASE_PARAM ((uint32_t)0x08000000)
|
||||
#define SD_OCR_WR_PROTECT_VIOLATION ((uint32_t)0x04000000)
|
||||
#define SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000)
|
||||
#define SD_OCR_CMD_CRC_FAILED ((uint32_t)0x00800000)
|
||||
#define SD_OCR_LOCK_UNLOCK_ERROR ((uint32_t)0x01000000)
|
||||
#define SD_OCR_CMD_CRC_ERROR ((uint32_t)0x00800000)
|
||||
#define SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000)
|
||||
#define SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000)
|
||||
#define SD_OCR_CARD_ECC_ERROR ((uint32_t)0x00200000)
|
||||
#define SD_OCR_CARD_CONTROLLER_ERR ((uint32_t)0x00100000)
|
||||
#define SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000)
|
||||
#define SD_OCR_STREAM_RD_UNDERRUN ((uint32_t)0x00040000)
|
||||
@@ -387,13 +387,13 @@ typedef struct
|
||||
*/
|
||||
#define SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000)
|
||||
#define SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000)
|
||||
#define SD_R6_CMD_CRC_FAILED ((uint32_t)0x00008000)
|
||||
#define SD_R6_CMD_CRC_ERROR ((uint32_t)0x00008000)
|
||||
#define SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000)
|
||||
#define SD_HIGH_CAPACITY ((uint32_t)0x40000000)
|
||||
#define SD_STD_CAPACITY ((uint32_t)0x00000000)
|
||||
#define SD_CHECK_PATTERN ((uint32_t)0x000001AA)
|
||||
#define SD_VOLTAGE_WINDOW_MMC ((uint32_t)0x80FF8000)
|
||||
#define SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF)
|
||||
#define SD_MAX_VOLT_TRIAL ((uint32_t)0x000000FF)
|
||||
#define SD_ALLZERO ((uint32_t)0x00000000)
|
||||
#define SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000)
|
||||
#define SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_clock.h
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief header file of clock program
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_conf.h
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief at32f415 config header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_int.h
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief header file of main interrupt service routines.
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file readme.txt
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief readme
|
||||
**************************************************************************
|
||||
*/
|
||||
@@ -17,3 +17,4 @@
|
||||
- sdio1_d3 pc11 ---> dat3
|
||||
- sdio1_ck pc12 ---> clk
|
||||
- sdio1_cmd pd2 ---> cmd
|
||||
for more detailed information. please refer to the application note document AN0105.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32_sdio.c
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief this file provides a set of functions needed to manage the
|
||||
* sdio/mmc card memory.
|
||||
**************************************************************************
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "at32_sdio.h"
|
||||
#include "at32f415_board.h"
|
||||
|
||||
/** @addtogroup AT32F415_periph_examples
|
||||
* @{
|
||||
@@ -74,6 +75,7 @@ sd_error_status_type sd_init(void)
|
||||
uint16_t clkdiv = 0;
|
||||
sd_error_status_type status = SD_OK;
|
||||
gpio_init_type gpio_init_struct = {0};
|
||||
uint8_t retry = 0;
|
||||
|
||||
/* gpioc and gpiod periph clock enable */
|
||||
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
|
||||
@@ -94,12 +96,17 @@ sd_error_status_type sd_init(void)
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_2;
|
||||
gpio_init(GPIOD, &gpio_init_struct);
|
||||
|
||||
/* reset sdio */
|
||||
sdio_reset(SDIOx);
|
||||
|
||||
/* power on */
|
||||
status = sd_power_on();
|
||||
|
||||
retry = 3;
|
||||
while(retry--){
|
||||
/* reset sdio */
|
||||
sdio_reset(SDIOx);
|
||||
/* power on */
|
||||
status = sd_power_on();
|
||||
|
||||
if(status == SD_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
if(status == SD_OK)
|
||||
{
|
||||
/* sdio card initialize */
|
||||
@@ -139,8 +146,8 @@ sd_error_status_type sd_init(void)
|
||||
{
|
||||
if(sd_card_info.card_type == SDIO_STD_CAPACITY_SD_CARD_V1_1 || sd_card_info.card_type == SDIO_STD_CAPACITY_SD_CARD_V2_0)
|
||||
{
|
||||
/* set sdio_ck to 4mhz */
|
||||
clkdiv = system_core_clock / 4000000;
|
||||
/* set sdio_ck to 12mhz */
|
||||
clkdiv = system_core_clock / 12000000;
|
||||
|
||||
if(clkdiv >= 2)
|
||||
{
|
||||
@@ -149,8 +156,8 @@ sd_error_status_type sd_init(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set sdio_ck to 4mhz */
|
||||
clkdiv = system_core_clock / 4000000;
|
||||
/* set sdio_ck to 48mhz */
|
||||
clkdiv = system_core_clock / 48000000;
|
||||
|
||||
if(clkdiv >= 2)
|
||||
{
|
||||
@@ -224,7 +231,7 @@ sd_error_status_type sd_power_on(void)
|
||||
/* enable to output sdio_ck */
|
||||
sdio_clock_enable(SDIOx, TRUE);
|
||||
|
||||
for(retry = 0; retry < 10; retry++)
|
||||
for(retry = 0; retry < 5; retry++)
|
||||
{
|
||||
/* send cmd0, get in idle stage */
|
||||
sdio_command_init_struct.argument = 0x0;
|
||||
@@ -239,16 +246,6 @@ sd_error_status_type sd_power_on(void)
|
||||
|
||||
/* get command status */
|
||||
status = command_error();
|
||||
|
||||
if(status == SD_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if any errors occured, return status */
|
||||
if(status != SD_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* send cmd8, check card interface feature */
|
||||
@@ -292,6 +289,8 @@ sd_error_status_type sd_power_on(void)
|
||||
/* send acmd41, check voltage operation range */
|
||||
while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL))
|
||||
{
|
||||
delay_ms(10);
|
||||
|
||||
/* send cmd55 before acmd41 */
|
||||
sdio_command_init_struct.argument = 0x00;
|
||||
sdio_command_init_struct.cmd_index = SD_CMD_APP_CMD;
|
||||
@@ -357,6 +356,8 @@ sd_error_status_type sd_power_on(void)
|
||||
/* send cmd1 */
|
||||
while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL))
|
||||
{
|
||||
delay_ms(10);
|
||||
|
||||
sdio_command_init_struct.argument = SD_VOLTAGE_WINDOW_MMC;
|
||||
sdio_command_init_struct.cmd_index = SD_CMD_SEND_OP_COND;
|
||||
sdio_command_init_struct.rsp_type = SDIO_RESPONSE_SHORT;
|
||||
@@ -1044,7 +1045,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
end_addr = start_addr + (nblks - 1) * 512;
|
||||
}
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = SDIO_DATA_BLOCK_SIZE_1B;
|
||||
sdio_data_init_struct.data_length = 0 ;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT ;
|
||||
@@ -1059,7 +1060,7 @@ sd_error_status_type sd_blocks_erase(long long addr, uint32_t nblks)
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if(card_type == SDIO_MULTIMEDIA_CARD || card_type == SDIO_HIGH_SPEED_MULTIMEDIA_CARD)
|
||||
@@ -1218,7 +1219,7 @@ sd_error_status_type sd_block_read(uint8_t *buf, long long addr, uint16_t blk_si
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if((blk_size > 0) && (blk_size <= 2048) && ((blk_size & (blk_size - 1)) == 0))
|
||||
@@ -1302,7 +1303,7 @@ sd_error_status_type sd_mult_blocks_read(uint8_t *buf, long long addr, uint16_t
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if((blk_size > 0) && (blk_size <= 2048) && ((blk_size & (blk_size - 1)) == 0))
|
||||
@@ -1391,7 +1392,7 @@ sd_error_status_type sd_block_write(const uint8_t *buf, long long addr, uint16_t
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if(card_type == SDIO_HIGH_CAPACITY_SD_CARD)
|
||||
@@ -1513,7 +1514,7 @@ sd_error_status_type sd_mult_blocks_write(const uint8_t *buf, long long addr, ui
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if(card_type == SDIO_HIGH_CAPACITY_SD_CARD)
|
||||
@@ -1655,7 +1656,7 @@ sd_error_status_type mmc_stream_read(uint8_t *buf, long long addr, uint32_t len)
|
||||
|
||||
SDIOx->dtctrl = 0x0;
|
||||
|
||||
/* clear DCSM configuration */
|
||||
/* clear dcsm configuration */
|
||||
sdio_data_init_struct.block_size = SDIO_DATA_BLOCK_SIZE_1B;
|
||||
sdio_data_init_struct.data_length = 0 ;
|
||||
sdio_data_init_struct.timeout = SD_DATATIMEOUT ;
|
||||
@@ -1670,7 +1671,7 @@ sd_error_status_type mmc_stream_read(uint8_t *buf, long long addr, uint32_t len)
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
/* send cmd11, read data */
|
||||
sdio_command_init_struct.argument = addr;
|
||||
@@ -1724,7 +1725,7 @@ sd_error_status_type mmc_stream_write(uint8_t *buf, long long addr, uint32_t len
|
||||
/* check card locked */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
/* send cmd20, write data */
|
||||
sdio_command_init_struct.argument = addr;
|
||||
@@ -2189,7 +2190,7 @@ sd_error_status_type command_rsp6_error(uint8_t cmd, uint16_t *prca)
|
||||
|
||||
response = sdio_response_get(SDIOx, SDIO_RSP1_INDEX);
|
||||
|
||||
if(SD_ALLZERO == (response & (SD_R6_GENERAL_UNKNOWN_ERROR | SD_R6_ILLEGAL_CMD | SD_R6_CMD_CRC_FAILED)))
|
||||
if(SD_ALLZERO == (response & (SD_R6_GENERAL_UNKNOWN_ERROR | SD_R6_ILLEGAL_CMD | SD_R6_CMD_CRC_ERROR)))
|
||||
{
|
||||
*prca = (uint16_t)(response >> 16);
|
||||
return status;
|
||||
@@ -2205,9 +2206,9 @@ sd_error_status_type command_rsp6_error(uint8_t cmd, uint16_t *prca)
|
||||
return SD_ILLEGAL_CMD;
|
||||
}
|
||||
|
||||
if(response & SD_R6_CMD_CRC_FAILED)
|
||||
if(response & SD_R6_CMD_CRC_ERROR)
|
||||
{
|
||||
return SD_CMD_CRC_FAILED;
|
||||
return SD_CMD_CRC_ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -2239,7 +2240,7 @@ sd_error_status_type sd_bus_wide_enable(confirm_state new_state)
|
||||
/* check card locked or not */
|
||||
if(response & SD_CARD_LOCKED)
|
||||
{
|
||||
return SD_LOCK_UNLOCK_FAILED;
|
||||
return SD_LOCK_UNLOCK_ERROR;
|
||||
}
|
||||
|
||||
if(sd_card_info.sd_scr_reg.sd_bus_width)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_clock.c
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief system clock config program
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f415_int.c
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief main interrupt service routines.
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file main.c
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @version v2.0.5
|
||||
* @date 2022-05-20
|
||||
* @brief main program
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
Reference in New Issue
Block a user