[ISSUE] Flash device failed: Compiler encountered an error

Hi,
I’ve struggeled for a while with my code.
I’m working on a windows laptop using visual studio code.
Whenever I try flashing a simple program, like a script that prints hi with 1000ms delay, VSCode works.
But if I try to flash more complicated projects, with several .h files, .cpp files, and an ino file, the vscode fails, and it spits out this error:

make[1]: Leaving directory '/firmware/modules/argon/user-part'
make[1]: *** [target/workspace.elf] Error 1
../build/recurse.mk:11: recipe for target 'modules/argon/user-part' failed
make: *** [modules/argon/user-part] Error 2
Flash device failed: Compiler encountered an error

	at makeError (C:\Users\Uzair\.vscode\extensions\particle.particle-vscode-core-1.4.6\node_modules\execa\index.js:174:9)
	at module.exports.Promise.all.then.arr (C:\Users\Uzair\.vscode\extensions\particle.particle-vscode-core-1.4.6\node_modules\execa\index.js:278:16)

- - - -

Anyone here who could help me?
My launch.json file looks like this:

{
    "version": "0.1.0",
    "configurations": [
        {
            "type": "cortex-debug",
            "request": "attach",
            "name": "Particle Debugger (photon, p1, electron)",
            "servertype": "openocd",
            "interface": "swd",
            "device": "STM32F205RG",
            "cwd": "${workspaceRoot}",
            "executable": "${command:particle.getDebuggerExecutable}",
            "preLaunchTask": "Particle: Flash application for debug (local)",
            "armToolchainPath": "${command:particle.getDebuggerCompilerDir}",
            "svdFile": "${command:particle.getDebuggerSVDFile}",
            "searchDir": [
                "${command:particle.getDebuggerSearchDir}"
            ],
            "configFiles": [
                "interface/cmsis-dap.cfg",
                "target/stm32f2x.cfg"
            ],
            "postAttachCommands": [
                "monitor reset halt"
            ],
            "windows": {
                "configFiles": [
                    "interface\\cmsis-dap.cfg",
                    "target\\stm32f2x.cfg"
                ]
            }
        },
        {
            "type": "cortex-debug",
            "request": "attach",
            "name": "Particle Debugger (argon, boron / bsom, xenon)",
            "servertype": "openocd",
            "interface": "swd",
            "device": "nRF52840_xxAA",
            "cwd": "${workspaceRoot}",
            "executable": "${command:particle.getDebuggerExecutable}",
            "preLaunchTask": "Particle: Flash application for debug (local)",
            "armToolchainPath": "${command:particle.getDebuggerCompilerDir}",
            "svdFile": "${command:particle.getDebuggerSVDFile}",
            "searchDir": [
                "${command:particle.getDebuggerSearchDir}"
            ],
            "configFiles": [
                "interface/cmsis-dap.cfg",
                "target/nrf52-particle.cfg"
            ],
            "windows": {
                "configFiles": [
                    "interface\\cmsis-dap.cfg",
                    "target\\nrf52-particle.cfg"
                ]
            }
        },
        {
            "type": "cortex-debug",
            "request": "attach",
            "name": "Particle Programmer Shield v1.0 (photon, p1, electron)",
            "servertype": "openocd",
            "interface": "swd",
            "device": "STM32F205RG",
            "cwd": "${workspaceRoot}",
            "executable": "${command:particle.getDebuggerExecutable}",
            "preLaunchTask": "Particle: Flash application for debug (local)",
            "armToolchainPath": "${command:particle.getDebuggerCompilerDir}",
            "svdFile": "${command:particle.getDebuggerSVDFile}",
            "searchDir": [
                "${command:particle.getDebuggerSearchDir}"
            ],
            "configFiles": [
                "interface/particle-ftdi.cfg",
                "target/stm32f2x.cfg"
            ],
            "postAttachCommands": [
                "monitor reset halt"
            ],
            "windows": {
                "configFiles": [
                    "interface\\particle-ftdi.cfg",
                    "target\\stm32f2x.cfg"
                ]
            }
        }
    ]
}

And this is my settings.json file:

{
    "extensions.ignoreRecommendations": true,
    "C_Cpp.default.configurationProvider": "particle.particle-vscode-core",
    "files.associations": {
        "*.ino": "cpp"
    },
    "particle.firmwareVersion": "1.1.0",
    "cortex-debug.openocdPath": "C:\\Users\\Uzair\\.particle\\toolchains\\openocd\\0.10.0-particle.1\\bin\\openocd.exe",
    "particle.targetPlatform": "argon",
    "particle.targetDevice": "e00fce68e5dc15d28594f686"
}

Have you setup your project via image ?

How does your file structure look?

Yes. Originally I just imported a project from bitbucket and modified it. But I struggled really long with compiling it, and instead chose to create a new particle project, and then add the src and lib folders.
So the current file structure looks like the orginal project from: https://bitbucket.org/circuitdojo/particle-squared-code/src/master/
but the vscode code folder is brand new, not copied from the cloned project.

Try removing the examples folder from the library.
You can also switch on the verbose build output to get some more elaborate output that may provide more clues.
image

I’m getting the same, error, I’d like to not remove the examples form the libraries, I think that would be a poor workaround. Has anyone else found a solution?

hi @Nicholas

can you share a minimal example .ino + project.properties that reproduces the error by chance? if not, can you confirm that removing the example files actually fixes the issue and share the name of library you are using?

thanks :pray:

I figured out the errors, I needed to update the workbench from beta to production and use the correct firmware selection to make sure the compiler was using the proper libraries. I forced the libraries to load by reloading them manually. I had to add include "Application.h" when not using the ino file. I’m writing the code in a c++ file so that I can also use it with another development platform. The Photon also required that I force an update using the CLI tool to the same firmware I was using when flashing the device locally, didn’t update on its own. Overall it’s not intuitive how to setup the workbench with using many libraries and many of error or warnings go away when you just clean the project. Like most IDE’s this setup shows some meaningless warnings sometimes.

@Nicholas I’m not sure about you, but I never had to use the workarounds that you used. There’s a high probability that it might just be something that was wrong in my code. I did a clean up round in my code, removed many unnecessary lines, removed libraries that I used and voila, problem solved.

Also, I got to apologize for not answering on the thread. Work got hectic and I had to pause the project for a while. But we’re back.

1 Like