1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/stm32f4: Corrected wrong spi baud rate control settings

This commit is contained in:
Fabian Nack 2015-01-16 09:12:38 +01:00
parent 9a365b0647
commit 672a362f2e

View File

@ -42,6 +42,19 @@ static inline void irq_handler_transfer(SPI_TypeDef *spi, spi_t dev);
static spi_state_t spi_config[SPI_NUMOF];
/* static bus div mapping */
static const uint8_t spi_bus_div_map[SPI_NUMOF] = {
#if SPI_0_EN
[SPI_0] = SPI_0_BUS_DIV,
#endif
#if SPI_1_EN
[SPI_1] = SPI_1_BUS_DIV,
#endif
#if SPI_2_EN
[SPI_2] = SPI_2_BUS_DIV,
#endif
};
int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
{
uint8_t speed_devider;
@ -49,19 +62,19 @@ int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
switch (speed) {
case SPI_SPEED_100KHZ:
return -2; /* not possible for stm32f4 */
return -2; /* not possible for stm32f4, APB2 minimum is 328 kHz */
break;
case SPI_SPEED_400KHZ:
speed_devider = 7; /* makes 656 kHz */
speed_devider = 0x05 + spi_bus_div_map[dev]; /* makes 656 kHz */
break;
case SPI_SPEED_1MHZ:
speed_devider = 6; /* makes 1.3 MHz */
speed_devider = 0x04 + spi_bus_div_map[dev]; /* makes 1.3 MHz */
break;
case SPI_SPEED_5MHZ:
speed_devider = 4; /* makes 5.3 MHz */
speed_devider = 0x02 + spi_bus_div_map[dev]; /* makes 5.3 MHz */
break;
case SPI_SPEED_10MHZ:
speed_devider = 3; /* makes 10.5 MHz */
speed_devider = 0x01 + spi_bus_div_map[dev]; /* makes 10.5 MHz */
break;
default:
return -1;