From fea392a35017c332d035b6fff3aeeb841402cc11 Mon Sep 17 00:00:00 2001 From: Alexander Krutwig Date: Wed, 10 Aug 2016 10:32:39 +0200 Subject: bsp/atsam: Add timeout to QSPI send command --- .../libbsp/arm/atsam/libraries/libchip/source/qspi.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/qspi.c b/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/qspi.c index fd9de3ae8a..c80d0dd53a 100644 --- a/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/qspi.c +++ b/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/qspi.c @@ -590,6 +590,7 @@ QspidStatus_t QSPI_SendCommand(Qspid_t *pQspid, uint8_t const KeepCfg) QspiInstFrame_t *const pFrame = pQspid->pQspiFrame; QspiMemCmd_t pCommand = pQspid->qspiCommand; QspidStatus_t Status = QSPI_UNKNOWN_ERROR; + uint32_t timeout = 15000; if (pFrame->InstFrame.bm.bAddrEn) QSPI_SetInstAddr(pQspid->pQspiHw, pFrame->Addr); @@ -600,7 +601,21 @@ QspidStatus_t QSPI_SendCommand(Qspid_t *pQspid, uint8_t const KeepCfg) memory_sync(); - while (!(pQspid->pQspiHw->QSPI_SR & QSPI_SR_INSTRE)); + /* + * FIXME: Timeout has been introduced due to a problem that was detected + * when QSPI_SR_INSTRE was not detected and the function is stuck in an + * endless loop. This is still an open issue. + * peripheral clock: 50Mhz -> 20 ns period time. + * timeout: set to 15000 loop cycles => 300000 ns. + * with loop instructions, the delay increases to 1ms altogether. + */ + while (!(pQspid->pQspiHw->QSPI_SR & QSPI_SR_INSTRE) && timeout > 0) { + --timeout; + } + + if (timeout == 0) { + Status = QSPI_WRITE_ERROR; + } // poll CR reg to know status if instruction has end if (!KeepCfg) -- cgit v1.2.3