STM32(F7) SPI+DMA stuck byte
Posted: Sun Jul 13, 2025 10:39 pm
Hi,
ChibiOS 21.11.x
I have a custom hw with STM32F767 and W25Q128 connected over SPI.
W25Q driver is based on serial_nor. Nothing special, just reworked micron_n25q.
I'm using MFS on this flash. Two banks of 512Kb.
After few write of big blob of data (25Kb) I got failure in verification code of mfs_flash_write(). Data read back is not equal to what was written.
I had to attach logic analyzer to find real cause of this issue.
Here is "good" write:
1. 0x05 poll for status - reply is 0x00, busy bit is zero. code starts writing next page
2. 0x06 - write enable command. No arguments, no reply.
3. 0x02 - write command with 3 bytes of address and 256 bytes of data.
Here is "bad" write:
1. 0x05 poll for status - reply is 0x00
2. 0x06 - write enable command
3. write command, should be 0x02 with three bytes of address. But 0x06 is transmitted again. And some random bytes. I checked previous and next writes and this three bytes of address is not in a line with previous and next writes.
So this command is ignored by W25Q chip, no data is actually written and MFS later fails on validation.
Every other write commands (before and after) looks like correct. This corruption observed only once during write of 25K of data.
My current theory is that Tx FIFO or some internal DMA buffer is not fully flushed after previous transaction. And when new transfer is initiated last byte of previous transfer is transmitted.
I already checked STM32F7 errata - did not found anything related. I also reading DS and checking init code of spi and dma. But everything looks good.
Any thoughts?
ChibiOS 21.11.x
I have a custom hw with STM32F767 and W25Q128 connected over SPI.
W25Q driver is based on serial_nor. Nothing special, just reworked micron_n25q.
I'm using MFS on this flash. Two banks of 512Kb.
After few write of big blob of data (25Kb) I got failure in verification code of mfs_flash_write(). Data read back is not equal to what was written.
I had to attach logic analyzer to find real cause of this issue.
Here is "good" write:
1. 0x05 poll for status - reply is 0x00, busy bit is zero. code starts writing next page
2. 0x06 - write enable command. No arguments, no reply.
3. 0x02 - write command with 3 bytes of address and 256 bytes of data.
Here is "bad" write:
1. 0x05 poll for status - reply is 0x00
2. 0x06 - write enable command
3. write command, should be 0x02 with three bytes of address. But 0x06 is transmitted again. And some random bytes. I checked previous and next writes and this three bytes of address is not in a line with previous and next writes.
So this command is ignored by W25Q chip, no data is actually written and MFS later fails on validation.
Every other write commands (before and after) looks like correct. This corruption observed only once during write of 25K of data.
My current theory is that Tx FIFO or some internal DMA buffer is not fully flushed after previous transaction. And when new transfer is initiated last byte of previous transfer is transmitted.
I already checked STM32F7 errata - did not found anything related. I also reading DS and checking init code of spi and dma. But everything looks good.
Any thoughts?