Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #include <board.h>
00090
00091 #include <stdio.h>
00092 #include <assert.h>
00093 #include <string.h>
00094 #include "stdlib.h"
00095
00096
00097
00098
00099
00100 #define MAXPAGESIZE 256
00101
00102 #define BUFFER_SIZE 512
00103
00104
00105
00106
00107
00108 static sXdmad xDmad;
00109
00110
00111 static Pin Qspi_pins[] = PINS_QSPI;
00112
00113
00114 static uint32_t Buffer[BUFFER_SIZE], TestBuffer[BUFFER_SIZE];
00115 static uint8_t PeripheralInit = 0;
00116
00117
00118
00119
00120
00121 static void _fillupbuffer(uint32_t *pBuff, uint32_t size)
00122 {
00123 uint32_t i;
00124
00125 for(i = 0; i < (size /4);) {
00126 pBuff[i++] = 0x9955030c;
00127 pBuff[i++] = 0x11232244;
00128 pBuff[i++] = 0xDEADBEAF;
00129 pBuff[i++] = 0xBEAFDEAD;
00130 pBuff[i++] = 0xFF770088;
00131 pBuff[i++] = 0xBAD69DAD;
00132 }
00133 }
00134
00135 static uint8_t _VerifyData(
00136 uint32_t AddrBegin, uint32_t AddrEnd, uint32_t *TestBuff , uint8_t secure)
00137 {
00138 static uint8_t TestPassed = 0;
00139 uint32_t i,j, Fault = 0;
00140 uint8_t *pBuffRx, *pBuffTx;
00141
00142 pBuffTx = (uint8_t *)TestBuff;
00143 TRACE_INFO_WP("Verifying data from 0x%x to 0x%x \n\r", AddrBegin, AddrEnd);
00144 if(secure) {
00145 TRACE_INFO(" Reading data with scramble ON \n\r");
00146 } else {
00147 TRACE_INFO(" Reading data with scramble OFF \n\r");
00148 }
00149 for(i = AddrBegin; i<AddrEnd;) {
00150 if(PeripheralInit==2)
00151 {
00152 S25FL1D_Read(Buffer, BUFFER_SIZE, i);
00153 pBuffRx = (uint8_t *)Buffer;
00154 pBuffRx = &pBuffRx[6];
00155 }
00156 else if(PeripheralInit==1)
00157 {
00158 S25FL1D_ReadQuadIO(Buffer, BUFFER_SIZE, i, 0, secure);
00159 pBuffRx = (uint8_t *)Buffer;
00160 }
00161
00162
00163 for( j=0; j< BUFFER_SIZE; j++) {
00164 if(pBuffRx[j] != pBuffTx[j]) {
00165 TestPassed = 1;
00166 if(Fault==0)
00167 printf("\n\rData does not match @ 0x%x ", i);
00168 Fault++;
00169 } else {
00170 if(Fault > 1)
00171 printf("upto 0x%x \r\n", i);
00172 Fault = 0;
00173 }
00174 }
00175 i +=BUFFER_SIZE;
00176 }
00177
00178 if(Fault > 1) {
00179 TRACE_INFO_WP("upto 0x%x \r\n", i);
00180 Fault = 0;
00181 }
00182
00183 if(TestPassed) {
00184 TRACE_ERROR("Data Does not match \n\r");
00185 }
00186 return TestPassed;
00187
00188 }
00189
00190 static void QSPI_UserMenu(void)
00191 {
00192 printf("\n\r===============Choose the peripheral==================");
00193 printf("\n\r 1. Run example as QSPI");
00194 printf("\n\r 2. Run example as SPI master");
00195 printf("\n\r 3. Display Menu");
00196 printf("\n\r======================================================\n\r");
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 int main(void)
00209 {
00210 uint32_t i;
00211 uint32_t deviceId;
00212 uint8_t ucKey;
00213 uint8_t TestPassed = 0;
00214
00215
00216 WDT_Disable( WDT ) ;
00217
00218
00219 printf( "-- QSPI Serialflash Example %s --\n\r", SOFTPACK_VERSION ) ;
00220 printf( "-- %s\n\r", BOARD_NAME ) ;
00221 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00222 SCB_EnableICache();
00223 SCB_EnableDCache();
00224 TimeTick_Configure();
00225
00226 PIO_Configure(Qspi_pins, PIO_LISTSIZE(Qspi_pins));
00227 ENABLE_PERIPHERAL(ID_QSPI);
00228
00229 QSPI_UserMenu();
00230
00231 while ( 1 ) {
00232 ucKey = DBG_GetChar() ;
00233
00234 switch ( ucKey ) {
00235
00236 case '1' :
00237 S25FL1D_InitFlashInterface(1);
00238 TRACE_INFO("QSPI drivers initialized ");
00239
00240 S25FL1D_QuadMode(ENABLE);
00241 PeripheralInit = 1;
00242 break ;
00243
00244 case '2' :
00245 S25FL1D_InitFlashInterface(0);
00246 TRACE_INFO("QSPI Initialized in SPI mode");
00247 S25FL1D_QuadMode(DISABLE);
00248 PeripheralInit = 2;
00249 break ;
00250
00251 case '3' :
00252 QSPI_UserMenu() ;
00253 PeripheralInit = 0;
00254 break ;
00255 default:
00256 break;
00257
00258 }
00259
00260
00261 if(PeripheralInit)
00262 {
00263 while(1) {
00264 deviceId = S25FL1D_ReadJedecId();
00265 printf("ID read: Manufacture ID = 0x%x, Device Type = 0x%x, \
00266 Capacity = 0x%x\n\r",
00267 (uint8_t)(deviceId), (uint8_t)(deviceId>>8), (uint8_t)(deviceId>>16));
00268 break;
00269 }
00270
00271 S25FL1D_EraseChip();
00272
00273
00274 _fillupbuffer(TestBuffer, BUFFER_SIZE);
00275 printf("Writing buffer to Flash memory...... \n\r");
00276
00277
00278 for( i = 0; i<0x200000;) {
00279 S25FL1D_Write(TestBuffer, BUFFER_SIZE, i, 0);
00280 i += BUFFER_SIZE;
00281 }
00282 TestPassed = _VerifyData(0, 0x200000, TestBuffer, 0);
00283
00284 printf("Erasing a block(64 KB) @ Add 0x10000 \n\r");
00285 S25FL1D_Erase64KBlock(0x10000);
00286
00287 memset(TestBuffer, 0xFFFFFF, BUFFER_SIZE);
00288 TestPassed = _VerifyData( 0x10000, (0x10000 + 64*1024), TestBuffer, 0);
00289
00290 if(TestPassed) {
00291 printf(" \n\r**** Test Failed ***** \n\r");
00292 } else {
00293 printf(" \n\r### Test Passed ###\n\r");
00294 }
00295 }
00296 PeripheralInit = 0;
00297 QSPI_UserMenu();
00298 }
00299 }