Solution
Dependencies: ELEC350-Practicals-FZ429
Fork of Task680-mbed-os-FZ429ZI by
main.cpp
- Committer:
- martinsimpson
- Date:
- 2017-10-20
- Revision:
- 0:1ce5a958aaf8
- Child:
- 2:fad34c30dcc4
File content as of revision 0:1ce5a958aaf8:
/* Access an SD Card using SPI */
#include "mbed.h"
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
SDBlockDevice sd(D11, D12, D13, D10); // mosi, miso, sclk, cs
uint8_t block[512] = "Hello World!\n";
int main()
{
printf("Initialise and write to a file\n");
//FileSystemLike(*sd);
// call the SDBlockDevice instance initialisation method.
if ( 0 != sd.init()) {
printf("Init failed \n");
return -1;
}
//FileSystemLike(*sd);
FATFileSystem fs("sd", &sd);
FILE *fp = fopen("/sd/test.txt","w");
if(fp == NULL) {
error("Could not open file for write\n");
}
//Put some text in the file...
fprintf(fp, "Martin Says Hi! One for the good guys\n");
//Tidy up here
fclose(fp);
sd.deinit();
printf("All done...\n");
/*
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 some the 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();
*/
}
