Add macros for setting correct F7 and H7 I2C timing

This commit is contained in:
Lucian Copeland 2020-06-10 16:36:44 -04:00
parent bf3a5afca1
commit c08702414e
6 changed files with 29 additions and 1 deletions

View File

@ -46,5 +46,9 @@
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal #define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1) #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_TX (&pin_PD08)
#define DEBUG_UART_RX (&pin_PD09) #define DEBUG_UART_RX (&pin_PD09)

View File

@ -40,6 +40,10 @@
#define CPY_SRAM_SUBMASK 0xFC // Mask 512 to 384 #define CPY_SRAM_SUBMASK 0xFC // Mask 512 to 384
#define CPY_SRAM_START_ADDR 0x20020000 #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 HSE_VALUE ((uint32_t)8000000)
#define LSE_VALUE ((uint32_t)32768) #define LSE_VALUE ((uint32_t)32768)
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal #define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal

View File

@ -39,6 +39,12 @@
#define CPY_SRAM_SUBMASK 0x00 #define CPY_SRAM_SUBMASK 0x00
#define CPY_SRAM_START_ADDR 0x24000000 #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 HSE_VALUE ((uint32_t)8000000)
#define LSE_VALUE ((uint32_t)32768) #define LSE_VALUE ((uint32_t)32768)
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal #define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal

View File

@ -39,5 +39,9 @@
#define CPY_SRAM_SUBMASK 0x00 #define CPY_SRAM_SUBMASK 0x00
#define CPY_SRAM_START_ADDR 0x24000000 #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 HSE_VALUE ((uint32_t)12000000)
#define BOARD_HAS_LOW_SPEED_CRYSTAL (0) #define BOARD_HAS_LOW_SPEED_CRYSTAL (0)

View File

@ -50,6 +50,10 @@
#define CPY_CLK_FLASH_LATENCY (FLASH_LATENCY_6) #define CPY_CLK_FLASH_LATENCY (FLASH_LATENCY_6)
#define CPY_CLK_USB_USES_AUDIOPLL (1) #define CPY_CLK_USB_USES_AUDIOPLL (1)
// Obtain I2C timing values for F7 and H7 boards from ST CubeMX
#define CPY_I2CFAST_TIMINGR 0x00401959
#define CPY_I2CSTANDARD_TIMINGR 0x00C0EAFF
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal #define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1) #define BOARD_HAS_LOW_SPEED_CRYSTAL (1)

View File

@ -120,7 +120,13 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
// Handle the HAL handle differences // Handle the HAL handle differences
#if (CPY_STM32H7 || CPY_STM32F7) #if (CPY_STM32H7 || CPY_STM32F7)
self->handle.Init.Timing = 0x40604E73; //Taken from STCube examples if (frequency == 400000) {
self->handle.Init.Timing = CPY_I2CFAST_TIMINGR;
} else if (frequency == 100000) {
self->handle.Init.Timing = CPY_I2CSTANDARD_TIMINGR;
} else {
mp_raise_ValueError(translate("MCU supports only I2C Standard and Fast modes"));
}
#else #else
self->handle.Init.ClockSpeed = frequency; self->handle.Init.ClockSpeed = frequency;
self->handle.Init.DutyCycle = I2C_DUTYCYCLE_2; self->handle.Init.DutyCycle = I2C_DUTYCYCLE_2;