1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
30
31
35
36
42
47
48
49
54
55
56
57
58
59
60
64
65
66
67
68
69
70
74
75
76
80
81
82
83
84
89
93
98
102
107
111
112
117
121
122
123
124
125
126
127
131
132
133
134
135
136
137
138
142
143
144
148
149
150
151
155
156
157
161
162
163
164
165
170
174
179
183
184
189
193
194
201
202
203
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
240
250
251
258
273
274
280
284
285
291
296
299
300
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
#define SRAM_WRITE_READ_ADDR_OFFSET ((uint32_t)0x0800)
#define SRAM_BUFFER_SIZE ((uint32_t)2048)
Private define
uint16_t sram_aTxBuffer[SRAM_BUFFER_SIZE];
uint16_t sram_aRxBuffer[SRAM_BUFFER_SIZE];
uint8_t ubSramWrite = 0, ubSramRead = 0, ubSramInit = 0, ubSramDmaWrite = 0, ubSramDmaRead = 0;
__IO uint32_t uwSramDMA_Transfer_Complete = 0;
Private variables
static void SRAM_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 SRAM_demo (void)
{
SRAM_SetHint();
if (BSP_SRAM_Init() != SRAM_OK)
{
ubSramInit++;
}if (BSP_SRAM_Init() != SRAM_OK) { ... }
Fill_Buffer(sram_aTxBuffer, SRAM_BUFFER_SIZE, 0xC20F);
if (BSP_SRAM_WriteData((SRAM_DEVICE_ADDR + SRAM_WRITE_READ_ADDR_OFFSET), sram_aTxBuffer, SRAM_BUFFER_SIZE) != SRAM_OK)
{
ubSramWrite++;
}if (BSP_SRAM_WriteData((SRAM_DEVICE_ADDR + SRAM_WRITE_READ_ADDR_OFFSET), sram_aTxBuffer, SRAM_BUFFER_SIZE) != SRAM_OK) { ... }
if (BSP_SRAM_ReadData((SRAM_DEVICE_ADDR + SRAM_WRITE_READ_ADDR_OFFSET), sram_aRxBuffer, SRAM_BUFFER_SIZE) != SRAM_OK)
{
ubSramRead++;
}if (BSP_SRAM_ReadData((SRAM_DEVICE_ADDR + SRAM_WRITE_READ_ADDR_OFFSET), sram_aRxBuffer, SRAM_BUFFER_SIZE) != SRAM_OK) { ... }
BSP_SDRAM_Init();
if (ubSramInit != 0)
{
BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SRAM Initialization : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SRAM Test Aborted.", LEFT_MODE);
}if (ubSramInit != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SRAM Initialization : OK.", LEFT_MODE);
}else { ... }
if (ubSramWrite != 0)
{
BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SRAM WRITE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SRAM Test Aborted.", LEFT_MODE);
}if (ubSramWrite != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SRAM WRITE : OK.", LEFT_MODE);
}else { ... }
if (ubSramRead != 0)
{
BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SRAM READ : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SRAM Test Aborted.", LEFT_MODE);
}if (ubSramRead != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SRAM READ : OK.", LEFT_MODE);
}else { ... }
if (Buffercmp(sram_aRxBuffer, sram_aTxBuffer, SRAM_BUFFER_SIZE) > 0)
{
BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SRAM COMPARE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SRAM Test Aborted.", LEFT_MODE);
}if (Buffercmp(sram_aRxBuffer, sram_aTxBuffer, SRAM_BUFFER_SIZE) > 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SRAM Test : OK.", LEFT_MODE);
}else { ... }
HAL_Delay(300);
if (BSP_SRAM_Init() != SRAM_OK)
{
ubSramInit++;
}if (BSP_SRAM_Init() != SRAM_OK) { ... }
Fill_Buffer(sram_aTxBuffer, SRAM_BUFFER_SIZE, 0x1234);
uwSramDMA_Transfer_Complete = 0;
if (BSP_SRAM_WriteData_DMA((SRAM_DEVICE_ADDR + SRAM_WRITE_READ_ADDR_OFFSET), sram_aTxBuffer, SRAM_BUFFER_SIZE) != SRAM_OK)
{
ubSramDmaWrite++;
}if (BSP_SRAM_WriteData_DMA((SRAM_DEVICE_ADDR + SRAM_WRITE_READ_ADDR_OFFSET), sram_aTxBuffer, SRAM_BUFFER_SIZE) != SRAM_OK) { ... }
while (uwSramDMA_Transfer_Complete == 0)
{
}while (uwSramDMA_Transfer_Complete == 0) { ... }
uwSramDMA_Transfer_Complete = 0;
if (BSP_SRAM_ReadData_DMA((SRAM_DEVICE_ADDR + SRAM_WRITE_READ_ADDR_OFFSET), sram_aRxBuffer, SRAM_BUFFER_SIZE) != SRAM_OK)
{
ubSramDmaRead++;
}if (BSP_SRAM_ReadData_DMA((SRAM_DEVICE_ADDR + SRAM_WRITE_READ_ADDR_OFFSET), sram_aRxBuffer, SRAM_BUFFER_SIZE) != SRAM_OK) { ... }
while (uwSramDMA_Transfer_Complete == 0)
{
}while (uwSramDMA_Transfer_Complete == 0) { ... }
BSP_SDRAM_Init();
if (ubSramDmaWrite != 0)
{
BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SRAM DMA WRITE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 190, (uint8_t *)"SRAM DMA Test Aborted.", LEFT_MODE);
}if (ubSramDmaWrite != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SRAM DMA WRITE : OK.", LEFT_MODE);
}else { ... }
if (ubSramRead != 0)
{
BSP_LCD_DisplayStringAt(20, 190, (uint8_t *)"SRAM DMA READ : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 205, (uint8_t *)"SRAM DMA Test Aborted.", LEFT_MODE);
}if (ubSramRead != 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 190, (uint8_t *)"SRAM DMA READ : OK.", LEFT_MODE);
}else { ... }
if (Buffercmp(sram_aRxBuffer, sram_aTxBuffer, SRAM_BUFFER_SIZE) > 0)
{
BSP_LCD_DisplayStringAt(20, 205, (uint8_t *)"SRAM DMA COMPARE : FAILED.", LEFT_MODE);
BSP_LCD_DisplayStringAt(20, 220, (uint8_t *)"SRAM DMA Test Aborted.", LEFT_MODE);
}if (Buffercmp(sram_aRxBuffer, sram_aTxBuffer, SRAM_BUFFER_SIZE) > 0) { ... }
else
{
BSP_LCD_DisplayStringAt(20, 205, (uint8_t *)"SRAM DMA Test : OK.", LEFT_MODE);
}else { ... }
while (1)
{
if (CheckForUserInput() > 0)
{
return;
}if (CheckForUserInput() > 0) { ... }
}while (1) { ... }
}{ ... }
/* ... */
static void SRAM_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 *)"SRAM", 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 the SRAM", 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(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;
}{ ... }
/* ... */
void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
{
uwSramDMA_Transfer_Complete++;
}{ ... }
/* ... */
void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
{
BSP_LCD_SetTextColor(LCD_COLOR_RED);
BSP_LCD_DisplayStringAt(20, 215, (uint8_t *)"DMA ERROR", LEFT_MODE);
}{ ... }
/* ... */
/* ... */