17
17
#ifndef MBED_SD_BLOCK_DEVICE_H
18
18
#define MBED_SD_BLOCK_DEVICE_H
19
19
20
- /* If the target has no SPI support then SDCard is not supported */
20
+ /* If the target has no SPI support, then SD Card is not supported. */
21
21
#if DEVICE_SPI
22
22
23
23
#include " BlockDevice.h"
30
30
31
31
/* * SDBlockDevice class
32
32
*
33
- * Access an SD Card using SPI
33
+ * Access an SD Card using SPI bus
34
34
*/
35
35
class SDBlockDevice : public mbed ::BlockDevice {
36
36
public:
37
- /* * Lifetime of an SD card
37
+ /* * Creates an SDBlockDevice on a SPI bus specified by pins
38
+ *
39
+ * @param mosi SPI master out, slave in pin
40
+ * @param miso SPI master in, slave out pin
41
+ * @param sclk SPI clock pin
42
+ * @param cs SPI chip select pin
43
+ * @param hz Clock speed of the SPI bus (defaults to 1MHz)
44
+ * @param crc_on Enable cyclic redundancy check (defaults to disabled)
38
45
*/
39
46
SDBlockDevice (PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz = 1000000 , bool crc_on = 0 );
40
47
virtual ~SDBlockDevice ();
41
48
42
49
/* * Initialize a block device
43
50
*
44
- * @return 0 on success or a negative error code on failure
51
+ * @return BD_ERROR_OK(0) - success
52
+ * BD_ERROR_DEVICE_ERROR - device driver transaction failed
53
+ * SD_BLOCK_DEVICE_ERROR_NO_DEVICE - device (SD card) is missing or not connected
54
+ * SD_BLOCK_DEVICE_ERROR_UNUSABLE - unusable card
55
+ * SD_BLOCK_DEVICE_ERROR_CRC - crc error
45
56
*/
46
57
virtual int init ();
47
58
48
59
/* * Deinitialize a block device
49
60
*
50
- * @return 0 on success or a negative error code on failure
61
+ * @return BD_ERROR_OK(0) - success
51
62
*/
52
63
virtual int deinit ();
53
64
@@ -56,18 +67,30 @@ class SDBlockDevice : public mbed::BlockDevice {
56
67
* @param buffer Buffer to write blocks to
57
68
* @param addr Address of block to begin reading from
58
69
* @param size Size to read in bytes, must be a multiple of read block size
59
- * @return 0 on success, negative error code on failure
70
+ * @return BD_ERROR_OK(0) - success
71
+ * SD_BLOCK_DEVICE_ERROR_NO_DEVICE - device (SD card) is missing or not connected
72
+ * SD_BLOCK_DEVICE_ERROR_CRC - crc error
73
+ * SD_BLOCK_DEVICE_ERROR_PARAMETER - invalid parameter
74
+ * SD_BLOCK_DEVICE_ERROR_NO_RESPONSE - no response from device
75
+ * SD_BLOCK_DEVICE_ERROR_UNSUPPORTED - unsupported command
60
76
*/
61
77
virtual int read (void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
62
78
63
79
/* * Program blocks to a block device
64
80
*
65
- * The blocks must have been erased prior to being programmed
81
+ * @note The blocks must be erased prior to programming
66
82
*
67
83
* @param buffer Buffer of data to write to blocks
68
84
* @param addr Address of block to begin writing to
69
- * @param size Size to write in bytes, must be a multiple of program block size
70
- * @return 0 on success, negative error code on failure
85
+ * @param size Size to write in bytes. Must be a multiple of program block size
86
+ * @return BD_ERROR_OK(0) - success
87
+ * SD_BLOCK_DEVICE_ERROR_NO_DEVICE - device (SD card) is missing or not connected
88
+ * SD_BLOCK_DEVICE_ERROR_CRC - crc error
89
+ * SD_BLOCK_DEVICE_ERROR_PARAMETER - invalid parameter
90
+ * SD_BLOCK_DEVICE_ERROR_UNSUPPORTED - unsupported command
91
+ * SD_BLOCK_DEVICE_ERROR_NO_INIT - device is not initialized
92
+ * SD_BLOCK_DEVICE_ERROR_WRITE - SPI write error
93
+ * SD_BLOCK_DEVICE_ERROR_ERASE - erase error
71
94
*/
72
95
virtual int program (const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
73
96
@@ -80,7 +103,13 @@ class SDBlockDevice : public mbed::BlockDevice {
80
103
*
81
104
* @param addr Address of block to mark as unused
82
105
* @param size Size to mark as unused in bytes, must be a multiple of erase block size
83
- * @return 0 on success, negative error code on failure
106
+ * @return BD_ERROR_OK(0) - success
107
+ * SD_BLOCK_DEVICE_ERROR_NO_DEVICE - device (SD card) is missing or not connected
108
+ * SD_BLOCK_DEVICE_ERROR_CRC - crc error
109
+ * SD_BLOCK_DEVICE_ERROR_PARAMETER - invalid parameter
110
+ * SD_BLOCK_DEVICE_ERROR_UNSUPPORTED - unsupported command
111
+ * SD_BLOCK_DEVICE_ERROR_NO_INIT - device is not initialized
112
+ * SD_BLOCK_DEVICE_ERROR_ERASE - erase error
84
113
*/
85
114
virtual int trim (mbed::bd_addr_t addr, mbed::bd_size_t size);
86
115
@@ -90,9 +119,9 @@ class SDBlockDevice : public mbed::BlockDevice {
90
119
*/
91
120
virtual mbed::bd_size_t get_read_size () const ;
92
121
93
- /* * Get the size of a programable block
122
+ /* * Get the size of a programmable block
94
123
*
95
- * @return Size of a programable block in bytes
124
+ * @return Size of a programmable block in bytes
96
125
* @note Must be a multiple of the read size
97
126
*/
98
127
virtual mbed::bd_size_t get_program_size () const ;
@@ -118,7 +147,7 @@ class SDBlockDevice : public mbed::BlockDevice {
118
147
119
148
/* * Get the BlockDevice class type.
120
149
*
121
- * @return A string represent the BlockDevice class type.
150
+ * @return A string representation of the BlockDevice class type.
122
151
*/
123
152
virtual const char *get_type () const ;
124
153
@@ -167,9 +196,9 @@ class SDBlockDevice : public mbed::BlockDevice {
167
196
int _cmd (SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAcmd = 0 , uint32_t *resp = NULL );
168
197
int _cmd8 ();
169
198
170
- /* Move the SDCard into the SPI Mode idle state
199
+ /* Move the SD Card into the SPI Mode idle state
171
200
*
172
- * The card is transitioned from SDCard mode to SPI mode by sending the
201
+ * The card is transitioned from SD Card mode to SPI mode by sending the
173
202
* CMD0 (GO_IDLE_STATE) command with CS asserted. See the notes in the
174
203
* "SPI Startup" section of the comments at the head of the
175
204
* implementation file for further details and specification references.
@@ -187,7 +216,7 @@ class SDBlockDevice : public mbed::BlockDevice {
187
216
188
217
/* SPI functions */
189
218
mbed::Timer _spi_timer; /* *< Timer Class object used for busy wait */
190
- uint32_t _init_sck; /* *< Intial SPI frequency */
219
+ uint32_t _init_sck; /* *< Initial SPI frequency */
191
220
uint32_t _transfer_sck; /* *< SPI frequency during data transfer/after initialization */
192
221
mbed::SPI _spi; /* *< SPI Class object */
193
222
0 commit comments