Implementation of a LocalFileSystem using S25FL216K serial flash memory. Currently only 256kB available!

Dependencies:   S25FL216K

Fork of S25FL216K_USBFileSystem by Erik -

Committer:
mkilivan
Date:
Tue Dec 23 21:36:32 2014 +0000
Revision:
5:c8918e47c566
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkilivan 5:c8918e47c566 1 /* mbed Flash_FileSystem Library
mkilivan 5:c8918e47c566 2 *
mkilivan 5:c8918e47c566 3 * Permission is hereby granted, free of charge, to any person obtaining a copy
mkilivan 5:c8918e47c566 4 * of this software and associated documentation files (the "Software"), to deal
mkilivan 5:c8918e47c566 5 * in the Software without restriction, including without limitation the rights
mkilivan 5:c8918e47c566 6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mkilivan 5:c8918e47c566 7 * copies of the Software, and to permit persons to whom the Software is
mkilivan 5:c8918e47c566 8 * furnished to do so, subject to the following conditions:
mkilivan 5:c8918e47c566 9 *
mkilivan 5:c8918e47c566 10 * The above copyright notice and this permission notice shall be included in
mkilivan 5:c8918e47c566 11 * all copies or substantial portions of the Software.
mkilivan 5:c8918e47c566 12 *
mkilivan 5:c8918e47c566 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mkilivan 5:c8918e47c566 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mkilivan 5:c8918e47c566 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mkilivan 5:c8918e47c566 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mkilivan 5:c8918e47c566 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mkilivan 5:c8918e47c566 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mkilivan 5:c8918e47c566 19 * THE SOFTWARE.
mkilivan 5:c8918e47c566 20 */
mkilivan 5:c8918e47c566 21
mkilivan 5:c8918e47c566 22 #include "Flash_FileSystem.h"
mkilivan 5:c8918e47c566 23
mkilivan 5:c8918e47c566 24 FlashSPI::FlashSPI(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* n) : FATFileSystem(n) , flash(mosi, miso, sclk, cs) {
mkilivan 5:c8918e47c566 25 //no init
mkilivan 5:c8918e47c566 26 _status = 0x01;
mkilivan 5:c8918e47c566 27 }
mkilivan 5:c8918e47c566 28
mkilivan 5:c8918e47c566 29 int FlashSPI::disk_initialize() {
mkilivan 5:c8918e47c566 30 // OK
mkilivan 5:c8918e47c566 31 _status = 0x00;
mkilivan 5:c8918e47c566 32 return 0;
mkilivan 5:c8918e47c566 33 }
mkilivan 5:c8918e47c566 34
mkilivan 5:c8918e47c566 35 int FlashSPI::disk_write(const uint8_t * buffer, uint64_t block_number) {
mkilivan 5:c8918e47c566 36 flash.eraseSector(block_number*4096);
mkilivan 5:c8918e47c566 37 flash.write(block_number*4096, (char*) buffer, 256);
mkilivan 5:c8918e47c566 38 flash.write(block_number*4096+256, (char*) buffer+256, 256);
mkilivan 5:c8918e47c566 39 return 0;
mkilivan 5:c8918e47c566 40 }
mkilivan 5:c8918e47c566 41
mkilivan 5:c8918e47c566 42 int FlashSPI::disk_read(uint8_t * buffer, uint64_t block_number) {
mkilivan 5:c8918e47c566 43 flash.read(block_number*4096, (char*) buffer, 512);
mkilivan 5:c8918e47c566 44 return 0;
mkilivan 5:c8918e47c566 45 }
mkilivan 5:c8918e47c566 46
mkilivan 5:c8918e47c566 47 int FlashSPI::disk_status() { return _status; }
mkilivan 5:c8918e47c566 48 int FlashSPI::disk_sync() { return 0; }
mkilivan 5:c8918e47c566 49 uint64_t FlashSPI::disk_sectors() { return 512; }
mkilivan 5:c8918e47c566 50
mkilivan 5:c8918e47c566 51