use this
Dependencies: BSP_DISCO_F429ZI SDRAM_DISCO_F429ZI mbed
main.cpp@0:d3bf1776d1c6, 2016-05-01 (annotated)
- Committer:
- grein028
- Date:
- Sun May 01 19:12:13 2016 +0000
- Revision:
- 0:d3bf1776d1c6
Use this demo for SDRAM it works great and should work in order to store the extra data. Here is a link to the chip for address lookups; http://www.issi.com/WW/pdf/42-45S16400J.pdf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
grein028 | 0:d3bf1776d1c6 | 1 | #include "mbed.h" |
grein028 | 0:d3bf1776d1c6 | 2 | #include "SDRAM_DISCO_F429ZI.h" |
grein028 | 0:d3bf1776d1c6 | 3 | |
grein028 | 0:d3bf1776d1c6 | 4 | SDRAM_DISCO_F429ZI sdram; |
grein028 | 0:d3bf1776d1c6 | 5 | |
grein028 | 0:d3bf1776d1c6 | 6 | DigitalOut led_green(LED1); |
grein028 | 0:d3bf1776d1c6 | 7 | DigitalOut led_red(LED2); |
grein028 | 0:d3bf1776d1c6 | 8 | |
grein028 | 0:d3bf1776d1c6 | 9 | Serial pc(USBTX, USBRX); |
grein028 | 0:d3bf1776d1c6 | 10 | |
grein028 | 0:d3bf1776d1c6 | 11 | #define BUFFER_SIZE ((uint32_t)0x0100) |
grein028 | 0:d3bf1776d1c6 | 12 | #define WRITE_READ_ADDR ((uint32_t)0x0800) |
grein028 | 0:d3bf1776d1c6 | 13 | |
grein028 | 0:d3bf1776d1c6 | 14 | void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Offset); |
grein028 | 0:d3bf1776d1c6 | 15 | uint8_t CompareBuffer(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength); |
grein028 | 0:d3bf1776d1c6 | 16 | |
grein028 | 0:d3bf1776d1c6 | 17 | int main() |
grein028 | 0:d3bf1776d1c6 | 18 | { |
grein028 | 0:d3bf1776d1c6 | 19 | uint32_t WriteBuffer[BUFFER_SIZE]; |
grein028 | 0:d3bf1776d1c6 | 20 | uint32_t ReadBuffer[BUFFER_SIZE]; |
grein028 | 0:d3bf1776d1c6 | 21 | FMC_SDRAM_CommandTypeDef SDRAMCommandStructure; |
grein028 | 0:d3bf1776d1c6 | 22 | |
grein028 | 0:d3bf1776d1c6 | 23 | pc.printf("\n\nSDRAM demo started\n"); |
grein028 | 0:d3bf1776d1c6 | 24 | led_red = 0; |
grein028 | 0:d3bf1776d1c6 | 25 | |
grein028 | 0:d3bf1776d1c6 | 26 | // Fill the write buffer |
grein028 | 0:d3bf1776d1c6 | 27 | FillBuffer(WriteBuffer, BUFFER_SIZE, 0xA244250F); |
grein028 | 0:d3bf1776d1c6 | 28 | |
grein028 | 0:d3bf1776d1c6 | 29 | // Write buffer |
grein028 | 0:d3bf1776d1c6 | 30 | sdram.WriteData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, WriteBuffer, BUFFER_SIZE); |
grein028 | 0:d3bf1776d1c6 | 31 | pc.printf("Write data DONE\n"); |
grein028 | 0:d3bf1776d1c6 | 32 | |
grein028 | 0:d3bf1776d1c6 | 33 | // Issue self-refresh command to SDRAM device |
grein028 | 0:d3bf1776d1c6 | 34 | SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_SELFREFRESH_MODE; |
grein028 | 0:d3bf1776d1c6 | 35 | SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; |
grein028 | 0:d3bf1776d1c6 | 36 | SDRAMCommandStructure.AutoRefreshNumber = 1; |
grein028 | 0:d3bf1776d1c6 | 37 | SDRAMCommandStructure.ModeRegisterDefinition = 0; |
grein028 | 0:d3bf1776d1c6 | 38 | if (sdram.Sendcmd(&SDRAMCommandStructure) != HAL_OK) |
grein028 | 0:d3bf1776d1c6 | 39 | { |
grein028 | 0:d3bf1776d1c6 | 40 | led_red = 1; |
grein028 | 0:d3bf1776d1c6 | 41 | error("BSP_SDRAM_Sendcmd FAILED\n"); |
grein028 | 0:d3bf1776d1c6 | 42 | } |
grein028 | 0:d3bf1776d1c6 | 43 | |
grein028 | 0:d3bf1776d1c6 | 44 | // SDRAM memory read back access |
grein028 | 0:d3bf1776d1c6 | 45 | SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_NORMAL_MODE; |
grein028 | 0:d3bf1776d1c6 | 46 | if (sdram.Sendcmd(&SDRAMCommandStructure) != HAL_OK) |
grein028 | 0:d3bf1776d1c6 | 47 | { |
grein028 | 0:d3bf1776d1c6 | 48 | led_red = 1; |
grein028 | 0:d3bf1776d1c6 | 49 | error("BSP_SDRAM_Sendcmd FAILED\n"); |
grein028 | 0:d3bf1776d1c6 | 50 | } |
grein028 | 0:d3bf1776d1c6 | 51 | |
grein028 | 0:d3bf1776d1c6 | 52 | while(1) { |
grein028 | 0:d3bf1776d1c6 | 53 | |
grein028 | 0:d3bf1776d1c6 | 54 | // Read back data from the SDRAM memory |
grein028 | 0:d3bf1776d1c6 | 55 | sdram.ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, ReadBuffer, BUFFER_SIZE); |
grein028 | 0:d3bf1776d1c6 | 56 | pc.printf("\nRead data DONE\n"); |
grein028 | 0:d3bf1776d1c6 | 57 | |
grein028 | 0:d3bf1776d1c6 | 58 | // Checking data integrity |
grein028 | 0:d3bf1776d1c6 | 59 | if (CompareBuffer(WriteBuffer, ReadBuffer, BUFFER_SIZE) != 0) |
grein028 | 0:d3bf1776d1c6 | 60 | { |
grein028 | 0:d3bf1776d1c6 | 61 | led_red = !led_red; |
grein028 | 0:d3bf1776d1c6 | 62 | pc.printf("Write/Read buffers are different\n"); |
grein028 | 0:d3bf1776d1c6 | 63 | } |
grein028 | 0:d3bf1776d1c6 | 64 | else |
grein028 | 0:d3bf1776d1c6 | 65 | { |
grein028 | 0:d3bf1776d1c6 | 66 | led_green = !led_green; |
grein028 | 0:d3bf1776d1c6 | 67 | pc.printf("Write/Read buffers are identical\n"); |
grein028 | 0:d3bf1776d1c6 | 68 | } |
grein028 | 0:d3bf1776d1c6 | 69 | |
grein028 | 0:d3bf1776d1c6 | 70 | wait(1); |
grein028 | 0:d3bf1776d1c6 | 71 | } |
grein028 | 0:d3bf1776d1c6 | 72 | } |
grein028 | 0:d3bf1776d1c6 | 73 | |
grein028 | 0:d3bf1776d1c6 | 74 | /** |
grein028 | 0:d3bf1776d1c6 | 75 | * @brief Fills buffer with user predefined data. |
grein028 | 0:d3bf1776d1c6 | 76 | * @param pBuffer: pointer on the buffer to fill |
grein028 | 0:d3bf1776d1c6 | 77 | * @param BufferLength: size of the buffer to fill |
grein028 | 0:d3bf1776d1c6 | 78 | * @param Value: first value to fill on the buffer |
grein028 | 0:d3bf1776d1c6 | 79 | * @retval None |
grein028 | 0:d3bf1776d1c6 | 80 | */ |
grein028 | 0:d3bf1776d1c6 | 81 | void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Value) |
grein028 | 0:d3bf1776d1c6 | 82 | { |
grein028 | 0:d3bf1776d1c6 | 83 | uint32_t tmpIndex = 0; |
grein028 | 0:d3bf1776d1c6 | 84 | |
grein028 | 0:d3bf1776d1c6 | 85 | /* Put in global buffer different values */ |
grein028 | 0:d3bf1776d1c6 | 86 | for (tmpIndex = 0; tmpIndex < BufferLength; tmpIndex++ ) |
grein028 | 0:d3bf1776d1c6 | 87 | { |
grein028 | 0:d3bf1776d1c6 | 88 | pBuffer[tmpIndex] = tmpIndex + Value; |
grein028 | 0:d3bf1776d1c6 | 89 | } |
grein028 | 0:d3bf1776d1c6 | 90 | } |
grein028 | 0:d3bf1776d1c6 | 91 | |
grein028 | 0:d3bf1776d1c6 | 92 | /** |
grein028 | 0:d3bf1776d1c6 | 93 | * @brief Compares two buffers. |
grein028 | 0:d3bf1776d1c6 | 94 | * @param pBuffer1, pBuffer2: buffers to be compared. |
grein028 | 0:d3bf1776d1c6 | 95 | * @param BufferLength: buffer's length |
grein028 | 0:d3bf1776d1c6 | 96 | * @retval 0: pBuffer2 identical to pBuffer1 |
grein028 | 0:d3bf1776d1c6 | 97 | * 1: pBuffer2 differs from pBuffer1 |
grein028 | 0:d3bf1776d1c6 | 98 | */ |
grein028 | 0:d3bf1776d1c6 | 99 | uint8_t CompareBuffer(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength) |
grein028 | 0:d3bf1776d1c6 | 100 | { |
grein028 | 0:d3bf1776d1c6 | 101 | while (BufferLength--) |
grein028 | 0:d3bf1776d1c6 | 102 | { |
grein028 | 0:d3bf1776d1c6 | 103 | if (*pBuffer1 != *pBuffer2) |
grein028 | 0:d3bf1776d1c6 | 104 | { |
grein028 | 0:d3bf1776d1c6 | 105 | return 1; |
grein028 | 0:d3bf1776d1c6 | 106 | } |
grein028 | 0:d3bf1776d1c6 | 107 | |
grein028 | 0:d3bf1776d1c6 | 108 | pBuffer1++; |
grein028 | 0:d3bf1776d1c6 | 109 | pBuffer2++; |
grein028 | 0:d3bf1776d1c6 | 110 | } |
grein028 | 0:d3bf1776d1c6 | 111 | |
grein028 | 0:d3bf1776d1c6 | 112 | return 0; |
grein028 | 0:d3bf1776d1c6 | 113 | } |