cancel
Showing results for 
Search instead for 
Did you mean: 

I would like to know why the code works in Keil MDK5, but not in STM32CubeIDE

JBerm
Associate

I am working with the attached code, and I am acquiring data from an extern ADC, using SPI communication. Also, I am using USB OTG FS communication to receive data from the computer, but when I add a simple code line that just multiplies a variable, the USB communication does not work, but when I delete this line, the USB works again, which doesn't makes sense.

The mentioned code line is

PID_X.Tunel_Current=((float)(USB_Communication.Send_Union.Send_Struct.Dat_P3[2]-131074)*0.0001953);

This code works perfectly in Keil, but in STMCUBE_IDE does not.

If I don't include the last multiplication ( *0.0001953 ), the code works fine on STM32CubeIDE. I don't understand why is this happening; this kind of behavior shouldn't be present in such an important IDE. I really don't want to switch back to Keil, but so far, seems the only option.

Please help

void Analog_Digital_Converter::Get_All_Value_Adc(){
 
	if(Analog_Digital_Converter::adc_get_value){
 
		USB_Communication.Send_Union.Send_Struct.Dat_P3[2] =	Analog_Digital_Converter::ADC_GetValue(Select_input_Ch_2,GPIO_PIN_9);
		USB_Communication.Send_Union.Send_Struct.Dat_P3[3] =	Analog_Digital_Converter::ADC_GetValue(Select_input_Ch_3,GPIO_PIN_9);
		USB_Communication.Send_Union.Send_Struct.Dat_P3[4] =	Analog_Digital_Converter::ADC_GetValue(Select_input_Ch_4,GPIO_PIN_9);
		USB_Communication.Send_Union.Send_Struct.Dat_P3[5] =	Analog_Digital_Converter::ADC_GetValue(Select_input_Ch_5,GPIO_PIN_9);
		USB_Communication.Send_Union.Send_Struct.Dat_P3[0] =	Analog_Digital_Converter::ADC_GetValue(Select_input_Ch_0,GPIO_PIN_9);
		USB_Communication.Send_Union.Send_Struct.Dat_P3[1] =	Analog_Digital_Converter::ADC_GetValue(Select_input_Ch_1,GPIO_PIN_9);
		PID_X.Tunel_Current=((float)(USB_Communication.Send_Union.Send_Struct.Dat_P3[2]-131074));
		PID_X.Tunel_Current*=0.000019531;
	}
}

3 REPLIES 3

Dupe https://community.st.com/s/question/0D50X0000B9vzOnSQI/i-would-like-to-know-why-the-code-works-in-keil-mdk5-but-not-in-stm32cubeide

One is a professional tool, the other isn't?

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

Hardware or software floating point? Stack space? RTOS or no RTOS? Is this in a interrupt routine or main code? Is the Keil compiler keeping the multiply as float and the BCC compiler promoting it to double, or vice versa, causing more or less stack usage? What about a different linking order between IDEs/compilers (RAM variables and functions in different locations) so some latent bug somewhere else in the code (screwy pointer access) is made visible with the BCC compiler by adding that one line of code?

RafaelJoseph
Associate II

it would be good if we could have good alternative to Keil and IAR that is directly supported by ST and other features not locked behind paywall