cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in the STM32F4xx mbed library

vech2001
Associate II
Posted on October 08, 2015 at 11:44

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.
1 REPLY 1
Nesrine M_O
Lead II
Posted on October 08, 2015 at 12:20

Hi chernikov.vasily,

I recommend you to post your issue in arm mbed related forum. 

-Syrine –