Sample SPI drivers for a number of the Adesto Technologies flash devices.
standardflash.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2018 Adesto Technologies Corporation, Inc
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted (subject to the limitations in the disclaimer below) provided
8  * that the following conditions are met:
9  *
10  * o Redistributions of source code must retain the above copyright notice, this list
11  * of conditions and the following disclaimer.
12  *
13  * o Redistributions in binary form must reproduce the above copyright notice, this
14  * list of conditions and the following disclaimer in the documentation and/or
15  * other materials provided with the distribution.
16  *
17  * o Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
42 #ifndef STANDARDFLASH_H_
43 #define STANDARDFLASH_H_
44 
45 #include "cmd_defs.h"
46 #include "spi_driver.h"
47 #include "helper_functions.h"
48 #include <stdio.h>
49 #include <stdlib.h>
50 
51 #if (PARTNO == AT25SF641) || \
52  (PARTNO == AT25SF321) || \
53  (PARTNO == AT25SF161) || \
54  (PARTNO == AT25SF081) || \
55  (PARTNO == AT25SF041) || \
56  (PARTNO == AT25SL128A) || \
57  (PARTNO == AT25SL641) || \
58  (PARTNO == AT25SL321) || \
59  (PARTNO == AT25DL081) || \
60  (PARTNO == AT25DL161) || \
61  (PARTNO == AT25DF081A) || \
62  (PARTNO == AT25DF321A) || \
63  (PARTNO == AT25DF641A) || \
64  (PARTNO == AT25QL128A) || \
65  (PARTNO == AT25QL641) || \
66  (PARTNO == AT25QL321) || \
67  (PARTNO == AT25QF641) || \
68  (ALL == 1)
69 
71 
72 /******************************************
73  *
74  *
75  * Standardflash Commands
76  *
77  *
78  ******************************************/
79 
91 
102 void standardflashSetQEBit();
103 
115 
123 
131 
146 void standardflashReadArrayLowFreq(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes);
147 
162 void standardflashReadArrayHighFreq(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes);
163 
176 void standardflashBytePageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes);
177 
186 void standardflashBlockErase4K(uint32_t address);
187 
196 void standardflashBlockErase32K(uint32_t address);
197 
206 void standardflashBlockErase64K(uint32_t address);
207 
216 
225 
233 void standardflashDPD();
234 
242 
252 void standardflashReadID(uint8_t *rxBuffer);
253 
262 void standardflashReadMID(uint8_t *rxBuffer);
263 #endif
264 #if (PARTNO == AT25SF641) || \
265  (PARTNO == AT25SF321) || \
266  (PARTNO == AT25SF161) || \
267  (PARTNO == AT25SF081) || \
268  (PARTNO == AT25SF041) || \
269  (PARTNO == AT25SL128A) || \
270  (PARTNO == AT25SL641) || \
271  (PARTNO == AT25SL321) || \
272  (PARTNO == AT25QL128A) || \
273  (PARTNO == AT25QL641) || \
274  (PARTNO == AT25QL321) || \
275  (PARTNO == AT25QF641) || \
276  (ALL == 1)
277 
287 void standardflashWriteSR(uint8_t *txBuffer, uint8_t txNumBytes);
288 #endif
289 
290 #if (PARTNO == AT25SF641) || \
291  (PARTNO == AT25SL128A) || \
292  (PARTNO == AT25SL641) || \
293  (PARTNO == AT25SL321) || \
294  (PARTNO == AT25QL128A) || \
295  (PARTNO == AT25QL641) || \
296  (PARTNO == AT25QL321) || \
297  (PARTNO == AT25QF641) || \
298  (PARTNO == AT25DL081) || \
299  (PARTNO == AT25DL161) || \
300  (PARTNO == AT25DF081A) || \
301  (PARTNO == AT25DF321A) || \
302  (PARTNO == AT25DF641A) || \
303  (ALL == 1)
304 void standardflashWriteSRB1(uint8_t regVal);
305 void standardflashWriteSRB2(uint8_t regVal);
306 #endif
307 
308 #if (PARTNO == AT25SF641) || \
309  (PARTNO == AT25SF321) || \
310  (PARTNO == AT25SF161) || \
311  (PARTNO == AT25SF081) || \
312  (PARTNO == AT25SF041) || \
313  (PARTNO == AT25SL128A) || \
314  (PARTNO == AT25SL641) || \
315  (PARTNO == AT25SL321) || \
316  (PARTNO == AT25QL128A) || \
317  (PARTNO == AT25QL641) || \
318  (PARTNO == AT25QL321) || \
319  (PARTNO == AT25QF641) || \
320  (ALL == 1)
321 
328 
335 uint8_t standardflashReadSRB1();
336 
343 uint8_t standardflashReadSRB2();
344 
358 void standardflashDualOutputRead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes);
359 
387 void standardflashDualIORead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes, uint8_t readMode, uint8_t modeByteValue);
388 
402 void standardflashQuadOutputRead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes);
403 
430 void standardflashQuadIORead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes, uint8_t readMode, uint8_t modeByteValue);
431 
440 
449 
456 void standardflashEraseSecurityRegister(uint32_t address);
457 
471 void standardflashProgramSecurityRegisters(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes);
472 
485 void standardflashReadSecurityRegisters(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes);
486 
495 void standardflashResumeFromDPDReadID(uint8_t *rxBuffer);
496 
511 void standardflashQuadPageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t mode);
512 #endif
513 
514 #if (PARTNO == AT25SF641) || \
515  (PARTNO == AT25SF321) || \
516  (PARTNO == AT25SF161) || \
517  (PARTNO == AT25SL128A) || \
518  (PARTNO == AT25SL641) || \
519  (PARTNO == AT25SL321) || \
520  (PARTNO == AT25QL128A) || \
521  (PARTNO == AT25QL641) || \
522  (PARTNO == AT25QL321) || \
523  (PARTNO == AT25QF641) || \
524  (ALL == 1)
525 
532 
540 #endif
541 
542 #if (PARTNO == AT25SF641) || \
543  (PARTNO == AT25SL128A) || \
544  (PARTNO == AT25SL641) || \
545  (PARTNO == AT25SL321) || \
546  (PARTNO == AT25QL128A) || \
547  (PARTNO == AT25QL641) || \
548  (PARTNO == AT25QL321) || \
549  (PARTNO == AT25QF641) || \
550  (ALL == 1)
551 
561 
571 
581 
590 void standardflashReset();
591 
599 
607 #endif
608 
609 #if (PARTNO == AT25DL081) || \
610  (PARTNO == AT25DL161) || \
611  (PARTNO == AT25DF081A) || \
612  (PARTNO == AT25DF321A) || \
613  (PARTNO == AT25DF641A) || \
614  (ALL == 1)
615 
621 void standardflashReadSR(uint8_t *rxBuffer);
622 
636 void standardflashDualInputBytePageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes);
637 
645 
653 
660 void standardflashProtectSector(uint32_t address);
661 
668 void standardflashUnprotectSector(uint32_t address);
669 
677 uint8_t standardflashReadSectorProtectionReg(uint32_t address);
678 
688 
696 uint8_t standardflashReadLockdownReg(uint32_t address);
697 
713 void standardflashProgramOTPReg(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes);
714 
715 #endif
716 
717 #endif /* STANDARDFLASH_H_ */
void standardflashReadArrayLowFreq(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes)
OPCODE: 0x03 Reads rxNumBytes starting from location &#39;address&#39; and stores the data in the byte arra...
void standardflashQuadOutputRead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes)
OPCODE: 0x6B Reads &#39;txNumBytes&#39; bytes of data in Quad Output Mode starting at &#39;address&#39; using SI...
void standardflashChipErase1()
OPCODE: 0x60 Erases the entire chip by setting all bits. standardflashChipErase2() is functionally ...
void standardflashReadArrayHighFreq(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes)
OPCODE: 0x0B Reads rxNumBytes starting from location &#39;address&#39; and stores the data in the byte arra...
void standardflashDualOutputRead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes)
OPCODE: 0x3B Reads &#39;txNumBytes&#39; bytes of data in Dual Output Mode starting at &#39;address&#39; using both ...
void standardflashWriteSR(uint8_t *txBuffer, uint8_t txNumBytes)
OPCODE: 0x01 Writes the value in data to the status register byte 1, or bytes 1 and 2...
void standardflashSetQEBit()
: Sets the QE bit in status register byte 2. Does not modify any other bits. This is accomplished by ...
Definition: standardflash.c:99
void standardflashWriteSRB2(uint8_t regVal)
uint8_t standardflashReadSRB2()
OPCODE: 0x35 Reads the value in the device status register (byte 2).
void standardflashBytePageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes)
OPCODE: 0x02 Programs &#39;txNumBytes&#39; bytes of data starting at the address indicated by address...
void standardflashDisableQPI()
OPCODE: 0xFF Switches the device from QPI mode to SPI mode, and sets a variable to spi mode...
void standardflashClearQEBit()
: Clears the QE bit in status register byte 2. Does not modify any other bits. This is accomplished b...
void standardflashQuadPageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t mode)
OPCODE: 0x33 Programs &#39;txNumBytes&#39; bytes of data starting at the address indicated by address using...
void standardflashProtectSector(uint32_t address)
OPCODE: 0x36 Protects a sector containing the address address.
void standardflashFreezeLockdownState()
OPCODE: 0x34 Freezes the current state of the sector lockdown registers.
void standardflashWriteSRB1(uint8_t regVal)
void standardflashProgramEraseSuspend()
OPCODE: 0xB0 Suspends an erase or program mid operation.
void standardflashReadMID(uint8_t *rxBuffer)
OPCODE: 0x9F Reads the manufacturer ID and stores the data in rxBuffer.
void standardflashReadID(uint8_t *rxBuffer)
OPCODE: 0x90 Legace Command: Reads the manufacturer ID and stores the data in rxBuffer.
void standardflashBlockErase4K(uint32_t address)
OPCODE: 0x20 Erases a block of data (4 KBytes) starting from page address &#39;address.&#39;.
void standardflashEnableQPI()
OPCODE: 0x38 Switches the device from SPI mode to QPI mode, and sets a variable to quad mode...
uint8_t standardflashReadLockdownReg(uint32_t address)
OPCODE: 0x35 Reads the sector lockdown register for address address.
void standardflashProgramSecurityRegisters(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes)
OPCODE: 0x42 Programs the security registers with the contents of txBuffer.
void standardflashEraseProgramSuspend()
OPCODE: 0x75 Suspends an erase or program mid operation.
void standardflashEnableReset()
OPCODE: 0x66 Enable software reset of the flash device.
void standardflashProgramOTPReg(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes)
OPCODE: 0x9B Programs &#39;txNumBytes&#39; bytes of data to the OTP register starting at the address indica...
void standardflashReset()
OPCODE: 0x99 Software reset the flash device.
void standardflashQuadIORead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes, uint8_t readMode, uint8_t modeByteValue)
OPCODE: 0xEB Reads &#39;txNumBytes&#39; bytes of data in Quad IO Mode starting at &#39;address&#39; using SI...
void standardflashWaitOnReady()
: Wait while Read/Busy Status bit in SRB is 1 (device is busy). This is accomplished by reading the f...
Definition: standardflash.c:77
Definitions for opcodes.
#define MAXIMUM_TX_BYTES
Definition: cmd_defs.h:46
void standardflashEraseProgramResume()
OPCODE: 0x7A Resumes a previously suspended erase or program.
void standardflashResumeFromDPD()
OPCODE: 0xAB Wake the device from deep power down mode. See dataflashDPD().
uint8_t standardflashReadSRB1()
OPCODE: 0x05 Reads the value in the device status register (byte 1).
void standardflashResumeFromDPDReadID(uint8_t *rxBuffer)
OPCODE: 0xAB Wake the device from deep power down mode and read the 1 byte ID. See standardflashDPD...
Declarations of spi_driver functions.
void standardflashChipErase2()
OPCODE: 0xC7 Erases the entire chip by setting all bits. standardflashChipErase1() is functionally ...
void standardflashDualInputBytePageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes)
OPCODE: 0xA2 Programs &#39;txNumBytes&#39; bytes of data starting at the address indicated by address using...
void standardflashDPD()
OPCODE: 0xB9 Put the device into deep power down mode. Call dataflashResumeFromDPD() to wake up...
uint8_t standardflashReadSectorProtectionReg(uint32_t address)
OPCODE: 0x3C Reads the sector protection register for address address.
void standardflashBlockErase64K(uint32_t address)
OPCODE: 0xD8 Erases a block of data (4 KBytes) starting from page address &#39;address.&#39;.
void standardflashReadSR(uint8_t *rxBuffer)
OPCODE: 0x05 Reads the value in the device status register (byte 1 and 2).
void standardflashUnprotectSector(uint32_t address)
OPCODE: 0x39 Un-protects a sector containing the address address.
void standardflashWriteEnableVolatileSR()
OPCODE: 0x50 Sends opcode to enable writing for the volatile status register.
void standardflashReadSecurityRegisters(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes)
OPCODE: 0x48 Reads the contents of the security registers and stores it in the rxBuffer.
void standardflashExitSecuredOTP()
OPCODE: 0xC1 Exit secured OTP region.
void standardflashContinuousReadModeDualReset()
OPCODE: 0xFFFF Resets the dual continuous read mode that was entered with standardflashDualIORead()...
Declarations of helper functions.
void standardflashEnterSecureOTP()
OPCODE: 0xB1 Enter secured OTP region.
void standardflashBlockErase32K(uint32_t address)
OPCODE: 0x52 Erases a block of data (4 KBytes) starting from page address &#39;address.&#39;.
void standardflashWriteDisable()
OPCODE: 0x04 Sends opcode to disable writing.
void standardflashDualIORead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes, uint8_t readMode, uint8_t modeByteValue)
OPCODE: 0xBB Reads &#39;txNumBytes&#39; bytes of data in Dual IO Mode starting at &#39;address&#39; using both SI a...
void standardflashContinuousReadModeQuadReset()
OPCODE: 0xFF Resets the quad continuous read mode that was entered with standardflashQuadIORead() w...
void standardflashWriteEnable()
OPCODE: 0x06 Sends opcode to enable writing.
void standardflashProgramEraseResume()
OPCODE: 0xD0 Resumes a previously suspended erase or program.
uint8_t txStandardflashInternalBuffer[MAXIMUM_TX_BYTES]
Definition: standardflash.c:73
void standardflashEraseSecurityRegister(uint32_t address)
OPCODE: 0x44 Sends opcode to erase the security registers.