6 years, 8 months ago.

Memory Allocation and Compilers

OK, I'm lazy. I'll admit it. But I have a question that I'm hoping someone can answer.... bear with me, the question is at the end, I want to give the background first.

I'm doing some code that is RTOS & Sockets API based (gather data from multiple UARTS, compare it, send the changes off to a PC via UDP - nothing spectacular).

I'm using an mbed LPC1768 in this instance.

When I build the application (or anything using Ethernet & Sockets, really), the compiler shows that I'm using more memory than the device has. That's kind of worrying. I was wondering if the issue was that some of the RAM was being allocated from the two 16k peripheral SRAM banks, and the online compiler (well, linker actually) wasn't smart enough to understand that.

I found this thread: http://mbed.org/forum/mbed/topic/3179/?page=1#comment-16243 and shamelessly stole Adam Green's code for my own purposes. The results showed what I suspected .. so that's great. Here is the output from the program, and an image of the compiler's result:

Static RAM bank allocations Main RAM = 8140 RAM0 = 16384 RAM1 = 11348


So I wondered if the offline tool would have the same result. I exported it to the latest LPCExpresso (Code Red) toolchain and compiled that.. but that overflows, too. Output:

rtos_ethernet.axf section `.bss' will not fit in region `RamLoc32' rtos_ethernet C/C++ Problem make: * [rtos_ethernet.axf] Error 1 C/C++ Problem region `RamLoc32' overflowed by 4384 bytes rtos_ethernet C/C++ Problem make: * [mbed-rtos/rtx/RTX_Conf_CM.o] Error 1 C/C++ Problem

The question then is.... is there a way to get the offline toolchain to stop throwing those errors? Or is it *really* an issue in the toolchain (ie, it does not know the right place to put what I presume are the ethernet buffers and is really overflowing the RAM)?

All very frustrating!


UPDATE: I asked a colleague with MDK-ARM V4 ($3000 / year - that's ridiculous!) to build an export. Interestingly, that compiler produces:

Program Size: Code=77518 RO-data=1654 RW-data=28416 ZI-data=7468 (he tells me the total RAM is RW + ZI = 35k or so, so that seems right).

When run, the output is correct:

Static RAM bank allocations Main RAM = 8152 RAM0 = 16384 RAM1 = 11348

1 Answer

6 years, 8 months ago.

LPCXpresso has two runtime libraries redlib and newlib, redlib doesn't support C++ so it uses newlib + GCC, which produces less optomised code than mbed or mdk. Mdk has some of the optimisations that the mbed compiler has apparently so produces an output closer to that of mbed's compiler.

Also allocating variables/buffers to another bank in LPCxpresso is slightly different, try prefixing a larger buffer with : <<code>>__DATA(RAM2)<</code>>

and see if that helps.