Skip to content

Commit

Permalink
2021-11-29 Add driver w25q32 for esp32/s2/s3
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhongv committed Nov 29, 2021
1 parent 84ec31b commit 625209b
Show file tree
Hide file tree
Showing 12 changed files with 777 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 25_esp32c3_flash_w25q32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(w25q64)
9 changes: 9 additions & 0 deletions 25_esp32c3_flash_w25q32/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := w25q64

include $(IDF_PATH)/make/project.mk

5 changes: 5 additions & 0 deletions 25_esp32c3_flash_w25q32/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

在 esp32 SDK实现驱动 Flash W25Q32 的封装,扩大容量存储更多的资源:https://blog.csdn.net/xh870189248/article/details/121308383

commit id : 7af719e426952995b2a205e821e7471a0b995125
适合的芯片模组有: ESP32 ESP32C3 ESP32S3 ESP32S2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(src "my_spi_flash.c")
set(inc "include")


idf_component_register(SRCS ${src}
INCLUDE_DIRS ${inc})
64 changes: 64 additions & 0 deletions 25_esp32c3_flash_w25q32/components/flash_w25qxx/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
menu "My_FLash_W25QXX Configuration"

choice BRAND_FLASH
prompt "brand 品牌选择"
default BRAND_FLASH_OTHER
help
select your flash brand
config BRAND_FLASH_OTHER
bool "other 通用品牌"
config ESP_CUSTOM_BOARD_WINBOND
bool "WinBond 华邦"
endchoice


config MISO_GPIO
int "MISO GPIO number"
range 0 46
default 19 if IDF_TARGET_ESP32
default 33 if IDF_TARGET_ESP32S2
default 18 if IDF_TARGET_ESP32C3
help
GPIO number (IOxx) to SPI MISO.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to MISO.
On the ESP32, GPIOs 35-39 are input-only so cannot be used as outputs.
On the ESP32-S2, GPIO 46 is input-only so cannot be used as outputs.

config MOSI_GPIO
int "MOSI GPIO number"
range 0 46
default 23 if IDF_TARGET_ESP32
default 35 if IDF_TARGET_ESP32S2
default 19 if IDF_TARGET_ESP32C3
help
GPIO number (IOxx) to SPI MOSI.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to MOSI.
On the ESP32, GPIOs 35-39 are input-only so cannot be used as outputs.
On the ESP32-S2, GPIO 46 is input-only so cannot be used as outputs.

config SCLK_GPIO
int "SCLK GPIO number"
range 0 46
default 18 if IDF_TARGET_ESP32
default 36 if IDF_TARGET_ESP32S2
default 10 if IDF_TARGET_ESP32C3
help
GPIO number (IOxx) to SPI SCLK.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to SCLK.
On the ESP32, GPIOs 35-39 are input-only so cannot be used as outputs.
On the ESP32-S2, GPIO 46 is input-only so cannot be used as outputs.

config CS_GPIO
int "CS GPIO number"
range 0 46
default 5 if IDF_TARGET_ESP32
default 34 if IDF_TARGET_ESP32S2
default 9 if IDF_TARGET_ESP32C3
help
GPIO number (IOxx) to SPI CS.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to CS.
On the ESP32, GPIOs 35-39 are input-only so cannot be used as outputs.
On the ESP32-S2, GPIO 46 is input-only so cannot be used as outputs.


endmenu
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef __SPI_FLASH__
#define __SPI_FLASH__

//W25X系列/Q系列芯片列表
//W25Q80 ID 0XEF13
//W25Q16 ID 0XEF14
//W25Q32 ID 0XEF15
//W25Q64 ID 0XEF16
//W25Q128 ID 0XEF17
//W25Q256 ID 0XEF18
#define W25Q80 0XEF13
#define W25Q16 0XEF14
#define W25Q32 0XEF15
#define W25Q64 0XEF16
#define W25Q128 0XEF17
#define W25Q256 0XEF18


//指令表
#define W25X_WriteEnable 0x06
#define W25X_WriteDisable 0x04
#define W25X_ReadStatusReg 0x05
// #define W25X_ReadStatusReg2 0x35
// #define W25X_ReadStatusReg3 0x15
#define W25X_WriteStatusReg 0x01
// #define W25X_WriteStatusReg2 0x31
// #define W25X_WriteStatusReg3 0x11
#define W25X_ReadData 0x03
#define W25X_FastReadData 0x0B
#define W25X_FastReadDual 0x3B
#define W25X_PageProgram 0x02
#define W25X_BlockErase 0xD8
#define W25X_SectorErase 0x20
#define W25X_ChipErase 0xC7
#define W25X_PowerDown 0xB9
#define W25X_ReleasePowerDown 0xAB
#define W25X_DeviceID 0xAB
#define W25X_ManufactDeviceID 0x90
#define W25X_JedecDeviceID 0x9F
#define W25X_Enable4ByteAddr 0xB7
#define W25X_Exit4ByteAddr 0xE9

void SPI_FLASH_Init(void);
uint16_t W25QXX_ReadID(void); //读取FLASH ID
uint8_t W25QXX_ReadSR(void); //读取状态寄存器S
void W25QXX_Write_SR(uint8_t sr); //写状态寄存器
void W25QXX_Write_Enable(void); //写使能
void W25QXX_Write_Disable(void); //写保护
void W25QXX_Write_NoCheck(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
void W25QXX_Read(uint8_t *pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead); //读取flash
void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite); //写入flash
void W25QXX_Erase_Chip(void); //整片擦除
void W25QXX_Erase_Sector(uint32_t Dst_Addr); //扇区擦除
void W25QXX_Wait_Busy(void); //等待空闲
void W25QXX_PowerDown(void); //进入掉电模式
void W25QXX_WAKEUP(void); //唤醒
uint16_t W25QXX_Read_Data(uint8_t *Temp_buff, uint32_t ReadAddr, uint16_t Size_Temp_buff); //读取缓存中的一组数据
uint32_t Read_Post_Len(uint32_t Start_Addr, uint32_t End_Addr); //读取缓存中正确的数据的总大小

#endif
Loading

0 comments on commit 625209b

Please sign in to comment.