LibDriver W25QXX  1.0.0
W25QXX full-featured driver
driver_w25qxx.h
Go to the documentation of this file.
1 
37 #ifndef DRIVER_W25QXX_H
38 #define DRIVER_W25QXX_H
39 
40 #include <stdint.h>
41 #include <stdio.h>
42 #include <string.h>
43 
44 #ifdef __cplusplus
45 extern "C"{
46 #endif
47 
62 typedef enum
63 {
64  W25Q80 = 0XEF13U,
65  W25Q16 = 0XEF14U,
66  W25Q32 = 0XEF15U,
67  W25Q64 = 0XEF16U,
68  W25Q128 = 0XEF17U,
69  W25Q256 = 0XEF18U,
70  W25Q512 = 0XEF19U,
71  W25Q1024 = 0XEF20U,
72  W25Q2048 = 0XEF21U,
74 
78 typedef enum
79 {
83 
87 typedef enum
88 {
92 
96 typedef enum
97 {
101 
114 typedef enum
115 {
121 
125 typedef enum
126 {
132 
133 
137 typedef enum
138 {
143 
147 typedef enum
148 {
155 
159 typedef enum
160 {
170 
174 typedef enum
175 {
184 
188 typedef enum
189 {
199 
212 typedef struct w25qxx_handle_s
213 {
214  uint8_t (*spi_qspi_init)(void);
215  uint8_t (*spi_qspi_deinit)(void);
216  uint8_t (*spi_qspi_write_read)(uint8_t instruction, uint8_t instruction_line,
217  uint32_t address, uint8_t address_line, uint8_t address_len,
218  uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len,
219  uint8_t dummy, uint8_t *in_buf, uint32_t in_len,
220  uint8_t *out_buf, uint32_t out_len, uint8_t data_line);
221  void (*delay_ms)(uint32_t ms);
222  void (*delay_us)(uint32_t us);
223  void (*debug_print)(const char *const fmt, ...);
224  uint8_t inited;
225  uint16_t type;
226  uint8_t address_mode;
227  uint8_t param;
228  uint8_t dummy;
230  uint8_t spi_qspi;
231  uint8_t buf[256 + 6];
232  uint8_t buf_4k[4096 + 1];
234 
238 typedef struct w25qxx_info_s
239 {
240  char chip_name[32];
241  char manufacturer_name[32];
242  char interface[16];
248  uint32_t driver_version;
250 
268 #define DRIVER_W25QXX_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
269 
276 #define DRIVER_W25QXX_LINK_SPI_QSPI_INIT(HANDLE, FUC) (HANDLE)->spi_qspi_init = FUC
277 
284 #define DRIVER_W25QXX_LINK_SPI_QSPI_DEINIT(HANDLE, FUC) (HANDLE)->spi_qspi_deinit = FUC
285 
292 #define DRIVER_W25QXX_LINK_SPI_QSPI_WRITE_READ(HANDLE, FUC) (HANDLE)->spi_qspi_write_read = FUC
293 
300 #define DRIVER_W25QXX_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
301 
308 #define DRIVER_W25QXX_LINK_DELAY_US(HANDLE, FUC) (HANDLE)->delay_us = FUC
309 
316 #define DRIVER_W25QXX_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
317 
337 uint8_t w25qxx_info(w25qxx_info_t *info);
338 
349 
359 uint8_t w25qxx_get_dual_quad_spi(w25qxx_handle_t *handle, w25qxx_bool_t *enable);
360 
370 uint8_t w25qxx_set_type(w25qxx_handle_t *handle, w25qxx_type_t type);
371 
381 uint8_t w25qxx_get_type(w25qxx_handle_t *handle, w25qxx_type_t *type);
382 
392 uint8_t w25qxx_set_interface(w25qxx_handle_t *handle, w25qxx_interface_t interface);
393 
403 uint8_t w25qxx_get_interface(w25qxx_handle_t *handle, w25qxx_interface_t *interface);
404 
418 
430 
446 uint8_t w25qxx_init(w25qxx_handle_t *handle);
447 
459 uint8_t w25qxx_deinit(w25qxx_handle_t *handle);
460 
475 uint8_t w25qxx_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
476 
492 uint8_t w25qxx_write(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
493 
509 uint8_t w25qxx_only_spi_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
510 
525 uint8_t w25qxx_fast_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
526 
544 uint8_t w25qxx_page_program(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint16_t len);
545 
560 uint8_t w25qxx_sector_erase_4k(w25qxx_handle_t *handle, uint32_t addr);
561 
576 uint8_t w25qxx_block_erase_32k(w25qxx_handle_t *handle, uint32_t addr);
577 
592 uint8_t w25qxx_block_erase_64k(w25qxx_handle_t *handle, uint32_t addr);
593 
605 uint8_t w25qxx_chip_erase(w25qxx_handle_t *handle);
606 
617 uint8_t w25qxx_power_down(w25qxx_handle_t *handle);
618 
630 
643 uint8_t w25qxx_get_manufacturer_device_id(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id);
644 
672 uint8_t w25qxx_fast_read_dual_output(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
673 
690 uint8_t w25qxx_fast_read_quad_output(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
691 
708 uint8_t w25qxx_fast_read_dual_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
709 
725 uint8_t w25qxx_fast_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
726 
743 uint8_t w25qxx_word_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
744 
761 uint8_t w25qxx_octal_word_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len);
762 
781 uint8_t w25qxx_page_program_quad_input(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint16_t len);
782 
793 uint8_t w25qxx_enable_write(w25qxx_handle_t *handle);
794 
806 
817 uint8_t w25qxx_disable_write(w25qxx_handle_t *handle);
818 
830 uint8_t w25qxx_get_status1(w25qxx_handle_t *handle, uint8_t *status);
831 
843 uint8_t w25qxx_get_status2(w25qxx_handle_t *handle, uint8_t *status);
844 
856 uint8_t w25qxx_get_status3(w25qxx_handle_t *handle, uint8_t *status);
857 
870 uint8_t w25qxx_set_status1(w25qxx_handle_t *handle, uint8_t status);
871 
884 uint8_t w25qxx_set_status2(w25qxx_handle_t *handle, uint8_t status);
885 
898 uint8_t w25qxx_set_status3(w25qxx_handle_t *handle, uint8_t status);
899 
911 
923 
939 uint8_t w25qxx_get_manufacturer_device_id_dual_io(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id);
940 
956 uint8_t w25qxx_get_manufacturer_device_id_quad_io(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id);
957 
970 uint8_t w25qxx_get_jedec_id(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t device_id[2]);
971 
983 
995 
1010 
1022 uint8_t w25qxx_enter_qspi_mode(w25qxx_handle_t *handle);
1023 
1035 uint8_t w25qxx_exit_qspi_mode(w25qxx_handle_t *handle);
1036 
1047 uint8_t w25qxx_enable_reset(w25qxx_handle_t *handle);
1048 
1059 uint8_t w25qxx_reset_device(w25qxx_handle_t *handle);
1060 
1074 uint8_t w25qxx_get_unique_id(w25qxx_handle_t *handle, uint8_t id[8]);
1075 
1088 uint8_t w25qxx_get_sfdp(w25qxx_handle_t *handle, uint8_t sfdp[256]);
1089 
1105 
1121 uint8_t w25qxx_program_security_register(w25qxx_handle_t *handle, w25qxx_security_register_t num, uint8_t data[256]);
1122 
1138 uint8_t w25qxx_read_security_register(w25qxx_handle_t *handle, w25qxx_security_register_t num, uint8_t data[256]);
1139 
1152 uint8_t w25qxx_individual_block_lock(w25qxx_handle_t *handle, uint32_t addr);
1153 
1166 uint8_t w25qxx_individual_block_unlock(w25qxx_handle_t *handle, uint32_t addr);
1167 
1181 uint8_t w25qxx_read_block_lock(w25qxx_handle_t *handle, uint32_t addr, uint8_t *value);
1182 
1196 
1232 uint8_t w25qxx_write_read_reg(w25qxx_handle_t *handle, uint8_t instruction, uint8_t instruction_line,
1233  uint32_t address, uint8_t address_line, uint8_t address_len,
1234  uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len,
1235  uint8_t dummy, uint8_t *in_buf, uint32_t in_len,
1236  uint8_t *out_buf, uint32_t out_len, uint8_t data_line);
1237 
1246 #ifdef __cplusplus
1247 }
1248 #endif
1249 
1250 #endif
uint8_t w25qxx_erase_program_resume(w25qxx_handle_t *handle)
resume erase or program
w25qxx_status2_t
w25qxx status 2 enumeration definition
uint8_t w25qxx_enable_volatile_sr_write(w25qxx_handle_t *handle)
enable volatile sr writing
uint8_t w25qxx_get_unique_id(w25qxx_handle_t *handle, uint8_t id[8])
get the unique id
uint8_t w25qxx_get_manufacturer_device_id_dual_io(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id)
get the manufacturer && device id information with dual io
uint8_t w25qxx_page_program_quad_input(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint16_t len)
quad page program with quad input
uint8_t w25qxx_get_sfdp(w25qxx_handle_t *handle, uint8_t sfdp[256])
get the sfdp
uint8_t w25qxx_set_status1(w25qxx_handle_t *handle, uint8_t status)
set the status 1
uint8_t w25qxx_reset_device(w25qxx_handle_t *handle)
reset the device
w25qxx_qspi_read_wrap_length_t
w25qxx qspi read wrap length enumeration definition
uint8_t w25qxx_read_security_register(w25qxx_handle_t *handle, w25qxx_security_register_t num, uint8_t data[256])
read the security register
uint8_t w25qxx_program_security_register(w25qxx_handle_t *handle, w25qxx_security_register_t num, uint8_t data[256])
program the security register
uint8_t w25qxx_individual_block_lock(w25qxx_handle_t *handle, uint32_t addr)
lock the individual block
uint8_t w25qxx_read_block_lock(w25qxx_handle_t *handle, uint32_t addr, uint8_t *value)
read the block lock
uint8_t w25qxx_get_manufacturer_device_id_quad_io(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id)
get the manufacturer && device id information with quad io
uint8_t w25qxx_exit_qspi_mode(w25qxx_handle_t *handle)
exit the qspi mode
uint8_t w25qxx_global_block_unlock(w25qxx_handle_t *handle)
unlock the whole block
w25qxx_qspi_read_dummy_t
w25qxx qspi read dummy enumeration definition
uint8_t w25qxx_fast_read_dual_output(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read with dual output in the fast mode
uint8_t w25qxx_individual_block_unlock(w25qxx_handle_t *handle, uint32_t addr)
unlock the individual block
w25qxx_security_register_t
w25qxx security register enumeration definition
uint8_t w25qxx_octal_word_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
octal word read with quad io
uint8_t w25qxx_get_jedec_id(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t device_id[2])
get the jedec id information
w25qxx_burst_wrap_t
w25qxx burst wrap enumeration definition
uint8_t w25qxx_get_status3(w25qxx_handle_t *handle, uint8_t *status)
get the status 3
uint8_t w25qxx_set_read_parameters(w25qxx_handle_t *handle, w25qxx_qspi_read_dummy_t dummy, w25qxx_qspi_read_wrap_length_t length)
set the read parameters
w25qxx_status1_t
w25qxx status 1 enumeration definition
uint8_t w25qxx_get_status2(w25qxx_handle_t *handle, uint8_t *status)
get the status 2
uint8_t w25qxx_enter_qspi_mode(w25qxx_handle_t *handle)
enter the qspi mode
uint8_t w25qxx_get_status1(w25qxx_handle_t *handle, uint8_t *status)
get the status 1
uint8_t w25qxx_set_status2(w25qxx_handle_t *handle, uint8_t status)
set the status 2
uint8_t w25qxx_global_block_lock(w25qxx_handle_t *handle)
lock the whole block
uint8_t w25qxx_enable_reset(w25qxx_handle_t *handle)
enable the reset
uint8_t w25qxx_fast_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read with quad io in the fast mode
uint8_t w25qxx_disable_write(w25qxx_handle_t *handle)
disable writing
uint8_t w25qxx_set_burst_with_wrap(w25qxx_handle_t *handle, w25qxx_burst_wrap_t wrap)
set the burst with wrap
uint8_t w25qxx_erase_program_suspend(w25qxx_handle_t *handle)
suspend erase or program
uint8_t w25qxx_fast_read_dual_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read with dual io in the fast mode
w25qxx_status3_t
w25qxx status 3 enumeration definition
uint8_t w25qxx_word_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
word read with quad io
uint8_t w25qxx_set_status3(w25qxx_handle_t *handle, uint8_t status)
set the status 3
uint8_t w25qxx_enable_write(w25qxx_handle_t *handle)
enable writing
uint8_t w25qxx_erase_security_register(w25qxx_handle_t *handle, w25qxx_security_register_t num)
erase the security register
uint8_t w25qxx_fast_read_quad_output(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read with quad output in the fast mode
@ W25QXX_STATUS2_SECURITY_REGISTER_3_LOCK_BITS
@ W25QXX_STATUS2_SECURITY_REGISTER_2_LOCK_BITS
@ W25QXX_STATUS2_SUSPEND_STATUS
@ W25QXX_STATUS2_COMPLEMENT_PROTECT
@ W25QXX_STATUS2_STATUS_REGISTER_PROTECT_1
@ W25QXX_STATUS2_SECURITY_REGISTER_1_LOCK_BITS
@ W25QXX_STATUS2_QUAD_ENABLE
@ W25QXX_QSPI_READ_WRAP_LENGTH_8_BYTE
@ W25QXX_QSPI_READ_WRAP_LENGTH_64_BYTE
@ W25QXX_QSPI_READ_WRAP_LENGTH_32_BYTE
@ W25QXX_QSPI_READ_WRAP_LENGTH_16_BYTE
@ W25QXX_QSPI_READ_DUMMY_4_55MHZ
@ W25QXX_QSPI_READ_DUMMY_6_80MHZ
@ W25QXX_QSPI_READ_DUMMY_2_33MHZ
@ W25QXX_QSPI_READ_DUMMY_8_80MHZ
@ W25QXX_SECURITY_REGISTER_2
@ W25QXX_SECURITY_REGISTER_3
@ W25QXX_SECURITY_REGISTER_1
@ W25QXX_BURST_WRAP_64_BYTE
@ W25QXX_BURST_WRAP_8_BYTE
@ W25QXX_BURST_WRAP_32_BYTE
@ W25QXX_BURST_WRAP_NONE
@ W25QXX_BURST_WRAP_16_BYTE
@ W25QXX_STATUS1_STATUS_REGISTER_PROTECT_0
@ W25QXX_STATUS1_WRITE_ENABLE_LATCH
@ W25QXX_STATUS1_BLOCK_PROTECT_1
@ W25QXX_STATUS1_TOP_BOTTOM_PROTECT_OR_BLOCK_PROTECT_3
@ W25QXX_STATUS1_BLOCK_PROTECT_0
@ W25QXX_STATUS1_SECTOR_PROTECT_OR_TOP_BOTTOM_PROTECT
@ W25QXX_STATUS1_BLOCK_PROTECT_2
@ W25QXX_STATUS1_ERASE_WRITE_PROGRESS
@ W25QXX_STATUS3_CURRENT_ADDRESS_MODE
@ W25QXX_STATUS3_OUTPUT_DRIVER_STRENGTH_75_PERCENTAGE
@ W25QXX_STATUS3_WRITE_PROTECT_SELECTION
@ W25QXX_STATUS3_OUTPUT_DRIVER_STRENGTH_50_PERCENTAGE
@ W25QXX_STATUS3_HOLD_RESET_FUNCTION
@ W25QXX_STATUS3_OUTPUT_DRIVER_STRENGTH_100_PERCENTAGE
@ W25QXX_STATUS3_POWER_UP_ADDRESS_MODE
@ W25QXX_STATUS3_OUTPUT_DRIVER_STRENGTH_25_PERCENTAGE
uint8_t w25qxx_chip_erase(w25qxx_handle_t *handle)
erase the chip
uint8_t w25qxx_release_power_down(w25qxx_handle_t *handle)
release power down
uint8_t w25qxx_only_spi_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read only in the spi interface
uint8_t w25qxx_block_erase_32k(w25qxx_handle_t *handle, uint32_t addr)
erase the 32k block
uint8_t w25qxx_get_address_mode(w25qxx_handle_t *handle, w25qxx_address_mode_t *mode)
get the chip address mode
uint8_t w25qxx_set_interface(w25qxx_handle_t *handle, w25qxx_interface_t interface)
set the chip interface
struct w25qxx_handle_s w25qxx_handle_t
w25qxx handle structure definition
struct w25qxx_info_s w25qxx_info_t
w25qxx information structure definition
uint8_t w25qxx_page_program(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint16_t len)
page program
uint8_t w25qxx_set_dual_quad_spi(w25qxx_handle_t *handle, w25qxx_bool_t enable)
enable or disable the dual quad spi
uint8_t w25qxx_get_type(w25qxx_handle_t *handle, w25qxx_type_t *type)
get the chip type
w25qxx_type_t
w25qxx type enumeration definition
Definition: driver_w25qxx.h:63
uint8_t w25qxx_get_interface(w25qxx_handle_t *handle, w25qxx_interface_t *interface)
get the chip interface
uint8_t w25qxx_init(w25qxx_handle_t *handle)
initialize the chip
uint8_t w25qxx_get_manufacturer_device_id(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id)
get the manufacturer && device id information
uint8_t w25qxx_info(w25qxx_info_t *info)
get chip's information
uint8_t w25qxx_sector_erase_4k(w25qxx_handle_t *handle, uint32_t addr)
erase the 4k sector
uint8_t w25qxx_deinit(w25qxx_handle_t *handle)
close the chip
w25qxx_address_mode_t
w25qxx address mode enumeration definition
Definition: driver_w25qxx.h:97
uint8_t w25qxx_set_type(w25qxx_handle_t *handle, w25qxx_type_t type)
set the chip type
uint8_t w25qxx_write(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
write data
uint8_t w25qxx_fast_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read in the fast mode
w25qxx_interface_t
w25qxx interface enumeration definition
Definition: driver_w25qxx.h:79
uint8_t w25qxx_set_address_mode(w25qxx_handle_t *handle, w25qxx_address_mode_t mode)
set the chip address mode
uint8_t w25qxx_get_dual_quad_spi(w25qxx_handle_t *handle, w25qxx_bool_t *enable)
get the dual quad spi status
uint8_t w25qxx_power_down(w25qxx_handle_t *handle)
power down
uint8_t w25qxx_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read data
uint8_t w25qxx_block_erase_64k(w25qxx_handle_t *handle, uint32_t addr)
erase the 64k block
w25qxx_bool_t
w25qxx bool enumeration definition
Definition: driver_w25qxx.h:88
@ W25Q80
Definition: driver_w25qxx.h:64
@ W25Q64
Definition: driver_w25qxx.h:67
@ W25Q32
Definition: driver_w25qxx.h:66
@ W25Q512
Definition: driver_w25qxx.h:70
@ W25Q16
Definition: driver_w25qxx.h:65
@ W25Q1024
Definition: driver_w25qxx.h:71
@ W25Q128
Definition: driver_w25qxx.h:68
@ W25Q2048
Definition: driver_w25qxx.h:72
@ W25Q256
Definition: driver_w25qxx.h:69
@ W25QXX_ADDRESS_MODE_3_BYTE
Definition: driver_w25qxx.h:98
@ W25QXX_ADDRESS_MODE_4_BYTE
Definition: driver_w25qxx.h:99
@ W25QXX_INTERFACE_QSPI
Definition: driver_w25qxx.h:81
@ W25QXX_INTERFACE_SPI
Definition: driver_w25qxx.h:80
@ W25QXX_BOOL_FALSE
Definition: driver_w25qxx.h:89
@ W25QXX_BOOL_TRUE
Definition: driver_w25qxx.h:90
uint8_t w25qxx_write_read_reg(w25qxx_handle_t *handle, uint8_t instruction, uint8_t instruction_line, uint32_t address, uint8_t address_line, uint8_t address_len, uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len, uint8_t dummy, uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf, uint32_t out_len, uint8_t data_line)
write and read register
w25qxx handle structure definition
uint8_t buf[256+6]
uint8_t(* spi_qspi_write_read)(uint8_t instruction, uint8_t instruction_line, uint32_t address, uint8_t address_line, uint8_t address_len, uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len, uint8_t dummy, uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf, uint32_t out_len, uint8_t data_line)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_qspi_deinit)(void)
uint8_t address_mode
void(* debug_print)(const char *const fmt,...)
void(* delay_us)(uint32_t us)
uint8_t dual_quad_spi_enable
uint8_t buf_4k[4096+1]
uint8_t(* spi_qspi_init)(void)
w25qxx information structure definition
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
char interface[16]
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]