Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

README.md 3.3KB

9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # SerialFlash
  2. SerialFlash provides low-latency, high performance access to SPI Flash memory with a filesystem-like interface. Familiar file-based functions, similar to the SD library, are used to access data.
  3. In-progress file write and erase operations do NOT block read access on other files. SerialFlash automatically allocates files with Flash page and sector awareness, and supports suspending in-progress write and erase operations, to minimize read latency even while the Flash memory is "busy" writing data.
  4. Performance oriented design does impose some usage limitations. Files are created with a fixed size which can never change or grow. Once created, files can not be renamed or deleted (except for erasing the entire chip). Files begin with all bytes erased (255). Each byte may be written only once. Files created as erasable may be fully erased, to allow new data to be written. Best performance is achieved by writing in 256 byte chunks, though individual bytes may be written.
  5. ## Hardware Compatibility
  6. ![W25Q128FV Chip](doc/w25q128fv.jpg)
  7. These chips have been tested with SerialFlash:
  8. Winbond W25Q80BV (http://www.adafruit.com/product/1564)
  9. Winbond W25Q64FV
  10. Winbond W25Q128FV
  11. Winbond W25Q256FV
  12. Micron N25Q512A
  13. Micron N25Q00AA
  14. Spansion S25FL127S
  15. Spansion S25FL256S
  16. Spansion S25FL512S
  17. SerialFlash automatically detects SPI Flash chip type and capacity to automatically handle differences between supported chips.
  18. ## Accessing Files
  19. ### Open A File
  20. SerialFlashFile file;
  21. file = SerialFlash.open("filename.bin");
  22. if (file) { // true if the file exists
  23. ### Read Data
  24. char buffer[256];
  25. file.read(buffer, 256);
  26. ### File Size & Positon
  27. file.size();
  28. file.position()
  29. file.seek(number);
  30. ### Write Data
  31. file.write(buffer, 256);
  32. Several limitations apply to writing. Only previously unwritten portions of the file may be written. File sizes can never change. Writes may only be done within the file's original size.
  33. file.erase();
  34. Only files created for erasing can be erased. The entire file is erased to all 255 (0xFF) bytes.
  35. ## Managing Files
  36. ### Create New Files
  37. SerialFlash.create(filename, size);
  38. SerialFlash.createErasable(filename, size);
  39. 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.
  40. 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.
  41. 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.
  42. ### Delete A File
  43. SerialFlash.remove(filename);
  44. The actual space used by the file is not reclaimed. However, a new file with this name may be created after the original is deleted.
  45. ### Check If A File Exists (without opening)
  46. SerialFlash.exists(filename);
  47. ### Directory Listing
  48. SerialFlash.opendir();
  49. SerialFlash.readdir(buffer, buflen, filelen);
  50. 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.
  51. ## Full Erase
  52. SerialFlash.erase();
  53. while (SerialFlash.ready() == false) {
  54. // wait, 30 seconds to 2 minutes for most chips
  55. }