Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SST25VF064C.h
00001 /////////////////////////////////////////////////////////////////////////////// 00002 // SST25VF064C.cpp - Flash driver 00003 // 00004 // COPYRIGHT (c) 2012 by David Van Wagner 00005 // 00006 // dave@vanwagner.org 00007 // http://techwithdave.blogspot.com 00008 // 00009 // License: Creative Commons Attribution-ShareAlike 3.0 Unported License 00010 // http://creativecommons.org/licenses/by-sa/3.0/ 00011 /////////////////////////////////////////////////////////////////////////////// 00012 00013 #include <mbed.h> 00014 #ifdef SPIDEBUG 00015 #include "SPIDebug.h" 00016 extern bool debug; 00017 #endif 00018 00019 class SST25VF064C 00020 { 00021 public: 00022 typedef char int8; 00023 typedef short int16; 00024 typedef long int32; 00025 typedef long long int64; 00026 00027 typedef unsigned char uint8; 00028 typedef unsigned short uint16; 00029 typedef unsigned long uint32; 00030 typedef unsigned long long uint64; 00031 00032 static const int SID_LEN = 32; 00033 static const int SECTOR_LEN = 4096; 00034 static const int PAGE_LEN = 256; 00035 static const int MAX_ADDR = 0x7FFFFF; 00036 00037 private: 00038 #ifdef SPIDEBUG 00039 SPIDebug* spi; 00040 CSDebug* cs; 00041 #else 00042 SPI* spi; 00043 DigitalOut* cs; 00044 #endif 00045 int frequency; 00046 00047 static uint8 SID_buffer[SID_LEN]; 00048 static uint8 sector_buffer[SECTOR_LEN]; 00049 static int32 buffered_addr; 00050 static bool buffered_erased; 00051 00052 public: 00053 SST25VF064C(PinName mosi, PinName miso, PinName sclk, PinName cs, int frequency=10000000); 00054 ~SST25VF064C(); 00055 00056 uint16 Id(); 00057 uint32 JEDECId(); 00058 uint8* SID(); // Security ID (128 bits = 16 bytes) 00059 00060 // Read Status Register 00061 // bit 0 BUSY 1=Write in progress 00062 // bit 1 WEL 1=Write Enabled 00063 // bit 2 BP0 block write protection 00064 // bit 3 BP1 block write protection 00065 // bit 4 BP2 block write protection 00066 // bit 5 BP3 block write protection 00067 // bit 6 SEC 1=Security ID space locked 00068 // bit 7 BPL 1=BP0..BP3 are read-only, 0=r/w 00069 uint8 RDSR(); 00070 void EWSR(); // Enable Write Status Register 00071 void WRSR(uint8 status); // Write Status Register 00072 00073 void WREN(); // Write Enable 00074 void WRDI(); // Write Disable 00075 bool BUSY(); // Write in Progress 00076 bool WEL(); // Write Enabled 00077 uint8 BP(); // Block Protection 00078 bool SEC(); // Security ID Locked 00079 bool BPL(); // Block Protection Locked 00080 void wait_while_busy(); 00081 00082 uint8 read(int32 addr); 00083 bool read(int32 addr, uint8* dst, int32 len); 00084 void hsread(int32 addr, uint8* dst, int32 len, int frequency); 00085 00086 void sector_erase_4k(int32 addr); 00087 void block_erase_32k(int32 addr); 00088 void block_erase_64k(int32 addr); 00089 void chip_erase(); 00090 00091 bool page_program(int32 addr, uint8* write_buffer, short len); 00092 bool write(int32 addr, uint8* write_buffer, int32 len); 00093 bool rewrite(int32 addr, uint8* write_buffer, int32 len); 00094 00095 bool buffered_write(uint8 data); 00096 bool buffered_write(uint8* src, int len); 00097 uint8 buffered_read(); 00098 bool buffered_read(uint8* dest, int len); 00099 void buffered_seek(int32 addr); 00100 void buffered_sync(); 00101 };
Generated on Thu Jul 14 2022 21:23:10 by
