pls work
Dependencies: mbed WS2813 PixelArray SDFileSystem ds3231
Fork of SDFileSystem_HelloWorld by
main.cpp
- Committer:
- deldering95
- Date:
- 2018-08-02
- Revision:
- 26:dcced86ba984
- Parent:
- 20:ec1c4f02d50e
- Child:
- 27:2b989633a518
File content as of revision 26:dcced86ba984:
#include "mbed.h" #include "SDFileSystem.h" Timer timer; //DigitalIn button(p21, PullUp); SDFileSystem sd(PC_12,PC_11,PC_10,PA_15, "sd", NC, SDFileSystem::SWITCH_NONE, 400000); RawSerial pc(PA_9,PA_10); char buffer[4096]; void writeTest() { //Test write performance by creating a 1MB file pc.printf("Testing %iB write performance...", sizeof(buffer)); FileHandle* file = sd.open("Test_File.bin", O_WRONLY | O_CREAT); pc.printf("whatever u want\n"); if (file != NULL) { timer.start(); for (int i = 0; i < (1048576 / sizeof(buffer)); i++) { pc.printf("%d\n",i); if (file->write(buffer, sizeof(buffer)) != sizeof(buffer)) { timer.stop(); pc.printf("write error!\n"); timer.reset(); return; } } timer.stop(); if (file->close()) pc.printf("failed to close file!\n"); else pc.printf("done!\n\tResult: %.2fKB/s\n", 1024 / (timer.read_us() / 1000000.0)); timer.reset(); } else { pc.printf("failed to create file!\n"); } } void readTest() { //Test read performance by reading the 1MB file created by writeTest() pc.printf("Testing %iB read performance...", sizeof(buffer)); FileHandle* file = sd.open("Test File.bin", O_RDONLY); if (file != NULL) { timer.start(); int iterations = 0; while (file->read(buffer, sizeof(buffer)) == sizeof(buffer)){ iterations++; pc.printf("%d\n",iterations);} timer.stop(); if (iterations != (1048576 / sizeof(buffer))) pc.printf("read error!\n"); else if (file->close()) pc.printf("failed to close file!\n"); else if (sd.remove("Test File.bin")) pc.printf("failed to delete file!\n"); else pc.printf("done!\n\tResult: %.2fKB/s\n", 1024 / (timer.read_us() / 1000000.0)); timer.reset(); } else { pc.printf("failed to open file!\n"); } } int main() { //Configure CRC, large frames, and write validation sd.crc(true); sd.large_frames(true); sd.write_validation(true); pc.baud(115200); pc.format(8, SerialBase::None, 1); pc.printf("pls work"); //Fill the buffer with random data for the write test //srand(time(NULL)); for (int i = 0; i < sizeof(buffer); i++){ buffer[i] = rand(); pc.printf("pls work %d\n",i);} while(1) { //Simple button debouncing wait(0.5); //Print the start message pc.printf("\nPress the button to perform tests: "); //Wait for the button to be pressed //while(button); //Make sure a card is present if (!sd.card_present()) { pc.printf("\nNo card present!\n"); continue; } //Try to mount the SD card pc.printf("\nMounting SD card..."); if (sd.mount() != 0) { pc.printf("failed!\n"); continue; } pc.printf("success!\n"); //Display the card type pc.printf("\tCard type: "); SDFileSystem::CardType cardType = sd.card_type(); if (cardType == SDFileSystem::CARD_NONE) pc.printf("None\n"); else if (cardType == SDFileSystem::CARD_MMC) pc.printf("MMC\n"); else if (cardType == SDFileSystem::CARD_SD) pc.printf("SD\n"); else if (cardType == SDFileSystem::CARD_SDHC) pc.printf("SDHC\n"); else pc.printf("Unknown\n"); //Display the card capacity pc.printf("\tSectors: %u\n", sd.disk_sectors()); pc.printf("\tCapacity: %.1fMB\n", sd.disk_sectors() / 2048.0); /*//Format the card pc.printf("Formatting SD card..."); if (sd.format() != 0) { pc.printf("failed!\n"); continue; } pc.printf("success!\n");*/ //Perform a read/write test writeTest(); readTest(); //Unmount the SD card sd.unmount(); } }