Skip to content

Add SDBlockDevice example #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SDBlockDevice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SDBlockDevice example

SDBlockDevice usage example for Mbed OS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .cpp appears underneath as an embedded element, right?

45 changes: 45 additions & 0 deletions SDBlockDevice/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "mbed.h"
#include "SDBlockDevice.h"

// Instantiate the SDBlockDevice by specifying the SPI pins connected to the SDCard
// socket. The PINS are:
// MOSI (Master Out Slave In)
// MISO (Master In Slave Out)
// SCLK (Serial Clock)
// CS (Chip Select)
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
uint8_t block[512] = "Hello World!\n";

int main()
{
// Call the SDBlockDevice instance initialisation method
if ( 0 != sd.init()) {
printf("Init failed \n");
return -1;
}
printf("sd size: %llu\n", sd.size());
printf("sd read size: %llu\n", sd.get_read_size());
printf("sd program size: %llu\n", sd.get_program_size());
printf("sd erase size: %llu\n", sd.get_erase_size());

// Set the frequency
if ( 0 != sd.frequency(5000000)) {
printf("Error setting frequency \n");
}

if ( 0 != sd.erase(0, sd.get_erase_size())) {
printf("Error Erasing block \n");
}

// Write data block to the device
if ( 0 == sd.program(block, 0, 512)) {
// Read the data block from the device
if ( 0 == sd.read(block, 0, 512)) {
// Print the contents of the block
printf("%s", block);
}
}

// Call the SDBlockDevice instance de-initialisation method
sd.deinit();
}
1 change: 1 addition & 0 deletions SDBlockDevice/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#c966348d3f9ca80843be7cdc9b748f06ea73ced0