lib : https://developer.mbed.org/users/DimiterK/code/W25Q64FVSSIG/ I try a little change code.

Dependents:   hexi_flash_mem

Fork of W25Q64FVSSIG by Dimiter K

Committer:
DimiterK
Date:
Sun Oct 09 23:05:55 2016 +0000
Revision:
0:b71060e03299
Child:
1:259668edf734
First release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DimiterK 0:b71060e03299 1 #include <mbed.h>
DimiterK 0:b71060e03299 2 #include <stdint.h>
DimiterK 0:b71060e03299 3
DimiterK 0:b71060e03299 4 #define CMD_WREN 0x06
DimiterK 0:b71060e03299 5 #define CMD_WR_DISABLE 0x04
DimiterK 0:b71060e03299 6 #define CMD_RDSR1 0x05
DimiterK 0:b71060e03299 7 #define CMD_RDSR2 0x35
DimiterK 0:b71060e03299 8 #define CMD_WRSR1 0x01 //write status register
DimiterK 0:b71060e03299 9 #define CMD_PAGEPROG 0x02
DimiterK 0:b71060e03299 10
DimiterK 0:b71060e03299 11 #define CMD_ERASE_SECTOR 0x20
DimiterK 0:b71060e03299 12 #define CMD_ERASE_BLOCK32 0x52
DimiterK 0:b71060e03299 13 #define CMD_ERASE_BLOCK64 0xD8
DimiterK 0:b71060e03299 14 #define CMD_ERASE_CHIP 0x60
DimiterK 0:b71060e03299 15
DimiterK 0:b71060e03299 16 #define CMD_PROG_SUSPEND 0x75
DimiterK 0:b71060e03299 17 #define CMD_PROG_RESUME 0x7A
DimiterK 0:b71060e03299 18 #define CMD_PWR_DOWN 0xB9
DimiterK 0:b71060e03299 19
DimiterK 0:b71060e03299 20 #define CMD_READ_DATA 0x03
DimiterK 0:b71060e03299 21 #define CMD_READ_HS 0x0B
DimiterK 0:b71060e03299 22
DimiterK 0:b71060e03299 23 #define CMD_MANU_ID 0x90
DimiterK 0:b71060e03299 24 #define CMD_JEDEC_ID 0x9F // Read Manufacturer and JDEC Device ID
DimiterK 0:b71060e03299 25 #define CMD_UNIQUE_ID 0x4B
DimiterK 0:b71060e03299 26
DimiterK 0:b71060e03299 27 #define CMD_READ_SFDP 0x5A
DimiterK 0:b71060e03299 28 #define CMD_ERASE_SEC_REG 0x44
DimiterK 0:b71060e03299 29 #define CMD_PROG_SEC_REG 0x42
DimiterK 0:b71060e03299 30 #define CMD_READ_SEC_REG 0x48
DimiterK 0:b71060e03299 31 #define CMD_ENABLE_RES 0x66
DimiterK 0:b71060e03299 32 #define CMD_RESET 0x99
DimiterK 0:b71060e03299 33
DimiterK 0:b71060e03299 34 #define DUMMY 0x00 // Dummy byte which can be changed to any value
DimiterK 0:b71060e03299 35
DimiterK 0:b71060e03299 36
DimiterK 0:b71060e03299 37 class W25Q64FV
DimiterK 0:b71060e03299 38 {
DimiterK 0:b71060e03299 39 public:
DimiterK 0:b71060e03299 40
DimiterK 0:b71060e03299 41 static const int SID_LEN = 32;
DimiterK 0:b71060e03299 42 static const int SECTOR_LEN = 4096;
DimiterK 0:b71060e03299 43 static const int PAGE_LEN = 256;
DimiterK 0:b71060e03299 44 static const int MAX_ADDR = 0x7FFFFF;
DimiterK 0:b71060e03299 45
DimiterK 0:b71060e03299 46 private:
DimiterK 0:b71060e03299 47
DimiterK 0:b71060e03299 48 SPI* spi;
DimiterK 0:b71060e03299 49 DigitalOut* cs;
DimiterK 0:b71060e03299 50
DimiterK 0:b71060e03299 51 int frequency;
DimiterK 0:b71060e03299 52 static uint8_t sector_buffer[SECTOR_LEN];
DimiterK 0:b71060e03299 53
DimiterK 0:b71060e03299 54
DimiterK 0:b71060e03299 55 public:
DimiterK 0:b71060e03299 56 W25Q64FV(PinName mosi, PinName miso, PinName sclk, PinName cs, int frequency=10000000);
DimiterK 0:b71060e03299 57 ~W25Q64FV();
DimiterK 0:b71060e03299 58
DimiterK 0:b71060e03299 59 uint16_t Id();
DimiterK 0:b71060e03299 60 uint32_t JEDECId();
DimiterK 0:b71060e03299 61
DimiterK 0:b71060e03299 62 // Read Status Register
DimiterK 0:b71060e03299 63 // bit 0 BUSY 1=Write in progress
DimiterK 0:b71060e03299 64 // bit 1 WEL 1=Write Enabled
DimiterK 0:b71060e03299 65 // bit 2 BP0 block write protection
DimiterK 0:b71060e03299 66 // bit 3 BP1 block write protection
DimiterK 0:b71060e03299 67 // bit 4 BP2 block write protection
DimiterK 0:b71060e03299 68 // bit 5 BP3 block write protection
DimiterK 0:b71060e03299 69 // bit 6 SEC 1=Security ID space locked
DimiterK 0:b71060e03299 70 // bit 7 BPL 1=BP0..BP3 are read-only, 0=r/w
DimiterK 0:b71060e03299 71 uint8_t readStatus();
DimiterK 0:b71060e03299 72 void writeStatusReg(int addr); // Write Status Register
DimiterK 0:b71060e03299 73
DimiterK 0:b71060e03299 74 void writeEnable(); // Write Enable
DimiterK 0:b71060e03299 75 void writeDisable(); // Write Disable
DimiterK 0:b71060e03299 76
DimiterK 0:b71060e03299 77 void writeSecurityReg(int addr);
DimiterK 0:b71060e03299 78
DimiterK 0:b71060e03299 79 uint8_t wait_while_busy(void);
DimiterK 0:b71060e03299 80
DimiterK 0:b71060e03299 81 uint8_t readByte(int32_t addr);
DimiterK 0:b71060e03299 82 bool read(uint32_t addr, uint8_t* dst, uint32_t len);
DimiterK 0:b71060e03299 83
DimiterK 0:b71060e03299 84 void hsread(uint32_t addr, uint8_t* dst, uint32_t len, int frequency);
DimiterK 0:b71060e03299 85
DimiterK 0:b71060e03299 86
DimiterK 0:b71060e03299 87 uint8_t readSFDP(int addr);
DimiterK 0:b71060e03299 88
DimiterK 0:b71060e03299 89 void sector_erase_4k(uint32_t addr);
DimiterK 0:b71060e03299 90 void block_erase_32k(uint32_t addr);
DimiterK 0:b71060e03299 91 void block_erase_64k(uint32_t addr);
DimiterK 0:b71060e03299 92 void chip_erase();
DimiterK 0:b71060e03299 93
DimiterK 0:b71060e03299 94 bool page_program(uint32_t addr, uint8_t* write_buffer, uint8_t len);
DimiterK 0:b71060e03299 95
DimiterK 0:b71060e03299 96 bool write(int32_t addr, uint8_t* write_buffer, int32_t len);
DimiterK 0:b71060e03299 97
DimiterK 0:b71060e03299 98 void writeArray(uint32_t address, uint8_t* pData, uint32_t arrayLength);
DimiterK 0:b71060e03299 99 void readArray(uint32_t address, uint8_t* pData, uint32_t arrayLength);
DimiterK 0:b71060e03299 100
DimiterK 0:b71060e03299 101
DimiterK 0:b71060e03299 102 };