SDRAM for DISCO_F746NG basic example
Dependencies: BSP_DISCO_F746NG
main.cpp@3:2bd1b98de6ec, 2019-11-20 (annotated)
- Committer:
- Jerome Coutant
- Date:
- Wed Nov 20 13:27:16 2019 +0100
- Revision:
- 3:2bd1b98de6ec
- Parent:
- 0:e674bc8aa29d
Update with STM32Cube_FW_F7_V1.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adustm | 0:e674bc8aa29d | 1 | #include "mbed.h" |
Jerome Coutant
3:2bd1b98de6ec
|
2
|
#include "stm32746g_discovery_sdram.h"
|
|
adustm | 0:e674bc8aa29d | 3 | |
adustm | 0:e674bc8aa29d | 4 | #define BUFFER_SIZE ((uint32_t)0x0100) |
adustm | 0:e674bc8aa29d | 5 | #define WRITE_READ_ADDR ((uint32_t)0x0800) |
Jerome Coutant
3:2bd1b98de6ec
|
6
|
|
|
adustm | 0:e674bc8aa29d | 7 | void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Offset); |
Jerome Coutant
3:2bd1b98de6ec
|
8
|
uint8_t CompareBuffer(uint32_t *pBuffer1, uint32_t *pBuffer2, uint16_t BufferLength);
|
|
Jerome Coutant
3:2bd1b98de6ec
|
9
|
|
|
adustm | 0:e674bc8aa29d | 10 | int main() |
adustm | 0:e674bc8aa29d | 11 | { |
adustm | 0:e674bc8aa29d | 12 | uint32_t WriteBuffer[BUFFER_SIZE]; |
adustm | 0:e674bc8aa29d | 13 | uint32_t ReadBuffer[BUFFER_SIZE]; |
adustm | 0:e674bc8aa29d | 14 | FMC_SDRAM_CommandTypeDef SDRAMCommandStructure; |
Jerome Coutant
3:2bd1b98de6ec
|
15
|
|
|
Jerome Coutant
3:2bd1b98de6ec
|
16
|
printf("\n\nSDRAM demo started\n");
|
|
Jerome Coutant
3:2bd1b98de6ec
|
17
|
|
|
Jerome Coutant
3:2bd1b98de6ec
|
18
|
BSP_SDRAM_Init();
|
|
Jerome Coutant
3:2bd1b98de6ec
|
19
|
|
|
adustm | 0:e674bc8aa29d | 20 | // Fill the write buffer |
adustm | 0:e674bc8aa29d | 21 | FillBuffer(WriteBuffer, BUFFER_SIZE, 0xA244250F); |
Jerome Coutant
3:2bd1b98de6ec
|
22
|
|
|
adustm | 0:e674bc8aa29d | 23 | // Write buffer |
Jerome Coutant
3:2bd1b98de6ec
|
24
|
BSP_SDRAM_WriteData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, WriteBuffer, BUFFER_SIZE);
|
|
Jerome Coutant
3:2bd1b98de6ec
|
25
|
printf("Write data DONE\n");
|
|
Jerome Coutant
3:2bd1b98de6ec
|
26
|
|
|
adustm | 0:e674bc8aa29d | 27 | // Issue self-refresh command to SDRAM device |
adustm | 0:e674bc8aa29d | 28 | SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_SELFREFRESH_MODE; |
adustm | 0:e674bc8aa29d | 29 | SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; |
adustm | 0:e674bc8aa29d | 30 | SDRAMCommandStructure.AutoRefreshNumber = 1; |
adustm | 0:e674bc8aa29d | 31 | SDRAMCommandStructure.ModeRegisterDefinition = 0; |
Jerome Coutant
3:2bd1b98de6ec
|
32
|
if (BSP_SDRAM_Sendcmd(&SDRAMCommandStructure) != HAL_OK) {
|
|
Jerome Coutant
3:2bd1b98de6ec
|
33
|
error("BSP_SDRAM_Sendcmd FAILED\n");
|
|
adustm | 0:e674bc8aa29d | 34 | } |
Jerome Coutant
3:2bd1b98de6ec
|
35
|
|
|
adustm | 0:e674bc8aa29d | 36 | // SDRAM memory read back access |
adustm | 0:e674bc8aa29d | 37 | SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_NORMAL_MODE; |
Jerome Coutant
3:2bd1b98de6ec
|
38
|
if (BSP_SDRAM_Sendcmd(&SDRAMCommandStructure) != HAL_OK) {
|
|
Jerome Coutant
3:2bd1b98de6ec
|
39
|
error("BSP_SDRAM_Sendcmd FAILED\n");
|
|
adustm | 0:e674bc8aa29d | 40 | } |
Jerome Coutant
3:2bd1b98de6ec
|
41
|
|
|
Jerome Coutant
3:2bd1b98de6ec
|
42
|
// Read back data from the SDRAM memory
|
|
Jerome Coutant
3:2bd1b98de6ec
|
43
|
BSP_SDRAM_ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, ReadBuffer, BUFFER_SIZE);
|
|
Jerome Coutant
3:2bd1b98de6ec
|
44
|
printf("Read data DONE\n");
|
|
Jerome Coutant
3:2bd1b98de6ec
|
45
|
|
|
Jerome Coutant
3:2bd1b98de6ec
|
46
|
// Checking data integrity
|
|
Jerome Coutant
3:2bd1b98de6ec
|
47
|
if (CompareBuffer(WriteBuffer, ReadBuffer, BUFFER_SIZE) != 0) {
|
|
Jerome Coutant
3:2bd1b98de6ec
|
48
|
printf("Write/Read buffers are different\n");
|
|
Jerome Coutant
3:2bd1b98de6ec
|
49
|
} else {
|
|
Jerome Coutant
3:2bd1b98de6ec
|
50
|
printf("Write/Read buffers are identical\n");
|
|
adustm | 0:e674bc8aa29d | 51 | } |
adustm | 0:e674bc8aa29d | 52 | } |
Jerome Coutant
3:2bd1b98de6ec
|
53
|
|
|
adustm | 0:e674bc8aa29d | 54 | /** |
adustm | 0:e674bc8aa29d | 55 | * @brief Fills buffer with user predefined data. |
adustm | 0:e674bc8aa29d | 56 | * @param pBuffer: pointer on the buffer to fill |
adustm | 0:e674bc8aa29d | 57 | * @param BufferLength: size of the buffer to fill |
adustm | 0:e674bc8aa29d | 58 | * @param Value: first value to fill on the buffer |
adustm | 0:e674bc8aa29d | 59 | * @retval None |
adustm | 0:e674bc8aa29d | 60 | */ |
adustm | 0:e674bc8aa29d | 61 | void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Value) |
adustm | 0:e674bc8aa29d | 62 | { |
Jerome Coutant
3:2bd1b98de6ec
|
63
|
uint32_t tmpIndex = 0;
|
|
Jerome Coutant
3:2bd1b98de6ec
|
64
|
|
|
Jerome Coutant
3:2bd1b98de6ec
|
65
|
/* Put in global buffer different values */
|
|
Jerome Coutant
3:2bd1b98de6ec
|
66
|
for (tmpIndex = 0; tmpIndex < BufferLength; tmpIndex++) {
|
|
Jerome Coutant
3:2bd1b98de6ec
|
67
|
pBuffer[tmpIndex] = tmpIndex + Value;
|
|
Jerome Coutant
3:2bd1b98de6ec
|
68
|
}
|
|
Jerome Coutant
3:2bd1b98de6ec
|
69
|
}
|
|
Jerome Coutant
3:2bd1b98de6ec
|
70
|
|
|
adustm | 0:e674bc8aa29d | 71 | /** |
adustm | 0:e674bc8aa29d | 72 | * @brief Compares two buffers. |
adustm | 0:e674bc8aa29d | 73 | * @param pBuffer1, pBuffer2: buffers to be compared. |
adustm | 0:e674bc8aa29d | 74 | * @param BufferLength: buffer's length |
adustm | 0:e674bc8aa29d | 75 | * @retval 0: pBuffer2 identical to pBuffer1 |
adustm | 0:e674bc8aa29d | 76 | * 1: pBuffer2 differs from pBuffer1 |
adustm | 0:e674bc8aa29d | 77 | */ |
Jerome Coutant
3:2bd1b98de6ec
|
78
|
uint8_t CompareBuffer(uint32_t *pBuffer1, uint32_t *pBuffer2, uint16_t BufferLength)
|
|
adustm | 0:e674bc8aa29d | 79 | { |
Jerome Coutant
3:2bd1b98de6ec
|
80
|
while (BufferLength--) {
|
|
Jerome Coutant
3:2bd1b98de6ec
|
81
|
if (*pBuffer1 != *pBuffer2) {
|
|
Jerome Coutant
3:2bd1b98de6ec
|
82
|
return 1;
|
|
Jerome Coutant
3:2bd1b98de6ec
|
83
|
}
|
|
Jerome Coutant
3:2bd1b98de6ec
|
84
|
|
|
Jerome Coutant
3:2bd1b98de6ec
|
85
|
pBuffer1++;
|
|
Jerome Coutant
3:2bd1b98de6ec
|
86
|
pBuffer2++;
|
|
adustm | 0:e674bc8aa29d | 87 | } |
Jerome Coutant
3:2bd1b98de6ec
|
88
|
|
|
Jerome Coutant
3:2bd1b98de6ec
|
89
|
return 0;
|
|
adustm | 0:e674bc8aa29d | 90 | } |