Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Crazy program size (Read 974 times)
yet-another-average-joe
Junior Member
**
Offline



Posts: 20
Crazy program size
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
Back to top
« Last Edit: Nov 17th, 2019 at 1:41pm by yet-another-average-joe »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10893
United Kingdom
Re: Crazy program size
Reply #1 - 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.
Back to top
 

Tim Leek
home
WWW  
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline



Posts: 20
Re: Crazy program size
Reply #2 - Nov 17th, 2019 at 1:50pm
 
Oops !

Roll Eyes


It's compiled in Release mode, as said in the OP.
Back to top
« Last Edit: Nov 17th, 2019 at 1:53pm by yet-another-average-joe »  

Please Register or Login to the Forum to see File Attachments
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10893
United Kingdom
Re: Crazy program size
Reply #3 - 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.

Back to top
« Last Edit: Nov 17th, 2019 at 1:58pm by Visual Micro »  

Tim Leek
home
WWW  
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline



Posts: 20
Re: Crazy program size
Reply #4 - 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 ?
Back to top
« Last Edit: Nov 17th, 2019 at 2:34pm by yet-another-average-joe »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10893
United Kingdom
Re: Crazy program size
Reply #5 - Nov 17th, 2019 at 2:34pm
 
if you click the reply button instead of using the quick reply box, can you attach files?
Back to top
 

Tim Leek
home
WWW  
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline



Posts: 20
Re: Crazy program size
Reply #6 - Nov 17th, 2019 at 2:41pm
 
I logged out and then logged in again, and got the Attachment button.
Back to top
 

Please Register or Login to the Forum to see File Attachments
 
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline



Posts: 20
Re: Crazy program size
Reply #7 - Nov 17th, 2019 at 2:42pm
 
And now the VisualMicro Board Options
Back to top
 

Please Register or Login to the Forum to see File Attachments
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10893
United Kingdom
Re: Crazy program size
Reply #8 - Nov 17th, 2019 at 2:45pm
 
It's a different board in the arduino ide?
Back to top
 

Tim Leek
home
WWW  
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline



Posts: 20
Re: Crazy program size
Reply #9 - 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.  Embarrassed
Back to top
 
 
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline



Posts: 20
Re: Crazy program size
Reply #10 - 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 !!!!!!!)
Back to top
 

Please Register or Login to the Forum to see File Attachments
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10893
United Kingdom
Re: Crazy program size
Reply #11 - Nov 18th, 2019 at 11:38am
 
Thanks for the info. That is useful.
Back to top
 

Tim Leek
home
WWW  
IP Logged
 
marcoStraubel
Newbies
*
Offline



Posts: 4
Re: Crazy program size
Reply #12 - Sep 3rd, 2020 at 2: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
Back to top
 
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline



Posts: 502
Re: Crazy program size
Reply #13 - Sep 3rd, 2020 at 6: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....
Back to top
 
 
IP Logged
 
marcoStraubel
Newbies
*
Offline



Posts: 4
Re: Crazy program size
Reply #14 - Sep 3rd, 2020 at 10: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
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10893
United Kingdom
Re: Crazy program size
Reply #15 - Sep 3rd, 2020 at 10: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.
Back to top
 

Tim Leek
home
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print