Creating custom board for STM32F429ZGT6

Also try removing the \n\r sequence

(which is really weird because it’s usually \r\n, but \n through printf should suffice.

extern "C" helped, launching script under debug session now works as it should - prints stuff to terminal! Finally :smiley:

build + upload + custom → swo viewer still silent

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-18:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 2000 kHz
Info : STLINK V2J37M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.243627
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : accepting 'tcl' connection on tcp/6666
Info : Target trace output  is enabled
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz

When you Ctrl+C out of it what does it look like? Was there more output above?

It’s really weird because I don’t even see the output where swo_viewer.py tries to connect to OpenoCD :confused:

Can you push the current state to github?

It was not full report:

> Executing task in folder BDSP: platformio run --target swo_viewer --environment erica_black_dsp <

Warning! Ignore unknown configuration option `swo_trace_clkin_freq` in section [env:erica_black_dsp]
Processing erica_black_dsp (platform: ststm32; board: erica_black_dsp; framework: stm32cube)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/erica_black_dsp.html
PLATFORM: ST STM32 (14.2.0) > BDSP
HARDWARE: STM32F429ZGT6 180MHz, 256KB RAM, 1MB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-stm32cubef4 1.26.2 
 - tool-ldscripts-ststm32 0.1.0 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 52 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
swo_viewer_task(["swo_viewer"], [])
Entrypoint
Starting OpenOCD with SWO Trace clock-in frequency 180000000, SWO trace frequency 115200. Invocation:
['/Users/t/.platformio/packages/tool-openocd/bin/openocd', '-s', '/Users/t/.platformio/packages/tool-openocd/scripts', '-f', 'interface/stlink.cfg', '-c', 'transport select hla_swd', '-f', 'target/stm32f4x.cfg', '-c', 'init; tpiu config internal - uart false 180000000 115200; itm ports on']
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-18:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 2000 kHz
Info : STLINK V2J37M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.245759
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : accepting 'tcl' connection on tcp/6666
Info : Target trace output  is enabled
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz

Hm, no output for the script – I’m starting to think whether there’s some Windows - Mac difference here.

In this function

Can you change it to

    def _output(self, s):
        print("[Stream ID %s] %s" % (self.id, s))
        if self.tcl_socket is not None:
            self.tcl_socket.sendall(b'puts "' + s.encode('utf-8') + b'"\r\n\x1a')

and retry? (So that output comes via OpenOCD and not the swo_viewer.py)

> Executing task in folder BDSP: platformio run --target swo_viewer --environment erica_black_dsp <

Warning! Ignore unknown configuration option `swo_trace_clkin_freq` in section [env:erica_black_dsp]
Processing erica_black_dsp (platform: ststm32; board: erica_black_dsp; framework: stm32cube)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/erica_black_dsp.html
PLATFORM: ST STM32 (14.2.0) > BDSP
HARDWARE: STM32F429ZGT6 180MHz, 256KB RAM, 1MB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-stm32cubef4 1.26.2 
 - tool-ldscripts-ststm32 0.1.0 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 52 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
swo_viewer_task(["swo_viewer"], [])
Entrypoint
Starting OpenOCD with SWO Trace clock-in frequency 180000000, SWO trace frequency 115200. Invocation:
['/Users/t/.platformio/packages/tool-openocd/bin/openocd', '-s', '/Users/t/.platformio/packages/tool-openocd/scripts', '-f', 'interface/stlink.cfg', '-c', 'transport select hla_swd', '-f', 'target/stm32f4x.cfg', '-c', 'init; tpiu config internal - uart false 180000000 115200; itm ports on']
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-18:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 2000 kHz
Info : STLINK V2J37M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.245204
Traceback (most recent call last):
  File "/Users/t/GitHub/synths/zendelay/targets/BDSP/swo_parser.py", line 193, in <module>
    swo_parser_main()
  File "/Users/t/GitHub/synths/zendelay/targets/BDSP/swo_parser.py", line 138, in swo_parser_main
    tcl_socket.connect((HOST, PORT))
ConnectionRefusedError: [Errno 61] Connection refused
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

@maxgerhardt Right now Im absolutley happy with being able to launch print in debug session.

More critical is to get clear why setting

board_build.stm32cube.custom_config_header = yes

does not work? It still seem to include full HAL library in linkage

Can you increase the startup time.sleep() in the swo_viewer.py further? It’s still starting up before OpenOCD is ready.

The header will be used, that works, but it does not affect which HAL files are compiled or not. PlatformIO does not scan for that, all files are in the build path. The linker will get rid of unused functions, so that should be no problem – things like crystal settings in the HAL config file matter.

arm-none-eabi-g++ -o .pio/build/erica_black_dsp/firmware.elf -T /Users/t/.platformio/packages/tool-ldscripts-ststm32/stm32f4/STM32F429ZGTX_FLASH.ld -Os -Wl,--gc-sections,--relax -mthumb -mcpu=cortex-m4 --specs=nano.specs --specs=nosys.specs -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_adc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_adc_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_can.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_cec.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_cortex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_crc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_cryp.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_cryp_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dac.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dac_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dcmi.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dcmi_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dfsdm.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dma.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dma2d.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dma_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_dsi.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_eth.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_exti.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_flash.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_flash_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_flash_ramfunc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_fmpi2c.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_fmpi2c_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_fmpsmbus.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_fmpsmbus_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_gpio.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_hash.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_hash_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_hcd.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_i2c.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_i2c_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_i2s.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_i2s_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_irda.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_iwdg.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_lptim.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_ltdc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_ltdc_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_mmc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_nand.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_nor.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_pccard.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_pcd.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_pcd_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_pwr.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_pwr_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_qspi.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_rcc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_rcc_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_rng.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_rtc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_rtc_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_sai.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_sai_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_sd.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_sdram.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_smartcard.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_smbus.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_spdifrx.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_spi.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_sram.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_tim.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_tim_ex.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_uart.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_usart.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_hal_wwdg.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_adc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_crc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_dac.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_dma.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_dma2d.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_exti.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_fmc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_fmpi2c.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_fsmc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_gpio.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_i2c.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_lptim.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_pwr.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_rcc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_rng.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_rtc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_sdmmc.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_spi.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_tim.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_usart.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_usb.o .pio/build/erica_black_dsp/FrameworkHALDriver/Src/stm32f4xx_ll_utils.o .pio/build/erica_black_dsp/src/main.o .pio/build/erica_black_dsp/src/stm32_f4xx_it.o -L/Users/t/.platformio/platforms/ststm32/ldscripts -L.pio/build/erica_black_dsp -L/Users/t/.platformio/packages/framework-stm32cubef4/Drivers/CMSIS/Lib/GCC -L/Users/t/.platformio/packages/framework-stm32cubef4/platformio/ldscripts -Wl,--start-group -lc -lgcc -lm -lstdc++ -lnosys .pio/build/erica_black_dsp/libFrameworkCMSISDevice.a -Wl,--end-group

It can see eth drivers here and others that should not have been included. Also build size for hello world takes 15% of flash,

Flash: [== ] 15.2% (used 159232 bytes from 1048576 bytes)

@maxgerhardt high flash usage was caused by
<iostream> :slight_smile:

I could easily find it out while trying to use memory profiler from Platformio tools. Right now I got build size small and SWO seems to work very fast.

I will be working on my implementation next

Big thumbs up to you for onboarding me, it was great!

I am considering to write an article based on this Thread to document for anyone the future the steps and questions that I had and post it somewhere.

Best
Peersky

You are right this can definitely be improved. Parsing the header and excluding the c files from the build should be doable just as it is in the STM8 platform – I’ve opened issue Exclude deactivated STM32HAL modules from build · Issue #568 · platformio/platform-ststm32 · GitHub about this. This improvement will however only be noticble when using framework = stm32cube in the project, in the “baremetal” project style where you copy all sources, including the STM32HAL drivers, into the project, you must manually delete the unwanted files (the easiest way which doesn’t involve scripting).

Alright that’s good. Looks like I still have to improve my SWO script though to make it connect to OpenOCD correctly without having to play around with inserting sleeps.

From my UX - most time consuming action is need for launching the python script AND the fact that to re-build & re-start debug I need to do three actions:

  1. Stop debug session
  2. Start debug (this will build updated code)
  3. Resume debug from main breakpoint.

If Start debug button would automatically cancel previous debug session - that would be just great!

There is a “restart” button on the right-most side of the toolbar for restarting the debug session, but the practical problem with that is that it rebuilds the firmware while the debugger still holds a lock on the firmware.elf, and so building fails (if code needs to be rebuilt). I should open an issue about that too in Issues · platformio/platformio-vscode-ide · GitHub I guess.

@maxgerhardt one other thing I got stuck with and maybe you can help:

I have my libraries organized nested way,
for instance bsp package has

/bsp -> bsp_base.h, bsp_debug.h
/bsp/peripherials/  -> adc.h gpio.h etc

Now in adc.h I do

include “…/debug.h”

This fails in link time with undefined references to functions which are defined in debug.h. As far as I understand it is becauase it tries to compile separate library per directory.
How can I solve this? Thanks!

Undefined refernences come from a file not being inside a folder that PlatformIO compiles. Where is the bsp folder located? It must be in src/ or in lib/.

It’s in project root directory, next to ini file,

I’ve added to config:

lib_extra_dirs =./bsp
            ../../../c-devlib
            ../../../zenlib
            ../../src

and

-Ibsp

It won’t get compiled there. Needs to be in src/ or lib/.

This is not the correct usage of lib_extra_dirs, it should point to a folder containing the folders for each library. At best you can try it via lib_deps = file://bsp but even that is a hack. Place the library as normal in lib/ should be the preferred way.

This works for bsp package. Anyway later on I want to move bsp as part that will be included together with the board (that’s whole sense of having board config I guess)

But I must have other files located in directory above the project because it’s multi platform app, platformio is used only for embedded target, but for desktop/standalone I am using JUCE framework and that’s whole different story.

So in ini file im defining
-D BUILD_TARGET_BDSP
with idea that based on this I can customize my app wrapper that it sets up correct interface to the target peripherials.

Because of that In my main.cpp I want to do

#include “…/…/…/src/App.h”

And in the App I want to include app specific processing library

#include “…/…/zenlib/zen.h”

But I have whole VSCode red with errors that include pathes are not found =/

What is correct way to define architecture the way I need it to be? Thanks

This looks like you have multiple workspaces (root folders) in VSCode. Each of these workspaces must have the .vscode folder which contains the crucial c_cpp_properties.json that is a per-workspace setting. Copy it from the original PlatformIO project.

^ That’s why it’s better to have all sources in the PlatformIO project instead of out-of-tree.