Skip to content

Build_opt.h only used when compiled with LTO #2698

Closed

Description

@bbc25185

Describe the bug
After testing, I noticed that the Build_opt.h file is used only if, as a compilation optimization, one with LTO is chosen.

To Reproduce
The Build_opt.h file contains the following code:
-DSERIAL_RX_BUFFER_SIZE=512 -DSERIAL_TX_BUFFER_SIZE=512
-DMAVLINK_COMM_NUM_BUFFERS=4
-DPIN_SERIAL1_RX=PB7 -DPIN_SERIAL1_TX=PB6
-DENABLE_HWSERIAL1
-DPIN_SERIAL2_RX=PA3 -DPIN_SERIAL2_TX=PA2
-DENABLE_HWSERIAL2
-DPIN_SERIAL3_RX=PB9 -DPIN_SERIAL3_TX=PB8
-DENABLE_HWSERIAL3
-DPIN_SERIAL4_RX=PA1 -DPIN_SERIAL4_TX=PA0
-DENABLE_HWSERIAL4

Steps to reproduce the behavior:
Selected Board: STM32G0 Series
Board Part Number: Generic G070KBTx
Usart Support: Enabled (No generic Serial)
Compiled with Optimize - Smallest: No error and Ram usage dont change with Buffer size change
Compiled with Optimize - Smallest with LTO: Various error reporting "note: 'SerialX' was previously declared here" and Buffer Size changing with Buffer Size setting.

Expected behavior
The file Build_opt.h always working

Desktop (please complete the following information):

  • Windows11
  • Arduino IDE version: 2.3.4
  • STM32 core version: 2.10.1
  • Tools menu settings if not the default: Usart Support: Enabled (no generic Serial)
  • Upload method: SWD

Board (please complete the following information):

  • Name: STM32G0 Series
  • Hardware Revision: Generic G070KBTx

Additional context
To solve the problem, I normally compiled with LTO but due to errors that appeared when I started implementing FreeRtos.
Without LTO the options in the Build_opt.h file are not applied for my project.

Activity

  1. fpistm commented on Mar 25, 2025

    @fpistm
    Member

    Hi @bbc25185
    Here my result:

    Default config::

    Sketch uses 19996 bytes (15%) of program storage space. Maximum is 131072 bytes.
    Global variables use 1432 bytes (3%) of dynamic memory, leaving 35432 bytes for local variables. Maximum is 36864 bytes.

    With your build_opt.h:

    Sketch uses 20304 bytes (15%) of program storage space. Maximum is 131072 bytes.
    Global variables use 6084 bytes (16%) of dynamic memory, leaving 30780 bytes for local variables. Maximum is 36864 bytes.
    

    Warning message:

    warning: "ENABLE_HWSERIAL4" redefined
       84 |       #define ENABLE_HWSERIAL4
          |               ^~~~~~~~~~~~~~~~
    

    That is normal as the default Serial for the GenericG070KBTx is the Serial4. So as you define it again in the build_opt.h....
    Maybe you got an Arduino cache issue but there is no issue with build_opt.h.

  2. locked and limited conversation to collaborators on Mar 25, 2025
  3. converted this issue into a discussion #2699 on Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions