1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
30
31
35
36
41
46
47
48
53
54
55
56
57
58
59
60
61
62
63
64
65
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
99
100
101
102
103
104
105
109
110
111
115
116
117
118
119
120
125
126
127
132
136
141
145
150
154
159
163
168
172
173
174
182
183
184
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
222
232
233
240
255
258
259
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
#define NOR_BUFFER_SIZE ((uint32_t)1000)
#define NOR_WRITE_READ_ADDR ((uint32_t)0x100000)
Private define
uint16_t nor_aTxBuffer[NOR_BUFFER_SIZE];
uint16_t nor_aRxBuffer[NOR_BUFFER_SIZE];
uint8_t ubIDStatus = 0, ubEraseStatus = 0, ubWriteStatus = 0, ubReadStatus = 0, ubInitStatus = 0;
Private variables
static void NOR_SetHint(void);
static void Fill_Buffer(uint16_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset);
static uint8_t Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength);
Private function prototypes
/* ... */
void NOR_demo (void)
{
static NOR_IDTypeDef pNOR_ID;
NOR_SetHint();
HAL_Delay(20);
if (BSP_NOR_Init() != NOR_STATUS_OK)
{
ubInitStatus++;
}if (BSP_NOR_Init() != NOR_STATUS_OK) { ... }
pNOR_ID.Manufacturer_Code = (uint16_t)0x00;
pNOR_ID.Device_Code1 = (uint16_t)0x00;
pNOR_ID.Device_Code2 = (uint16_t)0x00;
pNOR_ID.Device_Code3 = (uint16_t)0x00;
if (BSP_NOR_Read_ID(&pNOR_ID) != NOR_STATUS_OK)
ubIDStatus++;
if ((pNOR_ID.Manufacturer_Code != (uint16_t)0x0001) && (pNOR_ID.Manufacturer_Code != (uint16_t)0x0089))
ubIDStatus++;
else if (pNOR_ID.Device_Code1 != (uint16_t)0x227E)
ubIDStatus++;
else if (pNOR_ID.Device_Code2 != (uint16_t)0x2221)
ubIDStatus++;
else if (pNOR_ID.Device_Code3 != (uint16_t)0x2201)
ubIDStatus++;
BSP_NOR_ReturnToReadMode();
if (BSP_NOR_Erase_Block(NOR_WRITE_READ_ADDR) != NOR_STATUS_OK)
{
ubEraseStatus++;
}if (BSP_NOR_Erase_Block(NOR_WRITE_READ_ADDR) != NOR_STATUS_OK) { ... }
Fill_Buffer(nor_aTxBuffer, NOR_BUFFER_SIZE, 0xC20F);
if (BSP_NOR_WriteData(NOR_WRITE_READ_ADDR, nor_aTxBuffer, NOR_BUFFER_SIZE) != NOR_STATUS_OK)
{
ubWriteStatus++;
}if (BSP_NOR_WriteData(NOR_WRITE_READ_ADDR, nor_aTxBuffer, NOR_BUFFER_SIZE) != NOR_STATUS_OK) { ... }
if (BSP_NOR_ReadData(NOR_WRITE_READ_ADDR, nor_aRxBuffer, NOR_BUFFER_SIZE) != NOR_STATUS_OK)
{
ubReadStatus++;
}if (BSP_NOR_ReadData(NOR_WRITE_READ_ADDR, nor_aRxBuffer, NOR_BUFFER_SIZE) != NOR_STATUS_OK) { ... }
BSP_SDRAM_Init();
if (ubIDStatus != 0)
{
BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"NOR Read ID : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
}if (ubIDStatus != 0) { ... }
else
{
if (ubInitStatus != 0)
{
BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"NOR Initialization : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
}if (ubInitStatus != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"NOR Initialization : OK.", LEFT_MODE);
}else { ... }
if (ubEraseStatus != 0)
{
BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"NOR ERASE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
}if (ubEraseStatus != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"NOR ERASE : OK. ", LEFT_MODE);
}else { ... }
if (ubWriteStatus != 0)
{
BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"NOR WRITE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
}if (ubWriteStatus != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"NOR WRITE : OK. ", LEFT_MODE);
}else { ... }
if (ubReadStatus != 0)
{
BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"NOR READ : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
}if (ubReadStatus != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"NOR READ : OK. ", LEFT_MODE);
}else { ... }
if (Buffercmp(nor_aRxBuffer, nor_aTxBuffer, NOR_BUFFER_SIZE) > 0)
{
BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"NOR COMPARE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
}if (Buffercmp(nor_aRxBuffer, nor_aTxBuffer, NOR_BUFFER_SIZE) > 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"NOR Test : OK. ", LEFT_MODE);
}else { ... }
}else { ... }
while (1)
{
if (CheckForUserInput() > 0)
{
BSP_NOR_DeInit();
return;
}if (CheckForUserInput() > 0) { ... }
}while (1) { ... }
}{ ... }
/* ... */
static void NOR_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 *)"NOR", 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 NOR", 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);
BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"test ongoing...", LEFT_MODE);
}{ ... }
/* ... */
static void Fill_Buffer(uint16_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(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return 1;
}if (*pBuffer1 != *pBuffer2) { ... }
pBuffer1++;
pBuffer2++;
}while (BufferLength--) { ... }
return 0;
}{ ... }
/* ... */
/* ... */