jbaumann / pio_and_stm32cubeide

Use PlatformIO with Projects generated by STM32CubeIDE
Apache License 2.0
27 stars 10 forks source link

AttributeError: 'NoneType' object has no attribute 'get' #5

Closed EnziinSystem closed 1 year ago

EnziinSystem commented 2 years ago

Hello,

I create a simple project to test convert from STM32CubeIDE to PlatformIO.

Step 1: I use STM32CubeIDE to create a new project with "Add necessary files as a reference in the toolchain project configuration file" and I set up basic I/O, clock, generate code...

Step 2: In an other directory (empty), I create a new PlatformIO project

pio project init --board GenericSTM32F412ZGTx --project-option "framework=stm32cube"

Step 3: Copy all files from the STM32Cube project to the PlatformIO project in step 2 (includes hidden files).

Edit platformio.ini

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = stm32
; src_dir = ./
include_dir = Core/Inc

[env:stm32]
platform = ststm32
board = GenericSTM32F412ZGTx
framework = stm32cube
; This is the actual script that forces platformio into compiling the
; STM32CubeIDE project.
extra_scripts = pre:setup_cubemx_env_auto.py
; Set to the same toolchain as STM32CubeIDE
; For the mapping see
; https://api.registry.platformio.org/v3/packages/platformio/tool/toolchain-gccarmnoneeabi
platform_packages = toolchain-gccarmnoneeabi@1.90301.200702
; The name of the library directory in which the linked resources will
; be placed.
lib_deps = STLinkedResources
build_flags =
;   -Icommon/include/
  -std=gnu++17
  -fno-exceptions
  -Wall
;   -Werror
  -Wconversion
  -Wno-sign-conversion
  -Wno-sign-compare
build_unflags =
  -std=gnu++11
  -std=gnu++14
  -fpermissive

Step 5: Run build Platformio

~/Desktop/Working/PlatformIO/stm32/Motor$ pio run
Processing stm32 (platform: ststm32; board: GenericSTM32F412ZGTx; framework: stm32cube)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
SETUP_CUBEMX: Using the following source directories: 'Core, Drivers, Core/Startup'
SETUP_CUBEMX: Adding the following build flags: '-mthumb, -mcpu=cortex-m4, -mfpu=fpv4-sp-d16, -mfloat-abi=hard'
AttributeError: 'NoneType' object has no attribute 'get':
  File "/home/kevin/.platformio/penv/lib/python3.8/site-packages/platformio/builder/main.py", line 179:
    env.SConscript(item, exports="env")
  File "/home/kevin/.platformio/packages/tool-scons/scons-local-4.3.0/SCons/Script/SConscript.py", line 597:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/kevin/.platformio/packages/tool-scons/scons-local-4.3.0/SCons/Script/SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/kevin/Desktop/Working/PlatformIO/stm32/Motor/setup_cubemx_env_auto.py", line 232:
    ld_script_entry = tool_chain.find(
========================================================================== [FAILED] Took 0.36 seconds ==========================================================================

Please see image attchmented pioe

And zip file project.

Motor.zip

Thanks.

jbaumann commented 2 years ago

The script tries to identify a linker script provided by STM32CubeIDE. For C++ projects this is no longer stored in the GCC linker configuration (if it ever was). I have changed the code so that the script first looks at the GCC linker configuration and if this isn't successful tries the G++ linker configuration. Could you please test whether the new version of the script works for you?