SD Exported Functions
- group SD_Exported_Functions
Functions
-
void sd_config_init(uint8_t sdio_id, T_SD_CONFIG *sd_cfg)
Config the SD card type information for SD card.
Example usage
static const T_SD_CONFIG sd_card_cfg = { .sd_if_type = SD_IF_SD_CARD, .sdh_group = GROUP_0, .sdh_bus_width = SD_BUS_WIDTH_4B, .sd_bus_clk_sel = SD_BUS_CLK_20M }; void sd_init(void) { sd_config_init(SDHC_ID0, (T_SD_CONFIG *)&sd_card_cfg); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
sd_cfg – [in] Point to SD card configuration parameters, please refer to T_SD_CONFIG.
-
void sd_board_init(uint8_t sdio_id)
Config the PAD and PINMUX for SD card.
Example usage
void sd_init(void) { sd_config_init(SDHC_ID0, (T_SD_CONFIG *)&sd_card_cfg); sd_board_init(SDHC_ID0); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
-
T_SD_STATUS sd_card_init(uint8_t sdio_id)
Initial the SD card.
Example usage
void sd_init(void) { sd_config_init(SDHC_ID0, (T_SD_CONFIG *)&sd_card_cfg); sd_board_init(SDHC_ID0); sd_card_init(SDHC_ID0); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
- Return values:
0 – The SD card was initialized successfully.
0x1-0xFF – The SD card was failed to initialized.
- Returns:
The SD card init status, 0 is SD_OK. Please refer to T_SD_STATUS.
-
void sd_suspend(uint8_t sdio_id)
Suspend the SD host by disable SD CLK, when SD card is not powered off. Use sd_resume can be restored. At this time, SD card does not need to be powered on and initialized again.
Example usage
void sd_test(void) { sd_suspend(SDHC_ID0); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
-
void sd_resume(uint8_t sdio_id)
Resume the PAD config and SD host controller power on.
Example usage
void sd_test(void) { sd_resume(SDHC_ID0); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
-
T_SD_STATUS sd_init(uint8_t sdio_id)
Initialize the SD PAD, SD host and SD card, when SD card is powered off.
Example usage
void sd_test(void) { sd_init(SDHC_ID0); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
- Return values:
0 – The SD card was initialized successfully.
0x1-0xFF – The SD card was failed to initialized.
- Returns:
The SD card init status, 0 is SD_OK. Please refer to T_SD_STATUS.
-
void sd_print_binary_data(uint8_t *p, uint32_t len)
Print the SD card binary data by TRACE_BINARY.
Example usage
#define OPER_SD_CARD_ADDR ((uint32_t)0x8000) uint8_t *test_buf = NULL; void sd_test(void) { test_buf = os_mem_alloc(OS_MEM_TYPE_BUFFER, 512); sd_read(SDHC_ID0, OPER_SD_CARD_ADDR, (uint32_t)test_buf, 512, 1); sd_print_binary_data(test_buf, 512); }
- Parameters:
p – [in] Point to test buffer for SD read or write. This parameter must range from 0x0 to 0xFF.
len – [in] The data length to be printed. This parameter must range from 0x0 to 0xFFFFFFFF.
-
T_SD_STATUS sd_erase(uint8_t sdio_id, uint32_t start_addr, uint32_t end_addr)
Erase SD card from the specified start address to end address.
Example usage
void sd_test(void) { sd_erase(SDHC_ID0, start_addr, end_addr); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
start_addr – [in] The SD card start address to be erased. This parameter must range from 0x0 to 0xFFFFFFFF.
end_addr – [in] The SD card end address to be erased. This parameter must range from 0x0 to 0xFFFFFFFF.
- Return values:
0 – The SD card was erased successfully.
0x1-0xFF – The SD card was failed to erased.
- Returns:
The SD card erase status, 0 is SD_OK. Please refer to T_SD_STATUS.
-
T_SD_STATUS sd_read(uint8_t sdio_id, uint32_t sector, uint32_t buf, uint16_t blk_size, uint16_t blk_num)
Read data from a specified address in SD card.
Example usage
void sd_test(void) { uint32_t sd_status = 0; sd_status = sd_read(SDHC_ID0, OPER_SD_CARD_ADDR, (uint32_t)test_buf, SINGLE_BLOCK_SIZE, BLOCK_NUM); if (sd_status != 0) { IO_PRINT_ERROR0("sd_read fail"); return ; } }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
sector – [in] The specified SD card address to read. This parameter must range from 0x0 to 0xFFFFFFFF.
buf – [in] The buffer of SD card to read data. The buf address must be 4 bytes aligned and must range from 0x0 to 0xFF.
blk_size – [in] The block size of SD card to read. This parameter is recommended to set 512.
blk_num – [in] The block number of SD card to read. This parameter must range from 0x0 to 0xFFFF.
- Return values:
0 – The SD card was read successfully.
0x1-0xFF – The SD card was failed to read.
- Returns:
The SD card read status, 0 is SD_OK. Please refer to T_SD_STATUS.
-
T_SD_STATUS sd_write(uint8_t sdio_id, uint32_t sector, uint32_t buf, uint16_t blk_size, uint16_t blk_num)
Write data from a specified address in SD card.
Example usage
void sd_test(void) { uint32_t sd_status = 0; sd_status = sd_write(SDHC_ID0, OPER_SD_CARD_ADDR, (uint32_t)test_buf, SINGLE_BLOCK_SIZE, BLOCK_NUM); if (sd_status != 0) { IO_PRINT_ERROR0("sd_write fail"); return ; } }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
sector – [in] The specified SD card address to write. This parameter must range from 0x0 to 0xFFFFFFFF.
buf – [in] The buffer of SD card to write data. The buf address must be 4 bytes aligned and must range from 0x0 to 0xFF.
blk_size – [in] The block size of SD card to write. This parameter is recommended to set 512.
blk_num – [in] The block number of SD card to write. This parameter must range from 0x0 to 0xFFFF.
- Return values:
0 – The SD card was write successfully.
0x1-0xFF – The SD card was failed to write.
- Returns:
The SD card write status, 0 is SD_OK. Please refer to T_SD_STATUS.
-
T_SD_STATUS sd_set_block_len(uint8_t sdio_id, uint32_t block_len)
Set block length for standard capacity SD card.
Example usage
void sd_test(void) { sd_set_block_len(SDHC_ID0, block_len); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
block_len – [in] The block length to set. This parameter must range from 0x0 to 0xFFFFFFFF.
- Return values:
0 – The SD card block length was set successfully.
0x1-0xFF – The SD card block length was failed to set.
- Returns:
The SD card set block length status, 0 is SD_OK. Please refer to T_SD_STATUS.
-
void sd_sdh_clk_cmd(uint8_t sdio_id, bool NewState)
Start or stop the SD host operation clock.
Example usage
void sd_init(void) { sd_sdh_clk_cmd(SDHC_ID0, true); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
NewState – [in] New state of the SD host operation clock, can be set to true or false.
true Start the SD host operation clock.
false Stop the SD host operation clock.
-
T_SD_STATUS sd_check_program_status(uint8_t sdio_id)
Check if the SD card is in programming state.
Example usage
void sd_test(void) { uint32_t sd_status = 0; sd_status = sd_check_program_status(SDHC_ID0); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
- Return values:
0 – The SD card was checked successfully.
0x1-0xFF – The SD card was failed to check.
- Returns:
The SD card check program status, 0 is SD_OK. Please refer to T_SD_STATUS.
-
uint32_t sd_get_dev_block_size(uint8_t sdio_id)
Get the device block size.
Example usage
void test(void) { uint32_t block_size = 0; block_size = sd_get_dev_block_size(SDHC_ID0); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
- Returns:
The block size of device.
-
uint64_t sd_get_dev_capacity(uint8_t sdio_id)
Get the device capacity in bytes.
Example usage
void test(void) { uint64_t capacity = 0; capacity = sd_get_dev_capacity(SDHC_ID0); }
- Parameters:
sdio_id – [in] Identifier to select the SDIO peripheral to be configured, please refer to T_SDHC_ID.
- Returns:
The capacity of device.
-
void sd_config_init(uint8_t sdio_id, T_SD_CONFIG *sd_cfg)