Implementation of a LocalFileSystem using S25FL216K serial flash memory. Currently only 256kB available!
Dependencies: S25FL216K USBFileSystem
Dependents: S25FL216K_HelloWorld
Revision 0:9056eb697726, committed 2013-07-31
- Comitter:
- Sissors
- Date:
- Wed Jul 31 19:18:22 2013 +0000
- Child:
- 1:355e49586f92
- Commit message:
- v0.1, only 256kB accessible!
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Flash_USBFileSystem.cpp Wed Jul 31 19:18:22 2013 +0000 @@ -0,0 +1,51 @@ +/* mbed USBMSD_Ram Library + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "Flash_USBFileSystem.h" + +FlashUSB::FlashUSB(PinName mosi, PinName miso, PinName sclk, PinName cs) : USBFileSystem("USB"), flash(mosi, miso, sclk, cs) { + //no init + _status = 0x01; +} + +int FlashUSB::disk_initialize() { + // OK + _status = 0x00; + return 0; +} + +int FlashUSB::_disk_write(const uint8_t * buffer, uint64_t block_number) { + flash.eraseSector(block_number*4096); + flash.write(block_number*4096, (char*) buffer, 256); + flash.write(block_number*4096+256, (char*) buffer+256, 256); + return 0; +} + +int FlashUSB::disk_read(uint8_t * buffer, uint64_t block_number) { + flash.read(block_number*4096, (char*) buffer, 512); + return 0; +} + +int FlashUSB::_disk_status() { return _status; } +int FlashUSB::disk_sync() { return 0; } +uint64_t FlashUSB::disk_sectors() { return 512; } + + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Flash_USBFileSystem.h Wed Jul 31 19:18:22 2013 +0000 @@ -0,0 +1,28 @@ +#ifndef S25FL216K_USB +#define S25FL216K_USB + +#include "mbed.h" +#include "USBFileSystem.h" +#include "S25FL216K.h" + +/** Local filesystem made with S25FL216K serial flash memory + USBFileSystem library +*/ +class FlashUSB : public USBFileSystem { +public: + + FlashUSB(PinName mosi, PinName miso, PinName sclk, PinName cs); + virtual int disk_initialize(); + virtual int _disk_write(const uint8_t * data, uint64_t block); + virtual int disk_read(uint8_t * data, uint64_t block); + virtual int _disk_status(); + virtual int disk_sync(); + virtual uint64_t disk_sectors(); + +protected: + int _status; + S25FL216K flash; + + +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/S25FL216K.lib Wed Jul 31 19:18:22 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/S25FL216K/#2bcefc9e64f8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBFileSystem.lib Wed Jul 31 19:18:22 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/USBFileSystem/#dabe3383ef23