Skip to main content
Tesla DeLorean
Guru
December 15, 2018
Question

Bad math continues to persist

  • December 15, 2018
  • 2 replies
  • 686 views

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;

    This topic has been closed for replies.

    2 replies

    Uwe Bonnes
    Chief
    December 15, 2018

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

    Tesla DeLorean
    Guru
    December 15, 2018

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

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