I simply would like to report an issue that I am experiencing in these days.
I am developing on STM32F151 and ChibiOs is configured with:
#define CH_DBG_ENABLE_ASSERTS TRUE
When I start the timer TIM4, gpt_lld_start(GPTDriver *gptp) is executed until the prescaler is calculated:
Code: Select all
/* Prescaler value calculation.*/
psc = (uint16_t)((gptp->clock / gptp->config->frequency) - 1);
osalDbgAssert(((uint32_t)(psc + 1) * gptp->config->frequency) == gptp->clock, "invalid frequency");
In my case gptp->clock = 4194000 Hz and gptp->config->frequency = 10000 Hz then in theory psc = (4194000 / 10000) -1 = 418.4 but the preprocessor rounds it to 418.
When osalDbgAssert() is called to assert, the confirmation between psc and gptp->config->frequency fails because the result is:
(418+1)* 10000 = 4190000 Hz instead of 4194000 Hz.
This is the effect of the preprocessor thinking with integers instead of floating point.
I had a similar problem in the past with my own code and I solved converting those variables/defines into floating point number just for the preprocessor phase, but I am not sure if doing this in ChibiOs might be a good idea due to cosmetic and legibility reasons.