summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucian Copeland <hierophect@gmail.com>2020-06-11 11:17:51 -0400
committerLucian Copeland <hierophect@gmail.com>2020-06-11 11:17:51 -0400
commit724637faa3b96b20f4deed32d58dcb7b50672479 (patch)
tree4fd93efa4d77eaef9c873c6328dc8d8f464bef44
parentc08702414e410769de3d4821aa07f419c9ef7508 (diff)
Move I2C speed to clock-style definition
-rw-r--r--ports/stm/boards/nucleo_f746zg/mpconfigboard.h4
-rw-r--r--ports/stm/boards/nucleo_f767zi/mpconfigboard.h4
-rw-r--r--ports/stm/boards/nucleo_h743zi_2/mpconfigboard.h6
-rw-r--r--ports/stm/boards/openmv_h7/mpconfigboard.h4
-rw-r--r--ports/stm/common-hal/busio/I2C.c3
-rw-r--r--ports/stm/peripherals/clocks.h30
-rw-r--r--ports/stm/peripherals/stm32f7/stm32f746xx/clocks.h8
-rw-r--r--ports/stm/peripherals/stm32f7/stm32f767xx/clocks.h8
-rw-r--r--ports/stm/peripherals/stm32h7/stm32h743xx/clocks.h8
9 files changed, 56 insertions, 19 deletions
diff --git a/ports/stm/boards/nucleo_f746zg/mpconfigboard.h b/ports/stm/boards/nucleo_f746zg/mpconfigboard.h
index 13ec369bf..e2b54335a 100644
--- a/ports/stm/boards/nucleo_f746zg/mpconfigboard.h
+++ b/ports/stm/boards/nucleo_f746zg/mpconfigboard.h
@@ -46,9 +46,5 @@
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
-// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
-#define CPY_I2CFAST_TIMINGR 0x6000030D
-#define CPY_I2CSTANDARD_TIMINGR 0x20404768
-
#define DEBUG_UART_TX (&pin_PD08)
#define DEBUG_UART_RX (&pin_PD09)
diff --git a/ports/stm/boards/nucleo_f767zi/mpconfigboard.h b/ports/stm/boards/nucleo_f767zi/mpconfigboard.h
index b08a0062e..327651923 100644
--- a/ports/stm/boards/nucleo_f767zi/mpconfigboard.h
+++ b/ports/stm/boards/nucleo_f767zi/mpconfigboard.h
@@ -40,10 +40,6 @@
#define CPY_SRAM_SUBMASK 0xFC // Mask 512 to 384
#define CPY_SRAM_START_ADDR 0x20020000
-// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
-#define CPY_I2CFAST_TIMINGR 0x6000030D
-#define CPY_I2CSTANDARD_TIMINGR 0x20404768
-
#define HSE_VALUE ((uint32_t)8000000)
#define LSE_VALUE ((uint32_t)32768)
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
diff --git a/ports/stm/boards/nucleo_h743zi_2/mpconfigboard.h b/ports/stm/boards/nucleo_h743zi_2/mpconfigboard.h
index 15186e89d..2ac986701 100644
--- a/ports/stm/boards/nucleo_h743zi_2/mpconfigboard.h
+++ b/ports/stm/boards/nucleo_h743zi_2/mpconfigboard.h
@@ -39,12 +39,6 @@
#define CPY_SRAM_SUBMASK 0x00
#define CPY_SRAM_START_ADDR 0x24000000
-// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
-#define CPY_I2CFAST_TIMINGR 0x00B03FDB
-#define CPY_I2CSTANDARD_TIMINGR 0x307075B1
-
-
-
#define HSE_VALUE ((uint32_t)8000000)
#define LSE_VALUE ((uint32_t)32768)
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
diff --git a/ports/stm/boards/openmv_h7/mpconfigboard.h b/ports/stm/boards/openmv_h7/mpconfigboard.h
index 2f61e2421..77ae235ec 100644
--- a/ports/stm/boards/openmv_h7/mpconfigboard.h
+++ b/ports/stm/boards/openmv_h7/mpconfigboard.h
@@ -39,9 +39,5 @@
#define CPY_SRAM_SUBMASK 0x00
#define CPY_SRAM_START_ADDR 0x24000000
-// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
-#define CPY_I2CFAST_TIMINGR 0x00B03FDB
-#define CPY_I2CSTANDARD_TIMINGR 0x307075B1
-
#define HSE_VALUE ((uint32_t)12000000)
#define BOARD_HAS_LOW_SPEED_CRYSTAL (0)
diff --git a/ports/stm/common-hal/busio/I2C.c b/ports/stm/common-hal/busio/I2C.c
index 01d0703ca..00f15aaa6 100644
--- a/ports/stm/common-hal/busio/I2C.c
+++ b/ports/stm/common-hal/busio/I2C.c
@@ -33,6 +33,7 @@
#include "shared-bindings/microcontroller/__init__.h"
#include "supervisor/shared/translate.h"
#include "common-hal/microcontroller/Pin.h"
+#include "clocks.h"
// Arrays use 0 based numbering: I2C1 is stored at index 0
#define MAX_I2C 4
@@ -125,7 +126,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
} else if (frequency == 100000) {
self->handle.Init.Timing = CPY_I2CSTANDARD_TIMINGR;
} else {
- mp_raise_ValueError(translate("MCU supports only I2C Standard and Fast modes"));
+ mp_raise_ValueError(translate("Unsupported baudrate"));
}
#else
self->handle.Init.ClockSpeed = frequency;
diff --git a/ports/stm/peripherals/clocks.h b/ports/stm/peripherals/clocks.h
index 1f837c79e..192190e5e 100644
--- a/ports/stm/peripherals/clocks.h
+++ b/ports/stm/peripherals/clocks.h
@@ -24,4 +24,34 @@
* THE SOFTWARE.
*/
+// F4 Series
+#ifdef STM32F401xE
+#include "stm32f4/stm32f401xe/clocks.h"
+#endif
+#ifdef STM32F411xE
+#include "stm32f4/stm32f411xe/clocks.h"
+#endif
+#ifdef STM32F412Zx
+#include "stm32f4/stm32f412zx/clocks.h"
+#endif
+#ifdef STM32F405xx
+#include "stm32f4/stm32f405xx/clocks.h"
+#endif
+#ifdef STM32F407xx
+#include "stm32f4/stm32f407xx/clocks.h"
+#endif
+
+// F7 Series
+#ifdef STM32F746xx
+#include "stm32f7/stm32f746xx/clocks.h"
+#endif
+#ifdef STM32F767xx
+#include "stm32f7/stm32f767xx/clocks.h"
+#endif
+
+// H7 Series
+#ifdef STM32H743xx
+#include "stm32h7/stm32h743xx/clocks.h"
+#endif
+
void stm32_peripherals_clocks_init(void);
diff --git a/ports/stm/peripherals/stm32f7/stm32f746xx/clocks.h b/ports/stm/peripherals/stm32f7/stm32f746xx/clocks.h
index eb4462514..bd53c38cd 100644
--- a/ports/stm/peripherals/stm32f7/stm32f746xx/clocks.h
+++ b/ports/stm/peripherals/stm32f7/stm32f746xx/clocks.h
@@ -61,3 +61,11 @@
#ifndef BOARD_HSE_SOURCE
#define BOARD_HSE_SOURCE (RCC_HSE_ON)
#endif
+
+// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
+#ifndef CPY_I2CFAST_TIMINGR
+#define CPY_I2CFAST_TIMINGR 0x6000030D
+#endif
+#ifndef CPY_I2CSTANDARD_TIMINGR
+#define CPY_I2CSTANDARD_TIMINGR 0x20404768
+#endif
diff --git a/ports/stm/peripherals/stm32f7/stm32f767xx/clocks.h b/ports/stm/peripherals/stm32f7/stm32f767xx/clocks.h
index 187a024ad..a89756db0 100644
--- a/ports/stm/peripherals/stm32f7/stm32f767xx/clocks.h
+++ b/ports/stm/peripherals/stm32f7/stm32f767xx/clocks.h
@@ -61,3 +61,11 @@
#ifndef BOARD_HSE_SOURCE
#define BOARD_HSE_SOURCE (RCC_HSE_ON)
#endif
+
+// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
+#ifndef CPY_I2CFAST_TIMINGR
+#define CPY_I2CFAST_TIMINGR 0x6000030D
+#endif
+#ifndef CPY_I2CSTANDARD_TIMINGR
+#define CPY_I2CSTANDARD_TIMINGR 0x20404768
+#endif
diff --git a/ports/stm/peripherals/stm32h7/stm32h743xx/clocks.h b/ports/stm/peripherals/stm32h7/stm32h743xx/clocks.h
index ad241b7ef..e7c517096 100644
--- a/ports/stm/peripherals/stm32h7/stm32h743xx/clocks.h
+++ b/ports/stm/peripherals/stm32h7/stm32h743xx/clocks.h
@@ -68,3 +68,11 @@
#ifndef BOARD_HSE_SOURCE
#define BOARD_HSE_SOURCE (RCC_HSE_ON)
#endif
+
+// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
+#ifndef CPY_I2CFAST_TIMINGR
+#define CPY_I2CFAST_TIMINGR 0x00B03FDB
+#endif
+#ifndef CPY_I2CSTANDARD_TIMINGR
+#define CPY_I2CSTANDARD_TIMINGR 0x307075B1
+#endif