程序如下:
#include <stdio.h>
#include <string.h>
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
int main (void)
{
alt_u8 led = 0x2;
alt_u8 dir = 0;
volatile int i;
char* msg="Hello from Nios II!\n";
FILE* fp;
while (1)
{
fp = fopen("/dev/uart_0","w");
if(fp)
{
fprintf(fp,"%s",msg);
fclose(fp);
}
if (led & 0x9)
{
dir = (dir ^ 0x1);
}
if (dir)
{
led = led >> 1;
}
else
{
led = led << 1;
}
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, led);
i = 0;
while (i<5000000)
i++;
}
return 0;
}
编译出现错误如下:
**** Incremental build of configuration Debug for project hello_led_3 ****
make -s all
Compiling hello_led.c...
Linking hello_led_3.elf...
/cygdrive/d/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: section .rwdata [000039f0 -> 000043db] overlaps section .rodata [000039f0 -> 00003a3b]
collect2: ld returned 1 exit status
make: *** [hello_led_3.elf] Error 1
Build completed
以下是所用的ram:
Program memory(.text): sram_0(片外sram)
Read-only data memory(.rodata): onchip_memory
Read/write data memory(.rwdata): sram_0
Heap memory: sram_0
stack memory: sram_0
而所有的memory都用sram_0时,程序编译能通过,但是程序运行不正常(led能工作,但串口不能工作)
当所有的memory都使用onchip_memory时,程序编译通过,运行正常。
当Program memory(.text)和Read-only data memory(.rodata)使用onchip_memory,其他使用sram_0时,程序编译通过,运行正常。
是否是sram读写不正确呢?
你上面的编译错误是怎么是rwdata覆盖了rodata,你把rodata放在onchip上,你的onchip多大,你的最终的代码多大.应该是溢出了吧.
sram的读写是否正常,你先让代码在onchip中,对sram读写一下看看,正常不.
我的onchip是18K,最终代码为14K,sram是1M,读写正常。如果只把rwdata与rodata放入onchip中,其余放入sram中,程序也正常。编译结果如下:
**** Incremental build of configuration Debug for project hello_led_3 ****
make -s all
Compiling hello_led.c...
Linking hello_led_3.elf...
Info: (hello_led_3.elf) 14 KBytes program size (code + initialized data).
Info: 1009 KBytes free for stack + heap.
Post-processing to create sram_0.dat
Post-processing to create onchip_memory_0.dat
Post-processing to create sram_0.sym
Post-processing to create onchip_memory_0.sym
Post-processing to create onchip_memory_0.hex
Build completed
但如果只把rodata放入onchip中,其余放入sram中,则程序编译出现错误:
**** Incremental build of configuration Debug for project hello_led_3 ****
make -s all
Compiling hello_led.c...
Linking hello_led_3.elf...
/cygdrive/d/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: section .rwdata [000039f0 -> 000043db] overlaps section .rodata [000039f0 -> 00003a3b]
collect2: ld returned 1 exit status
make: *** [hello_led_3.elf] Error 1
Build completed
你看一看编译原理方面的东西
编译的时候把什么变量放在什么位置,不然的后可能会引起那些错误
看编译原理倒不至于,要是变成那么复杂,就没有人编程了.
你的问题有点奇怪,板子上又没有sdram,把所有的放到sdram中试试,我又点怀疑硬件问题.
把所有的放在sdram中程序运行正常。是不是硬件的问题呢?
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |