I am trying to benchmark code that handles ADC samples, to make sure I am processing things fast enough. At the start of the callback I turn on D2, turn it off at the end, and monitor that on my oscilloscope. The other day I stopped multiplying a variable by 2.0f, and suddenly execution time jumped up. Very minor tweaks to code are seeming to have very large impacts on execution time. I assume it has to do with compiler optimizations, so I set -O0 in the build flags, and at first it seemed like things were normal and I could benchmark as needed. In the past, commenting out certain functions would make a difference, so when it jumped up today, I added a second call to BSL_LCD_Clear(), and sure enough, execution time went back down. Just to be clear, the execution time DROPS, when I add the second call. The thing is, that code isn’t even reached most of the time. It’s only executed after a signal pulse has been detected, and the execution time is high even when no pulse is detected. I thought -O0 disabled all optimizations, but now I guess I am unsure. What other compiler options can I try to figure out why removing an extra function call that isn’t even called, causes exection time to jump out dramatically? The BSP_LCD_Clear() function is not the only one that affects it. In the past it was whether or not I stopped the ADC, and I forgot what it was before that.
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc) {
memcpy(&adc_buffer[0], &dma_buffer[0], sizeof(uint16_t) * (ADC_BUFFER_LENGTH / 2));
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
static uint32_t onCount = 0;
HAL_GPIO_WritePin(ARDUINO_D2_GPIO_Port, ARDUINO_D2_Pin, GPIO_PIN_SET);
memcpy(&adc_buffer[ADC_BUFFER_LENGTH / 2], &dma_buffer[ADC_BUFFER_LENGTH / 2], sizeof(uint16_t) * (ADC_BUFFER_LENGTH / 2));
bool on = IsOn();
if(on) {
onCount++;
} else {
if(onCount >= 8) {
StopADC();
Render();
StartADC();
}
onCount = 0;
}
HAL_GPIO_WritePin(ARDUINO_D2_GPIO_Port, ARDUINO_D2_Pin, GPIO_PIN_RESET);
}
void Render() {
BSP_LCD_Clear(LCD_COLOR_BLACK);
BSP_LCD_Clear(LCD_COLOR_BLACK); // Commenting this out causes execution time to jump.
DisplayFFT();
DisplaySignals();
while (!(LTDC->CDSR & LTDC_CDSR_VSYNCS)) {};
BSP_LCD_SetLayerVisible_NoReload(activeLayer, ENABLE);
activeLayer ^= 1;
BSP_LCD_SetLayerVisible(activeLayer, DISABLE);
BSP_LCD_SelectLayer(activeLayer);
}