cancel
Showing results for 
Search instead for 
Did you mean: 

Double arithmetics in Cube L0 (LPUART)

michaldemin
Associate II
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_))))

1 REPLY 1
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
Up vote any posts that you find helpful, it shows what's working..