cancel
Showing results for 
Search instead for 
Did you mean: 

Compiler optimisation issue (remove used functions)[solved]

MLE S.1
Associate III

Hi all,

On our card with a STM32L4 we use a siliconLabs BGM13P32 for the BLE.

The L4 communicate with the BLE SOC in NCP mode (see here for more details).

To do that i have integrated the SiliconLabs libs (BGLIB) to our project on stm32cubeIDE.

The project build fine, with no errors/warnings (default options) and i can communicate with the BLE SoC ...only if i use -O0 option in optimization options.

0693W000001pmqpQAA.png

If i use for example -Og, the functions used in BGLIB (siliconLabs) is removed from the binary (checked on .map file). The project build without errors but the com with the BLE SoC fails !

For information our project is in C++. Join with this post the class of our Bluetooth Com. (bluetoothCom.h/cpp).

The whole project is build with -Og optimisation option, just bluetoothCom.cpp use -O0 option to have a correct communication.

Do you have an idea how to resolve this ?

20 REPLIES 20
MLE S.1
Associate III

Thanks for your answers.

@Pavel A.​  i use source code (.c/.h) not a linked library.

@Community member​ , i suppose you talk about .list file generated by stm32cubeIDE ?

Under the result of this file for the method

void BluetoothCom::appHandleEvents(struct gecko_cmd_packet *evt)

With option -O0

0693W000001podsQAA.png

With option -Og

0693W000001poe7QAA.png

In debug mode (disassembly )

code working with -O0

0693W000001poelQAA.png

With -Og

0693W000001pof0QAA.png

All the siliconLabs function is declared as static inline0693W000001pofPQAQ.png

0693W000001pofoQAA.png

MLE S.1
Associate III

0693W000001pok5QAA.pngIf it can help, the callGraph with -O0 option

We can see the SiliconLabs functions

with -Og option ?!

0693W000001pokAQAQ.png

> Code not executed with -Og

Did you verify that it should be executed, i.e. that evt != NULL and BGLIB_MSG_ID(evt->header)==gecko_evt_system_boot_id?

JW

It has flipped the logic such that the case's body code are after the return()

The mvn.w r2,#95 is a byte load of 160, it is filling the structures directly.

The use of static functions allows the compiler much freer reign to fold the functions within the single object (source).

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

That's strange.

So what does -Og really mean: maximum optimization, that still allows debugging?

Why use -Og rather than -g -O0/O1?

-- pa

@Community member​ , yes i verify that in step mode after a breakpoint, the code in the switch is not executed

@Pavel A.​ the -Og option reduce the code size but it let you to have a good debug experience. If i use the O1/2 ... option the result his the same it seems the code is removed !

> yes i verify that in step mode after a breakpoint, the code in the switch is not executed

I did not ask if the code *was* executed, I asked, whether there *was a reason* for it to be executed:

>> Did you verify that it should be executed, i.e. that evt != NULL and BGLIB_MSG_ID(evt->header)==gecko_evt_system_boot_id?

Observe the content of registers respective to the variables in those test.

JW

Sorry you are right, only the case gecko_evt_le_connection_closed_id is triggered with breakpoint in "C++" code.

But if put a breakpoint in Disassembly side it is executed :

0693W000001pqQMQAY.png

MLE S.1
Associate III

If i add : -fno-inline in compilation options for bluetoothCom.cpp i see the function in map file and i can have a break point in c++ side when debugging. But it's not working yet ...

MLE S.1
Associate III

I have found the issue ...

On stm32 side i use DMA to transfert the data from uart to a circular buffer. The problem is that the SiliconLabs rxcallBack is implemented to read directly on uart register ...

I just modified my code like this :

int32_t BluetoothCom::BGAPI_Rx(uint32_t len1, uint8_t* data1) {
	uint32_t length = len1;
	while (length) {
		if(uart2.bytesAvailable())//needed to be sure DMA have transfert data from uart...
		{
			*data1 = uart2.readc();
			length --;
			data1 ++;
		}
	}
	return len1;
}

added -fno-inline option to file compilation option and now all work fine !

Thanks all for your answer, i have learn a lot with compilation options !