找回密码
 立即注册
楼主: wuzhengmin

25.SPI读写W25X40CL - 按k1(20251026已经解决)

[复制链接]
  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:09:13 | 显示全部楼层
三、推荐调试方法

1. 使用调试串口输出关键信息(如地址、写入数据、读取数据等);
2. 用 LED 指示程序运行状态(如写入开始、写入完成、读取开始等);
3. 使用逻辑分析仪分析 SPI 通信过程;
4. 逐步调试:先测试 Page 0 是否正常,再测试 Page 1;
5. 测试单个写入与读取操作是否正确,再测试连续多个页的读写。


其实,调试方法是我最薄弱的地方,逻辑分析仪和示波器都有买回来,但是实际上还不会用


四、结论与建议

综合分析:
W25X40CL 的地址设置为 0x000100 是合法的,只要确保擦除和写入流程正确;
死机问题大概率与 SPI 通信异常或资源冲突有关,建议检查中断处理与 SPI 状态;
数据不一致问题多由未擦除或通信错误导致,应确保擦除写入流程完整;
建议严格按照 Flash 写入流程进行操作:擦除 → 写入 → 等待完成 → 读取验证。

如能提供更详细的代码片段或现象截图(如串口输出内容、逻辑分析仪波形),可进一步帮助定位问题。

结论与建议都回答的很细致,全面,但是我觉得很大概率是 SPI 通信异常或资源冲突


因为通信错误导致数据不一致,所以2个问题实际是1个问题



回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:14:53 | 显示全部楼层
我们STC32G12K128试验箱9.6 上的存储芯片是:
GD AY2122 25Q40CTIG UFT369
我在网上找了下列手册
gd25q40ceigr-20210723-yr3pEpYLd芯片手册原文:

1. FEATURES

  
4M-bit Serial Flash
  
  
Fast Program/Erase Speed
  
  
-512K-byte
  
  
-Page Program  time: 0.6ms typical
  
  
-256 bytes per  programmable page
  
  
-Sector Erase  time: 45ms typical
  
  
-Block Erase  time: 0.15/0.25s typical
  
  
Standard, Dual, Quad SPI
  
  
-Chip Erase  time: 2.5s typical
  
  
-Standard SPI:  SCLK, CS#, SI, SO, WP#, HOLD#
  
  
-Dual SPI: SCLK,  CS#, IO0, IO1, WP#, HOLD#
  
  
Flexible Architecture
  
  
-Quad SPI: SCLK,  CS#, IO0, IO1, IO2, IO3
  
  
-Uniform Sector  of 4K-byte
  
  
-Uniform Block  of 32/64K-byte
  
  
High Speed Clock Frequency
  
  
-120MHz for fast  read with 30PF load
  
Low Power Consumption
  
  
-Dual I/O Data  transfer up to 240Mbits/s
  
  
-1μA typical  deep power down current
  
  
-Quad I/O Data  transfer up to 480Mbits/s
  
  
-1μA typical  standby current
  
  
Software/Hardware Write Protection
  
  
Advanced Security Features
  
  
-Write protect  all/portion of memory via software
  
  
-128-Bit Unique  ID for each device
  
  
-Enable/Disable  protection with WP# Pin
  
  
-4x256-Byte  Security Registers With OTP Locks
  
  
-Top/Bottom  block protection
  
  
-Serial Flash  Discoverable Parameters (SFDP) Register
  
  
Minimum 100,000 Program/Erase Cycles
  
  
Single Power Supply Voltage
  
  
-Full voltage  range: 2.7~3.6V
  
  
Data Retention
  
  
-20-year data  retention typical
  
Allows XIP (execute in place) Operation
  
  
-Continuous Read  With 8/16/32/64-byte Wrap
  



截图202510240811079750.jpg
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:16:51 | 显示全部楼层
简单翻译一下:

1. 特性
4M-bit串行闪存 快速编程/擦除速度
-52K-byte -页面编程时间:典型0.6ms
-每个可编程页面256字节 -扇区擦除时间:典型45ms
块擦除时间:典型0.15/0.25s
标准、双、四SPI -芯片擦除时间:典型2.5s
标准SPISCLKCS#SISOWP#HOLD#
-SPISCLKCS#IO0IOWP#HOLD# 灵活架构
-SPISCLKCS#IO0IO1IO2IO3 -K-byte的统一扇区
-32/64K-byte的统一块
高速时钟频率
-120MHz30PF负载快速读取 低功耗
-I/O数据传输高达240Mbits/s-典型待机电流1μA
-I/数据传输高达480Mbits/s-典型待机电流1μA
软件/硬件写保护 高级安全特性
-通过软件保护所有/部分内存 -每个设备的128位唯一ID
-通过WP#引脚启用/禁用保护-4x256-Byte安全寄器,带OTP
-顶部/底部块保护 -串行闪存可发现参数(SFDP)寄存器
最少100,00次编程/擦除周期 单一电源电压
-全电压范围:2.7~3.6V
数据保持
-典型2年数据保持 允许XIP(原地执行)操作
-8/16/32/64-byte回卷的连续

