Skip to content

Commit bd338e2

Browse files
authored
Merge pull request #21 from ARMmbed/sdblockdevice
Add SDBlockDevice example
2 parents cb3b0f3 + 9ebd096 commit bd338e2

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

SDBlockDevice/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SDBlockDevice example
2+
3+
SDBlockDevice usage example for Mbed OS
4+

SDBlockDevice/main.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "mbed.h"
2+
#include "SDBlockDevice.h"
3+
4+
// Instantiate the SDBlockDevice by specifying the SPI pins connected to the SDCard
5+
// socket. The PINS are:
6+
// MOSI (Master Out Slave In)
7+
// MISO (Master In Slave Out)
8+
// SCLK (Serial Clock)
9+
// CS (Chip Select)
10+
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
11+
uint8_t block[512] = "Hello World!\n";
12+
13+
int main()
14+
{
15+
// Call the SDBlockDevice instance initialisation method
16+
if ( 0 != sd.init()) {
17+
printf("Init failed \n");
18+
return -1;
19+
}
20+
printf("sd size: %llu\n", sd.size());
21+
printf("sd read size: %llu\n", sd.get_read_size());
22+
printf("sd program size: %llu\n", sd.get_program_size());
23+
printf("sd erase size: %llu\n", sd.get_erase_size());
24+
25+
// Set the frequency
26+
if ( 0 != sd.frequency(5000000)) {
27+
printf("Error setting frequency \n");
28+
}
29+
30+
if ( 0 != sd.erase(0, sd.get_erase_size())) {
31+
printf("Error Erasing block \n");
32+
}
33+
34+
// Write data block to the device
35+
if ( 0 == sd.program(block, 0, 512)) {
36+
// Read the data block from the device
37+
if ( 0 == sd.read(block, 0, 512)) {
38+
// Print the contents of the block
39+
printf("%s", block);
40+
}
41+
}
42+
43+
// Call the SDBlockDevice instance de-initialisation method
44+
sd.deinit();
45+
}

SDBlockDevice/mbed-os.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#c966348d3f9ca80843be7cdc9b748f06ea73ced0

0 commit comments

Comments
 (0)