Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 8 months ago.
high code size for trivial program
the program is just a blinking LED (see below), but the .bin file is 13.5kB. only part of that wil be Flash program memory, but 13.5kB is nevertheless a lot for such a trivial program. it should have been 100 bytes.
can anyone enlighten me? does mbed.h result in linking with a biggish library? can this be avoided? does mbed link unused functions?
thanks.
- include "mbed.h"
DigitalOut myled(LED1);
int main() { while(1) { myled = 1; LED is ON wait(0.2); 200 ms myled = 0; LED is OFF wait(1.0); 1 sec } }
1 Answer
10 years, 8 months ago.
For sure a problem is that the compiler is not smart enough, but then no compiler is smart enough. There are runtime checks which when resulting in an error will print error message on serial port, this will increase code size. Also the 13.5kB will be all in the flash memory. That said it is mainly a one-time overhead, so other code will not add alot more overhead.
But 100 bytes on an ARM is also extremely optimistic. Yes it is possible, but the mbed code will also set your PLL for example for proper clock rate. I don't know how many interrupt vectors yours has, but that is an additional 4 bytes per vector. Okay not much on the 13.5kB, but certainly making sure it is not going to fit within 100 bytes.
I cannot tell you what it is used all on, but I just did simple check, disabling stdio_messages (in targets/hal/STM/your target/device.h it is a define you can change, you do need to import mbed-src to do this and delete regular mbed). This reduced it by 6-7kB, so thats really a large part. And yes that is very large for just printing some code to an UART. It is because the C stdio library is used as layer between it, and this simply is large. It obviously also has its advantages, but it is quite large. And ideally a compiler could probably remove alot more code, but they aren't smart enough for that :).
You using ST Nucleo F030R8 ?
posted by Martin Kojtal 22 Feb 2015