PlatformIO Community

Could not initialize project! please help!

hi I’m a bit new to platformio and I’m trying to start a project for a stm32f031k6 nucleo and I’m trying to use mbed framework. every time i click finish to start my project i get this error:

PIO Core Call Error: 
The current working directory C:\Users\sean\Documents\PlatformIO\Projects\mbed test will be used for the project.

The next files/directories have been created in C:\Users\sean\Documents\PlatformIO\Projects\mbed test
include - Put project header files here
lib - Put here project specific (private) libraries
src - Put project source files here
platformio.ini - Project Configuration File


Error: Processing nucleo_f031k6 (platform: ststm32; board: nucleo_f031k6; framework: mbed)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f031k6.html
PLATFORM: ST STM32 (14.2.0) > ST Nucleo F031K6
HARDWARE: STM32F031K6T6 48MHz, 4KB RAM, 32KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES: 
 - framework-mbed 6.51506.201227 (5.15.6) 
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
ModuleNotFoundError: No module named 'tools.build_api':
 File "C:\Users\sean\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 177:
 env.SConscript("$BUILD_SCRIPT")
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Script\SConscript.py", line 591:
 return _SConscript(self.fs, *files, **subst_kw)
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Script\SConscript.py", line 280:
 exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
 File "C:\Users\sean\.platformio\platforms\ststm32\builder\main.py", line 121:
 target_elf = env.BuildProgram()
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Util.py", line 658:
 return self.method(*nargs, **kwargs)
 File "C:\Users\sean\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 61:
 env.ProcessProgramDeps()
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Util.py", line 658:
 return self.method(*nargs, **kwargs)
 File "C:\Users\sean\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 127:
 env.BuildFrameworks(env.get("PIOFRAMEWORK"))
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Util.py", line 658:
 return self.method(*nargs, **kwargs)
 File "C:\Users\sean\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 342:
 SConscript(env.GetFrameworkScript(f), exports="env")
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Script\SConscript.py", line 654:
 return method(*args, **kw)
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Script\SConscript.py", line 591:
 return _SConscript(self.fs, *files, **subst_kw)
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Script\SConscript.py", line 280:
 exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
 File "C:\Users\sean\.platformio\platforms\ststm32\builder\frameworks\mbed.py", line 37:
 "platformio-build.py"))
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Script\SConscript.py", line 654:
 return method(*args, **kw)
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Script\SConscript.py", line 591:
 return _SConscript(self.fs, *files, **subst_kw)
 File "C:\Users\sean\.platformio\packages\tool-scons\scons-local-4.1.0\SCons\Script\SConscript.py", line 280:
 exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
 File "C:\Users\sean\.platformio\packages\framework-mbed\platformio\platformio-build.py", line 45:
 from pio_mbed_adapter import PlatformioMbedAdapter
 File "C:\Users\sean\.platformio\packages\framework-mbed\platformio\pio_mbed_adapter.py", line 23:
 from tools.build_api import prepare_toolchain, UPDATE_WHITELIST
========================== [FAILED] Took 0.70 seconds ==========================

it works fine with arduino framework but wont work with mbed.
if i change the default location it starts the project but it doesn’t change to mbed framework and i still have the #include <arduino.h>.
if i change it to #include “mbed.h” then it tells me it cant locate the files to include.

any help will be amazing.
thank you very much

ps just warning everyone i am still a bit new to platformio.
thanks

Hm I can’t reproduce that error.

>pio run
Processing nucleo_f031k6 (platform: ststm32; board: nucleo_f031k6; framework: mbed)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f031k6.html
PLATFORM: ST STM32 (14.2.0) > ST Nucleo F031K6
HARDWARE: STM32F031K6T6 48MHz, 4KB RAM, 32KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES:
 - framework-mbed 6.51506.201227 (5.15.6)
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
Collecting mbed sources...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 4 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\nucleo_f031k6\FrameworkMbed\drivers\source\AnalogIn.o
...

You can try creating and compiling the project manually on the CLI:

cd .. 
mkdir mbed_nucleo_f031k6
cd mbed_nucleo_f031k6
pio init -b nucleo_f031k6 -O "framework = mbed"
explorer .

then add some minimal src/main.cpp code

#include <mbed.h>

int main() { return 0; }

and the mbed_app.json from the mbed-rtos-blink-baremetal project and run pio run in the CLI.

But, even it starts compiling, at the end it should fail at

Linking .pio\build\nucleo_f031k6\firmware.elf
[..].pio/build/nucleo_f031k6/STM32F031X6.ld.link_script.ld:82 cannot move location counter backwards (from 0000000020000368 to 0000000020000000)
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nucleo_f031k6\firmware.elf] Error 1

and that’s an error message that there’s not enough RAM to compile the firmware. With a firmware that does literally nothing. That Nucleo’s chip has only 32kByte of flash and 4Kbyte of RAM, this does not fit in the used mbed-os 5 version at all. Mbed-os is very memory intensive for both flash + RAM to the point where a bluepill (64KB flash, 20kByte RAM) can’t run the current mbed-os 6 version.

I’ve also tried different mbed-os versions (https://api.registry.platformio.org/v3/packages/platformio/tool/framework-mbed + platform_pacakges) and I cannot get it to compile without a RAM overflow.

The mbed-os online compiler can compile for the board, becaue it uses a truly ancient mbed-os 2 version (revision 172:65be27845400) from 2012.

grafik

grafik

PlatformIO however can’t compile for an mbed-os version that ancient.

I can only recommend to use Arduino (more up-to-date) or mbed-os 2 with either the online compiler or a local install (mbed-cli and friends).

Or, get a different F0 board that has a large-enough chip to support mbed-os.

Per https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json the current F0 supported targets for mbed-os 6 are:

  • NUCLEO_F070RB
  • NUCLEO_F072RB
  • NUCLEO_F091RC

See https://github.com/ARMmbed/mbed-os/pull/12960 on why that is.

For the mbed-os 5 line (5.15.7) there’s more targets available

  • NUCLEO_F030R8
  • NUCLEO_F031K6 (but doesn’t compile as can be seen)
  • NUCLEO_F042K6

I’ve opened https://github.com/ARMmbed/mbed-os/issues/15064 btw for the mbed-os 5 not compiling issue, but I doubt they can do anything about this.

thank you so much!! I’ll give it a try as soon as i can.
:smile: