daniel-p-carvalho opened a new pull request, #20442:
URL: https://github.com/apache/nuttx/pull/20442
## Summary
This PR adds 4-byte address mode support to the standard Winbond W25 SPI NOR
flash driver (`drivers/mtd/w25.c`).
Currently, the SPI driver only supports capacities up to 128 Mbit (16 MB)
using standard 3-byte addressing. With this change:
- Support is extended to 256 Mbit (32 MB, W25Q256) and 512 Mbit (64 MB,
W25Q512).
- Automatic detection of JEDEC capacity IDs 0x19 (256Mbit) and 0x20
(512Mbit).
- On initialization, the driver issues `W25_EN4B` (0xB7) to enter 4-byte
address mode when capacity >= 256 Mbit.
- The `struct w25_dev_s` sector counter `nsectors` is expanded to `uint32_t`
to support sector counts > 65535.
- A new helper `w25_sendaddr()` sends 3 or 4 address bytes depending on
device capacity for sector erase, byte read, page write, and byte write
operations.
- Updated documentation in
`Documentation/components/drivers/special/mtd/devices/w25q.rst`.
## Impact
- Is new feature added? YES, 4-byte addressing for W25 SPI flash >= 256Mbit.
- Impact on user: NO (chips <= 128Mbit behave identically using 3-byte
addressing).
- Impact on build: NO.
- Impact on hardware: YES, enables Winbond W25 chips >= 256Mbit on SPI buses.
- Impact on documentation: YES, updated `w25q.rst`.
- Impact on security: NO.
- Impact on compatibility: Fully backward-compatible.
## Testing
I confirm that changes are verified on local setup and works as intended:
- Build Host: Linux x86_64, GCC 13.x
- Target: ARM Cortex-M4, ST Nucleo-L432KC with Winbond W25Q256JV (256Mbit /
32MB) on custom baseboard
Testing logs after change:
- Boot detection:
```text
w25_readid: manufacturer: ef memory: 40 capacity: 19
w25_ioctl: blocksize: 256 erasesize: 4096 neraseblocks: 8192
```
- Raw block write & read beyond 16MB boundary at block 40000 (~20.48 MB,
offset 0x01388000):
```text
nsh> dd if=/dev/zero of=/dev/mtdblock0 bs=512 count=1 seek=40000
512 bytes (1 blocks) copied, 150000 usec, 3 KB/s
nsh> dd if=/dev/mtdblock0 of=/dev/null bs=512 count=1 skip=40000
512 bytes (1 blocks) copied, 20000 usec, 25 KB/s
```
- SmartFS mount and file reading on 32MB chip:
```text
nsh> mount -t smartfs /dev/smart0 /mnt
nsh> ls -l /mnt
/mnt:
-rwSrwSrw- 209 emtds.cfg
-rwSrwSrw- 106 modbus.cfg
-rwSrwSrw- 46 mfr.dat
-rwSrwSrw- 224 mdl.dat
-rwSrwSrw- 1750 dna.dat
nsh> cat /mnt/modbus.cfg
[Modbus]
mb_en=1
mb_addr=10
mb_resp_delay=0
mb_autobaud=0
mb_baudrate=13
mb_bits=48
mb_parity=0
mb_stop=0
```
## PR verification Self-Check
- [x] This PR introduces only one functional change.
- [x] I have updated all required description fields above.
- [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
- [ ] My PR is still work in progress (not ready for review).
- [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]