Created
October 2, 2020 08:49
-
-
Save tschiemer/c77ccae718c401fa7604f56b68034944 to your computer and use it in GitHub Desktop.
mbed os sd block decive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
#include "SDBlockDevice.h" | |
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"; | |
using namespace std::chrono; | |
Timer t; | |
int main() | |
{ | |
printf("\nRESTART delayer\n"); | |
// 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(50000000)) { | |
printf("Error setting frequency \n"); | |
} | |
// single block writes/reads ~2-5millisec, ie estimated "safe bound" for write and read ~10millisec | |
// 48 kHz sampling rate | |
// 12 bit sample quantization | |
// -> 1.5 * 48000 = 72000 Byte to read+write per second | |
// 72000 / 512 * 10 ms = 1406.25ms required --> too slow | |
// in principle with 8bit samples this should work.. | |
// consider using a board with SDIO support (like the stm32 l1/4xx) which should? have a higher throughput (even enough for stereo? ;) | |
for (int i = 0; i < 10; i++){ | |
if (0 != sd.erase(i*128, sd.get_erase_size())) { | |
printf("Error Erasing block \n"); | |
} | |
t.reset(); | |
t.start(); | |
// Write data block to the device | |
if (0 == sd.program(block, i*512, 512)) { | |
// if (0 == sd.read(block, 0, 512)) { | |
// Read the data block from the device | |
if (0 == sd.read(block, i*512, 512)) { | |
// // Print the contents of the block | |
// printf("%s", block); | |
} | |
} | |
t.stop(); | |
printf("i: %llu ms\n", duration_cast<milliseconds>(t.elapsed_time()).count()); | |
} | |
// Call the SDBlockDevice instance de-initialisation method | |
sd.deinit(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"target_overrides": { | |
"*": { | |
"platform.stdio-convert-newlines": true, | |
"target.features_add": ["STORAGE"], | |
"target.components_add": ["SD"] | |
}, | |
"NUCLEO_F303K8": { | |
"sd.SPI_MOSI": "SPI_MOSI", | |
"sd.SPI_MISO": "SPI_MISO", | |
"sd.SPI_CLK": "SPI_SCK", | |
"sd.SPI_CS": "SPI_CS" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment