2023-11-25 01:47 PM - edited 2023-11-26 06:53 AM
I am trying to access the APS6404 PSRAM with QuadSPI on STM32H743. For some reason, indirect-writes are fine; but as soon as I try an inderect-read (one-line, typical SPI essentially) the communication stalls. By stalling I mean the SR register is always "Busy" (== 32), but there is no data in FIFO, reading DR stalls the processor (since there's no data in the FIFO, the memory read operation stalls).
I don't think it's a problem with the IC, since something must be received anyway - this is SPI, after all. There's nothing really complex in my code, just setting the CCR register appropriately and AR register then. I've also tried adding dummy bits, but that does not help at all. What am I doing wrong?
My initialization code is as follows:
Write code:
void qspi_write1(uint32_t addr, uint8_t b) {
QUADSPI->CR |= QUADSPI_CR_ABORT; QUADSPI->FCR |= 0b11011;
QUADSPI->DLR = 0;
QUADSPI->DR = b;
QUADSPI->CCR = (0 << QUADSPI_CCR_DDRM_Pos) | (0 << QUADSPI_CCR_SIOO_Pos) | (0b00 << QUADSPI_CCR_FMODE_Pos)
| (0b01 << QUADSPI_CCR_DMODE_Pos) | (0b00 << QUADSPI_CCR_DCYC_Pos) | (0b00 << QUADSPI_CCR_ABMODE_Pos)
| (0b10 << QUADSPI_CCR_ADSIZE_Pos) | (0b01 << QUADSPI_CCR_ADMODE_Pos) | (0b01 << QUADSPI_CCR_IMODE_Pos)
| (0x02 << QUADSPI_CCR_INSTRUCTION_Pos);
QUADSPI->AR = addr;
WAITNBIT(QUADSPI->SR, QUADSPI_SR_BUSY);
}
Read code:
2023-11-25 02:12 PM
In indirect mode the processor should not stall because of accessing any QSPI register. Do you use MPU as recommended, to avoid the "speculative execution" and whatever cache related complications?
> something must be received anyway - this is SPI, after all.
Yes, but you also wait for certain bits in the SR. The status bits reflect the device POV. It is possible that MCU does a number of clock pulses, but the device does not see all these pulses and waits for more.
2023-11-25 02:25 PM
From the reference manual, DR register info:
In indirect read mode, reading this register gives (via the FIFO) the data which was received
from the flash memory. If the FIFO does not have as many bytes as requested by the read
operation and if BUSY=1, the read operation is stalled until enough data is present or until
the transfer is complete, whichever happens first.
So, if there is no info in the FIFO (which IS the case), processor can stall.
Next, as you can see from my code, yes, the processor stalls if I try to read at any moment the DR register, even if I add a delay, but, as you can see from my code, I am waiting while the BUSY flag is set and checking if there is something in the FIFO. There is not, SR == 34 (BUSY + TC, but FIFO is empty). Fifo flag threshold is at minimum.
What do you mean by "the device does not see all these pulses"? This code should work even if no IC is present, since uC is always the master in QSPI connection.
2023-11-28 02:47 AM
Hello @krezo107 and welcome to the Community 🙂,
Are you using the QUADSPI interface in indirect read mode when only data phase is activated?
If yes, note that it is mentioned in the errata sheet ES0392 that the QUADSPI cannot be used in indirect read mode when only data phase. In this case, the QUADSPI peripheral hangs and the BUSY flag of the QUADSPI_SR register remains high. An abort must be performed to reset the BUSY flag and exit the hanging state.
The workaround is insert a dummy phase with at least two dummy cycles.
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.