From 459f7ebce0c509a7ea291b87f92ac8bf4e2722c7 Mon Sep 17 00:00:00 2001 From: smlng <s@mlng.net> Date: Tue, 7 Aug 2018 12:15:45 +0200 Subject: [PATCH] cpu/cc2538: generalise SPI clock configuration The SPI bus frequency/clock is calculated relative to the MCUs core clock. Currently all boards use the default 32MHz, hence prescaler settings for SPI are all the same. This PR moves the default config for 32MHz to the CPU and allows to be overriden by board config if needed. --- boards/cc2538dk/include/periph_conf.h | 15 --------------- boards/openmote-b/include/periph_conf.h | 14 -------------- boards/openmote-cc2538/include/periph_conf.h | 15 --------------- boards/remote-pa/include/periph_conf.h | 15 --------------- boards/remote-reva/include/periph_conf.h | 15 --------------- boards/remote-revb/include/periph_conf.h | 15 --------------- cpu/cc2538/include/periph_cpu.h | 17 +++++++++++++++++ 7 files changed, 17 insertions(+), 89 deletions(-) diff --git a/boards/cc2538dk/include/periph_conf.h b/boards/cc2538dk/include/periph_conf.h index 4f020a128f..098df406f4 100644 --- a/boards/cc2538dk/include/periph_conf.h +++ b/boards/cc2538dk/include/periph_conf.h @@ -97,21 +97,6 @@ static const i2c_conf_t i2c_config[] = { #define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0])) /** @} */ -/** - * @brief Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz) - * - * Calculated with (CPSR * (SCR + 1)) = (CLOCK_CORECLOCK / bus_freq), where - * 1 < CPSR < 255 and - * 0 < SCR < 256 - */ -static const spi_clk_conf_t spi_clk_config[] = { - { .cpsr = 10, .scr = 31 }, /* 100khz */ - { .cpsr = 2, .scr = 39 }, /* 400khz */ - { .cpsr = 2, .scr = 15 }, /* 1MHz */ - { .cpsr = 2, .scr = 2 }, /* ~4.5MHz */ - { .cpsr = 2, .scr = 1 } /* ~10.7MHz */ -}; - /** * @name SPI configuration * @{ diff --git a/boards/openmote-b/include/periph_conf.h b/boards/openmote-b/include/periph_conf.h index a952f66aee..ec5a11bcf7 100644 --- a/boards/openmote-b/include/periph_conf.h +++ b/boards/openmote-b/include/periph_conf.h @@ -124,20 +124,6 @@ static const i2c_conf_t i2c_config[] = { #define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0])) /** @} */ -/** - * @brief Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz) - * - * Calculated with (CPSR * (SCR + 1)) = (CLOCK_CORECLOCK / bus_freq), - * where 1 < CPSR < 255 and 0 < SCR < 256 - */ -static const spi_clk_conf_t spi_clk_config[] = { - { .cpsr = 10, .scr = 31 }, /* 100khz */ - { .cpsr = 2, .scr = 39 }, /* 400khz */ - { .cpsr = 2, .scr = 15 }, /* 1MHz */ - { .cpsr = 2, .scr = 2 }, /* ~4.5MHz */ - { .cpsr = 2, .scr = 1 } /* ~10.7MHz */ -}; - /** * @name SPI configuration * @{ diff --git a/boards/openmote-cc2538/include/periph_conf.h b/boards/openmote-cc2538/include/periph_conf.h index 912c8bbf5a..2db19aae76 100644 --- a/boards/openmote-cc2538/include/periph_conf.h +++ b/boards/openmote-cc2538/include/periph_conf.h @@ -120,21 +120,6 @@ static const i2c_conf_t i2c_config[] = { #define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0])) /** @} */ -/** - * @brief Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz) - * - * Calculated with (CPSR * (SCR + 1)) = (CLOCK_CORECLOCK / bus_freq), where - * 1 < CPSR < 255 and - * 0 < SCR < 256 - */ -static const spi_clk_conf_t spi_clk_config[] = { - { .cpsr = 10, .scr = 31 }, /* 100khz */ - { .cpsr = 2, .scr = 39 }, /* 400khz */ - { .cpsr = 2, .scr = 15 }, /* 1MHz */ - { .cpsr = 2, .scr = 2 }, /* ~4.5MHz */ - { .cpsr = 2, .scr = 1 } /* ~10.7MHz */ -}; - /** * @name SPI configuration * @{ diff --git a/boards/remote-pa/include/periph_conf.h b/boards/remote-pa/include/periph_conf.h index c5fe4f3db7..a21e022c7c 100644 --- a/boards/remote-pa/include/periph_conf.h +++ b/boards/remote-pa/include/periph_conf.h @@ -45,21 +45,6 @@ static const i2c_conf_t i2c_config[] = { #define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0])) /** @} */ -/** - * @brief Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz) - * - * Calculated with (CPSR * (SCR + 1)) = (CLOCK_CORECLOCK / bus_freq), where - * 1 < CPSR < 255 and - * 0 < SCR < 256 - */ -static const spi_clk_conf_t spi_clk_config[] = { - { .cpsr = 10, .scr = 31 }, /* 100khz */ - { .cpsr = 2, .scr = 39 }, /* 400khz */ - { .cpsr = 2, .scr = 15 }, /* 1MHz */ - { .cpsr = 2, .scr = 2 }, /* ~4.5MHz */ - { .cpsr = 2, .scr = 1 } /* ~10.7MHz */ -}; - /** * @name SPI configuration * @{ diff --git a/boards/remote-reva/include/periph_conf.h b/boards/remote-reva/include/periph_conf.h index ebec0f3207..c2d713d2d9 100644 --- a/boards/remote-reva/include/periph_conf.h +++ b/boards/remote-reva/include/periph_conf.h @@ -49,21 +49,6 @@ static const i2c_conf_t i2c_config[] = { * @name SPI configuration * @{ */ -/** - * @brief Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz) - * - * Calculated with (CPSR * (SCR + 1)) = (CLOCK_CORECLOCK / bus_freq), where - * 1 < CPSR < 255 and - * 0 < SCR < 256 - */ -static const spi_clk_conf_t spi_clk_config[] = { - { .cpsr = 10, .scr = 31 }, /* 100khz */ - { .cpsr = 2, .scr = 39 }, /* 400khz */ - { .cpsr = 2, .scr = 15 }, /* 1MHz */ - { .cpsr = 2, .scr = 2 }, /* ~4.5MHz */ - { .cpsr = 2, .scr = 1 } /* ~10.7MHz */ -}; - static const spi_conf_t spi_config[] = { { .dev = SSI0, diff --git a/boards/remote-revb/include/periph_conf.h b/boards/remote-revb/include/periph_conf.h index 07e6a15479..8b7322a3fa 100644 --- a/boards/remote-revb/include/periph_conf.h +++ b/boards/remote-revb/include/periph_conf.h @@ -52,21 +52,6 @@ static const i2c_conf_t i2c_config[] = { * @name SPI configuration * @{ */ -/** - * @brief Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz) - * - * Calculated with (CPSR * (SCR + 1)) = (CLOCK_CORECLOCK / bus_freq), where - * 1 < CPSR < 255 and - * 0 < SCR < 256 - */ -static const spi_clk_conf_t spi_clk_config[] = { - { .cpsr = 10, .scr = 31 }, /* 100khz */ - { .cpsr = 2, .scr = 39 }, /* 400khz */ - { .cpsr = 2, .scr = 15 }, /* 1MHz */ - { .cpsr = 2, .scr = 2 }, /* ~4.5MHz */ - { .cpsr = 2, .scr = 1 } /* ~10.7MHz */ -}; - static const spi_conf_t spi_config[] = { { .dev = SSI0, diff --git a/cpu/cc2538/include/periph_cpu.h b/cpu/cc2538/include/periph_cpu.h index 0508516e96..6ebce4cc6f 100644 --- a/cpu/cc2538/include/periph_cpu.h +++ b/cpu/cc2538/include/periph_cpu.h @@ -195,6 +195,23 @@ typedef struct { uint8_t scr; /**< SCR clock divider */ } spi_clk_conf_t; +#ifndef BOARD_HAS_SPI_CLK_CONF +/** + * @brief Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz) + * + * SPI bus frequency = CLOCK_CORECLOCK / (CPSR * (SCR + 1)), with + * CPSR = 2..254 and even, + * SCR = 0..255 + */ +static const spi_clk_conf_t spi_clk_config[] = { + { .cpsr = 64, .scr = 4 }, /* 100khz */ + { .cpsr = 16, .scr = 4 }, /* 400khz */ + { .cpsr = 32, .scr = 0 }, /* 1.0MHz */ + { .cpsr = 2, .scr = 2 }, /* 5.3MHz */ + { .cpsr = 2, .scr = 1 } /* 8.0MHz */ +}; +#endif /* BOARD_HAS_SPI_CLK_CONF */ + /** * @name SPI configuration data structure * @{ -- GitLab