STM32 paths included in flash memory

Hi to all. Why are some paths included in flash memory when i read them from STM32 ST-LINK Utility?


My current settings in .ini file are :

[env:genericSTM32F103C8]

platform = ststm32

board = genericSTM32F103C8

framework = arduino

upload_protocol = stlink

debug_tool = stlink

I found similar problem in post STM32 Maple Library paths included in flash memory but solution not working for me.

Because the core uses the __FILE__ and __LINE__ macros in case of errors in clock initialization and pinmap selection.

Also, just like

says you can use the -fmacro-prefix-map compiler option to shorten the path “returned” by __FILE__.

Is there a way to turn off all of that with some build flags in .ini file (compiler options) ?

Yes such a thing can be constructed.

However, I am actually having trouble reproducing that the path gets included in new platform versions. The latest version has

#if defined(NDEBUG)
#if !defined(_Error_Handler)
#define _Error_Handler(str, value) \
  while (1) {\
  }
#endif
#if !defined(Error_Handler)
#define Error_Handler() \
  while (1) {\
  }
#endif
#else
void _Error_Handler(const char *, int);

#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
#endif

and so the Error_Handler() will be defined as an empty function, not taking __FILE__ and __LINE__ atall, if the macro NDEBUG (no debug) is defined. And by default, that macro is activated in the PlatformIO build process.

-DPLATFORMIO=60107 -DSTM32F103xB -DSTM32F1 -DSTM32F1xx -DARDUINO=10808 -DARDUINO_ARCH_STM32 -DARDUINO_GENERIC_F103C8TX -DBOARD_NAME="GENERIC_F103C8TX" -DHAL_UART_MODULE_ENABLED -DUSE_FULL_LL_DRIVER -DVARIANT_H="variant_generic.h" -DNDEBUG -Iinclude

(from Advanced → Verbose Build).

So instead of writing a work around for an older version, can you make sure you’re using the very latest STM32 platform instead? Quickest way to update is to go CLIpio pkg update -g -p ststm32.

I’m running PLATFORM: ST STM32 (15.5.1+sha.4c9ab2d) currently, pretty close to latest.

Yeah in the latest version I was only able to reproduce that the full paths are in there by explicitly disabling no-debug with

; deactiavte no debug --> build with debug macros
build_unflags = -DNDEBUG

and then, on my Windows system, I could get rid of the base paths by adding

build_flags = "-fmacro-prefix-map=${platformio.packages_dir}\framework-arduinoststm32=."

Which turned the string from

C:\Users\Max\.platformio\packages\framework-arduinoststm32\libraries\SrcWrapper\src\stm32\pinmap.c

to

.\libraries\SrcWrapper\src\stm32\pinmap.c

I did pio pkg update -g -p ststm32 .

With build_unflags = -DNDEBUG and build_flags = “-fmacro-prefix-map=${platformio.packages_dir}\framework-arduinoststm32=.” even more flash memory is occupied…I’m trying to free flash memory, if I didn’t explain that well - sorry…

Then remove that line again.

Now paths are still in flash, but yes - without that C:\User…

I presume that is the best that I can do with flags? There is no way to disable that totally for now by build flags?

They should have been disabled alltogether with the platform / arduino core upgrade.

I tested this with your platformio.ini as I said.

Can you post the full log when you hit “Build”?

I can’t attach it like a .txt file here. Here is the beginning of log if is helpful , if not - I will attach that log here as a comment (if that is ok because is pretty long)

Executing task in folder PLC_STM32_IO_TEST: C:\Users\HP\.platformio\penv\Scripts\platformio.exe run 

Processing bluepill_f103c8 (platform: ststm32; board: bluepill_f103c8; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/bluepill_f103c8.html
PLATFORM: ST STM32 (15.6.0) > BluePill F103C8
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.20400.0 (2.4.0)
 - framework-cmsis @ 2.50700.210515 (5.7.0)
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries

Can you upload a minimal project that

  1. uses the latest ststm32 platform version
  2. does not have any build flags or build unflags
  3. Exhibits that full paths are in the resulting binary?

Ok, now I uploaded blank main ( only setup and loop are in there)
.ini file contains:

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino

Log file from UPLOAD :

Executing task in folder minStm32: C:\Users\HP\.platformio\penv\Scripts\platformio.exe run --target upload 

Processing bluepill_f103c8 (platform: ststm32; board: bluepill_f103c8; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/bluepill_f103c8.html
PLATFORM: ST STM32 (15.6.0) > BluePill F103C8
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.20400.0 (2.4.0)
 - framework-cmsis @ 2.50700.210515 (5.7.0)
 - tool-dfuutil @ 1.11.0
 - tool-openocd @ 2.1100.211028 (11.0)
 - tool-stm32duino @ 1.0.2
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\bluepill_f103c8\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   3.8% (used 780 bytes from 20480 bytes)
Flash: [=         ]  10.8% (used 7072 bytes from 65536 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, mbed, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\bluepill_f103c8\firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
none separate

target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800015c msp: 0x20005000
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
======================================================================================== [SUCCESS] Took 8.24 seconds ======================================================================================== *  Terminal will be reused by tasks, press any key to close it. 

No paths in flash now! But I erased flash with STM32 ST-LINK Utility before uploading the code with Platformio.
Now, even if I upload my old code,there are no those paths in flash.
Is it possible that those paths for some reason existed in Flash before the stm32 platform update and my code upload didn’t delete them at those addresses (until I erased the whole flash manually )?

It could be possible if the firmware was significantly smaller and it the old data would be on a higher flash page than the old firmware would use.

1 Like