PlatformIO Community

Problem compiling for STM32F030C8T6

Dear all,

I have a problem with a program that I downloaded from internet. It refuses to compile for the board it was designed for. So it probably worked in the past. Now it is not working anymore. From the research I have done it is probably because of the board.json file.

Hereby the error I am getting.

> Executing task in folder 0 Origineel firmware: pio run <

Warning! `env_default` configuration option in section [platformio] is deprecated and will be removed in the next release! Please use `default_envs` instead
Processing BIGTREE_S42B_V1_0 (platform: ststm32; framework: stm32cube; board: STM32F030C8)
-------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/STM32F030C8.html
PLATFORM: ST STM32 (11.0.0) > STM32F030C8 (8k RAM. 64k Flash)
HARDWARE: STM32F030C8T6 48MHz, 8KB RAM, 64KB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-stm32cubef0 1.11.1 
 - tool-ldscripts-ststm32 0.1.0 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
AssertionError: Missing MCU or Product Line field:
  File "/home/frank/.platformio/penv/lib/python3.6/site-packages/platformio/builder/main.py", line 170:
    env.SConscript("$BUILD_SCRIPT")
  File "/home/frank/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/frank/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/frank/.platformio/platforms/ststm32/builder/main.py", line 99:
    target_elf = env.BuildProgram()
  File "/home/frank/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Environment.py", line 219:
    return self.method(*nargs, **kwargs)
  File "/home/frank/.platformio/penv/lib/python3.6/site-packages/platformio/builder/tools/platformio.py", line 61:
    env.ProcessProgramDeps()
  File "/home/frank/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Environment.py", line 219:
    return self.method(*nargs, **kwargs)
  File "/home/frank/.platformio/penv/lib/python3.6/site-packages/platformio/builder/tools/platformio.py", line 127:
    env.BuildFrameworks(env.get("PIOFRAMEWORK"))
  File "/home/frank/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Environment.py", line 219:
    return self.method(*nargs, **kwargs)
  File "/home/frank/.platformio/penv/lib/python3.6/site-packages/platformio/builder/tools/platformio.py", line 342:
    SConscript(env.GetFrameworkScript(f), exports="env")
  File "/home/frank/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/home/frank/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/frank/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/frank/.platformio/platforms/ststm32/builder/frameworks/stm32cube.py", line 43:
    assert PRODUCT_LINE, "Missing MCU or Product Line field"
==================================================== [FAILED] Took 0.44 seconds ====================================================
The terminal process "pio 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

The STM32F030C8.json file looks like this

{
  "build": {
    "core": "stm32",
    "cpu": "cortex-m0",
    "extra_flags": "-DSTM32F030x8",
    "f_cpu": "48000000L",
    "hwids": [
      [
        "0x1EAF",
        "0x0003"
      ],
      [
        "0x1EAF",
        "0x0004"
      ]
    ],
    "ldscript": "STM32F030C8_FLASH.ld",
    "mcu": "stm32f030c8t6",
    "variant": "stm32f0"
  },
  "debug": {
    "jlink_device": "STM32F030c8t6",
    "openocd_target": "stm32f0x",
    "svd_path": "STM32F030xx.svd"
  },
  "frameworks": [
    "arduino",
    "libopencm3",
    "stm32cube",
    "cmsis"
  ],
  "name": "STM32F030C8 (8k RAM. 64k Flash)",
  "upload": {
    "disable_flushing": false,
    "maximum_ram_size": 8192,
    "maximum_size": 65536,
    "protocol": "stlink",
    "protocols": [
	  "cmsis-dap",
      "jlink",
      "stlink",
      "blackmagic",
      "serial",
      "dfu"
    ],
    "require_upload_port": true,
    "use_1200bps_touch": false,
    "wait_for_upload_port": false
  },
  "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f0-series/stm32f030/stm32f030c8.html",
  "vendor": "Generic"
}

Any help would be greatly appreciated!

Edit:
I tried one last thing. I placed this into the platformio.ini file

platform      = ststm32
framework     = stm32cube
board           = disco_f030r8
upload_protocol = stlink

I don’t think this is the right board though. Now I am getting the fallowing error.

Error: timed out while waiting for target halted
embedded:startup.tcl:521: Error: Unable to reset target

I spend another entire morning at this problem. I have made some progress!
Selecting the board = disco_f030r8 solves my earlier weird compile errors. The disco_f030r8 is however not the correct microprocessor. I am running a STM32F030C8t6. The disco_f030r8 is a STM32F030R8T6. Looking at the datasheet the microsprocessors are very similar. I am a beginner in this area but the only difference I can find is the number of IO pins. In other words, I think it should be fine.

The one problem I am having is that PlatformIO cannot upload the firmware. I keep getting this error.
Error: timed out while waiting for target halted
embedded:startup.tcl:521: Error: Unable to reset target

So I tried stm32cubeprog. This program can upload/download the firmware. So everything is working. Sort of. It would be nice if platformIO can upload the firmware. Perhaps some build flag needs to be added? I cannot access the reset pin on the board. That could be the problem.

Already discussed in Compilation failure using platform-ststm32 10.0.0. The JSON is wrong for the latest-greatest STM32 platform version.

Since your chip is STM32F030C8T6 and considering the available startup files in C:\Users\<user>\.platformio\packages\framework-stm32cubef0\Drivers\CMSIS\Device\ST\STM32F0xx\Source\Templates\gcc, one can conclude that you need the startup_stm32f030x8.s file and thus you must add

"product_line": "STM32F030X8",

e.g. as an attribute below the e.g. mcu field.

Is the NRST of the STLink connected to the target chip? Seems like a problem with either the reset line connection, or how openOCD is instructed to do the reset. With STM32CubeProg, does it work with software reset, hardware reset or core reset?

Thanks for your reply maxgerhardt. Very much appreciated!
The NRST of the STLink is not connected to the target chip. This is not possible without soldering. STM32CubeProg is using software reset.
openOCD is probably instructed to use the NRST pin. I have been googling on how to change this, but this beyond my current skill level. Could you point me in the right direction?

Try and configure the reset method by changing the board manifest (your custom one is working now regarding compilation right?). You have the possibility to conrol extra openocd arguments, especially regarding reset.

See

openocd_extra_args in debug.

Dear maxgerhardt,
My custom board json file is not yet working. I get the following error.

/home/frank/.platformio/packages/toolchain-gccarmnoneeabi/bin/…/lib/gcc/arm-none-eabi/7.2.1/…/…/…/…/arm-none-eabi/bin/ld: cannot open linker script file STM32F030C8_FLASH.ld: No such file or directory
collect2: error: ld returned 1 exit status
*** [.pioenvs/BIGTREE_S42B_V1_0/firmware.elf] Error 1

To be honest, I am already done with my programming work after a day of figuring out someone else program and modifying it. I selected the disco_f030r8 board and used stm32cubeprog to upload the firmware. This is not ideal but it is very close to ideal. I got the work done this way. It would be somewhat interesting to know why the error occurs but I am okay with stopping at this point. I don’t want to waste your time if I don’t have to :wink:
Many thanks for your help!

Since you have written that in the board manifest, that file must also exist. Either you let STM32Cube generate that file and put it in your project folder, or you select the file that PlatofrmIO already knows, which is in the C:\Users\<user>\.platformio\packages\tool-ldscripts-ststm32\stm32f0 package.

grafik

And there’s a nice STM32F030C8TX_FLASH.ld that you can reference.

It is working! I removed the "ldscript": "STM32F030C8_FLASH.ld", line. Again, I don’t really know what I am doing when it comes these board files. Apperrently it can find the file on its own if I don’t mention it in the board file.
Thanks again :wink:

Not recommeneded, it will autogenerate a linker script from a generic template using just the RAM and FLASH size information – may work, may not work. The STM32Cube provided linker script, which are also available in PlatformIO per that file above, definitely work :smiley: .

Alright. I think it is best if I add the file to my project. Than everything stays together. Within the directory of my project there is a file. This file has always been there.
/buildroot/ldscripts/STM32F030C8_FLASH.ld
Apparently this file cannot be found which is weird because I think it is in the right location. What is happening here?

PlatformIO only searches the project root and its own packages for the file. Special paths must be given in full in e.g. the platformio.ini as

board_build.ldscript = buildroot/ldscripts/STM32F030C8_FLASH.ld

since this file seems to be only for that project.

I overread this in the beginning, but per documentation and release page you can also specify that the project is just built with an older platform version that matches when the project was created. Locate the platform = ststm32 line in the platformio.ini and add a @9.0.0, for example.

It also looks like this is https://github.com/bigtreetech/BIGTREETECH-S42B-V1.0/? Let me fire a quick a issue or pull request there.

See https://github.com/bigtreetech/BIGTREETECH-S42B-V1.0/pull/38

1 Like

This is indeed the https://github.com/bigtreetech/BIGTREETECH-S42B-V1.0/
Many thanks for all your work. It is working now! It compiles and seems to run (I cannot test this fully yet because connecting it to my 3D printers is not that simple and will take some time).

You discovered the missing CMSIS library as well. That is one of things I did solve on my own.

I am already having fun with the close loop stepper driver! Playing around with the PID values is very interesting indeed. I modified the firmware in order to work with a 400 steps steppermotor instead of 200 stepper. This is working as well.

Again thanks for all you work! Really appreciate it!

1 Like