I'm not the author of the code, but let's walk through the calculation:

The motor speed is calculated based on the zero-cross detection of BEMF voltage on a non-active phase. These zero-cross events times are measured by capturing the TIM0CNT register at the time the ADC routine detects a zero-cross.

That means, the time is scaled by the TIM0 settings.

In the application, the zero-cross periods are captured with periodZC_F_PhA, periodZC_R_PhA, etc., which are defined as tU16 (16 bit unsigned). To calculate one "electric" revolution of a motor = 6 commutations (or 6 zero-crosses), 6 periods are summed. For that case, the "period6ZC" is defined, formated as tU32 (or unsigned long) to prevent an overflow if all 6 zero-cross periods are summed.

If you sum all the 6 zero-cross periods, you'll get the time per single "electric" revolution. That means, if the motor is 2-pole motor (1 pole-pair motor), it would be the time per single "mechanical" revolution of the rotor. You can easily get the time per mechanical revolution for higher-pole motor simply by multipling it by number of pole-pairs.

Let's get back to the code: the period per 6 zero-crosses "period6ZC" is calculated on the line 813, within the 1 ms timer interrupt routine. Since the speed (rotor frequency) is just an inverted time period, it is calculated using line 814:

actualSpeed = SPEED_CALC_NUMERATOR / period6ZC;

Now, how to read it's scale? Let's assume the "actualSpeed" is tFrac32 (1.31 formated signed 32bit number). It would mean the maximal fraction number is 1.0, which is 2^31 = 2,147,483,648.

The task is to find the SPEED_CALC_NUMERATOR for which the period6ZC gives the number above.

Considering the timer TIM0 prescaler is set to 16 (TIM0TSCR2_PR = 4) and the bus clock is 12.5MHz, the timer tick is 12.5MHz / 16 = 781.25 kHz, which is 1.28us.

Let's assume the maximum mechanical speed of the motor is 10,000 RPM and the motor is 6-pole-pair. That would give us 10000/(60 seconds) = 166.67 revolutions per second, 166.67*(6 pole-pairs) = 1000 electrical revolutions per second, so 1000 * (6 commutations) = 6000 commutations/zero-crosses per second. That would make 1/6000 = 167.67us per one commutation. With our 1.28us timer, we can catch upto 130.28 periods at maximal speed.

For maximal speed, we can simply rearrange the "actualSpeed" calulation, assuming that:

At the full speed, if one period changes by 1 tick, then you'll get the period6ZC from 780 to 781, which makes 12.8041 RPM difference. The higher the SPEED_SCALE is, the higher the error is. If the assumption would be a change in all of the 6 periods (thus the period6ZC would change from 780 to 786), the resulting change to the speed would be 76.336 RPM. That makes the speed error 10,000 RPM +- 76, which is 0.76%

I believe this would make it clear. Please adjust the steps according to your case.