diff --git a/ports/stm32f4/boards/meowbit_v121/mpconfigboard.h b/ports/stm32f4/boards/meowbit_v121/mpconfigboard.h index 72d4f1c88e..bf738e9618 100644 --- a/ports/stm32f4/boards/meowbit_v121/mpconfigboard.h +++ b/ports/stm32f4/boards/meowbit_v121/mpconfigboard.h @@ -38,6 +38,7 @@ #define BOARD_OSC_DIV 12 #define BOARD_NO_VBUS_SENSE //#define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader +#define SHOW_FLASH_SPI // On-board flash #define SPI_FLASH_MOSI_PIN (&pin_PB15) diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c index afc6cfcbd5..e00b5e9f0c 100644 --- a/ports/stm32f4/common-hal/busio/SPI.c +++ b/ports/stm32f4/common-hal/busio/SPI.c @@ -428,31 +428,43 @@ STATIC void spi_clock_disable(uint8_t mask) { #ifdef SPI1 if (mask & (1 << 0)) { __HAL_RCC_SPI1_CLK_DISABLE(); + __HAL_RCC_SPI1_FORCE_RESET(); + __HAL_RCC_SPI1_RELEASE_RESET(); } #endif #ifdef SPI2 if (mask & (1 << 1)) { __HAL_RCC_SPI2_CLK_DISABLE(); + __HAL_RCC_SPI2_FORCE_RESET(); + __HAL_RCC_SPI2_RELEASE_RESET(); } #endif #ifdef SPI3 if (mask & (1 << 2)) { __HAL_RCC_SPI3_CLK_DISABLE(); + __HAL_RCC_SPI3_FORCE_RESET(); + __HAL_RCC_SPI3_RELEASE_RESET(); } #endif #ifdef SPI4 if (mask & (1 << 3)) { __HAL_RCC_SPI4_CLK_DISABLE(); + __HAL_RCC_SPI4_FORCE_RESET(); + __HAL_RCC_SPI4_RELEASE_RESET(); } #endif #ifdef SPI5 if (mask & (1 << 4)) { __HAL_RCC_SPI5_CLK_DISABLE(); + __HAL_RCC_SPI5_FORCE_RESET(); + __HAL_RCC_SPI5_RELEASE_RESET(); } #endif #ifdef SPI6 if (mask & (1 << 5)) { __HAL_RCC_SPI6_CLK_DISABLE(); + __HAL_RCC_SPI6_FORCE_RESET(); + __HAL_RCC_SPI6_RELEASE_RESET(); } #endif } diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 5b705a0883..b5d9bb9a80 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -296,6 +296,7 @@ extern const struct _mp_obj_module_t board_module; #define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL)) #define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI)) #define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX)) +#define BOARD_INTERNAL_SPI (defined(SHOW_FLASH_SPI)) // I2C and SPI are always allocated off the heap. diff --git a/shared-bindings/board/__init__.h b/shared-bindings/board/__init__.h index a9b652ba8d..2842057ad6 100644 --- a/shared-bindings/board/__init__.h +++ b/shared-bindings/board/__init__.h @@ -37,6 +37,8 @@ mp_obj_t common_hal_board_get_i2c(void); mp_obj_t common_hal_board_create_i2c(void); MP_DECLARE_CONST_FUN_OBJ_0(board_i2c_obj); +mp_obj_t common_hal_board_get_internal_spi(void); + mp_obj_t common_hal_board_get_spi(void); mp_obj_t common_hal_board_create_spi(void); MP_DECLARE_CONST_FUN_OBJ_0(board_spi_obj); diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 914bc43137..8d87a98ebd 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -29,6 +29,8 @@ #include "mpconfigboard.h" #include "py/runtime.h" +#include "supervisor/spi_flash_api.h" + #if CIRCUITPY_BUSIO #include "shared-bindings/busio/I2C.h" #include "shared-bindings/busio/SPI.h" @@ -89,6 +91,15 @@ mp_obj_t common_hal_board_create_spi(void) { } #endif +#if BOARD_INTERNAL_SPI +//Provide a reference to the internal SPI, if required. +mp_obj_t common_hal_board_get_internal_spi(void) { + //TODO: can we change the name of this without having to change every instance of spi in every + //flash file? + return (mp_obj_t)(&spi); +} +#endif + #if BOARD_UART mp_obj_t common_hal_board_get_uart(void) { return MP_STATE_VM(shared_uart_bus); diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index af22cb0df8..795de7b87b 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -100,6 +100,11 @@ void reset_displays(void) { continue; } #endif + #if BOARD_INTERNAL_SPI + if (original_spi == common_hal_board_get_internal_spi()) { + continue; + } + #endif memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); fourwire->bus = &fourwire->inline_bus; // Check for other displays that use the same spi bus and swap them too.