platformio / platform-ststm32

ST STM32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/ststm32
Apache License 2.0
405 stars 312 forks source link

Mismatched GCC version for STM32Duino #720

Closed maxgerhardt closed 1 year ago

maxgerhardt commented 1 year ago

PlatformIO uses arm-none-eabi-gcc 10.3.1 for all STM32 +https://github.com/stm32duino/Arduino_Core_STM32/ Arduino projects

https://github.com/platformio/platform-ststm32/blob/a6a0cd52968b5a209aa56f91a9e5e803fd5a769a/platform.py#L49-L52

however, the package declaration https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/main/package_stmicroelectronics_index.json declares that since version 2.5.0, the 12.2.1-1.2 version of the toolchain must be used.

Not doing so causes failures in e.g. the STM32FreeRTOS library beceause the older toolchain version was compiled with different Newlib library and newlib options (no _REENT_BACKWARD_BINARY_COMPAT) which shrinks down the size of struct _reent from over 1000 bytes to only 288 bytes which decreases the FreeRTOS TCB_t task control block structure accordingly. This basically means that with PlatofrmIO, each created FreeRTOS task has a signifacant higher heap memory usage and out-of-memory occurs ealier or instantly. See https://community.platformio.org/t/stm32duino-freertos-problems/35163.

valeros commented 1 year ago

Thanks for pointing it out, updated.

maxgerhardt commented 1 year ago

Could you verify that the debugger works in this toolchain version? The user is just stuck on it here

valeros commented 1 year ago

Indeed there is a problem, GDB v12 is not able to launch a debug server in pipe mode. I reverted the toolchain update to avoid breaking already working projects. As of now I'd probably recommend switching to GCC v12 directly in platformio.ini:

[env:nucleo_f401re]
platform = ststm32
framework = arduino
board = nucleo_f401re
debug_tool = custom
platform_packages = 
   toolchain-gccarmnoneeabi @ ~1.120201.0

and launching OpenOCD in a separate process, for example

"C:/Users/YOUR_USER/.platformio/packages/tool-openocd/bin/openocd.exe" -c "tcl_port disabled; telnet_port disabled" -f "C:/Users/YOUR_USER/.platformio/packages/tool-openocd/openocd/scripts/board/st_nucleo_f4.cfg"

Although, it seems only Windows is affected.

maxgerhardt commented 1 year ago

Very weird thing. Maybe https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases behaves differently? :/

valeros commented 1 year ago

We use that exact packages.

maxgerhardt commented 1 year ago

I assume GCC/GDB 12.3.1 also resolve the "GDB can't start OpenOCD in pipe mode" issue?

Does this also resolve https://github.com/platformio/platformio-core/issues/4741 on Linux?

valeros commented 1 year ago

I assume GCC/GDB 12.3.1 also resolve the "GDB can't start OpenOCD in pipe mode" issue?

Yes, it's shipped with GDB v13 with this issue fixed.

Does this also resolve https://github.com/platformio/platformio-core/issues/4741 on Linux?

Hopefully.