Skip to main content
Scott Dev
Senior
February 18, 2017
Question

Large compiled application size, is this normal?

  • February 18, 2017
  • 21 replies
  • 3460 views
Posted on February 18, 2017 at 08:47

Hi

  I am just a beginner in the STM32, I have been designing for 8bit Freescale parts for years. I am using ST's Nuleo64 STM32L07 processor.

 Using STM32CubeMX I designed a very simple application that simply captures the system timer, GPIO interupt for the push button. I simply wrote some code (just for me getting used to the system) using Keil V5. I simply use the system timer interupt to blink the LED, pressing the button changes the speed of the LED . Within Cubemx I also selected RTC,LPUART but done nothing with the code yet. After building the application and ran it I noticed that the size of the code is 6420, and ram 1176. To me this seams a lot for what it does, I am used of having more tighter code. The application uses HAL library, does this put a large overhead to the size of code and ram used? And am I better stripping out some of the code that CubeMX creates?

Thanks

Scott

    This topic has been closed for replies.

    21 replies

    Tesla DeLorean
    Guru
    February 18, 2017
    Posted on February 18, 2017 at 14:02

    One potential issue is the USART code might be pulling in the floating point math library.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Scott Dev
    Scott DevAuthor
    Senior
    February 18, 2017
    Posted on February 18, 2017 at 17:30

    Why would the floating point library be pulled in for the USART? All it does is transmit and receives bytes of data , no floating point calculations being caried out.

    Scott

    S.Ma
    Principal
    February 18, 2017
    Posted on February 18, 2017 at 18:18

    Clive already reported this part in December. It is a piece of code used to calculate the bitrate fractional divider from SYSCLK. Want to confirm it? Generate the MAP file from the linker project option and check if a float ansi lib has been pulled in the memory space. Easy check.

    AvaTar
    Senior III
    February 18, 2017
    Posted on February 18, 2017 at 19:23

    I don't use Cube, for good reasons - like this. But I can imagine that it foolishly uses floating point constants in peprocessor definitions.

    An experienced developer should know that. (To be clear, I mean ST's Cube developers ...)

    Tesla DeLorean
    Guru
    February 18, 2017
    Posted on February 18, 2017 at 22:45

    No I think there is purposeful casting of the maths related to the clock speed vs baud rate so it doesn't exceed scope. I would have done this with integer maths. All maths on the Cortex-M0 tends to be more library dependent given the core lacking key features. The incremental costs once you've got some base libraries pulled in is going to be more manageable.

    The .MAP file should provide some understanding about where the bytes are getting eaten.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    AvaTar
    Senior III
    February 19, 2017
    Posted on February 19, 2017 at 17:19

    No I think there is purposeful casting of the maths related to the clock speed vs baud rate ...

    IMHO that would make it even worse.

    Such sub-optimal implementations seem to be the price of a 'one-click' software ...

    AVI-crak
    Senior
    February 19, 2017
    Posted on February 19, 2017 at 11:39

    Use of standard functions (printf type) - pulls for itself a code from the libraries hidden for the user which are a part of ID (Keil V5).

    It is a part of standard functions of the SI language, but their implementation for all occasions. Bonuses aren't disconnected.

    Option of the small size of a code - own functions of a data output.

    In addition: study documentation on the chip - it is the first stage.

    Scott Dev
    Scott DevAuthor
    Senior
    February 19, 2017
    Posted on February 19, 2017 at 12:26

    In the past I have always written my own code instead of printf etc. on other proecssors, as found it to be too much of a big overhead. For my applications, creating a few buffers for sending and recieving data within interupts is all I need (along with house keeping), and doesnt make much of a dent in program size.

    Scott

    Maor Avni
    Associate II
    February 22, 2017
    Posted on February 22, 2017 at 11:44

    First of all you're working with 32-bit code, in contrast to 8-bit code. The coded instructions will be bigger by definition.

    Second, if you use Debug compilation, which usually means no code optimizations at all, the code will always be larger than optimized code.

    AvaTar
    Senior III
    February 22, 2017
    Posted on February 22, 2017 at 12:53

    First of all you're working with 32-bit code, in contrast to 8-bit code. The coded instructions will be bigger by definition.

    That is not quite true.

    The size of an instruction is defined by the number of instruction types to decode (like ADD, SUB, MOV, etc. in it's variants), and source and destination operand range. E.g. selecting one of 16 ARM core registers requires 4 bits of an instruction.

    The same holds true for 8-bit processors. The Z80, for example, had 8 general purpose registers, requiring 3 bits for encoding.Only does that 8-bit core need more cycles to fetch a multi-byte instruction on the 8-bit data bus. That's why many old cores have a dedicated accumulator register - many operations implicitly use this accu, saving bits in instruction size and thus fetches. However, in the a greater context, you often need more instructions to achieve certain operations, loosing more than you gained before.