Open-CMSIS-Pack / devtools

Open-CMSIS-Pack development tools - C++
Apache License 2.0
70 stars 52 forks source link

[csolution] Add separate 'define' and 'add-path' for assembler files (`define-asm`, `add-path-asm`) #607

Closed tcsunhao closed 5 days ago

tcsunhao commented 1 year ago

Macro defines under 'define' is populated into all sub compilers. For example, if we have following 'setup'

  setups:
    - setup: AC6
      for-compiler: AC6
      for-type: .debug
      defines:
      - DEBUG
      - CPU_MK64FN1M0VLL12
      - PRINTF_FLOAT_ENABLE=0
      - SCANF_FLOAT_ENABLE=0
      - PRINTF_ADVANCED_ENABLE=0
      - SCANF_ADVANCED_ENABLE=0
      - FRDM_K64F
      - FREEDOM
      - MCUXPRESSO_SDK

If we build with -v, we can get this

[2/21] C:\Keil_v5\ARM\ARMCLANG\bin\armclang.exe  -ID:/ocpa1/unzipped_packs/FRDM-K64F_BSP/demo_apps/hello_world/RTE/mdk/_hello_world.debug_mdk -IC:/opencmsispackroot/ARM/CMSIS/5.8.0/CMSIS/Core/Include -IC:/opencmsispackroot/NXP/MK64F12_DFP/14.0.0 -IC:/opencmsispackroot/NXP/MK64F12_DFP/14.0.0/components/lists -IC:/opencmsispackroot/NXP/MK64F12_DFP/14.0.0/components/uart -IC:/opencmsispackroot/NXP/MK64F12_DFP/14.0.0/drivers -IC:/opencmsispackroot/NXP/MK64F12_DFP/14.0.0/utilities/debug_console_lite -ID:/ocpa1/unzipped_packs/FRDM-K64F_BSP/demo_apps/hello_world -mcpu=Cortex-M4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mlittle-endian -DCPU_MK64FN1M0VLL12 -D_RTE_ -DDEBUG -DPRINTF_FLOAT_ENABLE=0 -DSCANF_FLOAT_ENABLE=0 -DPRINTF_ADVANCED_ENABLE=0 -DSCANF_ADVANCED_ENABLE=0 -DFRDM_K64F -DFREEDOM -DMCUXPRESSO_SDK  --target=arm-arm-none-eabi -c -c -o CMakeFiles/hello_world.debug+mdk.dir/D_/ocpa1/unzipped_packs/FRDM-K64F_BSP/demo_apps/hello_world/RTE/mdk/Device/MK64FN1M0VLL12/startup_MK64F12.o D:/ocpa1/unzipped_packs/FRDM-K64F_BSP/demo_apps/hello_world/RTE/mdk/Device/MK64FN1M0VLL12/startup_MK64F12.S

You can see that all 'defines' are populated into assemble startup_MK64F12.S which is obviously unnecessary and wrong.

One way to avoid this is to use MiscType because MiscType has sub compiler categories like asm/c/cpp. It is mentioned in https://github.com/Open-CMSIS-Pack/devtools/issues/276. However, sine all toolchains: MDK/IAR/Eclipse based all support such asm/c/cpp sub compiler categories, then we can regard that asm/c/cpp specific defines are commonly and widely used in embedded world. At least for assemble and c, they usually don't share macro defines which means we have to move all macro defines into MiscType, and it makes the common 'define' useless. And to define macros inside MiscType is unconvenient and indirect.

The same issue applis for include path.

Suggestion: support asm/c/cpp specific defines and macros like asm-define c-define cpp-define asm-include c-include cpp-include

ReinhardKeil commented 1 year ago

It looks like assembler files are somewhat the issue. What about this proposal:

define: only applies to C and C++ source files define-asm: only applies to assembly source files (new)

add-path: only applies to C and C++ source files add-path-asm: only applies to assembly source files (new)

As background: the startup assembler files should get replaced over time with C source files, like it is the case already with CMSIS v5.9. See here:

tcsunhao commented 1 year ago

Thank you @ReinhardKeil . Your proposal can meet our needs.

jkrech commented 1 year ago

define and add-path scope limited to C / CPP for CMSIS Toolbox 2.0 Specification

brondani commented 1 year ago

In particular the add-path scope limitation breaks the build of libraries where include paths are needed by assembly files, for example in RTX: https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/RTOS2/RTX/Source/GCC/irq_armv7m.S#L29

#include "rtx_def.h"

For this reason we are postponing the resolution of this issue.

jkrech commented 8 months ago

Given the above example we need to make use of the new file attribute language in the component description to add an include path specifically for assembler files e.g.:

  <file category="include" language="asm" name="CMSIS/RTOS2/RTX/Include" />
jkrech commented 2 months ago

define-asm is supported in CMSIS-Toolbox 2.4.0 and should be documented below define

add-path-asm is targeted for #118 for CMSIS-Toolbox 2.5.0. This feature needs to documented below add-path

Is it agreed that we don't require del-path-asm and undefine-asm?

jkrech commented 1 month ago

Documentation: add-path-asm below add-path

ReinhardKeil commented 5 days ago

This is completed