simple FS  v0.1.0
memory_winbond32.h
Go to the documentation of this file.
1 
22 #ifndef __MODULE_WINDBOND32_H
23 #define __MODULE_WINDBOND32_H
24 
25 #ifdef USE_HAL_DRIVER
26 #include "main.h"
27 #endif
28 
29 #include "memory_driver.h"
30 #include "simplefs_config.h"
31 
32 //--------------------------------------------------------------------------
33 
34 //#ifndef USE_SPI
35 //#ifndef USE_QSPI
36 //#error Select SPI or QSPI interface in module_winbond.h file
37 //#endif // USE_QSPI
38 //#endif // USE_SPI
39 
40 //#ifdef USE_SPI
41 //#ifdef USE_QSPI
42 //#error Select only on einterface (SPI or QSPI) interface in module_winbond.h file
43 //#endif // USE_QSPI
44 //#endif // USE_SPI
45 
46 #define MEMORY_MANUFACTURER_WINBOND 0xEF
47 #define MEMORY_MANUFACTURER_MICRON 0x20
48 #define MEMORY_MANUFACTURER_CYPRESS 0x01
49 
50 //COMMANDS
51 #define W_SR 0x01 //write status reg
52 #define PAGE_PGM 0x02 //page program
53 #define READ 0x03
54 #define W_DE 0x04 //write disable
55 #define R_SR1 0x05 //read status reg 1
56 #define W_EN 0x06 //write enable
57 #define FAST_READ 0x0b
58 #define SECTOR_E 0x20 //sector erase 4KB
59 #define QPAGE_PGM 0x32 //quad input page program
60 #define READ_DSPI 0x3B
61 #define R_SR2 0x35 //read status reg 2
62 #define R_UNIQUE_ID 0x4b //read unique ID (suggested)
63 #define W_SR_ENABLE 0x50
64 #define CHIP_ERASE2 0x60 //=CHIP_ERASE
65 #define BLK_E_32K 0x52 //block erase 32KB
66 #define E_SUSPEND 0x75 //erase suspend
67 #define E_RESUME 0x7a //erase resume
68 #define R_MANUF_ID 0x90 //read Manufacturer and Dev ID (deprecated)
69 #define R_JEDEC_ID 0x9f //read JEDEC ID = Manuf+ID (suggested)
70 #define HIGH_PERF_M 0xa3 //high performance mode
71 #define RELEASE 0xab //release power down or HPM/Dev ID (deprecated)
72 #define PDWN 0xb9 //power down
73 #define CHIP_ERASE 0xc7 //chip erase
74 #define BLK_E_64K 0xD8 //block erase 64KB
75 #define CONT_R_RST 0xff //continuous read mode reset
76 
77 
78 #define SR1_BUSY_MASK 0x01
79 #define SR1_WEN_MASK 0x02
80 #define WINBOND_MANUF 0xef
81 #define DEFAULT_TIMEOUT 200
82 #define WINBOND_32_PAGE 256
83 
84 #define WINBOND_32_SECTOR_SIZE WINBOND_32_PAGE*16
85 #define WINBOND_32_SECTOR_COUNT 1024
86 
87 
88 extern MemoryDriver_t memorySpi;
89 
90 typedef enum __winbond_status_mem_ {
91  MEMORY_EMPTY=0,
92  MEMORY_NOT_EMPTY,
93  MEMORY_BUSY,
94  MEMORY_ERROR
95 } Winbond_memoryStatus;
96 
97 typedef struct __winbond_driver_ {
98 #if USE_SPI_INTERFACE == NO_SPI
99  void *spi;
100 #endif
101 #if USE_SPI_INTERFACE == USE_SPI
102  #if SIMULATION == 0
103  SPI_HandleTypeDef *spi;
104  #else
105  void *spi;
106  #endif
107 #endif // USE_SPI
108 #if USE_SPI_INTERFACE == USE_QSPI
109  #if SIMULATION == 0
110  QSPI_HandleTypeDef *spi;
111  #else
112  void *spi;
113  #endif
114 #endif // QUSE_SPI
115  #if SIMULATION == 0
116  GPIO_TypeDef* PortCS;
117  #else
118  void* PortCS;
119  #endif
120  uint16_t PinCS;
121 // uint8_t w_cmd;
122  uint8_t *tx_data;
123  uint8_t *rx_data;
125 
126 #if USE_SPI_INTERFACE == NO_SPI
127 uint8_t winbond_init(void *hspi);
128 #endif
129 #if USE_SPI_INTERFACE == USE_SPI
130 uint8_t winbond_init(void *hspi, void *GPIOx, uint16_t GPIO_Pin);
131 #endif // USE_SPI
132 #if USE_SPI_INTERFACE == USE_QSPI
133 uint8_t winbond_init(void *hspi);
134 #endif // USE_SPI
135 //void setWriteEnable(uint8_t cmd);
136 //uint8_t writeEnable(void);
137 uint8_t winbond_isBusy(void);
138 uint16_t winbond_readSR(void);
139 uint8_t winbond_readManufacturer(void);
140 uint64_t winbond_readUniqueID();
141 uint8_t winbond_readMemoryType(void);
142 uint8_t winbond_readCapacity(void);
143 uint16_t winbond_read(uint32_t addr,uint8_t *buf,uint16_t n);
144 uint16_t winbond_read_DMA(uint32_t addr,uint8_t *buf,uint16_t n);
145 uint16_t winbond_write(uint32_t addr,uint8_t *buf,int32_t n);
146 uint8_t winbond_powerDown(void);
147 uint8_t winbond_powerUp(void);
148 uint8_t winbond_eraseSector(uint32_t addr_start);
149 uint8_t winbond_eraseAll(void);
150 Winbond_memoryStatus winbond_checkSector(uint16_t sector_index);
151 uint8_t winbond_writeToMemory(uint32_t address, uint8_t *buf,uint16_t n);
152 uint8_t *winbond_readChipInfo(void);
153 void winbond_dump(void);
154 
155 uint8_t winbond_dma_cmplt();
156 uint8_t winbond_dma_half();
157 #endif
158 
winbond_init
uint8_t winbond_init(void *hspi)
end IO functions
Definition: memory_winbond32.c:274
memory_driver.h
interface definition for specific types of memories.
__winbond_driver_
Definition: memory_winbond32.h:97
MemoryDriver_t
Interface that defines list of functions with basic operation with memory.
Definition: memory_driver.h:86