【原创】解决on_chip_memory过小的问题
1、NIOS II IDE 报错
有些同学开始学NIOS II时,使用的是ON_CHIP_MEMORY;在NIOS II IDE编译过程当中遇到以下问题:
Unable to reach errno (at 0x02081024) from the global pointer (at 0x0208aaf0) because the offset (-39628) is out of the allowed range, -32678 to 32767
或者,
Severity and Description Path Resource Location Creation Time Id
ld: region onchip_mem is full (ep2c_onchip_led_test.elf section .text). Region needs to be 5640 bytes larger.
ep2c_onchip_led_test line 0 1250685275234 14679
ld: section .bss [00001aac -> 00001bbf] overlaps section .text [00001020 -> 00003607] ep2c_onchip_led_test line 0
1250685275234 14682
ld: section .rodata [00001020 -> 0000104b] overlaps section .text [00001020 -> 00003607] ep2c_onchip_led_test
line 0 1250685275234 14680
ld: section .rwdata [0000104c -> 00001aab] overlaps section .text [00001020 -> 00003607] ep2c_onchip_led_test
line 0 1250685275234 14681
又或者:
make -s all includes
Compiling hello_led.c...
Linking ep2c_onchip_led_test.elf...
/cygdrive/c/altera/81/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/http://www.cnblogs.com/http://www.cnblogs.com/nios2-elf/bin/ld:
region onchip_mem is full (ep2c_onchip_led_test.elf section .text). Region needs to be 5640 bytes larger.
/cygdrive/c/altera/81/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/http://www.cnblogs.com/http://www.cnblogs.com/nios2-elf/bin/ld:
section .rodata [00001020 -> 0000104b] overlaps section .text [00001020 -> 00003607]
/cygdrive/c/altera/81/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/http://www.cnblogs.com/http://www.cnblogs.com/nios2-elf/bin/ld:
section .rwdata [0000104c -> 00001aab] overlaps section .text [00001020 -> 00003607]
/cygdrive/c/altera/81/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/http://www.cnblogs.com/http://www.cnblogs.com/nios2-elf/bin/ld:
section .bss [00001aac -> 00001bbf] overlaps section .text [00001020 -> 00003607]
collect2: ld returned 1 exit status
make: *** [ep2c_onchip_led_test.elf] Error 1
Build completed in 2.609 seconds
2、解决方法如下
第一步:
重新编译,问题就解决啦。。
3、问题分析
程序过大,存储空间过小是导致这种错误的根本原因。按照以上设置,笔者正常编译之后的控制台给出:
可以发现还有3516 Bytes的空间。
另,如果使用SDRAM建议不要勾选small C library和reduced devicedrivers。NIOS II IDE会根据选择的不同加载不同的驱动版本,从而程序代码也不相同,能实现的功能也不同。例如使用了ucosII操作系统勾选这两项将导致错误。使用altera提供的HAL驱动程序时也不要勾选上。