44 #if (PARTNO == AT25SF641) || \ 45 (PARTNO == AT25SF321) || \ 46 (PARTNO == AT25SF161) || \ 47 (PARTNO == AT25SF081) || \ 48 (PARTNO == AT25SF041) || \ 49 (PARTNO == AT25SL128A) || \ 50 (PARTNO == AT25SL641) || \ 51 (PARTNO == AT25SL321) || \ 52 (PARTNO == AT25DL081) || \ 53 (PARTNO == AT25DL161) || \ 54 (PARTNO == AT25DF081A) || \ 55 (PARTNO == AT25DF321A) || \ 56 (PARTNO == AT25DF641A) || \ 57 (PARTNO == AT25QL128A) || \ 58 (PARTNO == AT25QL641) || \ 59 (PARTNO == AT25QL321) || \ 60 (PARTNO == AT25QF641) || \ 68 static uint8_t MCU_SPI_MODE = 0;
70 static bool DISPLAY_OUTPUT = 0;
72 static void debugOn() {DISPLAY_OUTPUT = 1;};
73 static void debugOff() {DISPLAY_OUTPUT = 0;};
79 uint8_t SRArray[2] = {0, 0};
82 #if (PARTNO == AT25DL081) || \ 83 (PARTNO == AT25DL161) || \ 84 (PARTNO == AT25DF081A) || \ 85 (PARTNO == AT25DF321A) || \ 86 (PARTNO == AT25DF641A) 90 while(SRArray[1] & (1<<0));
95 while(SRArray[0] & (1<<0));
101 uint8_t SRArray[2] = {0, 0};
103 #if (PARTNO == AT25DL081) || \ 104 (PARTNO == AT25DL161) || \ 105 (PARTNO == AT25DF081A) || \ 106 (PARTNO == AT25DF321A) || \ 107 (PARTNO == AT25DF641A) 114 SRArray[1] |= (1 << 1);
119 #if (PARTNO == AT25DL081) || \ 120 (PARTNO == AT25DL161) || \ 121 (PARTNO == AT25DF081A) || \ 122 (PARTNO == AT25DF321A) || \ 123 (PARTNO == AT25DF641A) 137 uint8_t SRArray[2] = {0, 0};
139 #if (PARTNO == AT25DL081) || \ 140 (PARTNO == AT25DL161) || \ 141 (PARTNO == AT25DF081A) || \ 142 (PARTNO == AT25DF321A) || \ 143 (PARTNO == AT25DF641A) 150 SRArray[1] &= ~(1 << 1);
155 #if (PARTNO == AT25DL081) || \ 156 (PARTNO == AT25DL161) || \ 157 (PARTNO == AT25DF081A) || \ 158 (PARTNO == AT25DF321A) || \ 159 (PARTNO == AT25DF641A) 174 if(MCU_SPI_MODE ==
SPI)
187 if(MCU_SPI_MODE ==
SPI)
210 if(MCU_SPI_MODE ==
SPI)
224 uint32_t totalBytes = txNumBytes + 4;
226 for(uint32_t j = 0; j < txNumBytes; j++)
231 if(MCU_SPI_MODE ==
SPI)
244 if(MCU_SPI_MODE ==
SPI)
257 if(MCU_SPI_MODE ==
SPI)
270 if(MCU_SPI_MODE ==
SPI)
283 if(MCU_SPI_MODE ==
SPI)
296 if(MCU_SPI_MODE ==
SPI)
309 if(MCU_SPI_MODE ==
SPI)
322 if(MCU_SPI_MODE ==
SPI)
335 if(MCU_SPI_MODE ==
SPI)
348 if(MCU_SPI_MODE ==
SPI)
358 #if (PARTNO == AT25SF641) || \ 359 (PARTNO == AT25SF321) || \ 360 (PARTNO == AT25SF161) || \ 361 (PARTNO == AT25SF081) || \ 362 (PARTNO == AT25SF041) || \ 363 (PARTNO == AT25SL128A) || \ 364 (PARTNO == AT25SL641) || \ 365 (PARTNO == AT25SL321) || \ 366 (PARTNO == AT25QL128A) || \ 367 (PARTNO == AT25QL641) || \ 368 (PARTNO == AT25QL321) || \ 369 (PARTNO == AT25QF641) || \ 380 if(MCU_SPI_MODE ==
SPI)
391 #if (PARTNO == AT25SF641) || \ 392 (PARTNO == AT25SL128A) || \ 393 (PARTNO == AT25SL641) || \ 394 (PARTNO == AT25SL321) || \ 395 (PARTNO == AT25QL128A) || \ 396 (PARTNO == AT25QL641) || \ 397 (PARTNO == AT25QL321) || \ 398 (PARTNO == AT25QF641) || \ 399 (PARTNO == AT25DL081) || \ 400 (PARTNO == AT25DL161) || \ 401 (PARTNO == AT25DF081A) || \ 402 (PARTNO == AT25DF321A) || \ 403 (PARTNO == AT25DF641A) || \ 410 if(MCU_SPI_MODE ==
SPI)
424 if(MCU_SPI_MODE ==
SPI)
435 #if (PARTNO == AT25SF641) || \ 436 (PARTNO == AT25SF321) || \ 437 (PARTNO == AT25SF161) || \ 438 (PARTNO == AT25SF081) || \ 439 (PARTNO == AT25SF041) || \ 440 (PARTNO == AT25SL128A) || \ 441 (PARTNO == AT25SL641) || \ 442 (PARTNO == AT25SL321) || \ 443 (PARTNO == AT25QL128A) || \ 444 (PARTNO == AT25QL641) || \ 445 (PARTNO == AT25QL321) || \ 446 (PARTNO == AT25QF641) || \ 451 if(MCU_SPI_MODE ==
SPI)
465 if(MCU_SPI_MODE ==
SPI)
480 if(MCU_SPI_MODE ==
SPI)
501 void standardflashDualIORead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes, uint8_t readMode, uint8_t modeByteValue)
504 uint8_t transmissionSelect = 0x02;
511 transmissionSelect = 0x00;
517 transmissionSelect = 0x00;
525 transmissionSelect = 0x01;
533 transmissionSelect = 0x01;
536 printf(
"Error with standardflashDualIORead.\n");
537 printf(
"\t- Invalid dualReadMode value. Expected 0-3, received %d.\n", readMode);
538 printf(
"\tSee documentation for operating modes.\n");
542 if(transmissionSelect == 0x00)
550 else if(transmissionSelect == 0x01)
570 void standardflashQuadIORead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes, uint8_t readMode, uint8_t modeByteValue)
573 uint8_t transmissionSelect = 0x02;
580 transmissionSelect = 0x00;
586 transmissionSelect = 0x00;
594 transmissionSelect = 0x01;
602 transmissionSelect = 0x01;
605 printf(
"Error with standardflashQuadIORead.\n");
606 printf(
"\t- Invalid quadReadMode value. Expected 0-3, received %d.\n", readMode);
607 printf(
"\tSee documentation for operating modes.\n");
611 if(transmissionSelect == 0x00)
613 if(MCU_SPI_MODE ==
SPI)
622 else if(transmissionSelect == 0x01)
624 if(MCU_SPI_MODE ==
SPI)
649 if(MCU_SPI_MODE ==
SPI)
673 uint32_t totalBytes = txNumBytes + 4;
675 for(uint32_t j = 0; j < txNumBytes; j++)
700 if(MCU_SPI_MODE ==
SPI)
714 uint32_t totalBytes = txNumBytes + 4;
716 for(uint32_t j = 0; j < txNumBytes; j++)
721 if(MCU_SPI_MODE ==
SPI)
733 #if (PARTNO == AT25SF641) || \ 734 (PARTNO == AT25SF321) || \ 735 (PARTNO == AT25SF161) || \ 736 (PARTNO == AT25SL128A) || \ 737 (PARTNO == AT25SL641) || \ 738 (PARTNO == AT25SL321) || \ 739 (PARTNO == AT25QL128A) || \ 740 (PARTNO == AT25QL641) || \ 741 (PARTNO == AT25QL321) || \ 742 (PARTNO == AT25QF641) || \ 748 if(MCU_SPI_MODE ==
SPI)
761 if(MCU_SPI_MODE ==
SPI)
774 #if (PARTNO == AT25SF641) || \ 775 (PARTNO == AT25SL128A) || \ 776 (PARTNO == AT25SL641) || \ 777 (PARTNO == AT25SL321) || \ 778 (PARTNO == AT25QL128A) || \ 779 (PARTNO == AT25QL641) || \ 780 (PARTNO == AT25QL321) || \ 781 (PARTNO == AT25QF641) || \ 811 if(MCU_SPI_MODE ==
SPI)
824 if(MCU_SPI_MODE ==
SPI)
837 if(MCU_SPI_MODE ==
SPI)
850 if(MCU_SPI_MODE ==
SPI)
863 #if (PARTNO == AT25DL081) || \ 864 (PARTNO == AT25DL161) || \ 865 (PARTNO == AT25DF081A) || \ 866 (PARTNO == AT25DF321A) || \ 867 (PARTNO == AT25DF641A) || \ 873 if(MCU_SPI_MODE ==
SPI)
887 uint32_t totalBytes = txNumBytes + 4;
889 for(uint32_t j = 0; j < txNumBytes; j++)
942 uint8_t registerVal = 0;
965 uint8_t registerVal = 0;
979 uint32_t totalBytes = txNumBytes + 4;
981 for(uint32_t j = 0; j < txNumBytes; j++)
void standardflashWriteDisable()
OPCODE: 0x04 Sends opcode to disable writing.
#define CMD_STANDARDFLASH_READ_ID
void standardflashReadSR(uint8_t *rxBuffer)
OPCODE: 0x05 Reads the value in the device status register (byte 1 and 2).
#define CMD_STANDARDFLASH_ENABLE_QPI
void standardflashResumeFromDPD()
OPCODE: 0xAB Wake the device from deep power down mode. See dataflashDPD().
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 standardflashEraseProgramSuspend()
OPCODE: 0x75 Suspends an erase or program mid operation.
void SPI_QuadExchange(uint8_t standardSPINumBytes, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
Sends and receives bytes based on the function parameters. MOSI can used for the opcode and address...
void printSPIExchange(uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes)
Prints the byte array in hexadecimal with a formatted output. Indicates what bytes were sent...
#define CMD_STANDARDFLASH_READ_SECURITY_REG_PAGE
void standardflashWriteEnableVolatileSR()
OPCODE: 0x50 Sends opcode to enable writing for the volatile status register.
#define CMD_STANDARDFLASH_EXIT_SECURED_OTP
#define CMD_STANDARDFLASH_WRITE_DISABLE
void standardflashProgramOTPReg(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes)
OPCODE: 0x9B Programs 'txNumBytes' bytes of data to the OTP register starting at the address indica...
#define CMD_STANDARDFLASH_DUAL_IO_READ
void standardflashContinuousReadModeDualReset()
OPCODE: 0xFFFF Resets the dual continuous read mode that was entered with standardflashDualIORead()...
void standardflashResumeFromDPDReadID(uint8_t *rxBuffer)
OPCODE: 0xAB Wake the device from deep power down mode and read the 1 byte ID. See standardflashDPD...
#define CMD_STANDARDFLASH_READ_SECT_PROT_REG
#define CMD_STANDARDFLASH_UNPROTECT_SECTOR
#define CMD_STANDARDFLASH_WRITE_SRB2
void standardflashDPD()
OPCODE: 0xB9 Put the device into deep power down mode. Call dataflashResumeFromDPD() to wake up...
void standardflashQuadIORead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes, uint8_t readMode, uint8_t modeByteValue)
OPCODE: 0xEB Reads 'txNumBytes' bytes of data in Quad IO Mode starting at 'address' using SI...
void standardflashDualIORead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes, uint8_t readMode, uint8_t modeByteValue)
OPCODE: 0xBB Reads 'txNumBytes' bytes of data in Dual IO Mode starting at 'address' using both SI a...
uint8_t standardflashReadSectorProtectionReg(uint32_t address)
OPCODE: 0x3C Reads the sector protection register for address address.
#define CMD_STANDARDFLASH_QUAD_PAGE_PROGRAM
void standardflashEraseProgramResume()
OPCODE: 0x7A Resumes a previously suspended erase or program.
void standardflashReadArrayLowFreq(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes)
OPCODE: 0x03 Reads rxNumBytes starting from location 'address' and stores the data in the byte arra...
#define CMD_STANDARDFLASH_READ_LOCKDOWN_REG
#define CMD_STANDARDFLASH_READ_SR
#define CMD_STANDARDFLASH_PROGRAM_ERASE_RESUME
uint8_t standardflashReadSRB1()
OPCODE: 0x05 Reads the value in the device status register (byte 1).
#define CMD_STANDARDFLASH_ENTER_SECURED_OTP
void standardflashSetQEBit()
: Sets the QE bit in status register byte 2. Does not modify any other bits. This is accomplished by ...
#define CMD_STANDARDFLASH_READ_ARRAY_HF
void standardflashProgramEraseResume()
OPCODE: 0xD0 Resumes a previously suspended erase or program.
#define CMD_STANDARDFLASH_BYTE_PAGE_PROGRAM
void standardflashEnterSecureOTP()
OPCODE: 0xB1 Enter secured OTP region.
#define CMD_STANDARDFLASH_CHIP_ERASE1
void standardflashChipErase2()
OPCODE: 0xC7 Erases the entire chip by setting all bits. standardflashChipErase1() is functionally ...
void standardflashBlockErase32K(uint32_t address)
OPCODE: 0x52 Erases a block of data (4 KBytes) starting from page address 'address.'.
void standardflashDualInputBytePageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes)
OPCODE: 0xA2 Programs 'txNumBytes' bytes of data starting at the address indicated by address using...
void standardflashEraseSecurityRegister(uint32_t address)
OPCODE: 0x44 Sends opcode to erase the security registers.
void standardflashQuadPageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t mode)
OPCODE: 0x33 Programs 'txNumBytes' bytes of data starting at the address indicated by address using...
void standardflashBlockErase64K(uint32_t address)
OPCODE: 0xD8 Erases a block of data (4 KBytes) starting from page address 'address.'.
#define CMD_STANDARDFLASH_DUAL_OUTPUT_READ
void standardflashUnprotectSector(uint32_t address)
OPCODE: 0x39 Un-protects a sector containing the address address.
#define CMD_STANDARDFLASH_BLOCK_ERASE_32K
#define CMD_STANDARDFLASH_READ_SRB1
void standardflashContinuousReadModeQuadReset()
OPCODE: 0xFF Resets the quad continuous read mode that was entered with standardflashQuadIORead() w...
#define CMD_STANDARDFLASH_CHIP_ERASE2
void standardflashFreezeLockdownState()
OPCODE: 0x34 Freezes the current state of the sector lockdown registers.
void standardflashWriteSRB1(uint8_t regVal)
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 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 standardflashWriteSRB2(uint8_t regVal)
#define CMD_STANDARDFLASH_PROTECT_SECTOR
#define CMD_STANDARDFLASH_DUAL_BYTE_PAGE_PROGRAM
void standardflashExitSecuredOTP()
OPCODE: 0xC1 Exit secured OTP region.
void load4BytesToTxBuffer(uint8_t *txBuffer, uint8_t opcode, uint32_t address)
Loads 1 byte of opcode followed by 3 address bytes into the txBuffer. The data is stored at the first...
uint8_t txStandardflashInternalBuffer[MAXIMUM_TX_BYTES]
#define CMD_STANDARDFLASH_PROGRAM_ERASE_SUSPEND
void standardflashEnableReset()
OPCODE: 0x66 Enable software reset of the flash device.
#define CMD_STANDARDFLASH_DISABLE_QPI
#define CMD_STANDARDFLASH_RESUME_FROM_DPD
void standardflashClearQEBit()
: Clears the QE bit in status register byte 2. Does not modify any other bits. This is accomplished b...
void standardflashQuadOutputRead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes)
OPCODE: 0x6B Reads 'txNumBytes' bytes of data in Quad Output Mode starting at 'address' using SI...
void SPI_DualExchange(uint8_t standardSPINumBytes, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
Sends and receives bytes based on the function parameters. MOSI is used for the opcode and address...
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 'address' and stores the data in the byte arra...
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...
#define CMD_STANDARDFLASH_WE_FOR_VOLATILE_SR
void standardflashWaitOnReady()
: Wait while Read/Busy Status bit in SRB is 1 (device is busy). This is accomplished by reading the f...
void standardflashWriteEnable()
OPCODE: 0x06 Sends opcode to enable writing.
#define CMD_STANDARDFLASH_WRITE_SR
#define CMD_STANDARDFLASH_ENABLE_RESET
void SPI_Delay(uint32_t delayTime)
Performs a delayTime number of NOPs.
void standardflashProgramSecurityRegisters(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes)
OPCODE: 0x42 Programs the security registers with the contents of txBuffer.
#define CMD_STANDARDFLASH_READ_SRB2
#define CMD_STANDARDFLASH_ERASE_PROGRAM_RESUME
#define CMD_STANDARDFLASH_PROGRAM_OTP_REG
#define CMD_STANDARDFLASH_QUAD_IO_READ
#define CMD_STANDARDFLASH_READ_ARRAY_LF
#define CMD_STANDARDFLASH_CONT_READ_MODE_RST_DUAL
#define CMD_STANDARDFLASH_WRITE_SRB1
#define CMD_STANDARDFLASH_CONT_READ_MODE_RST_QUAD
void standardflashProtectSector(uint32_t address)
OPCODE: 0x36 Protects a sector containing the address address.
#define CMD_STANDARDFLASH_FREEZE_LOCKDOWN_STATE
#define CMD_STANDARDFLASH_BLOCK_ERASE_4K
#define CMD_STANDARDFLASH_READ_MID
void standardflashReset()
OPCODE: 0x99 Software reset the flash device.
#define CMD_STANDARDFLASH_RESET
void standardflashProgramEraseSuspend()
OPCODE: 0xB0 Suspends an erase or program mid operation.
Declarations of Standardflash functions.
void standardflashDualOutputRead(uint32_t address, uint8_t *rxBuffer, uint32_t rxNumBytes)
OPCODE: 0x3B Reads 'txNumBytes' bytes of data in Dual Output Mode starting at 'address' using both ...
#define CMD_STANDARDFLASH_QUAD_OUTPUT_READ
uint8_t standardflashReadSRB2()
OPCODE: 0x35 Reads the value in the device status register (byte 2).
void standardflashBlockErase4K(uint32_t address)
OPCODE: 0x20 Erases a block of data (4 KBytes) starting from page address 'address.'.
#define CMD_STANDARDFLASH_ERASE_SECURTIY_REG_PAGE
void standardflashBytePageProgram(uint32_t address, uint8_t *txBuffer, uint32_t txNumBytes)
OPCODE: 0x02 Programs 'txNumBytes' 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...
#define CMD_STANDARDFLASH_BLOCK_ERASE_64K
#define CMD_STANDARDFLASH_ERASE_PROGRAM_SUSPEND
void SPI_Exchange(uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
Sends and receives bytes based on the function parameters. MISO and MOSI fill their standard SPI role...
#define CMD_STANDARDFLASH_PROGRAM_SECURITY_REG_PAGE
#define CMD_STANDARDFLASH_WRITE_ENABLE
Standardflash Devices and Opcodes AT25SF041 AT25SF081 AT25SF161 AT25SF321 AT25SF641 AT25SL321 AT25SL6...
#define CMD_STANDARDFLASH_DEEP_POWER_DOWN