Build flugs in new version mbed

build_flags = -D MBED_BUILD_PROFILE_RELEASE
This flag does not reduce the size of the firmware in new version mbed (https://community.platformio.org/t/arm-mbed-os-5-13-4/9328)

@valeros please help

Hi @nikantovik! What platform do you use? MBED_BUILD_PROFILE_RELEASE and MBED_BUILD_PROFILE_DEVELOP (used by default) are not so different in terms of optimization (especially for RAM). Could you please try -D MBED_BUILD_PROFILE_DEBUG does it affect memory size?

  #include <mbed.h>
  
  DigitalOut led (PC_13);
  
  int main() {
  
   // put your setup code here, to run once:
  
    while(1) {
    led=!led;
  wait_ms(1000);
  }
  }

[env:genericSTM32F103C8]
platform = stm32@5.5.0
board = genericSTM32F103C8
framework = mbed
build_flags = -D MBED_BUILD_PROFILE_RELEASE

DATA:    [          ]   1.8% (used 368 bytes from 20480 bytes)
PROGRAM: [=         ]  11.6% (used 7612 bytes from 65536 bytes)
build_flags = -D MBED_BUILD_PROFILE_DEBUG

DATA:    [==        ]  16.8% (used 3448 bytes from 20480 bytes)
PROGRAM: [======    ]  61.9% (used 40548 bytes from 65536 bytes)

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = mbed
build_flags = -D MBED_BUILD_PROFILE_RELEASE

DATA:    [==        ]  17.3% (used 3536 bytes from 20480 bytes)
PROGRAM: [=====     ]  47.9% (used 31372 bytes from 65536 bytes)
build_flags = -D MBED_BUILD_PROFILE_DEBUG

DATA:    [==        ]  17.3% (used 3536 bytes from 20480 bytes)
PROGRAM: [======    ]  63.6% (used 41684 bytes from 65536 bytes)

Thanks for the info. I guess the problem is that in the new release they’ve moved code related to fault handling to the platform folder and now it’s compiled even in mbed 2 mode (that pulls in a bunch of heavy functions from libc). As a workaround you can try to add -DMBED_FAULT_HANDLER_DISABLED to your build_flags in platformio.ini

2 Likes

Thank you for help!!!

Hi
I have the same issue. Adding -DMBED_FAULT_HANDLER_DISABLED to platformio.ini did not make any difference. Was this issue fixed for you?

build_flags = -D MBED_BUILD_PROFILE_RELEASE
-D MBED_FAULT_HANDLER_DISABLED

Thanks for the reply.
Yes, I did the same. Sorry for the typo. But I couldnt find any change.

I also tried using “extra_scripts = linker_flags_newlib-nano.py”. This surprisingly, increased the PROGRAM size and reduced the DATA size.

Without newlib-nano:
Memory Usage → Redirecting...
DATA: [== ] 17.4% (used 3560 bytes from 20480 bytes)
PROGRAM: [= ] 8.9% (used 17424 bytes from 196608 bytes)

With newlib-nano:
Memory Usage → Redirecting...
DATA: [= ] 9.0% (used 1840 bytes from 20480 bytes)
PROGRAM: [== ] 15.3% (used 30036 bytes from 196608 bytes)