platformio / platformio/platformio-core

extra_script global defines not working

Open
#5,146 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted LDF
Dominant language
Python
Stars
9.5k
Forks
905
Avg merge
2d 13h
Merged PRs (30d)
2

Description

I am trying to add a global define to a project build extrascript like this:

global_env = DefaultEnvironment()
global_env.Append(CPPDEFINES=[("USBCON", 1),("HAL_PCD_MODULE_ENABLED",1),'USBCON'])
global_env.Append(CCFLAGS=["-D USBCON"])
print("<<<<<GLOBAL ENV DEFINES>>>>>")
print(global_env.get('CPPDEFINES'))
print("<<<<<GLOBAL ENV FLAGS>>>>>")
print(global_env.get('CCFLAGS'))

as per the example here: https://docs.platformio.org/en/latest/manifests/library-json/fields/build/extrascript.html

But defines and flags are not added, if i verbose build they are present in the log, but not present in the build command, build output:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F401CD.html
PLATFORM: ST STM32 (19.1.0) > STM32F401CD (96k RAM. 384k Flash)
HARDWARE: STM32F401CDU6 84MHz, 96KB RAM, 384KB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.21001.0 (2.10.1)
 - framework-cmsis @ 2.50900.0 (5.9.0)
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
<<<<<GLOBAL ENV DEFINES>>>>>
deque([('PLATFORMIO', 60118), 'STM32F4', 'STM32F401xE', 'STM32F4xx', ('USBD_VID', '0x05f3'), ('USBD_PID', '0x00D2'), ('USB_MANUFACTURER_STRING', 'STR(RailDriver)'), ('USB_PRODUCT_STRING', 'STR(RailDriver)'), 'STM32F4xx', ('ARDUINO', 10808), 'ARDUINO_ARCH_STM32', 'NDEBUG', 'ARDUINO_GENERIC_F401CDUX', ('BOARD_NAME', '\\"GENERIC_F401CDUX\\"'), 'HAL_UART_MODULE_ENABLED', 'USE_HAL_DRIVER', 'USE_FULL_LL_DRIVER', ('VARIANT_H', '\\"variant_generic.h\\"'), ('VECT_TAB_OFFSET', '0x0'), ('USBCON', 1), ('HAL_PCD_MODULE_ENABLED', 1), 'USBCON'])
<<<<<GLOBAL ENV FLAGS>>>>>
-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Os -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -D USBCON
Found 15 compatible libraries
Scanning dependencies...
Dependency Graph
|-- USBLibrarySTM32 @ 0.3.0 (License: LGPL-3.0-or-later, Path: D:\Source\GitHub\USBLibrarySTM32\examples\SerialUSB\.pio\libdeps\bluepill_f401\USBLibrarySTM32)
Building in release mode
arm-none-eabi-g++ -o .pio\build\bluepill_f401\src\main.cpp.o -c -std=gnu++17 -fno-threadsafe-statics -fno-rtti -fno-exceptions -fno-use-cxa-atexit -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Os -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DPLATFORMIO=60118 -DSTM32F4 -DSTM32F401xE -DSTM32F4xx -DUSBD_VID=0x05f3 -DUSBD_PID=0x00D2 -DUSB_MANUFACTURER_STRING=STR(RailDriver) -DUSB_PRODUCT_STRING=STR(RailDriver) -DSTM32F4xx -DARDUINO=10808 -DARDUINO_ARCH_STM32 -DNDEBUG -DARDUINO_GENERIC_F401CDUX -DBOARD_NAME=\"GENERIC_F401CDUX\" -DHAL_UART_MODULE_ENABLED -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DVARIANT_H=\"variant_generic.h\" -DVECT_TAB_OFFSET=0x0 -Iinclude -Isrc -I.pio\libdeps\bluepill_f401\USBLibrarySTM32\include -I.pio\libdeps\bluepill_f401\USBLibrarySTM32\src -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\cores\arduino\avr -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\cores\arduino\stm32 -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\libraries\SrcWrapper\inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\libraries\SrcWrapper\inc\LL -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\libraries\USBDevice\inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\libraries\VirtIO\inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Drivers\STM32F4xx_HAL_Driver\Inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Drivers\STM32F4xx_HAL_Driver\Src -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\STM32F4xx -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\ST\STM32_USB_Device_Library\Core\Inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\ST\STM32_USB_Device_Library\Core\Src -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\OpenAMP -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\OpenAMP\open-amp\lib\include -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\OpenAMP\libmetal\lib\include -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\OpenAMP\virtual_driver -IC:\Users\Levi\.platformio\packages\framework-cmsis\CMSIS\Core\Include -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Drivers\CMSIS\Device\ST\STM32F4xx\Include -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\gcc -IC:\Users\Levi\.platformio\packages\framework-cmsis\CMSIS\DSP\Include -IC:\Users\Levi\.platformio\packages\framework-cmsis\CMSIS\DSP\PrivateInclude -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\cores\arduino -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\variants\STM32F4xx\F401CC(F-U-Y)_F401C(B-D-E)(U-Y) src\main.cpp
(then the build fails cause the defines are missing)

Am i missing something? I followed the example almost literally but neither the flags or the defines are showing up?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the extra_script example linked in the issue and reproduce the STM32F401CD build using the shown DefaultEnvironment, CPPDEFINES, and CCFLAGS values. Compare the printed environment with the verbose compiler command; done means the requested defines and flags appear in that command and the build no longer fails because they are missing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
build-system, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.