1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
29
32
33
37
38
42
47
48
49
54
55
56
57
58
59
60
61
62
63
64
73
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
100
101
102
109
110
111
116
117
118
119
120
121
122
123
124
125
130
131
132
133
134
135
140
141
142
143
144
145
150
154
155
156
157
158
159
160
167
168
169
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
207
217
218
225
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
263
264
/* ... */
#include "main.h"
/* ... */
/* ... */ Includes
extern QSPI_InfoTypeDef QspiInfo;
External variables
#define BUFFER_SIZE ((uint32_t)0x0200)
#define WRITE_READ_ADDR ((uint32_t)0x0050)
Private define
uint8_t qspi_aTxBuffer[BUFFER_SIZE];
uint8_t qspi_aRxBuffer[BUFFER_SIZE];
Private variables
static void QSPI_SetHint(void);
static void Fill_Buffer (uint8_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset);
static uint8_t Buffercmp (uint8_t* pBuffer1, uint8_t* pBuffer2, uint32_t BufferLength);
static uint8_t CompareInfo(void);Private function prototypes
/* ... */
void QSPI_demo (void)
{
uint8_t status;
QSPI_SetHint();
status = BSP_QSPI_Init();
if (status == QSPI_NOT_SUPPORTED)
{
BSP_LCD_DisplayStringAt(20, 100, (uint8_t*)"QSPI Initialization : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 145, (uint8_t*)"Check the hardware configuration :", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 160, (uint8_t*)" refer to the UM of the board", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 175, (uint8_t*)" for the hardware modifications", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 190, (uint8_t*)" to connect the QSPI memory", LEFT_MODE);
}if (status == QSPI_NOT_SUPPORTED) { ... }
else if (status == QSPI_ERROR)
{
BSP_LCD_DisplayStringAt(20, 100, (uint8_t*)"QSPI Initialization : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
}else if (status == QSPI_ERROR) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 100, (uint8_t*)"QSPI Initialization : OK.", LEFT_MODE);
QspiInfo.FlashSize = (uint32_t)0x00;
QspiInfo.EraseSectorSize = (uint32_t)0x00;
QspiInfo.EraseSectorsNumber = (uint32_t)0x00;
QspiInfo.ProgPageSize = (uint32_t)0x00;
QspiInfo.ProgPagesNumber = (uint32_t)0x00;
QspiInfo.ManufID = (uint8_t)0x00;
BSP_QSPI_GetInfo(&QspiInfo);
if (CompareInfo() !=QSPI_OK)
{
BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI GET INFO : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 130, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
}if (CompareInfo() !=QSPI_OK) { ... }
else
{
if (QspiInfo.ManufID == QSPI_S25FL512S)
{
BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI GET INFO : OK. S25FL512S detected ", LEFT_MODE);
}if (QspiInfo.ManufID == QSPI_S25FL512S) { ... } else
{
BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI GET INFO : OK. N25Q512A detected ", LEFT_MODE);
}else { ... }
if(BSP_QSPI_Erase_Block(WRITE_READ_ADDR) != QSPI_OK)
{
BSP_LCD_DisplayStringAt(20, 130, (uint8_t*)"QSPI ERASE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 145, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
}if (BSP_QSPI_Erase_Block(WRITE_READ_ADDR) != QSPI_OK) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 130, (uint8_t*)"QSPI ERASE : OK. ", LEFT_MODE);
Fill_Buffer(qspi_aTxBuffer, BUFFER_SIZE, 0xD20F);
if(BSP_QSPI_Write(qspi_aTxBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != QSPI_OK)
{
BSP_LCD_DisplayStringAt(20, 145, (uint8_t*)"QSPI WRITE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 160, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
}if (BSP_QSPI_Write(qspi_aTxBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != QSPI_OK) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 145, (uint8_t*)"QSPI WRITE : OK. ", LEFT_MODE);
if(BSP_QSPI_Read(qspi_aRxBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != QSPI_OK)
{
BSP_LCD_DisplayStringAt(20, 160, (uint8_t*)"QSPI READ : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 175, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
}if (BSP_QSPI_Read(qspi_aRxBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != QSPI_OK) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 160, (uint8_t*)"QSPI READ : OK. ", LEFT_MODE);
if(Buffercmp(qspi_aRxBuffer, qspi_aTxBuffer, BUFFER_SIZE) > 0)
{
BSP_LCD_DisplayStringAt(20, 175, (uint8_t*)"QSPI COMPARE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 190, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
}if (Buffercmp(qspi_aRxBuffer, qspi_aTxBuffer, BUFFER_SIZE) > 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 175, (uint8_t*)"QSPI Test : OK. ", LEFT_MODE);
}else { ... }
}else { ... }
}else { ... }
}else { ... }
}else { ... }
}else { ... }
while (1)
{
if(CheckForUserInput() > 0)
{
return;
}if (CheckForUserInput() > 0) { ... }
}while (1) { ... }
}{ ... }
/* ... */
static void QSPI_SetHint(void)
{
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 80);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_SetFont(&Font24);
BSP_LCD_DisplayStringAt(0, 0, (uint8_t*)"QSPI", CENTER_MODE);
BSP_LCD_SetFont(&Font12);
BSP_LCD_DisplayStringAt(0, 30, (uint8_t*)"This example shows how to write", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, 45, (uint8_t*)"and read data on QSPI memory", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, 60, (uint8_t*)"(Hardware modifications needed)", CENTER_MODE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_DrawRect(10, 90, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize()- 100);
BSP_LCD_DrawRect(11, 91, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize()- 102);
BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
}{ ... }
/* ... */
static void Fill_Buffer(uint8_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset)
{
uint32_t tmpIndex = 0;
for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++ )
{
pBuffer[tmpIndex] = tmpIndex + uwOffset;
}for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++) { ... }
}{ ... }
/* ... */
static uint8_t Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint32_t BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return 1;
}if (*pBuffer1 != *pBuffer2) { ... }
pBuffer1++;
pBuffer2++;
}while (BufferLength--) { ... }
return 0;
}{ ... }
static uint8_t CompareInfo(void)
{
if ((QspiInfo.ManufID != QSPI_S25FL512S) && (QspiInfo.ManufID != QSPI_N25Q512A))
return QSPI_ERROR;
if (QspiInfo.FlashSize != 0x4000000)
return QSPI_ERROR;
if ((QspiInfo.EraseSectorSize != 0x40000) && (QspiInfo.EraseSectorSize != 0x10000))
return QSPI_ERROR;
if ((QspiInfo.ProgPageSize != 0x200) && (QspiInfo.ProgPageSize != 0x100))
return QSPI_ERROR;
if ((QspiInfo.EraseSectorsNumber != 0x100) && (QspiInfo.EraseSectorsNumber !=0x400))
return QSPI_ERROR;
if ((QspiInfo.ProgPagesNumber != 131072) && (QspiInfo.ProgPagesNumber != 262144))
return QSPI_ERROR;
return QSPI_OK;
}{ ... }
/* ... */
/* ... */