2015-10-08 02:44 AM
Hello. There's an issue in MBED's spi_api.c file. Function
void spi_frequency(spi_t *obj, int hz)
line
baud_rate = __builtin_ffs(divisor) - 1;
The problem is this line makes a hardware divisor value (
baud_rate) to become 1 step larger than it should be, resulting in 2x lower communication frequency than it is possible under given in HZ desired limitation. Let's say I'm going to have a power-of-2-casted divisor of 0x Then
__builtin_ffs
() returns ''8'' as it should;
baud_rate then becomes ''7'', which is 0b111 - and that value corresponds to f_PCLK/256 according to STM32F4xx refman, not f_PCLK/128!
What we need is harware divisor values equal to 0b000 for 0,1 and 2 division rates, and ''baud_rate-2'' for all other cases. So i suggest the following code:
lsbIndex = __builtin_ffs(divisor);
baud_rate = lsbIndex>1 ? lsbIndex-2 : 0;
where lsbIndex is a new uint32_t variable.
2015-10-08 03:20 AM
Hi chernikov.vasily,
I recommend you to post your issue in arm mbed related forum. -Syrine –