stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.81k stars 967 forks source link

LTO does not seem to work on 1.8.0, at least, with "generic" STM32F1xx boards. #1052

Closed sallevan closed 4 years ago

sallevan commented 4 years ago

Objective Link-time optimisation, or LTO for short, is the crucial feature for embedded programming. Specifically, even simple Fourier transform using CMSIS_DSP libraries can easily overflow flash ROM for STM32F1xx line of microcontrollers.

To Reproduce The easiest way to test if LTO works or not is to use empty sketch (without any libraries included and with empty setup() and loop() functions), thanks to USB subsystem already exists in Arduino core for STM32.

Steps to reproduce the behavior:

  1. Set up Arduino IDE for STM32 Core;
  2. Select Generic STM32F1 series
  3. Select your board variant (mine is Blue Pill STM32F103C8)
  4. Set up USB support -- f.e, select USB CDC ("generic" Serial, supersede U(S)ART)
  5. Select compiler optimisation settings without LTO, f.e, -O1
  6. Compile and load compiled empty sketch via ST-Link while keeping your board attached via USB -- you will see "ST Microelectronics Virtual COM Port" in Device Manager.
  7. Switch LTO on, f.e, by selecting -O1 with LTO
  8. Repeat step 6.

Expected behavior You clearly should see "ST Microelectronics Virtual COM Port" in Device Manager again -- but you won't. After Windows USB subsystem times out, you will see Windows message "USB device not recognised".

Desktop:

Board:

Additional context

I have tried to modify boards.txt file adding -fuse-linker-plugin to GCC command line next to -flto, but it doesn't help.

stas2z commented 4 years ago

-flto is almost broken in the arm gcc for a long time, its not core related

fpistm commented 4 years ago

@stas2z is right. LTO option is available but if you get error then simply do not use it. It seems in your case issue is related to the arduino cache but could not help on this too.