AnsweredAssumed Answered

Double arithmetics in Cube L0 (LPUART)

Question asked by demin.michal on Oct 7, 2016
Latest reply on Oct 7, 2016 by Clive One
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_))))





Outcomes