Skip to main content
michaldemin
Associate
October 7, 2016
Question

Double arithmetics in Cube L0 (LPUART)

  • October 7, 2016
  • 1 reply
  • 644 views
Posted on October 07, 2016 at 18:49

Hi,

First let me say how much i hate the new Cube L0 concept. Stdperipheral libraries were so much easier to use and cost so much less flash space.

Baudrate generator value is calculated using this formula

#define __DIV_LPUART(_PCLK_, _BAUD_)                ((uint32_t)(((((uint64_t)_PCLK_)*256.0) + (((uint64_t)_BAUD_)/2U)) / (((uint64_t)_BAUD_))))

It's nice, everythin in 64bit, except for the 256.0. This piece of code adds double arithmetics to the whole code. My (wanna be) bootloader went from 12kB to 6kB just by replacing this formula with:

 ((uint32_t)(((((uint64_t)_PCLK_) << 8) + (((uint64_t)_BAUD_) >> 1)) / (((uint64_t)_BAUD_))))

    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    October 7, 2016
    Posted on October 07, 2016 at 20:35

    I agree on the SPL stuff, and yikes!! Looks like LISP, they probably wanted 256L, still the divide has to be expensive.

    It is a bit like the SDIO code, where they transform the blocks into byte offsets and back again repeatedly for no reason, and had to use 64-bit math for 4GB cards, where the rest of us can get 2TB keeping the block count in 32-bit.

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