2025-06-27 4:02 AM - edited 2025-06-27 4:04 AM
There is no code generated for the led_rgb_toggle() call here:
led_rgb_toggle() is an inline function:
static inline void led_rgb_toggle( GPIO_PinState r_state, GPIO_PinState g_state, GPIO_PinState b_state )
{
#if defined PROJECT_WITH_RGB_LEDS
if( r_state ) HAL_GPIO_TogglePin( LED_R_GPIO_Port, LED_R_Pin );
if( g_state ) HAL_GPIO_TogglePin( LED_G_GPIO_Port, LED_G_Pin );
if( b_state ) HAL_GPIO_TogglePin( LED_B_GPIO_Port, LED_B_Pin );
#endif
}
PROJECT_WITH_RGB_LEDS is defined in the Project defines (name has been changed for confidentiality):
It is working in other places.
Why would there be no code generated here?
This is CubeIDE v1.13.0 on Win 11
There are no build errors or warnings.
Solved! Go to Solution.
2025-06-27 5:14 AM - edited 2025-06-27 5:15 AM
It was the Optimiser:
Turns out my definition of RGB_COLOUR_ALL was wrong, and actually equated to "none".
So the optimiser spotted that the call did nothing - and left it out!
As it should.
@Andrew Neil wrote:It is working in other places..
Actually, it wasn't:
I had tried setting a breakpoint in led_rgb_toggle(), and it seemed that breakpoint was being hit.
What I hadn't noticed was that the place the breakpoint actually hit wasn't in led_rgb_toggle() - it was in another nearby inline function, with a similar name.
In fact, led_rgb_toggle() was not being used anywhere else in the Project.
So another misdirection by the Optimiser.
Optimisation level was -Og.
2025-06-27 5:14 AM - edited 2025-06-27 5:15 AM
It was the Optimiser:
Turns out my definition of RGB_COLOUR_ALL was wrong, and actually equated to "none".
So the optimiser spotted that the call did nothing - and left it out!
As it should.
@Andrew Neil wrote:It is working in other places..
Actually, it wasn't:
I had tried setting a breakpoint in led_rgb_toggle(), and it seemed that breakpoint was being hit.
What I hadn't noticed was that the place the breakpoint actually hit wasn't in led_rgb_toggle() - it was in another nearby inline function, with a similar name.
In fact, led_rgb_toggle() was not being used anywhere else in the Project.
So another misdirection by the Optimiser.
Optimisation level was -Og.