COSA
An Object-Oriented Platform for Arduino Programming
S25FL127S.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_S25FL127S_HH
22 #define COSA_S25FL127S_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/SPI.hh"
26 #include "Cosa/Flash.hh"
27 
39 class S25FL127S : public Flash::Device, protected SPI::Driver {
40 public:
44  static const size_t PAGE_MAX = 256;
45  static const size_t PAGE_MASK = PAGE_MAX - 1;
46 
51 #if !defined(BOARD_ATTINYX5)
53  Flash::Device(64 * 1024L, 256),
54  SPI::Driver(csn, SPI::ACTIVE_LOW, SPI::DIV2_CLOCK, 0, SPI::MSB_ORDER, NULL)
55  {}
56 #else
58  Flash::Device(64 * 1024L, 256),
60  {}
61 #endif
62 
70  virtual bool begin();
71 
78  virtual bool is_ready();
79 
90  virtual int read(void* dest, uint32_t src, size_t size);
91 
104  virtual int erase(uint32_t dest, uint8_t size = 4);
105 
116  virtual int write(uint32_t dest, const void* src, size_t size);
117 
127  virtual int write_P(uint32_t dest, const void* buf, size_t size);
128 
132  union config_t {
133  uint8_t as_uint8;
134  struct {
135  uint8_t FREEZE:1;
136  uint8_t QUAD:1;
137  uint8_t TBPARAM:1;
138  uint8_t BPNV:1;
139  uint8_t RFU:1;
140  uint8_t TBPROT:1;
141  uint8_t LC:2;
142  };
143  config_t(uint8_t value = 0)
144  {
145  as_uint8 = value;
146  }
147  operator uint8_t()
148  {
149  return (as_uint8);
150  }
151  };
152 
157  uint8_t read_config()
158  {
159  return (issue(RDCR));
160  }
161 
165  union status1_t {
166  uint8_t as_uint8;
167  struct {
168  uint8_t WIP:1;
169  uint8_t WEL:1;
170  uint8_t BP:3;
171  uint8_t E_ERR:1;
172  uint8_t P_ERR:1;
173  uint8_t SRWD:1;
174  };
175  status1_t(uint8_t value = 0)
176  {
177  as_uint8 = value;
178  }
179  operator uint8_t()
180  {
181  return (as_uint8);
182  }
183  };
184 
189  uint8_t read_status1()
190  {
191  return (issue(RDSR1));
192  }
193 
197  union status2_t {
198  uint8_t as_uint8;
199  struct {
200  uint8_t PS:1;
201  uint8_t ES:1;
202  uint8_t RFU:3;
203  uint8_t IO3:1;
204  uint8_t PBW:1;
205  uint8_t BES:1;
206  };
207  status2_t(uint8_t value = 0)
208  {
209  as_uint8 = value;
210  }
211  operator uint8_t()
212  {
213  return (as_uint8);
214  }
215  };
216 
221  uint8_t read_status2()
222  {
223  return (issue(RDSR2));
224  }
225 
226 protected:
230  enum Command {
232  READ_ID = 0x90,
233  RDRID = 0x9f,
234  RSFDP = 0x5a,
235  RES = 0xab,
236 
238  RDSR1 = 0x05,
239  RDSR2 = 0x07,
240  RDCR = 0x35,
241  WRR = 0x01,
242  WRDI = 0x04,
243  WREN = 0x06,
244  CLSR = 0x30,
245  ABRD = 0x14,
246  ABWR = 0x15,
247  BRRD = 0x16,
248  BRWR = 0x17,
249  BRAC = 0x89,
250  DLPRD = 0x41,
251  PNVDLR = 0x43,
252  WVDLR = 0x4A,
253 
255  READ = 0x03,
256  READ4 = 0x13,
257  FAST_READ = 0x0b,
258  FAST_READ4 = 0x0c,
259  DOR = 0x3b,
260  DOR4 = 0x3c,
261  QOR = 0x6b,
262  QOR4 = 0x6c,
263  DIOR = 0xbb,
264  DIOR4 = 0xbc,
265  QIOR = 0xeb,
266  QIOR4 = 0xec,
267 
269  PP = 0x02,
270  PP4 = 0x12,
271  QPP = 0x32,
272  QPP4 = 0x34,
273  PGSP = 0x85,
274  PGRS = 0x8a,
275 
277  P4E = 0x20,
278  P4E4 = 0x21,
279  BER = 0x60,
280  SER = 0xd8,
281  SER4 = 0xdc,
282  ERSP = 0x75,
283  ERRS = 0x7a,
284 
286  OTPP = 0x42,
287  OTPR = 0x4b,
288 
290  DYBRD = 0xe0,
291  DYBWR = 0xe1,
292  PPBRD = 0xe2,
293  PPBP = 0xe3,
294  PPBE = 0xe4,
295  ASPRD = 0x2b,
296  ASPP = 0x2f,
297  PLBRD = 0xa7,
298  PLBWR = 0xa6,
299  PASSRD = 0xe7,
300  PASSP = 0xe8,
301  PASSU = 0xe9,
302 
304  RESET = 0xf0,
305  MBR = 0xff
306  } __attribute__((packed));
307 
309  static const uint8_t MANUFACTURER = 0x01;
310 
312  static const uint8_t DEVICE = 0x17;
313 
319  uint8_t issue(Command cmd);
320 
323 };
324 
325 #endif
PPB Erase.
Definition: S25FL127S.hh:294
AutoBoot Register Read.
Definition: S25FL127S.hh:245
uint8_t as_uint8
As unsigned 8-bit value.
Definition: S25FL127S.hh:166
virtual int write_P(uint32_t dest, const void *buf, size_t size)
Definition: S25FL127S.cpp:164
virtual int read(void *dest, uint32_t src, size_t size)
Definition: S25FL127S.cpp:61
PPB Lock Bit Write.
Definition: S25FL127S.hh:298
Dual I/O Read (3- or 4-byte address).
Definition: S25FL127S.hh:263
Read JEDEC Serial Flash Parameters.
Definition: S25FL127S.hh:234
S25FL127S(Board::DigitalPin csn=Board::D5)
Definition: S25FL127S.hh:52
uint8_t as_uint8
As unsigned 8-bit value.
Definition: S25FL127S.hh:198
virtual int erase(uint32_t dest, uint8_t size=4)
Definition: S25FL127S.cpp:81
Program Resume.
Definition: S25FL127S.hh:274
uint8_t TBPARAM
Parameter Sectors location (0=low,1=high).
Definition: S25FL127S.hh:137
config_t(uint8_t value=0)
Definition: S25FL127S.hh:143
Definition: SPI.hh:57
Erase 64 kB or 256 kB (4-byte addr).
Definition: S25FL127S.hh:281
Mode Bit Reset.
Definition: S25FL127S.hh:305
Data Learning Pattern Read.
Definition: S25FL127S.hh:250
#define NULL
Definition: Types.h:101
Software Reset.
Definition: S25FL127S.hh:304
Read Dual Out (3- or 4-byte address).
Definition: S25FL127S.hh:259
ASP Program.
Definition: S25FL127S.hh:296
Quad Page Program (3- or 4-byte address).
Definition: S25FL127S.hh:271
uint8_t as_uint8
As unsigned 8-bit value.
Definition: S25FL127S.hh:133
AutoBoot Register Write.
Definition: S25FL127S.hh:246
Fast Read (4-byte address).
Definition: S25FL127S.hh:258
uint8_t read_status2()
Definition: S25FL127S.hh:221
Fast Read (3- or 4-byte address).
Definition: S25FL127S.hh:257
Read Configuration Register#1.
Definition: S25FL127S.hh:240
Bank Register Write.
Definition: S25FL127S.hh:248
uint8_t read_config()
Definition: S25FL127S.hh:157
Program NV Data Learning Register.
Definition: S25FL127S.hh:251
Bank Register Access.
Definition: S25FL127S.hh:249
Parameter 4-kB, sector erase (4-byte addr).
Definition: S25FL127S.hh:278
Page Program (3- or 4-byte address).
Definition: S25FL127S.hh:269
uint8_t read_status1()
Definition: S25FL127S.hh:189
uint8_t issue(Command cmd)
Definition: S25FL127S.cpp:213
Clear Status Register#1.
Definition: S25FL127S.hh:244
Write Volatile Data Learning Register.
Definition: S25FL127S.hh:252
status1_t m_status
Definition: S25FL127S.hh:322
Password Program.
Definition: S25FL127S.hh:300
Erase Resume.
Definition: S25FL127S.hh:283
Write Register (Status-1, Config-1).
Definition: S25FL127S.hh:241
Read Quad Out (4-byte address).
Definition: S25FL127S.hh:262
Read Electronic Signature.
Definition: S25FL127S.hh:235
static const uint8_t MANUFACTURER
Definition: S25FL127S.hh:309
Read Quad Out (3- or 4-byte address).
Definition: S25FL127S.hh:265
ASP Read.
Definition: S25FL127S.hh:295
Write Disable.
Definition: S25FL127S.hh:242
Read Electronic Manufacturer Signature.
Definition: S25FL127S.hh:232
PPB Read.
Definition: S25FL127S.hh:292
PPB Lock Bit Read.
Definition: S25FL127S.hh:297
Bulk Erase.
Definition: S25FL127S.hh:279
Parameter 4-kB, sector erase.
Definition: S25FL127S.hh:277
Password unlock.
Definition: S25FL127S.hh:301
Read Dual Out (4-byte address).
Definition: S25FL127S.hh:260
uint8_t TBPROT
Start of Block Protection (0=high,1=low).
Definition: S25FL127S.hh:140
Read Quad Out (3- or 4-byte address).
Definition: S25FL127S.hh:261
static const size_t PAGE_MASK
Definition: S25FL127S.hh:45
Bank Register Read.
Definition: S25FL127S.hh:247
uint8_t FREEZE
< As bit-fields.
Definition: S25FL127S.hh:135
status2_t(uint8_t value=0)
Definition: S25FL127S.hh:207
Read (4-byte address).
Definition: S25FL127S.hh:256
Erase Suspend.
Definition: S25FL127S.hh:282
uint8_t RFU
Reserved for Future Use.
Definition: S25FL127S.hh:139
uint8_t LC
Latency Code (see table 8.7, pp. 60).
Definition: S25FL127S.hh:141
Definition: Flash.hh:26
Quad Page Program (4-byte address).
Definition: S25FL127S.hh:272
OTP Program.
Definition: S25FL127S.hh:286
virtual bool begin()
Definition: S25FL127S.cpp:24
static const size_t PAGE_MAX
Definition: S25FL127S.hh:44
Read Status Register#1.
Definition: S25FL127S.hh:238
Active low logic during transaction.
Definition: SPI.hh:80
PPB Program.
Definition: S25FL127S.hh:293
virtual bool is_ready()
Definition: S25FL127S.cpp:46
DYB Read.
Definition: S25FL127S.hh:290
Program Suspend.
Definition: S25FL127S.hh:273
uint8_t BPNV
BP2-0 in status register (0=NV,1=Volatile).
Definition: S25FL127S.hh:138
Read (3- or 4-byte address).
Definition: S25FL127S.hh:255
Page Program (4-byte address).
Definition: S25FL127S.hh:270
Divide system clock by 2.
Definition: SPI.hh:61
Most significant bit first.
Definition: SPI.hh:73
OTP Read.
Definition: S25FL127S.hh:287
Read Quad Out (4-byte address).
Definition: S25FL127S.hh:266
virtual int write(uint32_t dest, const void *src, size_t size)
Definition: S25FL127S.cpp:115
static const uint8_t DEVICE
Definition: S25FL127S.hh:312
Read Status Register#2.
Definition: S25FL127S.hh:239
Erase 64 kB or 256 kB.
Definition: S25FL127S.hh:280
Password Read.
Definition: S25FL127S.hh:299
Read ID (JEDEC).
Definition: S25FL127S.hh:233
DYB Write.
Definition: S25FL127S.hh:291
uint8_t QUAD
Quad I/O operation.
Definition: S25FL127S.hh:136
Driver(Board::DigitalPin cs, Pulse pulse=DEFAULT_PULSE, Clock rate=DEFAULT_CLOCK, uint8_t mode=0, Order order=MSB_ORDER, Interrupt::Handler *irq=NULL)
Definition: SOFT_SPI.cpp:25
Device(uint32_t bytes, uint16_t count)
Definition: Flash.hh:54
Dual I/O Read (4-byte address).
Definition: S25FL127S.hh:264
Write Enable.
Definition: S25FL127S.hh:243
status1_t(uint8_t value=0)
Definition: S25FL127S.hh:175