3 years, 3 months ago.

MBED Code Size: Quick View of .bin file


When I look at the bin file thats is generated from mbed compliation I see the following text/literals in it. I am wondering why are there such text/literals data like the location gpio.c or spi_api.c in the final executable

^@./mbed-dev/platform/mbed_critical.c^@interrupt_enable_counter < UINT32_MAX^@interrupts_disabled^@./mbed-dev/targets/TARGET_NXP/TARGET_LPC82X/gpio_api.c^@^@^@mG^@^@wG^@^@<81>G^@^@<8b>G^@^@<95>G^@^@<9f>G^@^@©G^@^@³G^@^@./mbed-dev/targets/TARGET_NXP/TARGET_LPC82X/pinmap.c^@^@^H^A^P^B^X^@^@^A^H^B^P./mbed-dev/targets/TARGET_NXP/TARGET_LPC82X/serial_api.c^@(stop_bits == 1) || (stop_bits == 2)^@(data_bits > 6) && (data_bits < 10)^@(parity == ParityNone) || (parity == ParityEven) || (parity == ParityOdd)^@No available UART^@^D^H^F^@^D^@^E^X^C^X^E^P^D^P^F^H./mbed-dev/targets/TARGET_NXP/TARGET_LPC82X/spi_api.c^@((bits >= 1) && (bits <= 16)) && ((mode >= 0) && (mode <= 3))^@No available SPI^@^@^@^@^@^@^@^@^@^@^@^@^@

2 Answers

3 years, 3 months ago.

Hi Ram, the strings you can see in the binary are connected to MBED_ASSERT, in your case they are generated by this code:

void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
    // 0: 1 stop bits, 1: 2 stop bits
    MBED_ASSERT((stop_bits == 1) || (stop_bits == 2));
    MBED_ASSERT((data_bits > 6) && (data_bits < 10)); // 0: 7 data bits ... 2: 9 data bits
    MBED_ASSERT((parity == ParityNone) || (parity == ParityEven) || (parity == ParityOdd));

MBED_ASSERTS converts provided expressions to string to print them in case the assertion fails. By default mbed OS is compiled with some debug informations see https://docs.mbed.com/docs/mbed-os-api/en/mbed-os-5.2/build_profiles/

Hope that helps.

Thanks. Can they a be removed for production code for better memory management ?

posted by Surendar S 21 Feb 2017

You can use small/release profile (add profile small or profile release to your command line, it was recently renamed so it depends on version of mbed OS, just give it a go if it fails to compile try the other one) to remove all the debug information, that will only work in mbed CLI, mbed online compiler can only use the default/develop profile at the moment. If you don't have issues with running out of memory, it may be useful to keep debug info just in case something goes wrong.

posted by Bartek Szatkowski 21 Feb 2017
3 years, 3 months ago.

If you want to avoid the runtime assertion, you can put NDEBUG string in the Compile Macros. This only works with mbed-dev library build.