HAL_ADC_ConvCpltCallback optimized away
Post edited to follow the community rules: Please review how to share a code in this post.
Using the stm32g030k8 and the Version: 1.18.1 STM32CubeIDE
I just recently applied an optimization in order to get more space for my application firmware. And then I realize that the HAL_ADC_ConvCpltCallback has been optimized away. I use the -Og (debug optimization) to use the less agressive and more debug friendly optimization.
__attribute__((used)) void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc1)
{
ADC_Average_Buff[CHANNEL_VREF] = ADC_DMA_Buff[CHANNEL_VREF];
ADC_Average_Buff[CHANNEL_VBAT] = ADC_DMA_Buff[CHANNEL_VBAT];
ADC_Average_Buff[CHANNEL_CURRENT] = ADC_DMA_Buff[CHANNEL_CURRENT];
ADC_Average_Buff[CHANNEL_TEMPERATURE] = ADC_DMA_Buff[CHANNEL_TEMPERATURE];
ADC_Average_Buff[CHANNEL_VREF] += ADC_DMA_Buff[CHANNEL_VREF];
ADC_Average_Buff[CHANNEL_VBAT] += ADC_DMA_Buff[CHANNEL_VBAT];
ADC_Average_Buff[CHANNEL_CURRENT] += ADC_DMA_Buff[CHANNEL_CURRENT];
ADC_Average_Buff[CHANNEL_TEMPERATURE] += ADC_DMA_Buff[CHANNEL_TEMPERATURE];
//-------------------------------------------------------------
if (ADC_Samples >= ADC_SAMPLES - 1)
{
//------------------------------
// Voltage Reference calculation
if (ADC_Average_Buff[CHANNEL_VREF] > 0)
{
VoltageReference_Dig = (uint16_t) ADC_Average_Buff[CHANNEL_VREF] / ADC_SAMPLES;
VoltageReference = (uint16_t) __LL_ADC_CALC_VREFANALOG_VOLTAGE( VoltageReference_Dig, LL_ADC_RESOLUTION_12B);
}
else
{
VoltageReference = VDDA_APPLI;
// WARNING: Measure error, action: pending.
}
//------------------------------
// Voltage Battery calculation
if (ADC_Average_Buff[CHANNEL_VBAT] > 0)
{
VoltageBattery_Dig = (uint16_t) ADC_Average_Buff[CHANNEL_VBAT]/ ADC_SAMPLES;
VoltageBattery_Pin = (uint16_t) __LL_ADC_CALC_DATA_TO_VOLTAGE( VoltageReference, VoltageBattery_Dig,LL_ADC_RESOLUTION_12B);
ConversionFloat_Auxiliar = (float) (VoltageBattery_Pin);
if (ConversionFloat_Auxiliar > 0)
{
ConversionFloat_Auxiliar = ((((ConversionFloat_Auxiliar / 1000) / ADC_VBAT_R2) * (ADC_VBAT_R2 + ADC_VBAT_R1)) * 1000)+ ADC_VBAT_OFFSET;
//ConversionFloat_Auxiliar /= 1000;
}
else
{
ConversionFloat_Auxiliar = 0;
}
VoltageBattery = (uint16_t)ConversionFloat_Auxiliar;
}
else
{
// WARNING: Measure error, action: pending.
}
//------------------------------
// Current Motor calculation
if (ADC_Average_Buff[CHANNEL_CURRENT] > 0) // index == 1
{
VoltageMotorShunt_Dig = (uint16_t) ADC_Average_Buff[CHANNEL_CURRENT] / ADC_SAMPLES;
VoltageMotorShunt_Pin = (uint16_t) __LL_ADC_CALC_DATA_TO_VOLTAGE( VoltageReference, VoltageMotorShunt_Dig,
LL_ADC_RESOLUTION_12B);
ConversionFloat_Auxiliar = (float) (VoltageMotorShunt_Pin);
if (ConversionFloat_Auxiliar > 0)
{
ConversionFloat_Auxiliar = (((ConversionFloat_Auxiliar / 1000)/ ADC_SHUNT) * 1000) + ADC_MOTOR_SHUNT_OFFSET;
}
else
{
ConversionFloat_Auxiliar = 0;
}
CurrentMotor = ConversionFloat_Auxiliar;
}
else
{
// WARNING: Measure error, action: pending.
}
//------------------------------
// Temperature calculation
if (ADC_Average_Buff[CHANNEL_TEMPERATURE] > 0)
{
Temperature_Dig = (uint16_t) ADC_Average_Buff[CHANNEL_TEMPERATURE] / ADC_SAMPLES;
Temperature = 100*(int16_t) __LL_ADC_CALC_TEMPERATURE(VoltageReference, Temperature_Dig, LL_ADC_RESOLUTION_12B);
}
else
{
// WARNING: Measure error, action: pending.
}
//------------------------------
// Initialization buffers
ADC_Samples = 0;
ADC_Average_Buff[CHANNEL_VREF] = 0;
ADC_Average_Buff[CHANNEL_VBAT] = 0;
ADC_Average_Buff[CHANNEL_CURRENT] = 0;
ADC_Average_Buff[CHANNEL_TEMPERATURE] = 0;
//------------------------------
//------------------------------
}
else
{
ADC_Samples++;
}
} // End HAL_ADC_ConvCpltCallbackAs the reader can see, I have added the __attribute__((used)) but it is still being optimized away. I also check if the ADC_DMAConvCplt or HAL_ADC_IRQHandler or DMA1_Channel1_IRQHandler are being called, but they are not being called.
what should I do next?
Thanks for all.
