cancel
Showing results for 
Search instead for 
Did you mean: 

Bad math continues to persist

I've complained about this before, but it is still broken and shows lack of grasp.

STM32Cube_FW_L4_V1.13.0\Projects\NUCLEO-L432KC\Examples\RTC\RTC_LSI\Src\main.c

The following code results in answers which are a multiple of 8, and loses precision which could otherwise be achieved if the math was thought through and ordered correctly.

  /* Frequency computation */

  uwLsiFreq = (uint32_t) SystemCoreClock / uwPeriodValue;

  uwLsiFreq *= 8;

Should be

  uwLsiFreq = (SystemCoreClock * 8) / uwPeriodValue;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
2 REPLIES 2
Uwe Bonnes
Principal III

Probably the code cares for some STM32Xxxx running above 540 Mhz. ;)

Well the H7 can get close to that, but still...

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