00001 /* ---------------------------------------------------------------------------- 00002 * SAM Software Package License 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2014, Atmel Corporation 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the disclaimer below. 00013 * 00014 * Atmel's name may not be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00020 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00023 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00026 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * ---------------------------------------------------------------------------- 00028 */ 00029 00030 /** 00031 * \page qspi_xip QSPI XIP Example 00032 * 00033 * \section Purpose 00034 * 00035 * This example demonstrates how to setup the QSPI Flash in XIP mode to execute 00036 * code from QSPI flash. 00037 * 00038 * \section Requirements 00039 * 00040 * This package can be used with SAMV7x evaluation kits. 00041 * 00042 * \section Description 00043 * 00044 * Ths code writes the coremark benchmark code into flash via SPI and enables 00045 * quad mode spi to read code and to execute from it. 00046 * 00047 * \section Usage 00048 * 00049 * -# Build the program and download it inside the SAM V71 Xplained Ultra board. 00050 * Please refer to the Getting Started with SAM V71 Microcontrollers.pdf 00051 * -# Optionally, on the computer, open and configure a terminal application 00052 * (e.g. HyperTerminal on Microsoft Windows) with these settings: 00053 * - 115200 bauds 00054 * - 8 bits of data 00055 * - No parity 00056 * - 1 stop bit 00057 * - No flow control 00058 * -# Start the application. 00059 * -# Upon startup, the application will output the following lines on the 00060 * terminal window: 00061 * \code 00062 * -- QSPI XIP Example xxx -- 00063 * -- SAMxxxxx-xx 00064 * -- Compiled: xxx xx xxxx xx:xx:xx -- 00065 * QSPI drivers initialized 00066 * \endcode 00067 * \section References 00068 * - qspi_flash/main.c 00069 * - qspi.c 00070 * - s25fl1.c 00071 */ 00072 00073 /** 00074 * \file 00075 * 00076 * This file contains all the specific code for the Qspi_serialflash example. 00077 */ 00078 00079 /*---------------------------------------------------------------------------- 00080 * Headers 00081 *----------------------------------------------------------------------------*/ 00082 00083 #include <board.h> 00084 #include <stdio.h> 00085 #include <assert.h> 00086 #include <string.h> 00087 #include "stdlib.h" 00088 #include "getting_started_hex.h" 00089 00090 /*---------------------------------------------------------------------------- 00091 * Local definitions 00092 *----------------------------------------------------------------------------*/ 00093 00094 /** SPI peripheral pins to configure to access the serial flash. */ 00095 #define QSPI_PINS PINS_QSPI 00096 00097 /*---------------------------------------------------------------------------- 00098 * Local variables 00099 *----------------------------------------------------------------------------*/ 00100 /** Pins to configure for the application. */ 00101 static Pin pins[] = QSPI_PINS; 00102 00103 unsigned char pBuffercode[6612]; 00104 00105 /*---------------------------------------------------------------------------- 00106 * Global functions 00107 *----------------------------------------------------------------------------*/ 00108 00109 /** 00110 * \brief Application entry point for QSPI_XIP example. 00111 * Initializes the serial flash and performs XIP. 00112 * 00113 * \return Unused (ANSI-C compatibility). 00114 */ 00115 00116 int main(void) 00117 { 00118 uint8_t MemVerify = 0; 00119 uint32_t __Start_SP, idx; 00120 uint32_t (*__Start_New)(void); 00121 uint32_t Buffer[4]; 00122 00123 uint8_t *pMemory = (uint8_t *)( QSPIMEM_ADDR ); 00124 00125 /* Disable watchdog */ 00126 WDT_Disable( WDT ) ; 00127 00128 /* Output example information */ 00129 printf( "-- QSPI XIP Example %s --\n\r", SOFTPACK_VERSION ) ; 00130 printf( "-- %s\n\r", BOARD_NAME ) ; 00131 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ; 00132 SCB_EnableICache(); 00133 SCB_EnableDCache(); 00134 TimeTick_Configure(); 00135 00136 /* Initialize the QSPI and serial flash */ 00137 PIO_Configure(pins, PIO_LISTSIZE(pins)); 00138 ENABLE_PERIPHERAL(ID_QSPI); 00139 00140 S25FL1D_InitFlashInterface(1); 00141 printf("QSPI drivers initialized\n\r"); 00142 00143 /* enable quad mode */ 00144 S25FL1D_QuadMode(ENABLE); 00145 00146 /* erase entire chip */ 00147 S25FL1D_EraseChip(); 00148 00149 /* Flash the code to QSPI flash */ 00150 printf("Writing to Memory\n\r"); 00151 00152 S25FL1D_Write((uint32_t *)pBuffercode, sizeof(pBuffercode), 0, 0); 00153 00154 printf("Example code written 0x%x to Memory\n\r", sizeof(pBuffercode)); 00155 00156 printf("Verifying \n\r"); 00157 /* Start continuous read mode to enter in XIP mode*/ 00158 S25FL1D_ReadQuadIO(Buffer, sizeof(Buffer), 0, 1, 0 ); 00159 00160 for(idx = 0; idx < sizeof(pBuffercode); idx++) { 00161 if(*pMemory == pBuffercode[idx]) { 00162 pMemory++; 00163 } else { 00164 MemVerify = 1; 00165 printf("Data does not match at 0x%x \n\r", (unsigned)pMemory); 00166 break; 00167 } 00168 } 00169 if(!MemVerify) { 00170 printf("Everything is OK \n\r"); 00171 /* set PC and SP */ 00172 __Start_New = (uint32_t(*) (void) ) Buffer[1]; 00173 __Start_SP = Buffer[0]; 00174 00175 printf("\n\r Starting getting started example from QSPI flash \n\r"); 00176 printf("========================================================= \n\r"); 00177 00178 __set_MSP(__Start_SP); 00179 00180 __Start_New(); 00181 } 00182 while(1); 00183 }