Write and read data from SDRAM using mbed libraries

16 Aug 2018

Hi!

I'm trying to write and read data from SDRAM by SDRAM_DISCO_F429ZI.h.

I created very simple program just for writing and reading data basing on example: https://os.mbed.com/teams/ST/code/DISCO-F429ZI_SDRAM_demo/file/3a9aa7743ad9/main.cpp/

The problem is that data after read are different than I wrote to the RAM. I will be grateful for any suggestion what I did wrong.

Here is code:

write_and_read_from_RAM

#include "mbed.h"
#include "SDRAM_DISCO_F429ZI.h"
SDRAM_DISCO_F429ZI sdram;
DigitalOut led_green(LED1);
DigitalOut led_red(LED2);

int main()
{
    uint32_t buff[1];
    uint32_t WriteBuffer[4];
    uint32_t ReadBuffer[1];
    uint32_t adr = 0x30000;
    
    led_green = 0;
    led_red = 0;
    
    wait_ms(500);
    
    uint32_t i;
    for (i = 0; i<=3; i++)
    {
        WriteBuffer[i]=i;
        buff[0] = i;
        sdram.WriteData(SDRAM_DEVICE_ADDR + adr + i, buff, 0x0001);  
    }
    
    for (i = 0; i<=3; i++)
    {
        led_green = 1;
        led_red = 1;
        wait_ms(500);
        
        sdram.ReadData(SDRAM_DEVICE_ADDR + adr + i, ReadBuffer, 0x0001);
        
        if (WriteBuffer[i] == ReadBuffer [0])
        {
            led_green = 1;
            led_red = 0;
        }
        else
        {
            led_green = 0;
            led_red = 1;
        }
        wait_ms(1000);
    }       
  return 0;
}

When Write and Read is in the same for loop everything is ok. The problem occurs when Read is in other loop than Write. I use mbed on-line compiler.