メモリについて
main開始直後でもmallocで確保出来るのは25Kほど。
しょぼん(´・ω・`)としていたら、twitterで教えてもらったのでメモ。
参考:
http://twitter.com/tedd_okano/status/58525435058851841
http://mbed.org/forum/mbed/topic/604/?page=1#comment-3025
つまり
mbedは64KのRAMが積まれているが、メインメモリとしては32Kしか使えない。
残りはUSB/Ethernet用にそれぞれ16K予約されていて、この部分を使うには__attribute__指定でグローバルメモリとして確保する必要がある。
参考:
http://mbed.org/projects/libraries/svn/mbed/trunk/LPC1768/LPC1768.sct
AHBSRAM0 がUSB用
AHBSRAM1 がEthernet用
ちなみに、CANRAMを指定すると起動しなくなった
#include "mbed.h"
DigitalOut myled(LED1);
unsigned char usbArea[1024] __attribute__((section("AHBSRAM0")));
unsigned char ethArea[1024] __attribute__((section("AHBSRAM1")));
int main()
{
void *p;
int i=0;
while(1)
{
p = malloc(i);
if (p == NULL) break;
free(p);
i++;
}
printf("%d bytes can be used.\n", i - 1);
printf("Start Address(usbArea) 0x%08X\n", usbArea);
printf("Start Address(ethArea) 0x%08X\n", ethArea);
while(1)
{
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
結果
26188 bytes can be used.
Start Address(usbArea) 0x2007C000
Start Address(ethArea) 0x20080000
Please log in to post comments.
