This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

sdram仿真的问题



/*向SDRAM中写入数据*/
    souraddr =  (int *)0x1ff000;
    deminaddr = (int *)0x200000;
//souraddr =  (int *)0x40000;
    //deminaddr = (int *)0x41000;
//souraddr =  (int *)0x1fefff;
    //deminaddr = (int *)0x1fffff;
    while(souraddr<deminaddr)
    {
     *souraddr++ = datacount*2;
     datacount++ ;
    }
    /*读出SRAM中的数据*/
    souraddr =  (int *)0x1ff000;
    datacount = 0;
我做5509SDRAM的实验,其中SDRAM占用0x40000-0x1fffff空间,
FLASH占用0x200000-0x3fffff空间,用到了CPLD。
我试的时候,从0x40000开始写0x1000个数,没问题。
从0x1fefff开始写0x1000个数,也没问题。
从0x1ff000开始写0x1000个数就不行了。
我单步执行,发现*souraddr增加到0x1fffff以后再加就回到0x1ff000了。
这是为什么?我感觉没有溢出啊。
请大侠指教,谢谢!
  • 你好,

    这是受C55x c编译器只能寻址16bit地址(64K)的限制, 解决方法见下面的FAQ.

    In C55x, why does a long pointer fail when incremented over a 64k boundary?

     
    Problem:
    When a long pointer is incremented and crosses over a 64k boundary (ie, an address which is a multiple of 0x0001_0000) why isn't the upper 7 bits of the address modified? It appears the address just wraps around the same 64k block of memory.


     
    Solution:

    Even when the large memory, which supports 23-bit pointers, is used the
    compiler does not calculate the offset from the base address correctly
    when crossing a 64k page boundary.

    For example, if you have a pointer which starts at 0x2f000 and increment
    the pointer to pass address 0x2ffff, instead of becoming 0x30000 the address
    will wrap around and become 0x20000. The same is true for arrays, which
    should not span a 64k page boundary.

    A workaround is to manually check for a boundary change and keep
    track of what the next page should be.

    #pragma DATA_SECTION(gMp3, "ERAM")
    int gMp3[200000];
    int  *p;
    unsigned long int  nextPage;   
    unsigned long  i;
    nextPage = (((unsigned long int)gMp3 & 0x7F0000) >> 16) + 1;    
    for ( i = 0; i < 200000; i++){
        *p++ = 0x0000;      
         /* IMPORTANT: need this to manage page boundries manually. */
         if (((unsigned long int)p & 0xFFFF) == 0)
          {      p = (int *)(nextPage++ << 16);
          }