VS Arduino
>> >> Crazy program size
https://www.visualmicro.com/forums/YaBB.pl?num=1573997932

Message started by yet-another-average-joe on Nov 17th, 2019 at 1:38pm

Title: Crazy program size
Post by yet-another-average-joe on Nov 17th, 2019 at 1:38pm
Hello,

please consider this very simple code ; not a real life application, but I've been facing this problem for a long time, and it shows the problem.


Code (c++):


void setup()
{
     Serial.begin(115200);
}

inline int dummy() { return 0; }

void loop()
{
     //static bool done = false;
     //static int x;

     //if (!done)
     //{
     //      x = dummy();
     //      done = true;
     //}

     static int x = dummy();
     Serial.println(x);
     delay(1000);
}



Compiled for STM32F103C Series, with Arduino IDE, and with default options, the binary is 11604 bytes

Compile the same code with VisualMicro/Visual Studio, default options, release. The binary is now 74776 bytes !!!!!! Needless to say that such a program cannot be flashed on a regular BluePill (genuine STM32 = 64KB if not "unlocked", or chinese 64K clones)

Bootloader : "Roger's Core"

As soon as a static variable is initialized with a function within a function, the binary becomes insanely huge... (the commented code is a workaround). Inlined or not,  the problem remains the same.

There's probably some offending parameter in the compiler and/or linker command, but I have no idea.

Visual Studio 2017, Arduino IDE 1.8.10, VisualMicro 1909.27.0

Title: Re: Crazy program size
Post by Visual Micro on Nov 17th, 2019 at 1:42pm
Please follow the guide in yellow above. That shows the answer to all questions.

Things that affect program size are what optimization setting you have configured and if debug is enabled or not. If debug is enabled then which one.

The guide in yellow shows us the build settings, versions etc and avoid the need for you to give that important information.

Title: Re: Crazy program size
Post by yet-another-average-joe on Nov 17th, 2019 at 1:50pm
Oops !

::)


It's compiled in Release mode, as said in the OP.
https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=Sortie-MicroBuild_001.txt ( 39 KB | 1 Download )

Title: Re: Crazy program size
Post by Visual Micro on Nov 17th, 2019 at 1:58pm
Thanks, please do same in arduino by switch on File>Preferences>Compile Verbose.

We need to compare your board options because the platform you are using allows for debug and optimization settings that you see on the vMicro (board options) menus.


Title: Re: Crazy program size
Post by yet-another-average-joe on Nov 17th, 2019 at 2:32pm
I made a mistake with Arduino IDE related files. I deleted the messages and the attchments.

I first got "You do not have permission to post attachments in this board" when I attempted to attach files. Now, I have no option for attachments

Maybe I could post the files on my Git and give you a link ?

Title: Re: Crazy program size
Post by Visual Micro on Nov 17th, 2019 at 2:34pm
if you click the reply button instead of using the quick reply box, can you attach files?

Title: Re: Crazy program size
Post by yet-another-average-joe on Nov 17th, 2019 at 2:41pm
I logged out and then logged in again, and got the Attachment button.
https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=Arduino_IDE_Output_02.txt ( 602 KB | 2 Downloads )
Arduino_IDE_board_options_02.png ( 34 KB | 0 Downloads )

Title: Re: Crazy program size
Post by yet-another-average-joe on Nov 17th, 2019 at 2:42pm
And now the VisualMicro Board Options
VMicro_IDE_board_options_01_001.png ( 28 KB | 2 Downloads )

Title: Re: Crazy program size
Post by Visual Micro on Nov 17th, 2019 at 2:45pm
It's a different board in the arduino ide?

Title: Re: Crazy program size
Post by yet-another-average-joe on Nov 17th, 2019 at 3:48pm
Oh yes you are right ! This is the explanation.