2. GENERAL DESCRIPTION
The GD25Q40C (4M-bit) Serial flash supports the standardSerial Peripheral Interface (SPI), and supports the Dual/Quad SPI: SerialClock, Chip Select, Serial Data I/O0 (SI), I/O1 (SO), I/O2 (WP#), and I/O3(HOLD#). The Dual I/O data is transferred with speed of 240Mbits/s and the QuadI/O & Quad output data is transferred with speed of 480Mbits/s.

GD25Q40C4M-bit)串行闪存支持标准串行外设接口(SPI),并支持双四SPI:串行时钟、芯片选择、串行数据I/O0SI)、I/O1SO)、I/O2WP#I/O3HOLD#)。双I/O数据以240Mbits/s的速度传输,四I/O和四输出数据以40Mbits/s的速度传输。
注意:如果芯片未被选中,则必须将CS#驱动为高电平。上电后任何时候都不要让CS#悬空



回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:17:56 | 显示全部楼层
3.MEMORY ORGANIZATION3. 内存组织


截图202510240817455762.jpg
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:20:28 | 显示全部楼层



简单讲,这块存储芯片,不管你怎么选地址,擦除的话,都要4K对齐,一次过删除

才能往里写数据,就是说,擦除 的地址,最后3位一定都是000

Each sector has (每个扇区是4K 4*1024/256=16页)统一块扇区架构 GD25Q40C 64K字节块扇区架构
0扇区  0X000000----0X000FFF   1扇区   0X001000----0X001FFF   
2扇区  0X002000----0X002FFF   3扇区   0X003000----0X003FFF   
4扇区   0X004000----0X004FFF   5扇区   0X005000----0X005FFF   
6扇区   0X006000----0X006FFF   7扇区   0X007000----0X007FFF   
8扇区   0X008000----0X008FFF   9扇区   0X009000----0X009FFF   
10扇区  0X00A000----0X00AFFF   11扇区  0X00B000----0X00BFFF   
12扇区  0X00C000----0X00CFFF   13扇区  0X00D000----0X00DFFF   
14扇区  0X00E000----0X00EFFF   15扇区  0X00F000----0X00FFFF   


回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:23:07 | 显示全部楼层
当然,最大也不能超过07F000

记住总共有4M,超出就没有拉

截图202510240823015189.jpg
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:26:14 | 显示全部楼层
看看命令字:


7.1. Write Enable (WREN) (06H)
The Write Enable(WREN) command is for setting the Write Enable Latch (WEL) bit. The WriteEnable Latch (WEL) bit must be set prior to every Page Program (PP), SectorErase (SE), Block Erase (BE), and Chip Erase (CE), Write Status Register (WRSR)and Erase/Program Security Registers command. The Write Enable (WREN) commandsequence: CS# goes low à sending the Write Enable command à CS# goes high.




7.1. Write Enable(WREN) (06H)
写使能(WREN)命令用于设置写使能寄存(WEL)位。在每个页面编程(PP)、扇区擦除(SE)、块擦除(BE)、芯片擦除(CE)、状态寄存器(WRSR)和擦除/编程安全寄存器命令之前,必须设置写使能寄存器(WEL)位。写能(WREN)命令序列:CS# 变低 发送写使能命令 CS# 变高。


截图202510240825539859.jpg
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:28:17 | 显示全部楼层
7.2. Write Disable (WRDI) (04H)
The Write Disablecommand is for resetting the Write Enable Latch (WEL) bit. The Write Disablecommand sequence: CS# goes low àSending the Write Disable command àCS# goes high. The WEL bit is reset by following condition: Powerup andupon completion of the Write Status Register, Page Program, Sector Erase, BlockErase, Chip Erase, Erase/Program Security Registers and Reset commands.



7.2. Write Disable(WRDI) (04H) 写禁止命令用于重置写使能寄存器(W)位。写禁止命令序列: CS# 变低 发送写禁止命令 CS# 变高。WEL 位通过以下条件置:上电和完成写状态寄存器、页面编程、扇区擦除、块擦除、芯片擦除、擦除/编程安全寄存器和位命令。

