[rtems commit] bsp/atsam: Add timeout to QSPI send command

Sebastian Huber sebh at rtems.org
Thu Aug 18 06:57:06 UTC 2016


Module:    rtems
Branch:    master
Commit:    fea392a35017c332d035b6fff3aeeb841402cc11
Changeset: http://git.rtems.org/rtems/commit/?id=fea392a35017c332d035b6fff3aeeb841402cc11

Author:    Alexander Krutwig <alexander.krutwig at embedded-brains.de>
Date:      Wed Aug 10 10:32:39 2016 +0200

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 fd9de3a..c80d0dd 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)



More information about the vc mailing list