Arduino_Core_STM32  was selected in Arduino IDE (I never use this IDE except for ISP and blink, and didn't notice...), and Roger's Core is selected in Visual Studio.

2 cores are installed :

Roger Clarke Melbourne core AKA "Roger's Core", and Arduino_Core_STM32

These 2 cores are extremely confusing.

I use Roger's Core, and have to, as I like to use a library that does not compile and link with the other one (STL).

Compiling/linking the example code with Arduino_Core_STM32 in VS/VM does not produce such a huge binary when using static initializations.

Compiling in Arduino IDE with Roger'Core is also a memory hog.

So it is probably a core related problem. It will probably never be solved as Roger gave up a few months ago...

Thank you for your time, I apologize for the inconvenience.  :-[

Title: Re: Crazy program size
Post by yet-another-average-joe on Nov 17th, 2019 at 5:43pm
(followup for those who have the same problem and who could read this, following some Google search...)

It's not a bug, it's a feature. See here : https://github.com/rogerclarkmelbourne/Arduino_STM32/pull/444

Definitely NOT Visual Micro related.

Problem (wich is not a problem...) seems to be solved adding "-fno-threadsafe-statics" in Compiler/Advanced/Extra .cpp flags . It drastically reduces the hex file size for the code example. (74476KB to 16036KB !!!!!!!)
statics.PNG ( 14 KB | 6 Downloads )

Title: Re: Crazy program size
Post by Visual Micro on Nov 18th, 2019 at 11:38am
Thanks for the info. That is useful.

Title: Re: Crazy program size
Post by marcoStraubel on Sep 3rd, 2020 at 1:26pm
Hi,

I guess that is not the end of the story. I found this thread while looking for a comparable issue for a totally different MCU. I'm using the relatively new ATTiny1604 8-bit chip with Spence Konde's megaTinyCore (https://github.com/SpenceKonde/megaTinyCore)

The example as of the first post compiles in Arduino IDE creating a 696Byte small hex file. In AtmelStudio + VM it compiles to 12655Bytes.

The same effect applies to my own code which is a test for longer sleep (standby) and wake up by an overflow interrupt of the MCU-internal RTC:

Code (c++):
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>

#define LED_PIN 3
#define RTC_EXAMPLE_PERIOD (4) // enter seconds to sleep -1 .. so 4 means 5 seconds of sleep
bool ledState = false;
volatile bool pleaseToggle = false;

void setup() {
    // Set all pins to low power mode:
    for (uint8_t i = 0; i < 8; i++) {
      *((uint8_t *)&PORTA + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
    }
 
    for (uint8_t i = 0; i < 4; i++) {
      *((uint8_t *)&PORTB + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
    }

    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, ledState);
   
    Serial.begin(500000);
    delay(500);   
    Serial.println(F("\n---> setup()"));      
   
    RTC_init();
    delay(500);    
   
    interrupts(); 
}

void loop() {
   
  if (pleaseToggle){
    Serial.println(F("> ISR()"));
    pleaseToggle = false;
    ledState ^= 1;
    digitalWrite(LED_PIN, ledState); 
  }
  Serial.println(F("> loop()"));
 
  Serial.println(F("- Good Night"));
  Serial.flush();
  set_sleep_mode(SLEEP_MODE_STANDBY);
  sleep_enable();
  sleep_cpu(); //Go into sleep
  Serial.println(F("- Good Morning"));
   
}

void RTC_init()
{
    Serial.println(F("> RTC_init()"));
    while (RTC.STATUS > 0) {} // Wait for all register to be synchronized
 
    RTC.PER = RTC_EXAMPLE_PERIOD;
    RTC.INTCTRL = 0 << RTC_CMP_bp
    | 1 << RTC_OVF_bp; //Overflow interrupt.
   
    RTC.CTRLA = RTC_PRESCALER_DIV1024_gc
    | 1 << RTC_RTCEN_bp         //Enable RTC
    | 1 << RTC_RUNSTDBY_bp;     //Run in standby
 
    RTC.CLKSEL = RTC_CLKSEL_INT1K_gc;
}


ISR(RTC_CNT_vect)
{
  RTC.INTFLAGS = RTC_OVF_bm;
  pleaseToggle = true;
}

*.hex file size:

  • Aduino IDE: 2787Bytes
  • Visualµ: 13093Bytes

Maybe worth to know: If I comment all "Serial" related lines, the size drops dramatically. However, still not the same.
*.hex file size:

  • Aduino IDE: 962Bytes
  • Visualµ: 3330Bytes

FYI1: Althought the huge size, I'm still within the 16kB flash size of the used Attiny. I can upload the hex file and its working fine.
FYI2: The mentioned extra compile flags do not help. However, I guess this was BluePill-specific.

Best Regards,
Marco

Title: Re: Crazy program size
Post by Simon Hopkinson on Sep 3rd, 2020 at 5:06pm
Could you attach the build log from Visual Micro, with the options shown at the top of the forum set for Verbose / Show Build Properties?

I have compiled the sketch in Release mode, with the vMicro > Debugger > Debug set to OFF, and it is 2829 bytes....

Title: Re: Crazy program size
Post by marcoStraubel on Sep 3rd, 2020 at 9:21pm
OK... you got me.

It wasn't the obvious "Debug-Off" option that was enabled but the option "Automatic Software Debugging (Release/Debug)"

After unchecking this option I'm back to 2787bytes for RTC file. ... Exactly the same as in the Arduino IDE.

Problem solved. Thanks

Title: Re: Crazy program size
Post by Visual Micro on Sep 3rd, 2020 at 9:52pm
Good to hear it is working.

More Info

When Automatic Debugging is enabled it is possible to switch the "Configuration Name" on the tool bar between "Release" and "Debug", that automatically enables or disables usb debugging (unless you have specifically set the type of Debugger to Off or other value)

The resulting program size for usb debug depends in part on which commands the debugger uses relative to the commands your code also uses. For example, if your code does not use Serial then enabling the debugger on a hardware serial port would enable the Arduino Serial, which in turn allocates a buffer and consumes other resoures. GDB hardware deugging does not suffer the same penalty but often requires compiler optimization to be reduced, causing similar overhead.

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.