Skip to content

fix(BLE): Pass Project Optimization Flag Down to Cordio #661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

Jake-Carter
Copy link
Contributor

Pass Project Optimization Flag Down to Cordio

Description

MXC_OPTIMIZE_CFLAGS was not being passed down to the Cordio library build. Therefore, users had no easy way to change the optimization level of the library.

This PR passes down the project's optimization flags to Cordio. Users can individually set the optimization level for the library if needed.

!!This will change user's default Cordio builds from -Os to -Og!!

+# Allow user to set Cordio optimization level if needed
+CORDIO_OPTIMIZE_CFLAGS ?= ${MXC_OPTIMIZE_CFLAGS}
+
 # Add rule to build the Driver Library
 ${CORDIO_BUILD_DIR}/${CORDIO_LIB}: ${CORDIO_C_FILES} ${PROJECTMK}
        $(MAKE) -f ${CORDIO_DIR}/platform/targets/maxim/build/libCordio.mk lib MAXIM_PATH=${MAXIM_PATH} PROJECT=${CORDIO_LIB} \
        CORDIO_LIB_VAR=${CORDIO_LIB_VAR} BUILD_DIR=${CORDIO_BUILD_DIR} MFLOAT_ABI=$(MFLOAT_ABI) \
        DUAL_CORE=$(DUAL_CORE) RISCV_CORE=$(RISCV_CORE) TRACE=${TRACE} DEBUG=${DEBUG} RTOS=${RTOS} \
-       CFG_DEV="${CFG_DEV}" PROJECTMK=${PROJECTMK} BOARD=${BOARD}
+       CFG_DEV="${CFG_DEV}" PROJECTMK=${PROJECTMK} BOARD=${BOARD} MXC_OPTIMIZE_CFLAGS=${CORDIO_OPTIMIZE_CFLAGS}

I have 2 main concerns over this:

  1. When end users re-build Cordio the debug behavior is consistent, but the optimization level for the library has changed. Therefore, the library is objectively different.
  2. Developers building from source need to be aware of this change.

Alternative Implementation

Alternatively, the following implementation preserves -Os as the default at the following tradeoffs:

  1. When users re-build the library from source, debug behavior could be inconsistent
  2. Developers and users must manage another variable unique to the Cordio library.
  3. Mismatch between project optimization and Cordio optimization
  4. Projects build with DEBUG=1 by default. This will add debug flags (-g -ggdb -DDEBUG to Cordio resulting in a 13KB library size increase, but debug behavior could still remain inconsistent with -Os. This is debatably a larger issue that may need to be addressed separately.
+# Allow user to set Cordio optimization level if needed
+CORDIO_OPTIMIZE_CFLAGS ?= -Os
+
 # Add rule to build the Driver Library
 ${CORDIO_BUILD_DIR}/${CORDIO_LIB}: ${CORDIO_C_FILES} ${PROJECTMK}
        $(MAKE) -f ${CORDIO_DIR}/platform/targets/maxim/build/libCordio.mk lib MAXIM_PATH=${MAXIM_PATH} PROJECT=${CORDIO_LIB} \
        CORDIO_LIB_VAR=${CORDIO_LIB_VAR} BUILD_DIR=${CORDIO_BUILD_DIR} MFLOAT_ABI=$(MFLOAT_ABI) \
        DUAL_CORE=$(DUAL_CORE) RISCV_CORE=$(RISCV_CORE) TRACE=${TRACE} DEBUG=${DEBUG} RTOS=${RTOS} \
-       CFG_DEV="${CFG_DEV}" PROJECTMK=${PROJECTMK} BOARD=${BOARD}
+       CFG_DEV="${CFG_DEV}" PROJECTMK=${PROJECTMK} BOARD=${BOARD} MXC_OPTIMIZE_CFLAGS=${CORDIO_OPTIMIZE_CFLAGS}

Copy link
Contributor

@lorne-maxim lorne-maxim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the first implementation outlined in this PR's description.

@github-actions github-actions bot removed the BLE Related to Bluetooth label Aug 4, 2023
@Jake-Carter Jake-Carter merged commit ef8abb2 into analogdevicesinc:main Aug 4, 2023
@Jake-Carter Jake-Carter deleted the fix/cordio_optimize branch August 4, 2023 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants