Electronics > Projects, Designs, and Technical Stuff

[SOLVED] Weird SPI flash problem (Winbond W25Q32JV)

(1/1)

Unixon:
Hi, everyone.

I have a couple of strange problems with W25Q32JV SPI flash chip on a piece of hardware with STM32F051 MCU. I'm running SPI at 12Mbps.

1) After the first write operation something starts inserting 2 or 3 leading zero bytes at every following read transaction. First read gets 2 or 3 zero bytes, all next reads get 2 zero bytes before actual data. Data bytes are correct, but shifted, last 2 or 3 bytes of the actual data are missing (beyond transaction window). All read operations before the first write operation return correct data without leading zero bytes.

Steps to reproduce:
1.1 erase a sector, write one or more pages, reset uC, do not power off
1.2 read one or more pages of that sector - all bytes are correct
1.3 erase the sector again and write one or more pages
1.4 read one or more pages of that sector again - every read result is now preceded with zero bytes

2) Write operations to the first page of every sector, but the first sector, seem to be ignored, while the first page of the first sector always writes successfully. Under some conditions, I haven't figured this out yet, writing to the first page of a sector individually succeeds, but after next sector erase operation that page stays empty. Zero bytes also appear over empty pages.

Steps to reproduce:
1.1 erase 2 or more adjacent sectors
1.2 write some data to these sectors
1.3 read data back - all bytes are correct except for first pages of 2nd and following sectors, these pages are still filled with 0xFF

I'm trying to figure out is it a hardware of a software problem. Since I'm not powering off the flash chip, 'first' operation I'm referring to isn't really the first for the flash chip, but they are truly first for MCU SPI hardware and firmware. After a long debugging I can say it is unlikely a memory access problem in the firmware or another bug like that and SPI flash driver looks up to documentation. Yet, something is very wrong.

Any ideas?

p.s. Would it help if I provide schematics and related pieces of firmware?

Unixon:
Update:

Hooked my scope to SPI bus, looks like flash IC still returns correct data when leading zeroes appear.
Then this weird thing happens somewhere inside MCU. OK, at least it's not a faulty flash IC.

Is there anything notorious about STM32 SPI hardware or HAL library that can do this stuff?
Am I not reading out some internal SPI buffers after previous transactions?

Unixon:
Update:

Well, it appears that in fact leading zero bytes were a buffering problem, calling HAL_SPIEx_FlushRxFifo() before SPI transaction for data cleared one of issues.
But why does the SPI buffers anything anyway? Shouldn't it always transmit and receive equal amount of data?
Probably HAL splits Rx/Tx streams and puts an unused part of SPI exchange in Tx-only or Rx-only transfers into buffer instead of throwing it away immediately.

Unixon:
Update:

OK, problem solved. Fixing one issue with SPI buffering automatically fixed the other one too, however, it is not clear how.

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod