程序如下: #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读写不正确呢? |