Very large program storage generate in Arduino

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
hamsafar_a85
Posts: 11
Joined: Tue May 09, 2017 10:48 am
Contact:

Re: Very large program storage generate in Arduino

Post by hamsafar_a85 » Sat May 13, 2017 7:40 am

RogerClark wrote:The problem with new causing the binary size to be much larger than expected was partially fixed last year in this commit

https://github.com/rogerclarkmelbourne/ ... 2a824d80b7

By the addition of new.cpp

However, it does not seem to work in all circumstances

Someone will need to investigate why the functions in new.cpp are not being called in this case
Thanks,I install latest your library.

This simple code:

Code: Select all

void setup() 
{
  pinMode(PC13, OUTPUT);
}

void loop() 
{
  digitalWrite(PC13, HIGH);   
  delay(1000);                      
  digitalWrite(PC13, LOW);   
  delay(1000);              
}
with STM32F103C8 IC is:
Sketch uses 12876 bytes (19%) of program storage space. Maximum is 65536 bytes.
Global variables use 2816 bytes of dynamic memory.

While this code with UNO is:
Sketch uses 928 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

racemaniac
Posts: 622
Joined: Sat Nov 07, 2015 9:09 am

Re: Very large program storage generate in Arduino

Post by racemaniac » Sat May 13, 2017 7:51 am

that's indeed a pretty normal baseline :)
all the basic stuff takes up more space than what you see on an arduino, but you have plenty of space to continue working with :)

hamsafar_a85
Posts: 11
Joined: Tue May 09, 2017 10:48 am
Contact:

Re: Very large program storage generate in Arduino

Post by hamsafar_a85 » Sat May 13, 2017 7:59 am

stevestrong wrote:Can you show us your code?
Yes,
my code:
https://ufile.io/olblzz
Last edited by hamsafar_a85 on Sun May 21, 2017 9:11 am, edited 1 time in total.

hamsafar_a85
Posts: 11
Joined: Tue May 09, 2017 10:48 am
Contact:

Re: Very large program storage generate in Arduino

Post by hamsafar_a85 » Sat May 13, 2017 8:11 am

racemaniac wrote:that's indeed a pretty normal baseline :)
all the basic stuff takes up more space than what you see on an arduino, but you have plenty of space to continue working with :)
Yes, but for large code it increase too...

stevestrong
Posts: 1829
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Very large program storage generate in Arduino

Post by stevestrong » Sat May 13, 2017 10:04 am

The FLASH and RAM values you get by comparing to UNO are normal.
Don´t worry, any further added code does not increase the code size proportionally.

Can you also share a map file? Looking to the MAP file you can determine which modules causes the largest code size.
It seems that the code you shared is not all what you are using, there are some libraries missing.

edogaldo
Posts: 285
Joined: Fri Jun 03, 2016 8:19 am

Re: Very large program storage generate in Arduino

Post by edogaldo » Sat May 13, 2017 10:45 am

hamsafar_a85 wrote:with STM32F103C8 IC is:
Sketch uses 12876 bytes (19%) of program storage space. Maximum is 65536 bytes.
Global variables use 2816 bytes of dynamic memory.

While this code with UNO is:
Sketch uses 928 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
The amount of resources used by ARMs is huge respect to the amount used by AVRs anyway consider that the firsts are 8bit mcus while seconds are 32bit; also you should better compare STM32 compilation with a Leonardo compilation as STM32 also implements USB that the UNO does not have

stevestrong
Posts: 1829
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Very large program storage generate in Arduino

Post by stevestrong » Sat May 13, 2017 12:11 pm

hamsafar_a85 wrote:I compile my project for UNO and my program size is about 16kB but when compile it for Maple mini code is too big!!!
Sketch uses 85056 bytes (76%) of program storage space. Maximum is 110592 bytes.
Global variables use 6272 bytes of dynamic memory.

How can I reduce the program space?
I really doubt that it is exactly the same program code which on UNO is only 16kB.

Anyway, I checked your MAP file and everything looks fine.
These are the largest modules:
stm32f1_code.jpg
stm32f1_code.jpg (138.93 KiB) Viewed 296 times

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Very large program storage generate in Arduino

Post by Rick Kimball » Sat May 13, 2017 12:24 pm

A better benchmark would be to use an Arduino board that is comparable to the stm32f103. Our code size looks pretty good when you compare it to the Arduino Due. That core uses uses ~22k for a blink sketch. The Due also uses a cortex-m3 so at least you are comparing apples to apples.
Sketch uses 22124 bytes (4%) of program storage space. Maximum is 524288 bytes.
For grins I tested against my msp430g2553 arduino port:
Sketch uses 808 bytes (4%) of program storage space. Maximum is 16384 bytes.
Global variables use 18 bytes (3%) of dynamic memory, leaving 494 bytes for local variables. Maximum is 512 bytes.
The bottom line, the size of the code depends on the chip architecture, the compiler used, the actual core code, and how you code your program.
-rick

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Very large program storage generate in Arduino

Post by Rick Kimball » Sat May 13, 2017 12:45 pm

hamsafar_a85 wrote:
stevestrong wrote:Can you show us your code?
Yes,
my code:
https://ufile.io/olblz
Where is the version that compiles for stm32f103? This code seems to have avr specific code.

Which FastLED code are you using? There seems to be an issue with the first FastLED library I found using google.

https://github.com/FastLED/FastLED/issues/142
-rick

ag123
Posts: 808
Joined: Thu Jul 21, 2016 4:24 pm

Re: Very large program storage generate in Arduino

Post by ag123 » Sat May 13, 2017 1:42 pm

among the differences, uno probably won't support many things that's *just there* on stm32, that we mostly 'take for granted'
e.g. on stm32 there is usb-serial and stm32f1 is a native usb device, uno *don't do usb and can't do usb*, stm32 also has many more other resources such as 2 SPI ports, uarts, ADCs, DMA, clocks that can be programmed on the fly, turning on / off clocks to individual peripheral buses, multiple AFIO assignments, low power states etc etc. having support for these hardware may inevitably require more codes to support it hence a somewhat bulkier binary size

hence my guess is when compilers are building for atmega328, things that is 'not there' is simply *skipped* as the mcu won't have the hardware to support them and would result in compile errors if they are built after all

the FastLeds library seemed rather large i'd think, i'm not too sure if it contain ifdefs that perhaps to skip over sections of code that's not used, otherwise when the library is compiled, all the related objects may be included in the binary hence contributing to binary bloat as well

Post Reply