STSTM32 build_flags break 'inline' keyword, debug_build_flags breaks debugging

I noticed two things:

  • applying anything in *build_flags breaks inline keyword unless optimisation setting happens to be last in *build_flags
  • applying any debug_build_flags breaks debugging

I even made “clean” project in attempt to isolate issue.
My platformio.ini:

src_dir = Src
include_dir = Inc

debug_flagz     = -DHELLO_THERE=1
normal_flagz    = -DGENERAL_KENOBI=1

platform = ststm32
board = disco_f030r8
framework = stm32cube

; Broken inline in debug, build works fine
debug_build_flags = ${common.debug_flagz}

; Debug with dbgasm, no preview in c
; debug_build_flags = ${common.debug_flagz} -Og

; Works fine
; build_unflags = -Os
; build_flags = ${common.normal_flagz} -O3

; Now build doesnt recognize inline keyword
build_flags = ${common.normal_flagz}

debug_tool = jlink
upload_protocol = jlink

Removing jlink lines doesn’t make any difference.
I tried multiple combinations of commented lines, and different flags. Even working versions didn’t seem to work after applying broken one until vscode restart. For sake of completeness part of my main.c:

volatile uint8_t counter = 0;

inline void toggle_led3(void){
  HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);

int main(void)
  while (1)
    #ifdef HELLO_THERE
    HAL_GPIO_WritePin(LD4_GPIO_Port,LD4_Pin, 1);



And compiler error produced in broken state:

.pio/build/disco_f030r8/src/main.o: In function `main':
main.c:(.text.main+0x2c): undefined reference to `toggle_led3'
collect2: error: ld returned 1 exit status
*** [.pio/build/disco_f030r8/firmware.elf] Error 1

After removing inline from function definition code compiles and works fine.

Generating flags with pre python script works fine.

Am i doing something wrong? I’ve been using build_flags in my projects since more than a year ago, and I don’t recall inline breaking, could be that I just don’t like inline functions, I guess. I only noticed that I am onto something when I added debug_build_flags.

If anybody wants to try it, i did put my test project on github:

You’re having a C programming level error in your code, just add

extern inline void toggle_led3(void);

above the inline definition and relate to c - C99 referring to inline function: undefined reference to XXX and why should I put it to header? - Stack Overflow, then it compiles for me.

Seems like forcing optimization will “turn on” inline, otherwise the compiler is “free to ignore it” (So uncommenting build_flags = ${common.normal_flagz} -O2 in your platformio.ini will work).
Another solution is to make your inline function static, then it build for me.
See some inline rules here.

1 Like

Okay then, so i was just confused about what inline actually does.
But i don’t think that adding debug_build_flags should break debugging.

I figured out what’s wrong with debug_build_flags. Adding custom build flags seems to override default debug configuration completely, so code built with that option lacks debug information by default.
Adding appropiate options to gcc solves debugging problem.