Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
z_qflash_W25QXXX.h
Go to the documentation of this file.
1
27#ifndef Z_QFLASH_W25QXXX_H_
28#define Z_QFLASH_W25QXXX_H_
29
30/* Includes */
31#include "main.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
48#define FLASH_QSPI_PORT hqspi
57//#define EXT_FLASH_QSPI_POLLING_MODE
58#define EXT_FLASH_QSPI_DMA_MODE
69//#define FLASH_QSPI_WAIT_FOR_READING_COMPLETE
77//#define FLASH_QSPI_MEMORY_MAPPED
86//#define FLASH_QMODE_1 ///< Standard 1-bit SPI.
87//#define FLASH_QMODE_2 ///< Dual SPI (2-bit data lines).
88#define FLASH_QMODE_4
99#define EXT_FLASH_PAGE_SIZE 0x0100
100#define EXT_FLASH_SECTOR_SIZE 0x1000
101#define EXT_FLASH_BLOCK_SIZE 0x00010000
102#define EXT_FLASH_SIZE 0x04000000
103#define EXT_FLASH_PAGE_NUM (EXT_FLASH_SIZE / EXT_FLASH_PAGE_SIZE)
104#define EXT_FLASH_SECTOR_NUM (EXT_FLASH_SIZE / EXT_FLASH_SECTOR_SIZE)
105#define EXT_FLASH_BLOCK_NUM (EXT_FLASH_SIZE / EXT_FLASH_BLOCK_SIZE) // End of User Configuration group
109
110
111/* here values for the W25Q80DV/DL chips
112#define EXT_FLASH_PAGE_SIZE 0x0100 //256B page size (bytes)
113#define EXT_FLASH_SECTOR_SIZE 0x1000 //4kB sector size (bytes)
114#define EXT_FLASH_BLOCK_SIZE 0x00010000 //64kB block size (bytes)
115#define EXT_FLASH_SIZE 0X00100000 //1MB-8Mb total size (bytes)
116#define EXT_FLASH_PAGE_NUM 0x1000 //4096 pages
117#define EXT_FLASH_SECTOR_NUM 0x0100 //256 sectors
118#define EXT_FLASH_BLOCK_NUM 0x0010 //16 blocks
119*/
120
121/* here values for the W25Q64JV chips
122#define EXT_FLASH_PAGE_SIZE 0x0100 //256B page size (bytes)
123#define EXT_FLASH_SECTOR_SIZE 0x1000 //4kB sector size (bytes)
124#define EXT_FLASH_BLOCK_SIZE 0x00010000 //64kB block size (bytes)
125#define EXT_FLASH_SIZE 0X00800000 //8MB-64Mb total size (bytes)
126#define EXT_FLASH_PAGE_NUM 0x8000 //32768 pages
127#define EXT_FLASH_SECTOR_NUM 0x0800 //2048 sectors
128#define EXT_FLASH_BLOCK_NUM 0x0080 //128 blocks
129*/
130
131/* here values for the W25Q128JV chips
132#define EXT_FLASH_PAGE_SIZE 0x0100 //256b page size (bits)
133#define EXT_FLASH_SECTOR_SIZE 0x1000 //4kB sector size (bytes)
134#define EXT_FLASH_BLOCK_SIZE 0x00010000 //64kB block size (bytes)
135#define EXT_FLASH_SIZE 0X01000000 //16MB-128Mb total size (bytes)
136#define EXT_FLASH_PAGE_NUM 0x00010000 //32768 pages
137#define EXT_FLASH_SECTOR_NUM 0x1000 //4096 sectors
138#define EXT_FLASH_BLOCK_NUM 0x0100 //256 blocks
139*/
140
141/*|||||||| END OF USER/PROJECT PARAMETERS ||||||||*/
142
143
144
145/*|||||||||||||| LIBRARY PARAMETERS ||||||||||||||*/
146
147/***************************************************
148 ********* below information set behaviour *********
149 ****** of QSPI in the various configurations *****
150 ******* (eg. read command to use in single, *******
151 ************* dual, quad mode, etc.) **************
152 ***************************************************/
153
154//default configuration
161#define QFLASH_INSTRUCTION_MODE QSPI_INSTRUCTION_1_LINE
162#define QFLASH_ADDRESS_SIZE QSPI_ADDRESS_32_BITS
163#define QFLASH_ALTERNATE_BYTE_MODE QSPI_ALTERNATE_BYTES_NONE
164#define QFLASH_DDR_MODE QSPI_DDR_MODE_DISABLE
165#define QFLASH_DDR_HOLD_HALF_CYCLE QSPI_DDR_HHC_ANALOG_DELAY
166#define QFLASH_SIOO_MODE QSPI_SIOO_INST_EVERY_CMD
167#define QFLASH_DUMMY_CYCLES 0
168
169#define QFLASH_DEF_TIMEOUT HAL_QSPI_TIMEOUT_DEFAULT_VALUE
170#define QFLASH_BSY_TIMEOUT 400000 //a chip erase command requires up to 100s. (see "AC Electrical Characteristics" on Winbond datasheets)
171
172#ifdef FLASH_QMODE_1
173//quad mode parameters
174#define QFLASH_ADDRESS_MODE QSPI_ADDRESS_1_LINE
175#define QFLASH_DATA_MODE QSPI_DATA_1_LINE
176//quad mode read parameters
177#define QFLASH_READ_COMMAND W25_FREAD
178#define QFLASH_READ_DUMMYC 8
179#define QFLASH_ALT_BYTES 0xFF
180#define QFLASH_ALT_BYTES_S QSPI_ALTERNATE_BYTES_8_BITS
181#define QFLASH_ALT_BYTES_M QSPI_ALTERNATE_BYTES_NONE
182//quad mode write parameters
183#define QFLASH_WRITE_COMMAND W25_PAGE_P
184#define QFLASH_WDATA_MODE QSPI_DATA_1_LINE
185
186#elif defined FLASH_QMODE_2
187//dual mode parameters
188#define QFLASH_ADDRESS_MODE QSPI_ADDRESS_2_LINES
189#define QFLASH_DATA_MODE QSPI_DATA_2_LINES
190//dual mode read parameters
191#define QFLASH_READ_COMMAND W25_FREAD_DUAL
192#define QFLASH_READ_DUMMYC 0
193#define QFLASH_ALT_BYTES 0xFF
194#define QFLASH_ALT_BYTES_S QSPI_ALTERNATE_BYTES_8_BITS
195#define QFLASH_ALT_BYTES_M QSPI_ALTERNATE_BYTES_2_LINES
196//dual mode write parameters
197#define QFLASH_WRITE_COMMAND W25_PAGE_P
198#define QFLASH_WDATA_MODE QSPI_DATA_1_LINE
199
200#elif defined FLASH_QMODE_4
201//quad mode parameters
202#define QFLASH_ADDRESS_MODE QSPI_ADDRESS_4_LINES
203#define QFLASH_DATA_MODE QSPI_DATA_4_LINES
204//quad mode read parameters
205#define QFLASH_READ_COMMAND W25_FREAD_QUAD
206#define QFLASH_READ_DUMMYC 4//4// TODO 6
207#define QFLASH_ALT_BYTES 0xFF
208#define QFLASH_ALT_BYTES_S QSPI_ALTERNATE_BYTES_8_BITS
209#define QFLASH_ALT_BYTES_M QSPI_ALTERNATE_BYTES_4_LINES
210//quad mode write parameters
211#define QFLASH_WRITE_COMMAND W25_FPAGE_P_QUAD_4B
212#define QFLASH_WDATA_MODE QSPI_DATA_4_LINES
213#endif
214
215/*|||||||||||| END OF LIBRARY PARAMETERS |||!!||||||||*/
216
217
218
219
220/*||||||||||||||| DEVICE PARAMETERS ||||||||||||||||||*/
221// W25QXX EEPROM family commands
222
223#define W25_RESET_EN 0x66 //sequence is 0x66 + 0x99 + 30us delay
224#define W25_RESET 0x99 //sequence is 0x66 + 0x99 + 30us delay
225#define W25_W_ENABLE 0x06
226#define W25_READ 0x03
227#define W25_FREAD 0x0B
228#define W25_FREAD_DUAL 0xBB
229#define W25_FREAD_QUAD 0xEB
230#define W25_PAGE_P 0x02
231#define W25_FPAGE_P_QUAD 0x32
232#define W25_FPAGE_P_QUAD_4B 0x34
233#define W25_S_ERASE4K 0x20
234#define W25_S_ERASE4K_4B 0x21
235#define W25_B_ERASE32K 0x52
236#define W25_B_ERASE64K 0xD8
237#define W25_B_ERASE64K_4B 0xDC
238#define W25_CH_ERASE 0xC7
239#define W25_POWERDOWN 0xB9
240#define W25_POWERUP_ID 0xAB
241#define W25_JEDEC_ID 0x9F
242#define W25_R_SR1 0x05
243#define W25_R_SFPD_REG 0x5A
244#define W25_W_DISABLE 0x04
245#define W25_MAN_DEVICE_ID 0x90
246#define W25_R_SR2 0x35
247#define W25_W_SR2 0x31
248#define W25_R_SR3 0x15
249#define W25_W_SR3 0x11
250#define W25_SR_W_ENABLE 0x50
251#define W25_ENTER_4B_ADDR 0xB7
252
253
254
255
256/* unused commands
257#define W25_MAN_DEVICE_ID 0x90
258#define W25_UNIQUE_ID 0x4B
259#define W25_EP_SUS 0x75
260#define W25_EP_RES 0x7A
261#define W25_W_SR1 0x01
262#define W25_R_SFPD_REG 0x5A
263#define W25_E_SEC_REG 0x44
264#define W25_P_SEC_REG 0x42
265#define W25_R_SEC_REG 0x48
266#define W25_G_BL_LOCK 0x7E
267#define W25_G_BL_UNLK 0x98
268#define W25_R_BL_LOCK 0x3D
269#define W25_I_BL_LOCK 0x36
270#define W25_I_BL_UNLK 0x39
271#define W25_EP_SUSPEND 0x75
272#define W25_EP_RESUME 0x75
273 end of unused commands */
274// W25QXX EEPROM family commands
275
276#define W25_DUMMY 0x00 //dummy MUST be 0x00, in "read manufacturer"
277
278// bit masks of W25QXX SR1, SR2, SR3 registers
279#define SR1_BIT_BSY (01U) //status only: 1 means busy device
280#define SR1_BIT_WEL (02U) //status only: 1 means write enabled. set by W25_W_ENABLE command
281#define SR2_BIT_QE (0x02U)
283/* unused bitmasks
284#define SR1_BIT_BP0 (04U) //writable: block protect bit 0
285#define SR1_BIT_BP1 (08U) //writable: block protect bit 1
286#define SR1_BIT_BP2 (10U) //writable: block protect bit 2
287#define SR1_BIT_TB (20U) //writable: top(=1)/bottom(=0) starting, block protection bit
288#define SR1_BIT_SEC (40U) //writable: sector(4kb)/block(64kb) block protection (1=sector)
289#define SR1_BIT_SRP (80U) //writable: set SR registers protection (together with SRL)
290#define SR2_BIT_SRL (01U) //writable: set SR registers protection (together with SRL)
291#define SR2_BIT_QE (02U) //writable: enable (=1) QUAD SPI mode. if =0 SPI is Standard/Dual
292#define SR2_BIT_LB1 (08U) //OTP: 1 means Security Register 1 is permanently set readonly
293#define SR2_BIT_LB2 (10U) //OTP: 1 means Security Register 2 is permanently set readonly
294#define SR2_BIT_LB3 (20U) //OTP: 1 means Security Register 3 is permanently set readonly
295#define SR2_BIT_CMP (40U) //writable: complement protect: reverse protection of BP0-1-2,TB,SEC
296#define SR2_BIT_SUS (80U) //writable: suspend status: 1 indicates erase/program suspended
297#define SR3_BIT_WPS (04U) //writable: Write protect scheme: 1=using individual block flag, 0=using BPx, etc, flags
298#define SR3_BIT_DRV0 (20U) //writable: sets output driver strength
299#define SR3_BIT_DRV1 (40U) //writable: sets output driver strength
300 end of W25QXX SR1, SR2, SR3 registers bitmasks */
301
302/*||||||||||| END OF DEVICE PARAMETERS ||||||||||||*/
303
304
305
306
307/*||||||||||| DEFINITIONS FOR E.L. GENERATION ||||||||||||*/
308
309#ifndef HAL_MAX_DELAY // if there is no the uc HAL definition (building an E.L.
310
314typedef enum
315{
316 HAL_OK = 0x00,
317 HAL_ERROR = 0x01,
318 HAL_BUSY = 0x02,
319 HAL_TIMEOUT = 0x03
321
322#endif
323
324/*||||||||||| END OF DEFINITIONS FOR E.L. GENERATION ||||||||||||*/
325
326// --- Public Function Prototypes ---
327
334uint8_t QFlash_IsQSPIAvailable(void);
336uint8_t QFlash_IsDataAvailable(void);
338void QFlash_DefaultCmd(QSPI_CommandTypeDef *sCommand);
349HAL_StatusTypeDef QFlash_ReadJedecID(uint8_t *dataptr);
350HAL_StatusTypeDef QFlash_ReadSFDP(uint8_t* dataptr);
351HAL_StatusTypeDef QFlash_ReadDevID(uint8_t *dataptr);
364HAL_StatusTypeDef QFlash_ReadSR1(uint8_t *dataptr);
365HAL_StatusTypeDef QFlash_ReadSR2(uint8_t *dataptr);
366HAL_StatusTypeDef QFlash_ReadSR3(uint8_t *dataptr);
381#ifdef FLASH_QSPI_MEMORY_MAPPED
382 #define ON_EXT_FLASH __attribute__((section("ExtFlashSection"))) __attribute__((aligned(4)))
383 HAL_StatusTypeDef QFlash_EnableMemoryMappedMode(void);
384#else
385 HAL_StatusTypeDef QFlash_Read(uint32_t address, uint8_t* buffer, uint32_t dataSize);
386 HAL_StatusTypeDef QFlash_Write(uint32_t addr, uint8_t* data, uint32_t dataSize);
387 HAL_StatusTypeDef QFlash_SErase4k(uint32_t addr);
388 HAL_StatusTypeDef QFlash_BErase32k(uint32_t addr);
389 HAL_StatusTypeDef QFlash_BErase64k(uint32_t addr);
391#endif
401void DataReader_ReadData(uint32_t address24, uint8_t* buffer, uint32_t length);
402void DataReader_StartDMAReadData(uint32_t address24, uint8_t* buffer, uint32_t length);
412void HAL_QSPI_CmdCpltCallback(QSPI_HandleTypeDef *hqspi);
413void HAL_QSPI_RxCpltCallback(QSPI_HandleTypeDef *hqspi);
414void HAL_QSPI_TxCpltCallback(QSPI_HandleTypeDef *hqspi);
415void HAL_QSPI_ErrorCallback(QSPI_HandleTypeDef *hqspi);
419#endif /* INC_Z_QFLASH_W25QXXX_H_ */
QSPI_HandleTypeDef hqspi
HAL QSPI handle for the external flash memory.
Definition main.c:58
void HAL_QSPI_TxCpltCallback(QSPI_HandleTypeDef *hqspi)
void HAL_QSPI_CmdCpltCallback(QSPI_HandleTypeDef *hqspi)
void HAL_QSPI_RxCpltCallback(QSPI_HandleTypeDef *hqspi)
void HAL_QSPI_ErrorCallback(QSPI_HandleTypeDef *hqspi)
HAL_StatusTypeDef QFlash_Reset(void)
HAL_StatusTypeDef QFlash_WriteSR2(uint8_t data)
writes to register 2
HAL_StatusTypeDef QFlash_WriteEnable(void)
enables writes
HAL_StatusTypeDef QFlash_ReadSR3(uint8_t *dataptr)
HAL_StatusTypeDef QFlash_PowerDown(void)
HAL_StatusTypeDef QFlash_ReadSR2(uint8_t *dataptr)
HAL_StatusTypeDef QFlash_CheckSR1(void)
HAL_StatusTypeDef QFlash_WriteDisable(void)
disables writes
HAL_StatusTypeDef QFlash_PowerUp(void)
HAL_StatusTypeDef QFlash_ReadSR1(uint8_t *dataptr)
HAL_StatusTypeDef QFlash_WriteSR3(uint8_t data)
writes to register 3
HAL_StatusTypeDef QFlash_WaitForWritingComplete(void)
HAL_StatusTypeDef QFlash_ReadDevID(uint8_t *dataptr)
HAL_StatusTypeDef QFlash_ReadManufactutrerAndDevID(uint16_t *dataptr)
read id of the winbond
HAL_StatusTypeDef QFlash_ReadJedecID(uint8_t *dataptr)
HAL_StatusTypeDef QFlash_ReadSFDP(uint8_t *dataptr)
HAL_StatusTypeDef QFlash_Init(void)
HAL_StatusTypeDef QFlash_BErase32k(uint32_t addr)
HAL_StatusTypeDef QFlash_SErase4k(uint32_t addr)
HAL_StatusTypeDef QFlash_BErase64k(uint32_t addr)
HAL_StatusTypeDef QFlash_ChipErase(void)
HAL_StatusTypeDef QFlash_Write(uint32_t addr, uint8_t *data, uint32_t dataSize)
HAL_StatusTypeDef QFlash_Read(uint32_t address, uint8_t *buffer, uint32_t dataSize)
HAL_StatusTypeDef QFlash_WaitForDataAvailable(uint32_t timeout)
HAL_StatusTypeDef QFlash_WaitForQSPIAvailable(uint32_t timeout)
uint8_t QFlash_IsQSPIAvailable(void)
void QFlash_DefaultCmd(QSPI_CommandTypeDef *sCommand)
uint8_t QFlash_IsDataAvailable(void)
void DataReader_ReadData(uint32_t address24, uint8_t *buffer, uint32_t length)
void DataReader_WaitForReceiveDone(void)
void DataReader_StartDMAReadData(uint32_t address24, uint8_t *buffer, uint32_t length)
: Header for main.c file. This file contains the common defines of the application.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_TIMEOUT
@ HAL_ERROR
@ HAL_OK
@ HAL_BUSY