Skip to content

Commit 2afca4e

Browse files
committed
Fix flash-display conflict error
1 parent d8bc57c commit 2afca4e

6 files changed

Lines changed: 32 additions & 0 deletions

File tree

ports/stm32f4/boards/meowbit_v121/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define BOARD_OSC_DIV 12
3939
#define BOARD_NO_VBUS_SENSE
4040
//#define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader
41+
#define SHOW_FLASH_SPI
4142

4243
// On-board flash
4344
#define SPI_FLASH_MOSI_PIN (&pin_PB15)

ports/stm32f4/common-hal/busio/SPI.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,31 +428,43 @@ STATIC void spi_clock_disable(uint8_t mask) {
428428
#ifdef SPI1
429429
if (mask & (1 << 0)) {
430430
__HAL_RCC_SPI1_CLK_DISABLE();
431+
__HAL_RCC_SPI1_FORCE_RESET();
432+
__HAL_RCC_SPI1_RELEASE_RESET();
431433
}
432434
#endif
433435
#ifdef SPI2
434436
if (mask & (1 << 1)) {
435437
__HAL_RCC_SPI2_CLK_DISABLE();
438+
__HAL_RCC_SPI2_FORCE_RESET();
439+
__HAL_RCC_SPI2_RELEASE_RESET();
436440
}
437441
#endif
438442
#ifdef SPI3
439443
if (mask & (1 << 2)) {
440444
__HAL_RCC_SPI3_CLK_DISABLE();
445+
__HAL_RCC_SPI3_FORCE_RESET();
446+
__HAL_RCC_SPI3_RELEASE_RESET();
441447
}
442448
#endif
443449
#ifdef SPI4
444450
if (mask & (1 << 3)) {
445451
__HAL_RCC_SPI4_CLK_DISABLE();
452+
__HAL_RCC_SPI4_FORCE_RESET();
453+
__HAL_RCC_SPI4_RELEASE_RESET();
446454
}
447455
#endif
448456
#ifdef SPI5
449457
if (mask & (1 << 4)) {
450458
__HAL_RCC_SPI5_CLK_DISABLE();
459+
__HAL_RCC_SPI5_FORCE_RESET();
460+
__HAL_RCC_SPI5_RELEASE_RESET();
451461
}
452462
#endif
453463
#ifdef SPI6
454464
if (mask & (1 << 5)) {
455465
__HAL_RCC_SPI6_CLK_DISABLE();
466+
__HAL_RCC_SPI6_FORCE_RESET();
467+
__HAL_RCC_SPI6_RELEASE_RESET();
456468
}
457469
#endif
458470
}

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ extern const struct _mp_obj_module_t board_module;
296296
#define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL))
297297
#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI))
298298
#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX))
299+
#define BOARD_INTERNAL_SPI (defined(SHOW_FLASH_SPI))
299300

300301
// I2C and SPI are always allocated off the heap.
301302

shared-bindings/board/__init__.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ mp_obj_t common_hal_board_get_i2c(void);
3737
mp_obj_t common_hal_board_create_i2c(void);
3838
MP_DECLARE_CONST_FUN_OBJ_0(board_i2c_obj);
3939

40+
mp_obj_t common_hal_board_get_internal_spi(void);
41+
4042
mp_obj_t common_hal_board_get_spi(void);
4143
mp_obj_t common_hal_board_create_spi(void);
4244
MP_DECLARE_CONST_FUN_OBJ_0(board_spi_obj);

shared-module/board/__init__.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "mpconfigboard.h"
3030
#include "py/runtime.h"
3131

32+
#include "supervisor/spi_flash_api.h"
33+
3234
#if CIRCUITPY_BUSIO
3335
#include "shared-bindings/busio/I2C.h"
3436
#include "shared-bindings/busio/SPI.h"
@@ -89,6 +91,15 @@ mp_obj_t common_hal_board_create_spi(void) {
8991
}
9092
#endif
9193

94+
#if BOARD_INTERNAL_SPI
95+
//Provide a reference to the internal SPI, if required.
96+
mp_obj_t common_hal_board_get_internal_spi(void) {
97+
//TODO: can we change the name of this without having to change every instance of spi in every
98+
//flash file?
99+
return (mp_obj_t)(&spi);
100+
}
101+
#endif
102+
92103
#if BOARD_UART
93104
mp_obj_t common_hal_board_get_uart(void) {
94105
return MP_STATE_VM(shared_uart_bus);

shared-module/displayio/__init__.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ void reset_displays(void) {
100100
continue;
101101
}
102102
#endif
103+
#if BOARD_INTERNAL_SPI
104+
if (original_spi == common_hal_board_get_internal_spi()) {
105+
continue;
106+
}
107+
#endif
103108
memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t));
104109
fourwire->bus = &fourwire->inline_bus;
105110
// Check for other displays that use the same spi bus and swap them too.

0 commit comments

Comments
 (0)