2024-04-12 3:27 AM
I have seen that it takes about 28 ticks to read registers, so I think my stm32h750 runs really at 17Mhz, it seems is not risk, so perhaps it exists another more fast stm32 micro that have more 17 MIPS
2024-04-12 3:29 AM
If you get unexpected results, look on your side first for errors!
2024-04-12 3:58 AM
Which optimizer setting you use ? (try -O2 or -Ofast , i use -O2 most time.)
+
How you measure this ?
2024-04-12 4:09 AM - last edited on 2024-04-29 5:55 AM by STTwo-32
Hello @JLope.11,
Welcome to the ST community! Can you share with us the code or more details about it?
Also, as AScha.3 said which optimizer do you use? It differs if you use Keil or IAR.
Thanks,
SMSAD.1
2024-04-12 4:29 AM - last edited on 2025-12-04 2:18 AM by Andrew Neil
Of course, I used this to read registers:
a0=HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CNTxR;
a1=HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CNTxR;I was surprised to see a difference of 28-32 ticks between the readings. This was annoying!
I then tried reading the DWT->CYCCNT counter and got slightly better results.
I used stm32cubeide with default parameters
2024-04-12 4:42 AM - last edited on 2025-12-04 2:18 AM by Andrew Neil
Now I used this code and -O2 optimization for speed and see a lot of improvements, here is a better code:
a0=DWT->CYCCNT;
a1=DWT->CYCCNT;
i=GPIOC->IDR & GPIO_PIN_0;
a2=DWT->CYCCNT;
i=GPIOC->IDR & GPIO_PIN_0;
a3=DWT->CYCCNT;
i=GPIOC->IDR & GPIO_PIN_0;
a4=DWT->CYCCNT;
a5=DWT->CYCCNT;
printf("a0,1,2,3,4,5= %5lu %5lu %5lu %5lu %5lu %5lu ",a0,a1,a2,a3,a4,a5);
printf("d1,1,2,3,4= %4lu %4lu %4lu %4lu %4lu\r\n",a1-a0,a2-a1,a3-a2,a4-a3,a5-a4);Now I see to read the counter is needed 10ticks always, and the gpio pin 34-42 tics,
Thanks a lot!
To set optimizations:
Right-click on your project in the Project Explorer window in properties, C/C++ Build->Settings,
in Setting windows, click MCU/GCC Compiler->Optimization: set -O2
2025-12-04 2:09 AM
Here is a code I used to check MFLOPS of the stm32h750.
I have run at 480Mhz and obtained:
MFLOPS: 477.1571 tics: 1005958 freq: 480000000 Hz
I think appear less than 480 because some time is used to control loop and read the counters
//433
void measure_mflops(void)
{
// Ensure DWT is enabled (do this once at init)
uint32_t start = DWT->CYCCNT;
volatile float x = 0.0f; // volatile helps prevent over-optimization
for (int i = 0; i < 10000; i++)
{
// 20 lines × 5 FLOPs = 100 FLOPs per iteration
x = ((x + 1.001f * x) * 0.1f - 1.001f) * 1.032f;
// ... (19 more times)
}
uint32_t stop = DWT->CYCCNT;
uint32_t tics = stop - start;
// Use actual CPU frequency
extern uint32_t SystemCoreClock;
float mflops = (float)SystemCoreClock / (float)tics; // because 1e6 FLOPs / (tics / f) / 1e6 = f / tics
printf("MFLOPS: %.4f tics: %lu, freq: %lu Hz\r\n", mflops, tics, SystemCoreClock);
(void)x; // ensure x is used
}
//No se usa, solo para que use %f:
void _init_printf_float(void) {
double d = 0.0;
d = fabs(d); // forces linker to include float printf support
}