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 Pin Qspi_pins[] = PINS_QSPI;
00109
00110
00111 COMPILER_ALIGNED(32) static uint32_t Buffer[BUFFER_SIZE],
00112 TestBuffer[BUFFER_SIZE];
00113
00114 static uint8_t PeripheralInit = 0;
00115
00116
00117
00118
00119
00120 static void _fillupbuffer(uint32_t *pBuff, uint32_t size)
00121 {
00122 uint32_t i;
00123
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",
00144 (unsigned int)AddrBegin, (unsigned int)AddrEnd);
00145
00146 if (secure) {
00147 TRACE_INFO(" Reading data with scramble ON \n\r");
00148 } else {
00149 TRACE_INFO(" Reading data with scramble OFF \n\r");
00150 }
00151
00152 for (i = AddrBegin; i < AddrEnd; ) {
00153 if (PeripheralInit == 2) {
00154 S25FL1D_Read(Buffer, BUFFER_SIZE, i);
00155 pBuffRx = (uint8_t *)Buffer;
00156 pBuffRx = &pBuffRx[6];
00157 } else if (PeripheralInit == 1) {
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
00167 if (Fault == 0)
00168 printf("\n\rData does not match @ 0x%x ", (unsigned int)i);
00169
00170 Fault++;
00171 } else {
00172 if (Fault > 1)
00173 printf("upto 0x%x \r\n", (unsigned int)i);
00174
00175 Fault = 0;
00176 }
00177 }
00178
00179 i += BUFFER_SIZE;
00180 }
00181
00182 if (Fault > 1) {
00183 TRACE_INFO_WP("upto 0x%x \r\n", (unsigned int)i);
00184 Fault = 0;
00185 }
00186
00187 if (TestPassed)
00188 TRACE_ERROR("Data Does not match \n\r");
00189
00190 return TestPassed;
00191
00192 }
00193
00194 static void QSPI_UserMenu(void)
00195 {
00196 printf("\n\r===============Choose the peripheral==================");
00197 printf("\n\r 1. Run example as QSPI");
00198 printf("\n\r 2. Run example as SPI master");
00199 printf("\n\r 3. Display Menu");
00200 printf("\n\r======================================================\n\r");
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 int main(void)
00213 {
00214 uint32_t i;
00215 uint32_t deviceId;
00216 uint8_t ucKey;
00217 uint8_t TestPassed = 0;
00218
00219
00220 WDT_Disable(WDT);
00221
00222
00223 printf("-- QSPI Serialflash Example %s --\n\r", SOFTPACK_VERSION);
00224 printf("-- %s\n\r", BOARD_NAME);
00225 printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME);
00226 SCB_EnableICache();
00227 SCB_EnableDCache();
00228 TimeTick_Configure();
00229
00230 PIO_Configure(Qspi_pins, PIO_LISTSIZE(Qspi_pins));
00231 ENABLE_PERIPHERAL(ID_QSPI);
00232
00233 QSPI_UserMenu();
00234
00235 while (1) {
00236 ucKey = DBG_GetChar();
00237
00238 switch (ucKey) {
00239 case '1' :
00240 S25FL1D_InitFlashInterface(1);
00241 TRACE_INFO("QSPI drivers initialized ");
00242
00243 S25FL1D_QuadMode(ENABLE);
00244 PeripheralInit = 1;
00245 break;
00246
00247 case '2' :
00248 S25FL1D_InitFlashInterface(0);
00249 TRACE_INFO("QSPI Initialized in SPI mode");
00250 S25FL1D_QuadMode(DISABLE);
00251 PeripheralInit = 2;
00252 break;
00253
00254 case '3' :
00255 QSPI_UserMenu();
00256 PeripheralInit = 0;
00257 break;
00258
00259 default:
00260 break;
00261
00262 }
00263
00264
00265 if (PeripheralInit) {
00266 while (1) {
00267 deviceId = S25FL1D_ReadJedecId();
00268 printf("ID read: Manufacture ID = 0x%x, Device Type = 0x%x, \
00269 Capacity = 0x%x\n\r",
00270 (uint8_t)(deviceId), (uint8_t)(deviceId >> 8), (uint8_t)(deviceId >> 16));
00271 break;
00272 }
00273
00274
00275 S25FL1D_EraseChip();
00276
00277
00278 _fillupbuffer(TestBuffer, BUFFER_SIZE);
00279 printf("Writing buffer to Flash memory...... \n\r");
00280
00281
00282 for (i = 0; i < 0x200000; ) {
00283 S25FL1D_Write(TestBuffer, BUFFER_SIZE, i, 0);
00284 i += BUFFER_SIZE;
00285 }
00286
00287 TestPassed = _VerifyData(0, 0x200000, TestBuffer, 0);
00288
00289 printf("Erasing a block(64 KB) @ Add 0x10000 \n\r");
00290 S25FL1D_Erase64KBlock(0x10000);
00291
00292 memset(TestBuffer, 0xFFFFFF, BUFFER_SIZE);
00293 SCB_CleanDCache_by_Addr((uint32_t *)TestBuffer, sizeof(TestBuffer));
00294 TestPassed = _VerifyData(0x10000, (0x10000 + 64 * 1024), TestBuffer, 0);
00295
00296 if (TestPassed)
00297 printf(" \n\r**** Test Failed ***** \n\r");
00298 else
00299 printf(" \n\r### Test Passed ###\n\r");
00300 }
00301
00302 PeripheralInit = 0;
00303 QSPI_UserMenu();
00304 }
00305 }