[rtems commit] bsp/atsam: Support QSPI flash

Sebastian Huber sebh at rtems.org
Mon Jun 6 11:17:32 UTC 2016


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

Author:    Alexander Krutwig <alexander.krutwig at embedded-brains.de>
Date:      Thu Jun  2 13:25:26 2016 +0200

bsp/atsam: Support QSPI flash

---

 c/src/lib/libbsp/arm/atsam/Makefile.am             |  1 +
 c/src/lib/libbsp/arm/atsam/README                  |  3 ++
 c/src/lib/libbsp/arm/atsam/configure.ac            |  1 +
 .../arm/atsam/libraries/libchip/source/qspi.c      | 39 +++++++++++++++++++---
 c/src/lib/libbsp/arm/atsam/preinstall.am           |  4 +++
 .../libbsp/arm/atsam/startup/linkcmds.memory.in    |  1 +
 .../libbsp/arm/atsam/startup/linkcmds.qspiflash    | 21 ++++++++++++
 7 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/c/src/lib/libbsp/arm/atsam/Makefile.am b/c/src/lib/libbsp/arm/atsam/Makefile.am
index 1d8b8fe..b632796 100644
--- a/c/src/lib/libbsp/arm/atsam/Makefile.am
+++ b/c/src/lib/libbsp/arm/atsam/Makefile.am
@@ -18,6 +18,7 @@ project_lib_DATA += startup/linkcmds
 project_lib_DATA += startup/linkcmds.memory
 project_lib_DATA += startup/linkcmds.intsram
 project_lib_DATA += startup/linkcmds.sdram
+project_lib_DATA += startup/linkcmds.qspiflash
 
 ###############################################################################
 #                  Header                                                     #
diff --git a/c/src/lib/libbsp/arm/atsam/README b/c/src/lib/libbsp/arm/atsam/README
index 5b56c0d..3df2c01 100644
--- a/c/src/lib/libbsp/arm/atsam/README
+++ b/c/src/lib/libbsp/arm/atsam/README
@@ -41,6 +41,9 @@ Use ATSAM_MEMORY_INTSRAM_SIZE=XYZ to set the size of internal SRAM in bytes
 Use ATSAM_MEMORY_SDRAM_SIZE=XYZ to set the size of external SDRAM in bytes
 (default 0x00200000).
 
+Use ATSAM_MEMORY_QSPIFLASH_SIZE=XYZ to set the size of QSPI flash in bytes
+(default 0x00200000).
+
 The pins may be configured by the application at link-time.  See
 <bsp/pin-config.h>.
 
