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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
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 !

View solution in original post

20 REPLIES 20
Brian TIDAL
ST Employee

Hi,

you may try removing --gc-sections in the linker options.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
MLE S.1
Associate III

I suppose you talk about this option :

0693W000001pnDFQAY.png

MLE S.1
Associate III

But this didn't working ...

Brian TIDAL
ST Employee

Hi,

I guess the functions are not removed from the binary but just inlined. Can you add the following option : -fno-inline and verify that the functions are present in the map file?

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

> I guess the functions are not removed from the binary but just inlined.

+1

"Works only if optimizations off" means crappy code, usually missing volatile.

It appeaars that you have the source code, so debug it as usually - establish precisely what "does not work" means, develop theories why is it so, perform experiments, etc - it's all yours now.

JW

I added -fno-inline here but the function is yet removed from the map file

0693W000001poIQQAY.png

Thanks for your help ... For your information for the moment i'm just use the code give by SiliconLabs with no modifications (appart for the C++) --> "means crappy code"

I make some test and i post a message here because i'm stuck and need help. If i'm writing a message here is not to hear --> RTFM ...

You're in a very small room, and practically no one is using the same combination of softwares, you'll need to root-cause what's going on.

You've got the .MAP file, you can generate a .LST or .LSS and see what actually got built.

Is the compiler folding the code, or is the linker jettisoning it?

With C++ got to watch the name mangling. The linker is going to throw out things which aren't explicitly bound.

Watch WEAK usages and link ordering. If the linker can find easy closure it will throw out stuff that takes more effort.

Watch for appropriate use of volatile and static.

Watch for over aggressive optimization as it walks back up the call-chain, seen Keil eat things where coders assume a function provides fencing to things which are inherently volatile.

Scope optimization with #pragma / attributes around code blocks to bisect where the issue actually is.

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

Is the SiliconLabs library pre-built or you build it from source?

If the former, there can be some incompatibility between your code and their library (difference in esoteric code generation options).

Try to generate a binary file for your executable and compare sizes with -O0 vs. -Og

Try to step into the SiLabs library (in disassembly mode).

-- pa