diff options
Diffstat (limited to 'stmhal')
-rw-r--r-- | stmhal/dma.c | 6 | ||||
-rw-r--r-- | stmhal/dma.h | 2 | ||||
-rw-r--r-- | stmhal/i2c.c | 47 |
3 files changed, 54 insertions, 1 deletions
diff --git a/stmhal/dma.c b/stmhal/dma.c index df40cc696d..cf861fe127 100644 --- a/stmhal/dma.c +++ b/stmhal/dma.c @@ -162,11 +162,17 @@ static const DMA_InitTypeDef dma_init_struct_dac = { // DMA1 streams const dma_descr_t dma_I2C_1_RX = { DMA1_Stream0, DMA_CHANNEL_1, DMA_PERIPH_TO_MEMORY, dma_id_0, &dma_init_struct_spi_i2c }; const dma_descr_t dma_SPI_3_RX = { DMA1_Stream2, DMA_CHANNEL_0, DMA_PERIPH_TO_MEMORY, dma_id_2, &dma_init_struct_spi_i2c }; +#if defined(MCU_SERIES_F7) +const dma_descr_t dma_I2C_4_RX = { DMA1_Stream2, DMA_CHANNEL_2, DMA_PERIPH_TO_MEMORY, dma_id_2, &dma_init_struct_spi_i2c }; +#endif const dma_descr_t dma_I2C_3_RX = { DMA1_Stream2, DMA_CHANNEL_3, DMA_PERIPH_TO_MEMORY, dma_id_2, &dma_init_struct_spi_i2c }; const dma_descr_t dma_I2C_2_RX = { DMA1_Stream2, DMA_CHANNEL_7, DMA_PERIPH_TO_MEMORY, dma_id_2, &dma_init_struct_spi_i2c }; const dma_descr_t dma_SPI_2_RX = { DMA1_Stream3, DMA_CHANNEL_0, DMA_PERIPH_TO_MEMORY, dma_id_3, &dma_init_struct_spi_i2c }; const dma_descr_t dma_SPI_2_TX = { DMA1_Stream4, DMA_CHANNEL_0, DMA_MEMORY_TO_PERIPH, dma_id_4, &dma_init_struct_spi_i2c }; const dma_descr_t dma_I2C_3_TX = { DMA1_Stream4, DMA_CHANNEL_3, DMA_MEMORY_TO_PERIPH, dma_id_4, &dma_init_struct_spi_i2c }; +#if defined(MCU_SERIES_F7) +const dma_descr_t dma_I2C_4_TX = { DMA1_Stream5, DMA_CHANNEL_2, DMA_MEMORY_TO_PERIPH, dma_id_5, &dma_init_struct_spi_i2c }; +#endif #if defined(MICROPY_HW_ENABLE_DAC) && MICROPY_HW_ENABLE_DAC const dma_descr_t dma_DAC_1_TX = { DMA1_Stream5, DMA_CHANNEL_7, DMA_MEMORY_TO_PERIPH, dma_id_5, &dma_init_struct_dac }; const dma_descr_t dma_DAC_2_TX = { DMA1_Stream6, DMA_CHANNEL_7, DMA_MEMORY_TO_PERIPH, dma_id_6, &dma_init_struct_dac }; diff --git a/stmhal/dma.h b/stmhal/dma.h index 5199bd3721..d9d771270b 100644 --- a/stmhal/dma.h +++ b/stmhal/dma.h @@ -33,11 +33,13 @@ typedef struct _dma_descr_t dma_descr_t; extern const dma_descr_t dma_I2C_1_RX; extern const dma_descr_t dma_SPI_3_RX; +extern const dma_descr_t dma_I2C_4_RX; extern const dma_descr_t dma_I2C_3_RX; extern const dma_descr_t dma_I2C_2_RX; extern const dma_descr_t dma_SPI_2_RX; extern const dma_descr_t dma_SPI_2_TX; extern const dma_descr_t dma_I2C_3_TX; +extern const dma_descr_t dma_I2C_4_TX; extern const dma_descr_t dma_DAC_1_TX; extern const dma_descr_t dma_DAC_2_TX; extern const dma_descr_t dma_SPI_3_TX; diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 8f5f8c2d93..9227d1d9dc 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -113,8 +113,11 @@ I2C_HandleTypeDef I2CHandle2 = {.Instance = NULL}; #if defined(MICROPY_HW_I2C3_SCL) I2C_HandleTypeDef I2CHandle3 = {.Instance = NULL}; #endif +#if defined(MICROPY_HW_I2C4_SCL) +I2C_HandleTypeDef I2CHandle4 = {.Instance = NULL}; +#endif -STATIC bool pyb_i2c_use_dma[3]; +STATIC bool pyb_i2c_use_dma[4]; STATIC const pyb_i2c_obj_t pyb_i2c_obj[] = { #if defined(MICROPY_HW_I2C1_SCL) @@ -132,6 +135,11 @@ STATIC const pyb_i2c_obj_t pyb_i2c_obj[] = { #else {{&pyb_i2c_type}, NULL, NULL, NULL, NULL}, #endif + #if defined(MICROPY_HW_I2C4_SCL) + {{&pyb_i2c_type}, &I2CHandle4, &dma_I2C_4_TX, &dma_I2C_4_RX, &pyb_i2c_use_dma[3]}, + #else + {{&pyb_i2c_type}, NULL, NULL, NULL, NULL}, + #endif }; #if defined(MICROPY_HW_I2C_BAUDRATE_TIMING) @@ -192,6 +200,10 @@ void i2c_init0(void) { memset(&I2CHandle3, 0, sizeof(I2C_HandleTypeDef)); I2CHandle3.Instance = I2C3; #endif + #if defined(MICROPY_HW_I2C4_SCL) + memset(&I2CHandle4, 0, sizeof(I2C_HandleTypeDef)); + I2CHandle3.Instance = I2C4; + #endif } void i2c_init(I2C_HandleTypeDef *i2c) { @@ -221,6 +233,13 @@ void i2c_init(I2C_HandleTypeDef *i2c) { sda_pin = &MICROPY_HW_I2C3_SDA; __I2C3_CLK_ENABLE(); #endif + #if defined(MICROPY_HW_I2C4_SCL) + } else if (i2c == &I2CHandle4) { + i2c_unit = 4; + scl_pin = &MICROPY_HW_I2C4_SCL; + sda_pin = &MICROPY_HW_I2C4_SDA; + __I2C3_CLK_ENABLE(); + #endif } else { // I2C does not exist for this board (shouldn't get here, should be checked by caller) return; @@ -262,6 +281,11 @@ void i2c_init(I2C_HandleTypeDef *i2c) { HAL_NVIC_EnableIRQ(I2C3_EV_IRQn); HAL_NVIC_EnableIRQ(I2C3_ER_IRQn); #endif + #if defined(MICROPY_HW_I2C4_SCL) + } else if (i2c->Instance == I2C4) { + HAL_NVIC_EnableIRQ(I2C4_EV_IRQn); + HAL_NVIC_EnableIRQ(I2C4_ER_IRQn); + #endif } } @@ -292,6 +316,14 @@ void i2c_deinit(I2C_HandleTypeDef *i2c) { HAL_NVIC_DisableIRQ(I2C3_EV_IRQn); HAL_NVIC_DisableIRQ(I2C3_ER_IRQn); #endif + #if defined(MICROPY_HW_I2C4_SCL) + } else if (i2c->Instance == I2C4) { + __HAL_RCC_I2C4_FORCE_RESET(); + __HAL_RCC_I2C4_RELEASE_RESET(); + __HAL_RCC_I2C4_CLK_DISABLE(); + HAL_NVIC_DisableIRQ(I2C4_EV_IRQn); + HAL_NVIC_DisableIRQ(I2C4_ER_IRQn); + #endif } } @@ -328,6 +360,11 @@ void i2c_ev_irq_handler(mp_uint_t i2c_id) { hi2c = &I2CHandle3; break; #endif + #if defined(MICROPY_HW_I2C4_SCL) + case 4: + hi2c = &I2CHandle4; + break; + #endif default: return; } @@ -375,6 +412,11 @@ void i2c_er_irq_handler(mp_uint_t i2c_id) { hi2c = &I2CHandle3; break; #endif + #if defined(MICROPY_HW_I2C4_SCL) + case 4: + hi2c = &I2CHandle4; + break; + #endif default: return; } @@ -448,6 +490,9 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki #if defined(MICROPY_HW_I2C3_SCL) else if (self->i2c->Instance == I2C3) { i2c_num = 3; } #endif + #if defined(MICROPY_HW_I2C4_SCL) + else if (self->i2c->Instance == I2C4) { i2c_num = 4; } + #endif if (self->i2c->State == HAL_I2C_STATE_RESET) { mp_printf(print, "I2C(%u)", i2c_num); |