diff --git a/c/src/lib/libbsp/arm/atsam/configure.ac b/c/src/lib/libbsp/arm/atsam/configure.ac
index 5082618..1297367 100644
--- a/c/src/lib/libbsp/arm/atsam/configure.ac
+++ b/c/src/lib/libbsp/arm/atsam/configure.ac
@@ -77,6 +77,7 @@ ATSAM_LINKCMD([ATSAM_MEMORY_TCM_SIZE],[size of tightly coupled memories (TCM) in
 ATSAM_LINKCMD([ATSAM_MEMORY_INTFLASH_SIZE],[size of internal flash in bytes],[${INTFLASH}])
 ATSAM_LINKCMD([ATSAM_MEMORY_INTSRAM_SIZE],[size of internal SRAM in bytes],[${INTSRAM}])
 ATSAM_LINKCMD([ATSAM_MEMORY_SDRAM_SIZE],[size of external SDRAM in bytes],[0x00200000])
+ATSAM_LINKCMD([ATSAM_MEMORY_QSPIFLASH_SIZE],[size of QSPI flash in bytes],[0x00200000])
 
 AC_CONFIG_FILES([
 Makefile
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 e279ff9..367789f 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
@@ -211,6 +211,35 @@ __STATIC_INLINE void QSPI_ScrambleData(Qspi *pQspi, uint32_t wKey,
 	pQspi->QSPI_SMR = (EnableFlag | (Random << 1));
 }
 
+static void do_copy(uint8_t *dst, const uint8_t *src, size_t n, bool aligned)
+{
+	if (aligned) {
+		while (n > 3) {
+			*(uint32_t *)dst = *(uint32_t *)src;
+			dst += 4;
+			src += 4;
+			n -= 4;
+		}
+	}
+
+	while (n > 0) {
+		*dst = *src;
+		++dst;
+		++src;
+		--n;
+	}
+}
+
+static void copy_to_io(void *dst, const void *src, size_t n)
+{
+	do_copy(dst, src, n, ((uintptr_t)dst) % 4 == 0);
+}
+
+static void copy_from_io(void *dst, const void *src, size_t n)
+{
+	do_copy(dst, src, n, ((uintptr_t)src) % 4 == 0);
+}
+
 /*----------------------------------------------------------------------------
  *        Exported functions
  *----------------------------------------------------------------------------*/
@@ -721,11 +750,11 @@ QspidStatus_t QSPI_ReadWriteMem(Qspid_t *pQspid, Access_t const ReadWrite)
 	assert(((ReadWrite > CmdAccess)
 			  && (ReadWrite <= WriteAccess)) ? true : false);
 
-	if (ReadWrite == WriteAccess)
-		memcpy(pQspiMem, pBuffer.pDataTx , pBuffer.TxDataSize);
-	else
-		memcpy(pBuffer.pDataRx, pQspiMem, pBuffer.RxDataSize);
-
+	if (ReadWrite == WriteAccess) {
+		copy_to_io(pQspiMem, pBuffer.pDataTx , pBuffer.TxDataSize);
+	} else {
+		copy_from_io(pBuffer.pDataRx, pQspiMem, pBuffer.RxDataSize);
+	}
 	memory_sync();
 	QSPI_EndTransfer(pQspid->pQspiHw);
 
diff --git a/c/src/lib/libbsp/arm/atsam/preinstall.am b/c/src/lib/libbsp/arm/atsam/preinstall.am
index 3cc1000..83776db 100644
--- a/c/src/lib/libbsp/arm/atsam/preinstall.am
+++ b/c/src/lib/libbsp/arm/atsam/preinstall.am
@@ -52,6 +52,10 @@ $(PROJECT_LIB)/linkcmds.sdram: startup/linkcmds.sdram $(PROJECT_LIB)/$(dirstamp)
 	$(INSTALL_DATA) $< $(PROJECT_LIB)/linkcmds.sdram
 TMPINSTALL_FILES += $(PROJECT_LIB)/linkcmds.sdram
 
+$(PROJECT_LIB)/linkcmds.qspiflash: startup/linkcmds.qspiflash $(PROJECT_LIB)/$(dirstamp)
+	$(INSTALL_DATA) $< $(PROJECT_LIB)/linkcmds.qspiflash
+TMPINSTALL_FILES += $(PROJECT_LIB)/linkcmds.qspiflash
+
 $(PROJECT_INCLUDE)/tm27.h: ../../shared/include/tm27.h $(PROJECT_INCLUDE)/$(dirstamp)
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/tm27.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/tm27.h
diff --git a/c/src/lib/libbsp/arm/atsam/startup/linkcmds.memory.in b/c/src/lib/libbsp/arm/atsam/startup/linkcmds.memory.in
index 6dd70ca..74764a3 100644
--- a/c/src/lib/libbsp/arm/atsam/startup/linkcmds.memory.in
+++ b/c/src/lib/libbsp/arm/atsam/startup/linkcmds.memory.in
@@ -5,4 +5,5 @@ MEMORY {
 	INTSRAM   : ORIGIN = 0x20400000, LENGTH = @ATSAM_MEMORY_INTSRAM_SIZE@ - 2 * @ATSAM_MEMORY_TCM_SIZE@ - 4K
 	NOCACHE   : ORIGIN = 0x20400000 + @ATSAM_MEMORY_INTSRAM_SIZE@ - 2 * @ATSAM_MEMORY_TCM_SIZE@ - 4K, LENGTH = 4K
 	SDRAM     : ORIGIN = 0x70000000, LENGTH = @ATSAM_MEMORY_SDRAM_SIZE@
+	QSPIFLASH  : ORIGIN = 0x80000000, LENGTH = @ATSAM_MEMORY_QSPIFLASH_SIZE@
 }
diff --git a/c/src/lib/libbsp/arm/atsam/startup/linkcmds.qspiflash b/c/src/lib/libbsp/arm/atsam/startup/linkcmds.qspiflash
new file mode 100644
index 0000000..d7529f7
--- /dev/null
+++ b/c/src/lib/libbsp/arm/atsam/startup/linkcmds.qspiflash
@@ -0,0 +1,21 @@
+INCLUDE linkcmds.memory
+
+REGION_ALIAS ("REGION_START", QSPIFLASH);
+REGION_ALIAS ("REGION_VECTOR", INTSRAM);
+REGION_ALIAS ("REGION_TEXT", QSPIFLASH);
+REGION_ALIAS ("REGION_TEXT_LOAD", QSPIFLASH);
+REGION_ALIAS ("REGION_RODATA", QSPIFLASH);
+REGION_ALIAS ("REGION_RODATA_LOAD", QSPIFLASH);
+REGION_ALIAS ("REGION_DATA", INTSRAM);
+REGION_ALIAS ("REGION_DATA_LOAD", QSPIFLASH);
+REGION_ALIAS ("REGION_FAST_TEXT", ITCM);
+REGION_ALIAS ("REGION_FAST_TEXT_LOAD", QSPIFLASH);
+REGION_ALIAS ("REGION_FAST_DATA", DTCM);
+REGION_ALIAS ("REGION_FAST_DATA_LOAD", QSPIFLASH);
+REGION_ALIAS ("REGION_BSS", INTSRAM);
+REGION_ALIAS ("REGION_WORK", INTSRAM);
+REGION_ALIAS ("REGION_STACK", INTSRAM);
+REGION_ALIAS ("REGION_NOCACHE", NOCACHE);
+REGION_ALIAS ("REGION_NOCACHE_LOAD", QSPIFLASH);
+
+INCLUDE linkcmds.armv7m




More information about the vc mailing list