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.0KB

9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
9 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. Winbond W25Q128FV is the only chip actually tested so far.
  8. Spansion and Micron SPI Flash chip testing is planned...
  9. TODO: add a list of chips, with verified, should work, or unsupported status.
  10. SerialFlash automatically detects SPI Flash chip type and capacity to automatically handle differences between supported chips.
  11. ## Accessing Files
  12. ### Open A File
  13. SerialFlashFile file;
  14. file = SerialFlash.open("filename.bin");
  15. if (file) { // true if the file exists
  16. ### Read Data
  17. char buffer[256];
  18. file.read(buffer, 256);
  19. ### File Size & Positon
  20. file.size();
  21. file.position()
  22. file.seek(number);
  23. ### Write Data
  24. file.write(buffer, 256);
  25. 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.
  26. file.erase(); // not yet implemented
  27. Only files created for erasing can be erased. The entire file is erased to all 255 (0xFF) bytes.
  28. ## Managing Files
  29. ### Create New Files
  30. SerialFlash.create(filename, size);
  31. SerialFlash.createErasable(filename, size);
  32. 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.
  33. 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.
  34. 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.
  35. ### Directory Listing
  36. SerialFlash.opendir();
  37. SerialFlash.readdir(buffer, buflen, filelen);
  38. 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.
  39. ## Full Erase
  40. SerialFlash.erase();
  41. while (SerialFlash.ready() == false) {
  42. // wait, 30 seconds to 2 minutes for most chips
  43. }