Set Custom Build Path

I’m trying to build project files using ARMCC compiler, which is officially not supported by PlatformIO. I have managed to replace existing GCC compiler/assembler/linker flags and compile project files. The only problem I currently face is not being able to provide a correct build path where my output ˙.ofiles would be stored and where linker would be looking at when generating.elf` file.

As you can see from the picture, files are compiled and output files are (presumably) generated in the marked folder however as you can see those folders end up empty after each build. Therefore linker is unable to find the during linking process.

I have a hunch that this path is hard-coded somewhere in internal PlatformIO files and might not be easy to overwrite it like I did for the compiler flags. Therefore I ask whether anyone has any clue how this should/could be done?


This script was modifed from the one provided by @maxgerhardt: GitHub - maxgerhardt/platformio-with-clang: Highly experimental PlatformIO + Clang (instead of GCC) test project
Here, compiler/assembler/linker flags are completely removed (and other flags that might not be compatible with ARMCC) and some flags are re-written to accommodate basic build needs.

import os

platform = env.PioPlatform()

# Use ARMCC for framework
for e in [env, projenv]:
        GDB="arm-none-eabi-gdb", # to retain compatbility
    e.Replace(CCFLAGS = [])
    e.Replace(ASFLAGS = [])
    e.Replace(LINKFLAGS = [])
    e.Replace(CPPFLAGS = [])
    e.Replace(CFLAGS = [])
    e.Replace(CXXFLAGS = [])
    e.Replace(LDFLAGS = [])
    e.Replace(LIBS = [])
    e.Replace(LIBDIR = [])
    e.Replace(LDLIBS = [])
    e.Replace(LFLAGS = [])
    e.Replace(MAKEFLAGS = [])
    e.Replace(_LIBFLAGS = [])
    e.Replace(CCFLAGS = [
        "--c99", "-c", "--cpu=Cortex-M3", "-g", "-O0", "-M", "--thumb",
        "--apcs=interwork", "--split_sections", "-DUSE_HAL_DRIVER", "-DSTM32F103xE", "-DUSER_VECT_TAB_ADDRESS",
        "-o C:\\Users\\gacnik\\Desktop\\PVC2-SES-PlatformIO\\PVC2 test\\.pio\\build\\genericSTM32F103VC\\src\\Drivers\\STM32F1xx_HAL_Driver\\Src"
    e.Replace(ASFLAGS = [
        "--cpu=Cortex-M3", "-g", "--apcs=interwork", "-M"
    e.Replace(LINKFLAGS = [
        "-o C:\\Users\\gacnik\\Desktop\\PVC2-SES-PlatformIO\\PVC2 test\\.pio\\build\\genericSTM32F103VC\\src\\Drivers\\STM32F1xx_HAL_Driver\\Src"

    # Add to path.. somehow PlatformIO does not do this although it's the toolchain package.
    pkg = platform.get_package("toolchain-armcc")
        os.path.join(pkg.path, "bin")
        if os.path.isdir(os.path.join(pkg.path, "bin"))
        else pkg.path,

# Throw out GCC completely
del platform.packages["toolchain-gccarmnoneeabi"]

My platformio.ini file look like this. I provide path to actual ARM toolchain, which is used to create toolchain-armcc package. Also, a custom linker (generated from CubeMX) and startup (copied from Keil uVision) file are used for this project.

# add compiler package
platform = ststm32
board = genericSTM32F103VC
extra_scripts =
platform_packages = toolchain-armcc@symlink://C:\Keil_v5\ARM\ARMCC\bin
board_build.ldscript = "src\STM32F103VCTx_FLASH.ld"
build_flags = 

In original ARM toolchain folder there is also a package.json file which is basically a slightly modified version of the one from toolchain-gccarmnoneeabi package.

I have determined that the path, where output .o files should be generated, is set to correct path. I checked using the pio run -t envdump command. This probably means that output files might not get generated due to compiler actually not producing .o files? However, I’m pretty sure I have all the necessary flags for the compiler to generate output files. Should the .platformio\platforms\ststm32\builder\ script be inspected or should I search for solution elsewhere?

I don’t think there should be -o flags in the flags, the build system will automatically add them for each compiled file. That’s basically the $TARGET and $SOURCE variable in the invocation.

Same for -o in the link flags.

Well, its true that without -o option nothing really changes. But as I said, it seems the problem might not be in path setting but rather the question, whether compiler actually makes .o files during compilation.

If I switch back to GCC, output files are generated in the given folder (under .pio). I think something might need to be changed (indirectly) from currently existing file which automates whole build process.