RAM issue on LPC1768

Hi there
I’m using current mbed-os 5.14.02 on my LPC1768 device for a pretty small application (right now, just a UDP receiver). I reduced the code to a hello-world style but I still have RAM issues, because the compiler reports a usage of >35kB where 32KB are available. My Code is below, can anyone please help me to understand where the RAM usage comes from, and how to reduce it ?
thanks

Code

// xTest - Demo
// seems to use 35.6 kB RAM …?

#include “mbed.h”
#include “EthernetInterface.h”

EthernetInterface eth;
#define ETH_IP_ADDRESS “172.16.1.199”
#define ETH_IP_SUBNET “255.255.255.0”
char rxBuffer[200];
#define CMD_PORT_Rx 0x6066 // Rx=in

//---------------------------------------------------------------------------

void receive()
{
SocketAddress client;
UDPSocket socket;
socket.open(&eth);
int bind = socket.bind(CMD_PORT_Rx);

while (true)
{
int n = socket.recvfrom(&client, rxBuffer, sizeof(rxBuffer)-1);
}
}

//---------------------------------------------------------------------------

int main()
{
Thread tReceiver;

eth.set_network(ETH_IP_ADDRESS, ETH_IP_SUBNET, “0.0.0.0”);
eth.connect();
// pc.printf(“IP Address is %s\r\n”, eth.get_ip_address());

tReceiver.start(receive);

while (1)
{
rtos::ThisThread::sleep_for(t);
}
}

Do you need the functionality of an RTOS in this application? Whilst that does seem like an excessively high amount of RAM usage (and this is not a fix for that, but a workaround), you may be able to use Bare Metal if you don’t need the features of an RTOS.

Ahoj,
But with Bare metal is not available APIs for Network interfaces and Network socket or?

BR, Jan

My final application needs some µs precision timing, in order to drive stepper motors. All command and data in fed into the LPC via network, so, yes I need RTOS accuracy and Network interface.

I had all this already working all while ago based on mbed-rtos - but the online compiler will not compile my old sources anymore, I have tons of errors I don’t understand. So I changed another while ago to 5.10 and using mbed-os, and I got this working, too.

But every time I upgrade to the current mbed-os, I have new issues coming up. Even with such a simple program.

I was in doubt whether the RAM consumption, reported by the onliner compiler is accurate, but my code currently crashes with memory exceptions when I start using std::vector (for strings)

I still wonder why this mini-project consumes so much RAM

Can you share your code and error messages?

If this helps,

Mbed-os-blinky currently uses 8.7kB RAM and 30.5kB Flash for the LPC1768

However if you have included EthernetInterface.h and initialed this then even a while(1) will still burn all your resources.

Currently HTTP and HTTPs will burn more RAM than what’s available (32k) on the LPC1768. you also do not have TRNG so HTTPs is a no go here either.

Choose a platform with TRNG at least 128kB RAM and to be useful Flash at least 1mB.
Also CPU clock speed above 150Mhz is important otherwise it will trip up on some HTTP functions, as I found out particularly on Wi-Fi.

Something else, HTTPS socket re-use can be an issue, you can’t leave it connected to the end point for too long otherwise the connection drops, depending on who you are connected to that connection can be terminated after only few seconds if there’s no traffic, Google Firebase is one I have experienced.
Some cloud services will also use your data quota including TSL connection overhead so socket re-use is useful here.

The LPC1768 is equipped with 64kB RAM. The upper 32kB is used by (reserved for) the Ethernet and CAN interfaces. Since you are using the Ethernet interface you should not worry when your program is using more than 32kB.