ARM中有关malloc函数的问题
请教各位一下,希望能抽空给俺看看,帮忙解决一下!
我的硬件是LPC2378+1161做的USB host的程序,我现在的问题是,如果我的程序中用到了malloc函数,我自己弄得这一块没有任何问题,但是和同事的大程序和起来后,在jtag仿真的时候可以下载到Flash中,但是运行的话进不了main()函数,会死在目标板初始化里面,根本跳不到main函数入口,而我自己的程序独立跑起来却很正常,不知是何原因?
上网查了下,说有可能是硬件里面堆的起始地址设置的不对,而我们的工程模板是ARM芯片厂商提供的,问了下他们说堆的起始地址没有问题,而且已经将容量设置为最大,没有办法了。
解决办法尝试了一下几种:1,将所有的malloc函数全部替换,用它申请内存的时候就定义一个数组,把这个数组交给别的指针变量来使用,但是这样程序虽然进入了main函数,却经常跑飞,跳到“去数据终止”中去,
2,定义一个大数组,将这个大数组当作一个特定的“堆”来用,自己写个申请和释放内存的函数,可是这个“内存”管理起来也相当麻烦,申请还好些,释放就有点困难,要用链表来管理这些“内存”,这对嵌入式系统来说开销的内存好像有点大了,会影响到真个系统的性能,所以好像也不是什么好办法。
问题提出来,世间有些紧,希望大家多多帮忙!!
[解决办法]
1161? isp1161? It sounds too old.
About your issue, I have encounted once that the system could not pass the C library initialization stage when I inject some code which link in some C's system-dependent functions, say, clock(), because I did not define my own version, my arm compiler choose its own version instead which compromised system initialization on my hardware.
Anyway, check out whether you need some system- or hardware- dependent functions which normally supply by compiler vendor on PC, and you don't define it.
If you are running some operate system on hardware, linux or some else, malloc would be supplied by operate system's lib .If you don't run a operate system, you should define your own malloc function.
[解决办法]
what you means by Your module could run alone? On target hardware or on some emulation? I don't think ADS could supply a general malloc which could be used on any arm systems.
To be honest, I have no experice on a standalone application, the platforms I touch all have operate system , linux or nucleus.
About 1161, I used to have nightmare with it. When I was in college, I run into a project dealing with some embedded video phone system with usb camera. The hardware board was designed for all kinds of moving targets, but the designer happened to choose ISP116x as usb host chip, which is way not fit for mass data tranfer, resulting to spending my days and days in lab to make most usage of its bandwidth.
Anyway, you could contact NXP for newly released chips.
[解决办法]
malloc 如果没有os支持
可能需要自己实现 交换ram的空间
而非flash的空间这样简单一些
[解决办法]
Recently I read some documents about ADS, seams default implementation of malloc would make use of memory left by the image, starting at the last address of ZI output section. But if you use scatter files for link, you need to implement it yourself.
You could check the final out image files to find out, in symbol table, whether the malloc is referenced and defined.
If in your solution version, there is no reference or define for malloc, then it's better chance for malloc to be the cause.