BSP
Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
#define SRAM_WRITE_READ_ADDR_OFFSET
#define SRAM_BUFFER_SIZE
Private variables
sram_aTxBuffer
sram_aRxBuffer
ubSramWrite
ubSramRead
ubSramInit
ubSramDmaWrite
ubSramDmaRead
uwSramDMA_Transfer_Complete
Private function prototypes
SRAM_demo()
SRAM_SetHint()
Fill_Buffer(uint16_t *, uint32_t, uint32_t)
Buffercmp(uint16_t *, uint16_t *, uint16_t)
HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *)
HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *)
Files
loading...
CodeScopeSTM32 Libraries and SamplesBSPSrc/sram.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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
201
202
203
204
205
206
207
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file BSP/Src/sram.c * @author MCD Application Team * @brief This example code shows how to use the SRAM Driver ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F4xx_HAL_Examples * @{ *//* ... */ /** @addtogroup BSP * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define SRAM_WRITE_READ_ADDR_OFFSET ((uint32_t)0x0800) #define SRAM_BUFFER_SIZE ((uint32_t)2048) Private define /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ 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 /* Private function prototypes -----------------------------------------------*/ 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 /* Private functions ---------------------------------------------------------*/ /** * @brief SRAM Demo * @param None * @retval None *//* ... */ void SRAM_demo (void) { SRAM_SetHint(); /*##-1- Configure the SRAM device ##########################################*/ /* SRAM device configuration */ if (BSP_SRAM_Init() != SRAM_OK) { ubSramInit++; }if (BSP_SRAM_Init() != SRAM_OK) { ... } /*##-2- SRAM memory read/write access ######################################*/ /* Fill the buffer to write */ Fill_Buffer(sram_aTxBuffer, SRAM_BUFFER_SIZE, 0xC20F); /* Write data to the SRAM memory */ 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) { ... } /* Read back data from the SRAM memory */ 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) { ... } /*##-3- Checking data integrity ############################################*/ /* SDRAM initialization */ 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 { ... } /* Tempo to allow message display */ HAL_Delay(300); /*##-4- SRAM memory DMAread/DMAwrite access ######################################*/ /* Disable the LCD to avoid the refresh from the SRAM */ if (BSP_SRAM_Init() != SRAM_OK) { ubSramInit++; }if (BSP_SRAM_Init() != SRAM_OK) { ... } /* Fill the buffer to write with new values */ Fill_Buffer(sram_aTxBuffer, SRAM_BUFFER_SIZE, 0x1234); uwSramDMA_Transfer_Complete = 0; /* Write data to the SRAM memory through DMA */ 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) { ... } /* Wait for the DMA write completion */ while (uwSramDMA_Transfer_Complete == 0) { /* infinite loop */ }while (uwSramDMA_Transfer_Complete == 0) { ... } /* Read back data from the SRAM memory */ 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) { ... } /* Wait for the DMA write completion */ while (uwSramDMA_Transfer_Complete == 0) { /* infinite loop */ }while (uwSramDMA_Transfer_Complete == 0) { ... } /*##-5- Checking data integrity ############################################*/ /* SDRAM initialization */ 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) { ... } }{ ... } /** * @brief Display SRAM Demo Hint * @param None * @retval None *//* ... */ static void SRAM_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Demo description */ 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); /* Set the LCD Text Color */ 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); }{ ... } /** * @brief Fills buffer with user predefined data. * @param pBuffer: pointer on the buffer to fill * @param uwBufferLenght: size of the buffer to fill * @param uwOffset: first value to fill on the buffer * @retval None *//* ... */ static void Fill_Buffer(uint16_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset) { uint32_t tmpIndex = 0; /* Put in global buffer different values */ for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++ ) { pBuffer[tmpIndex] = tmpIndex + uwOffset; }for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++) { ... } }{ ... } /** * @brief Compares two buffers. * @param pBuffer1, pBuffer2: buffers to be compared. * @param BufferLength: buffer's length * @retval 0: pBuffer identical to pBuffer1 * 1: pBuffer differs from pBuffer1 *//* ... */ 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; }{ ... } /** * @brief DMA transfer complete callback. * @param hdma: pointer to a SRAM_HandleTypeDef structure that contains * the configuration information for SRAM module. * @retval None *//* ... */ void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma) { uwSramDMA_Transfer_Complete++; }{ ... } /** * @brief DMA transfer complete error callback. * @param hdma: pointer to a SRAM_HandleTypeDef structure that contains * the configuration information for SRAM module. * @retval None *//* ... */ 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); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */