How to config PIO for Blackpill f401ccu6

Hi everyone

Can you give me some tips on how to setup Platformio in Visual Studio Code to use the STM32Duino core (Arduino_Core_STM32)?

I have been trying for days but it didn’t work. My code can be built and uploaded to blackpill f401ccu6 from arduino ide 1.8.19
But when I try to build with platformio it gives me many errors what should I do to make it work in platformio I am so tired of fixing it I hope someone can guide me how to do it

My latest setup

;[env:blackpill_f401cc]
[env:blackpill_f401cc]
platform = stm32duino
platform_packages =
   framework-arduinoststm32@https://github.com/stm32duino/Arduino_Core_STM32.git#2.9.0
;platform = ststm32
;board =  STM32F401CCU6x 
board = blackpill_f401cc
;board_build.core = stm32
framework = arduino
lib_deps = waspinator/AccelStepper@^1.64```

What? The board belongs to platform = ststm32 per documentation. Also, per release notes, the latest version (19.0.0) of the ststm32 platform already uses the 2.9.0 version of the STM32 core, so no need to use platform_packages. Plain and simple

[env:blackpill_f401cc]
platform = ststm32@19.0.0
board = blackpill_f401cc
framework = arduino
lib_deps =
   waspinator/AccelStepper@^1.64

sets up the basic environment for the board, with the AccelStepper library installed.

Please show the compilation errors and code you’re getting with that configuration.

error log

In file included from src\main.cpp:24:
src\c64enh_font.h:8:9: error: narrowing conversion of '-7' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
    8 |         -7, 8, 32, '~'+1+18,   // -width, height, firstChar, lastChar -7, 8, 32, ('~' + 1 + 18),
      |         ^~
In file included from src\main.cpp:25:
src\term9x14_font.h:6:9: error: narrowing conversion of '-9' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
    6 |         -9, 16, ' ', '~'+1, //-9, 16, ' ', '~'+1,
      |         ^~
In file included from src\main.cpp:29:
.pio\libdeps\blackpill_f401cc\AccelStepper\src/AccelStepper.h:417:17: warning: 'boolean' is deprecated [-Wdeprecated-declarations]
  417 |     boolean run();
      |                 ^
In file included from C:\Users\ryoda\.platformio\packages\framework-arduinoststm32\cores\arduino/wiring.h:34,
                 from C:\Users\ryoda\.platformio\packages\framework-arduinoststm32\cores\arduino/Arduino.h:36,
                 from lib\N5110_SPI-master/N5110_SPI.h:20,
                 from src\main.cpp:19:
C:\Users\ryoda\.platformio\packages\framework-arduinoststm32\cores\arduino/wiring_constants.h:110:14: note: declared here
  110 | typedef bool boolean __attribute__((deprecated));
      |              ^~~~~~~
.pio\libdeps\blackpill_f401cc\AccelStepper\src/AccelStepper.h:423:22: warning: 'boolean' is deprecated [-Wdeprecated-declarations]
  423 |     boolean runSpeed();
      |                      ^


      |                                 ^~~~~~~~~~~~~~
src\main.cpp:1198:33: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 1198 |             lcd.printStr(12, 4, "Press UP to");
      |                                 ^~~~~~~~~~~~~
src\main.cpp:1199:32: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 1199 |             lcd.printStr(0, 5, "              ");
      |                                ^~~~~~~~~~~~~~~~
src\main.cpp:1200:32: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 1200 |             lcd.printStr(0, 5, "continue!   ")
      |                                ^~~~~~~~~~~~~~
src\main.cpp:1203:11: error: 'winding' was not declared in this scope
 1203 |           winding(); //continue the winding.
      |           ^~~~~~~
Compiling .pio\build\blackpill_f401cc\FrameworkArduino\WSerial.cpp.o
Compiling .pio\build\blackpill_f401cc\FrameworkArduino\WString.cpp.o
Archiving .pio\build\blackpill_f401cc\lib486\libSPI.a
*** [.pio\build\blackpill_f401cc\src\main.cpp.o] Error 1
type or paste code here

full error log

The code can be build and with Arduino IDE 1.8. And this link has been added in “additional boards manager urls”
https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json

How should I fix it?

So why is the negative number -7 in an array declared with type unsigned 8-bit integer, whose values go from 0 to 255? The Arduino IDE should throw the same warning. You can silence the warning if you think the code is correct by putting build_flags = -Wno-narrowing in the platformio.ini

This seems to be coming from you not putting the function declaration before the call site. There should be like a

// predeclare function
void winding();

at the top of the file. See the FAQ for proper .ino to .cpp conversion.

now can build. me check in my arduino ide setting compiler wronning is none

error

src\c64enh_font.h:8:9: error: narrowing conversion of '-7' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
    8 |         -7, 8, 32, '~'+1+18,   // -width, height, firstChar, lastChar -7, 8, 32, ('~' + 1 + 18),

Change -7 to 249 and fix “error: ‘winding’ was not declared in this scope” As per your advice
And I have one last question I’d like help with.

I added
extra_scripts = post:extra_script.py

platformio.ini

[env:blackpill_f401cc]
platform = ststm32@19.0.0
board = blackpill_f401cc
framework = arduino
lib_deps = waspinator/AccelStepper@^1.64
extra_scripts = post:extra_script.py

post:extra_script.py

Import("env")
# Custom HEX from ELF
env.AddPostAction(
    "$BUILD_DIR/${PROGNAME}.elf",
    env.VerboseAction(" ".join([
        "$OBJCOPY", "-O", "ihex", "-R", ".eeprom",
        "$BUILD_DIR/${PROGNAME}.elf", "$BUILD_DIR/${PROGNAME}.hex"
    ]), "Building $BUILD_DIR/${PROGNAME}.hex")
)

it error

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/blackpill_f401cc.html
PLATFORM: ST STM32 (19.0.0) > WeAct Studio BlackPill V2.0 (STM32F401CC)
HARDWARE: STM32F401CCU6 84MHz, 64KB RAM, 256KB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.20900.0 (2.9.0)
 - framework-cmsis @ 2.50900.0 (5.9.0)
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 16 compatible libraries
Scanning dependencies...
Dependency Graph
|-- AccelStepper @ 1.64.0
|-- N5110 SPI LowResource @ 1.0.9
|-- SPI @ 1.1.0
Building in release mode
Linking .pio\build\blackpill_f401cc\firmware.elf
Building C:\Users\ryoda\Documents\PlatformIO\Projects\Coil Winding Machine\.pio\build\blackpill_f401cc/firmware.hex
Usage: arm-none-eabi-objcopy [option(s)] in-file [out-file]
 Copies a binary file, possibly transforming it in the process
 The options are:
  -I --input-target <bfdname>      Assume input file is in format <bfdname>
  -O --output-target <bfdname>     Create an output file in format <bfdname>
  -B --binary-architecture <arch>  Set output arch, when input is arch-less
  -F --target <bfdname>            Set both input and output format to <bfdname>
     --debugging                   Convert debugging information, if possible
  -p --preserve-dates              Copy modified/access timestamps to the output
  -D --enable-deterministic-archives
                                   Produce deterministic output when stripping archives
  -U --disable-deterministic-archives
                                   Disable -D behavior (default)
  -j --only-section <name>         Only copy section <name> into the output
     --add-gnu-debuglink=<file>    Add section .gnu_debuglink linking to <file>
  -R --remove-section <name>       Remove section <name> from the output
     --remove-relocations <name>   Remove relocations from section <name>
  -S --strip-all                   Remove all symbol and relocation information
  -g --strip-debug                 Remove all debugging symbols & sections
     --strip-dwo                   Remove all DWO sections
     --strip-unneeded              Remove all symbols not needed by relocations
  -N --strip-symbol <name>         Do not copy symbol <name>
     --strip-unneeded-symbol <name>
                                   Do not copy symbol <name> unless needed by
                                     relocations
     --only-keep-debug             Strip everything but the debug information
     --extract-dwo                 Copy only DWO sections
     --extract-symbol              Remove section contents but keep symbols
     --keep-section <name>         Do not strip section <name>
  -K --keep-symbol <name>          Do not strip symbol <name>
     --keep-section-symbols        Do not strip section symbols
     --keep-file-symbols           Do not strip file symbol(s)
     --localize-hidden             Turn all ELF hidden symbols into locals
  -L --localize-symbol <name>      Force symbol <name> to be marked as a local
     --globalize-symbol <name>     Force symbol <name> to be marked as a global
  -G --keep-global-symbol <name>   Localize all symbols except <name>
  -W --weaken-symbol <name>        Force symbol <name> to be marked as a weak
     --weaken                      Force all global symbols to be marked as weak
  -w --wildcard                    Permit wildcard in symbol comparison
  -x --discard-all                 Remove all non-global symbols
  -X --discard-locals              Remove any compiler-generated symbols
  -i --interleave[=<number>]       Only copy N out of every <number> bytes
     --interleave-width <number>   Set N for --interleave
  -b --byte <num>                  Select byte <num> in every interleaved block
     --gap-fill <val>              Fill gaps between sections with <val>
     --pad-to <addr>               Pad the last section up to address <addr>
     --set-start <addr>            Set the start address to <addr>
    {--change-start|--adjust-start} <incr>
                                   Add <incr> to the start address
    {--change-addresses|--adjust-vma} <incr>
                                   Add <incr> to LMA, VMA and start addresses
    {--change-section-address|--adjust-section-vma} <name>{=|+|-}<val>
                                   Change LMA and VMA of section <name> by <val>
     --change-section-lma <name>{=|+|-}<val>
                                   Change the LMA of section <name> by <val>
     --change-section-vma <name>{=|+|-}<val>
                                   Change the VMA of section <name> by <val>
    {--[no-]change-warnings|--[no-]adjust-warnings}
                                   Warn if a named section does not exist
     --set-section-flags <name>=<flags>
                                   Set section <name>'s properties to <flags>
     --set-section-alignment <name>=<align>
                                   Set section <name>'s alignment to <align> bytes
     --add-section <name>=<file>   Add section <name> found in <file> to output
     --update-section <name>=<file>
                                   Update contents of section <name> with
                                   contents found in <file>
     --dump-section <name>=<file>  Dump the contents of section <name> into <file>
     --rename-section <old>=<new>[,<flags>] Rename section <old> to <new>
     --long-section-names {enable|disable|keep}
                                   Handle long section names in Coff objects.
     --change-leading-char         Force output format's leading character style
     --remove-leading-char         Remove leading character from global symbols
     --reverse-bytes=<num>         Reverse <num> bytes at a time, in output sections with content
     --redefine-sym <old>=<new>    Redefine symbol name <old> to <new>
     --redefine-syms <file>        --redefine-sym for all symbol pairs
                                     listed in <file>
     --srec-len <number>           Restrict the length of generated Srecords
     --srec-forceS3                Restrict the type of generated Srecords to S3
     --strip-symbols <file>        -N for all symbols listed in <file>
     --strip-unneeded-symbols <file>
                                   --strip-unneeded-symbol for all symbols listed
                                     in <file>
     --keep-symbols <file>         -K for all symbols listed in <file>
     --localize-symbols <file>     -L for all symbols listed in <file>
     --globalize-symbols <file>    --globalize-symbol for all in <file>
     --keep-global-symbols <file>  -G for all symbols listed in <file>
     --weaken-symbols <file>       -W for all symbols listed in <file>
     --add-symbol <name>=[<section>:]<value>[,<flags>]  Add a symbol
     --alt-machine-code <index>    Use the target's <index>'th alternative machine
     --writable-text               Mark the output text as writable
     --readonly-text               Make the output text write protected
     --pure                        Mark the output file as demand paged
     --impure                      Mark the output file as impure
     --prefix-symbols <prefix>     Add <prefix> to start of every symbol name
     --prefix-sections <prefix>    Add <prefix> to start of every section name
     --prefix-alloc-sections <prefix>
                                   Add <prefix> to start of every allocatable
                                     section name
     --file-alignment <num>        Set PE file alignment to <num>
     --heap <reserve>[,<commit>]   Set PE reserve/commit heap to <reserve>/
                                   <commit>
     --image-base <address>        Set PE image base to <address>
     --section-alignment <num>     Set PE section alignment to <num>
     --stack <reserve>[,<commit>]  Set PE reserve/commit stack to <reserve>/
                                   <commit>
     --subsystem <name>[:<version>]
                                   Set PE subsystem to <name> [& <version>]
     --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi|zstd}]
                                   Compress DWARF debug sections
     --decompress-debug-sections   Decompress DWARF debug sections using zlib
     --elf-stt-common=[yes|no]     Generate ELF common symbols with STT_COMMON
                                     type
     --verilog-data-width <number> Specifies data width, in bytes, for verilog output
  -M  --merge-notes                Remove redundant entries in note sections
      --no-merge-notes             Do not attempt to remove redundant notes (default)
  -v --verbose                     List all object files modified
  @<file>                          Read options from <file>
  -V --version                     Display this program's version number
  -h --help                        Display this output
     --info                        List object formats & architectures supported
arm-none-eabi-objcopy: supported targets: elf32-littlearm elf32-littlearm-fdpic elf32-bigarm elf32-bigarm-fdpic elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex plugin
*** [.pio\build\blackpill_f401cc\firmware.elf] Error 1
======================================================================================== [FAILED] Took 3.09 seconds ================================================================================

how to fix

thanks

Due to spaces in your project folder name (this is usually deadly for build systems), you have to do proper quoting of the arguments, specifically the file paths.

Import("env")
# Custom HEX from ELF
env.AddPostAction(
    "$BUILD_DIR/${PROGNAME}.elf",
    env.VerboseAction(" ".join([
        "$OBJCOPY", "-O", "ihex", "-R", ".eeprom",
        "\"$BUILD_DIR/${PROGNAME}.elf\"", "\"$BUILD_DIR/${PROGNAME}.hex\""
    ]), "Building $BUILD_DIR/${PROGNAME}.hex")
)
1 Like