|
px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
|
Driver that communicates with an SD (Secure Digital) Card using SPI.
File(s):
Reference:
Data Structures | |
| struct | px_sd_cid_t |
| CID - Card ID register; Ref 1. Paragraph "5.2 CID Register", page 113. More... | |
| struct | px_sd_csd_t |
| CSD - Card Specific Data register; Paragraph "5.3 CSD Register", page 114. More... | |
| union | px_sd_csd_t.ver |
| struct | px_sd_csd_t.ver.csd_1_0 |
| struct | px_sd_csd_t.ver.csd_2_0 |
Macros | |
| #define | PX_SD_MAX_SPI_CLOCK_HZ 25000000ul |
| Maximum SPI Clock rate. More... | |
| #define | PX_SD_SPI_MODE PX_SPI_MODE0 |
| SPI Clock / Data phase. More... | |
| #define | PX_SD_SPI_DATA_ORDER PX_SPI_DATA_ORDER_MSB |
| SPI Data order. More... | |
| #define | PX_SD_SPI_MO_DUMMY_BYTE 0xff |
| SPI Master Out dummy byte. More... | |
| #define | PX_SD_BLOCK_SIZE 512ul |
| Size of each data block. More... | |
Functions | |
| void | px_sd_init (px_spi_handle_t *handle) |
| Initialise driver. More... | |
| bool | px_sd_reset (void) |
| Detect and reset SD card. More... | |
| bool | px_sd_rd_cid (px_sd_cid_t *cid) |
| Read Card ID Register. More... | |
| bool | px_sd_rd_csd (px_sd_csd_t *csd) |
| Read Card Specific Data. More... | |
| bool | px_sd_get_status (uint16_t *status) |
| Read Card Status. More... | |
| uint32_t | px_sd_get_capacity_in_blocks (const px_sd_csd_t *csd) |
| Extract and calculate card capacity from Card Specific Data (CSD). More... | |
| bool | px_sd_rd_block (uint8_t *data, uint32_t block_adr) |
| Read a data block from the SD card. More... | |
| uint8_t | px_sd_rd_blocks (uint8_t *data, uint32_t block_adr, uint8_t nr_of_blocks) |
| Read a number of data blocks from the SD card. More... | |
| bool | px_sd_wr_block (const uint8_t *data, uint32_t block_adr) |
| Write a data block to the SD card. More... | |
| uint8_t | px_sd_wr_blocks (const uint8_t *data, uint32_t block_adr, uint8_t nr_of_blocks) |
| Write a number of data blocks to the SD card. More... | |
| bool | px_sd_wait_wr_is_finished (void) |
| Wait up to 500 ms for write block transaction to finish. More... | |
| struct px_sd_cid_t |
CID - Card ID register; Ref 1. Paragraph "5.2 CID Register", page 113.
| struct px_sd_csd_t |
CSD - Card Specific Data register; Paragraph "5.3 CSD Register", page 114.
| Data Fields | ||
|---|---|---|
| uint8_t | reserved1: 6 | |
| uint8_t | csd_structure: 2 | CSD structure version 1.0 or 2.0. |
| uint8_t | taac | data read access-time-1 |
| uint8_t | nsac | data read access-time-2 in CLK cycles (NSAC*100) |
| uint8_t | tran_speed | max. data transfer rate |
| uint8_t | ccc_hi | card command classes |
| uint8_t | read_bl_len: 4 | max. read data block length |
| uint8_t | ccc_lo: 4 | card command classes |
| union px_sd_csd_t.ver | ver | |
| uint8_t | write_bl_len_hi: 2 | max. write data block length |
| uint8_t | r2w_factor: 3 | write speed factor |
| uint8_t | reserved3: 2 | |
| uint8_t | wp_grp_enable: 1 | write protect group enable |
| uint8_t | reserved4: 5 | |
| uint8_t | write_partial: 1 | partial blocks for write allowed |
| uint8_t | write_bl_len_low: 2 | max. write data block length |
| uint8_t | reserved5: 2 | |
| uint8_t | file_format: 2 | File format. |
| uint8_t | tmp_write_protect: 1 | temporary write protection |
| uint8_t | perm_write_protect: 1 | permanent write protection |
| uint8_t | copy: 1 | copy flag |
| uint8_t | file_format_grp: 1 | File format. |
| uint8_t | crc7_end_bit | CRC. |
| struct px_sd_csd_t.ver.csd_1_0 |
| struct px_sd_csd_t.ver.csd_2_0 |
| #define PX_SD_MAX_SPI_CLOCK_HZ 25000000ul |
| #define PX_SD_SPI_MODE PX_SPI_MODE0 |
| #define PX_SD_SPI_DATA_ORDER PX_SPI_DATA_ORDER_MSB |
| #define PX_SD_SPI_MO_DUMMY_BYTE 0xff |
| void px_sd_init | ( | px_spi_handle_t * | handle | ) |
| bool px_sd_reset | ( | void | ) |
| bool px_sd_rd_cid | ( | px_sd_cid_t * | cid | ) |
| bool px_sd_rd_csd | ( | px_sd_csd_t * | csd | ) |
| bool px_sd_get_status | ( | uint16_t * | status | ) |
| uint32_t px_sd_get_capacity_in_blocks | ( | const px_sd_csd_t * | csd | ) |
Extract and calculate card capacity from Card Specific Data (CSD).
| csd | Card Specific Data |
| bool px_sd_rd_block | ( | uint8_t * | data, |
| uint32_t | block_adr | ||
| ) |
Read a data block from the SD card.
The data block size is PX_SD_BLOCK_SIZE and the specified array must be big enough to accept the whole data block.
| data | Pointer to array where data block must be stored |
| block_adr | Address of block to read. |
| true | Data block succcesfully read |
| false | Error while trying to read data block |
| uint8_t px_sd_rd_blocks | ( | uint8_t * | data, |
| uint32_t | block_adr, | ||
| uint8_t | nr_of_blocks | ||
| ) |
Read a number of data blocks from the SD card.
The data block size is PX_SD_BLOCK_SIZE and the specified array must be big enough to accept (nr_of_blocks x PX_SD_BLOCK_SIZE).
| data | Pointer to array where data blocks must be stored |
| block_adr | Address of start block to read |
| nr_of_blocks | Number of blocks to read |
| bool px_sd_wr_block | ( | const uint8_t * | data, |
| uint32_t | block_adr | ||
| ) |
Write a data block to the SD card.
The data block size is PX_SD_BLOCK_SIZE and the specified array must contain the whole data block. Poll px_sd_wait_write_finished() to find out when write operation has finished, e.g. before powering down SD card.
| data | Pointer to array containing data block content to be written |
| block_adr | Address of block to write. |
| true | Data block succcesfully written |
| false | Error while trying to write data block |
| uint8_t px_sd_wr_blocks | ( | const uint8_t * | data, |
| uint32_t | block_adr, | ||
| uint8_t | nr_of_blocks | ||
| ) |
Write a number of data blocks to the SD card.
The data block size is PX_SD_BLOCK_SIZE and the specified array must contain (nr_of_blocks x PX_SD_BLOCK_SIZE). Poll px_sd_wait_write_finished() to find out when write operation has finished, e.g. before powering down SD card.
| data | Pointer to array containing content to be written |
| block_adr | Address of start block to write. |
| nr_of_blocks | Number of blocks to write |