微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > nios中使用main函数的问题(请教)

nios中使用main函数的问题(请教)

时间:10-02 整理:3721RD 点击:
nios6.0中不能使用main函数作为开头。必须使用int main (void) __attribute__ ((weak, alias ("alt_main")));int alt_main(void);然后自己初始化cpu的各项,作为开头!这是为什么?请教各位大侠~~~~~
最简单的例子:
程序1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "system.h"
#include "sys/alt_sys_init.h"
#include "sys/alt_irq.h"
#include "priv/alt_file.h"
int main (void) __attribute__ ((weak, alias ("alt_main")));
int alt_main(void)
{
alt_irq_init (ALT_IRQ_BASE);
alt_sys_init();
alt_io_redirect (ALT_STDOUT, ALT_STDIN, ALT_STDERR);
int i;
i=1;
return 0;
}
--------这样就没问题,编译能通过!
如果改成这样:
程序2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "system.h"
#include "sys/alt_sys_init.h"
#include "sys/alt_irq.h"
#include "priv/alt_file.h"
int main(void)
{
int i;
i=1;
return 0;
}
----------编译就不能通过了,提示如下
Console中的提示——————————————————
**** Incremental build of configuration Debug for project uart ****
make -s all
Compiling hello_uart.c...
Linking uart.elf...
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: region onchip_memory_0 is full (uart.elf section .text). Region needs to be 1564 bytes larger.
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: section .rodata [00000020 -> 00000047] overlaps section .exceptions [00000020 -> 000001c7]
/cygdrive/d/MyProgram/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 [00000048 -> 00000ab7] overlaps section .exceptions [00000020 -> 000001c7]
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: section .bss [00000ab8 -> 00000ccb] overlaps section .text [000001c8 -> 0000261b]
collect2: ld returned 1 exit status
make: *** [uart.elf] Error 1
Build completed
Problems中的提示——(共五个错误)————————————————
*** [uart.elf] Error 1
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld region onchip_memory_0 is full (uart.elf section .text). Region needs to be 1564 bytes larger.
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld section .bss [00000ab8 -> 00000ccb] overlaps section .text [000001c8 -> 0000261b]
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld section .rodata [00000020 -> 00000047] overlaps section .exceptions [00000020 -> 000001c7]
/cygdrive/d/MyProgram/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 [00000048 -> 00000ab7] overlaps section .exceptions [00000020 -> 000001c7]
PS:一直都存在这个问题,原来做中断做控制等实验都用int main (void) __attribute__ ((weak, alias ("alt_main")))开头,也就没有多管。但现在要学习串口通信,用int main (void) __attribute__ ((weak, alias ("alt_main")))开头也不行了!
通信程序(来自网上)如下:
程序3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "system.h"
#include "sys/alt_sys_init.h"
#include "sys/alt_irq.h"
#include "priv/alt_file.h"
int main (void) __attribute__ ((weak, alias ("alt_main")));
int alt_main(void)
{
alt_irq_init (ALT_IRQ_BASE);
alt_sys_init();
alt_io_redirect (ALT_STDOUT, ALT_STDIN, ALT_STDERR);
char* msg = "hello world";
FILE* fp;
fp = fopen ("/dev/uart_0", "w");
if (fp)
{
fprintf(fp, "%s",msg);
fclose (fp);
}
return 0;
}
编译后提示的错误与程序2的很类似:
Console中的提示——————————————————
**** Incremental build of configuration Debug for project uart ****
make -s all
Compiling hello_uart.c...
Linking uart.elf...
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: region onchip_memory_0 is full (uart.elf section .text). Region needs to be 1564 bytes larger.
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: section .rodata [00000020 -> 00000047] overlaps section .exceptions [00000020 -> 000001c7]
/cygdrive/d/MyProgram/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 [00000048 -> 00000ab7] overlaps section .exceptions [00000020 -> 000001c7]
/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: section .bss [00000ab8 -> 00000ccb] overlaps section .text [000001c8 -> 0000261b]
collect2: ld returned 1 exit status
make: *** [uart.elf] Error 1
Build completed

谢谢 各位大侠了~~~~

已解决
原因是RAM设置得太小~~~
哈哈 也是别人搞定的

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top