截图202510240827556159.jpg
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:29:21 | 显示全部楼层
7.3. Read Status Register (RDSR) (05H or35H)
The Read StatusRegister (RDSR) command is for reading the Status Register. The Status Registermay be read at any time, even while a Program, Erase or Write Status Registercycle is in progress. When one of these cycles is in progress, it isrecommended to check the Write In Progress (WIP) bit before sending a newcommand to the device. It is also possible to read the Status Registercontinuously. For command code “05H”, the SO will output Status Register bitsS7~S0. The command code “35H”, the SO will output Status Register bits S15~S8.


7.3. 读取状态寄存器 (RDSR) (05H 35H) 读取状态寄器 (RDSR) 命令用于读取状态寄存器。状态寄存器可以在任何时候被读取,即使在程序、擦除或写状态寄存器正在进行中。当这些周期正在进行中时,建议在向设备发送新命令之前检查写操作正在进行 (WIP) 位。也可以连续读取状态寄存器对于命令代码 05H”,SO 将输出状态寄存器位 S7~S0。对于命令代码 35H”,SO 将输出状态寄器位 S15~S8

截图202510240828583933.jpg
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-11-02 09:54:45
已绑定手机

8

主题

594

回帖

1075

积分

金牌会员

积分
1075
发表于 2025-10-24 08:30:49 | 显示全部楼层
7.4. Write Status Register (WRSR) (01H)
The Write Status Register (WRSR) commandallows new values to be written to the Status Register. Before it can beaccepted, a Write Enable (WREN) command must previously have been executed.After the Write Enable (WREN) command has been decoded and executed, the devicesets the Write Enable Latch (WEL).
The Write Status Register (WRSR) commandhas no effect on S15, S13, S12, S11, S1 and S0 of the Status Register. CS# mustbe driven high after the eighth or sixteen bit of the data byte has beenlatched in. If not, the Write Status Register (WRSR) command is not executed.If CS# is driven high after eighth bit of the data byte, the CMP and QE bitwill be cleared to 0. As soon as CS# is driven high, the self-timed Write StatusRegister cycle (whose duration is tW) is initiated. While the Write Status Register cycle isin progress, the Status Register may still be read to check the value of theWrite In Progress (WIP) bit. The Write In Progress (WIP) bit is 1 during theself-timed Write Status Register cycle, and is 0 when it is completed. When thecycle is completed, the Write Enable Latch (WEL) is reset.
The Write StatusRegister (WRSR) command allows the user to change the values of the BlockProtect (BP4, BP3, BP2, BP1, BP0) bits, to define the size of the area that isto be treated as read-only, as defined in Table1. The Write Status Register(WRSR) command also allows the user to set or reset the Status Register Protect(SRP) bit in accordance with the Write Protect (WP#) signal. The StatusRegister Protect (SRP) bit and Write Protect (WP#) signal allow the device tobe put in the Hardware Protected Mode. The Write Status Register (WRSR) commandis not executed once the Hardware Protected Mode is entered.


7.4. 写状态寄存器 (WRSR) (01H) 写状态寄存 (WRSR) 命令允许将新值写入状态寄存器。在可以接受之前,必须先执行写使能 (WREN) 命令。在使能 (WREN) 命令解码和执行后,设备会设置写使能锁存器 (WEL) 写状态寄存器 (WRS) 命令对状态寄存器的 S15S13S12S11S1 S0 没有影响。 在数据字第八位或第十六位被锁存后,必须将 CS# 驱动为高电平。否则,写状态寄存器 (WRSR) 命令不会执行。如果在数据字节的第八位之后将 CS# 驱动为高电平,CMP QE 位将被清零为 0。一旦 CS 被驱动为高电平,自定时写状态寄存器周期 (其持续时间为 tW) 即启动。在写状态寄存器周期进行期间状态寄存器仍然可以读取,以检查写操作进行 (WIP) 位的值。在自定时写状态寄存器周期期间,写操作进行 (IP) 位为 1,完成后为 0 当周期完成后,写使能锁存器 (WEL) 将被复位。 写状态存器 (WRSR) 命令允许用户改变块保护 (BP4BP3BP2BP1BP0) 位的值,以定义将被只读的区域的大小,如表1所示。写状态寄存器 (WRSR) 命令还允许用户根据写保护 (WP#) 信号设置或位状态寄存器保护 (SRP) 位。状态寄存器保护 (SRP) 位和写保护 (WP#) 信号允许设备进入保护模式。一旦进入硬件保护模式,写状态寄存器 (WRSR) 命令将不再执行

截图202510240830288710.jpg
回复

使用道具 举报 送花

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-11-2 20:20 , Processed in 0.132736 second(s), 90 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表