You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.7KB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # SerialFlash
  2. Use SPI Flash memory with a filesystem-like interface.
  3. ## Accessing Files
  4. ### Open A File
  5. SerialFlashFile file;
  6. file = SerialFlash.open("filename.bin");
  7. if (file) { // true if the file exists
  8. ### Read Data
  9. char buffer[256];
  10. file.read(buffer, 256);
  11. ### File Size & Positon
  12. file.size();
  13. file.position()
  14. file.seek();
  15. ### Write Data
  16. file.write(buffer, 256);
  17. Several limitations apply to writing. Only previously unwritten portions of the file may be written. Files sizes can never change. Writes may only be done within the file's original size.
  18. file.erase(); // not yet implemented
  19. Only files created for erasing can be erased. The entire file is erased to all 255 (0xFF) bytes.
  20. ## Managing Files
  21. ### Create New Files
  22. SerialFlash.create(filename, size);
  23. SerialFlash.createErasable(filename, size);
  24. New files must be created using these funtions. Each returns true if the file is successfully created, or false if not enough space is available.
  25. Once created, files can never be renamed or deleted. The file's size can never change. Writing additional data can NOT grow the size of file.
  26. Files created for erasing automatically increase in size to the nearest number of erasable blocks, resulting in a file that may be 4K to 128K larger than requested.
  27. ### Directory Listing
  28. SerialFlash.opendir();
  29. SerialFlash.readdir(buffer, buflen, filelen);
  30. A list of files stored in the Flash can be accessed with readdir(), which returns true for each file, or false to indicate no more files.
  31. ## Full Erase
  32. SerialFlash.erase();
  33. while (SerialFlash.ready() == false) {
  34. // wait, 30 seconds to 2 minutes for most chips
  35. }