summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-02 19:01:11 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-02 19:01:11 +1100
commit5ddd1488bd5ac7a41d76e68b84ff858d7fa0aad7 (patch)
tree2e7bf1ef2406fef83e279094ff3988232dcb469c
parent57d2ac130016cf8500423171cb630ec5b2f09b3a (diff)
stm32/spi: Allow SPI peripheral state to persist across a soft reset.
The SPI sub-system is independent from the uPy state (eg the heap) and so can safely persist across a soft reset. And this is actually necessary for drivers that rely on SPI and that also need to persist across soft reset (eg external SPI flash memory).
-rw-r--r--ports/stm32/main.c2
-rw-r--r--ports/stm32/spi.c9
2 files changed, 3 insertions, 8 deletions
diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index 60615736d..7a530ff83 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -457,6 +457,7 @@ int main(void) {
#if MICROPY_HW_HAS_SWITCH
switch_init0();
#endif
+ spi_init0();
#if defined(USE_DEVICE_MODE)
// default to internal flash being the usb medium
@@ -556,7 +557,6 @@ soft_reset:
i2c_init0();
#endif
- spi_init0();
pyb_usb_init0();
// Initialise the local flash filesystem.
diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c
index 2b743bdfa..31157d882 100644
--- a/ports/stm32/spi.c
+++ b/ports/stm32/spi.c
@@ -135,29 +135,24 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
};
void spi_init0(void) {
- // reset the SPI handles
+ // Initialise the SPI handles.
+ // The structs live on the BSS so all other fields will be zero after a reset.
#if defined(MICROPY_HW_SPI1_SCK)
- memset(&SPIHandle1, 0, sizeof(SPI_HandleTypeDef));
SPIHandle1.Instance = SPI1;
#endif
#if defined(MICROPY_HW_SPI2_SCK)
- memset(&SPIHandle2, 0, sizeof(SPI_HandleTypeDef));
SPIHandle2.Instance = SPI2;
#endif
#if defined(MICROPY_HW_SPI3_SCK)
- memset(&SPIHandle3, 0, sizeof(SPI_HandleTypeDef));
SPIHandle3.Instance = SPI3;
#endif
#if defined(MICROPY_HW_SPI4_SCK)
- memset(&SPIHandle4, 0, sizeof(SPI_HandleTypeDef));
SPIHandle4.Instance = SPI4;
#endif
#if defined(MICROPY_HW_SPI5_SCK)
- memset(&SPIHandle5, 0, sizeof(SPI_HandleTypeDef));
SPIHandle5.Instance = SPI5;
#endif
#if defined(MICROPY_HW_SPI6_SCK)
- memset(&SPIHandle6, 0, sizeof(SPI_HandleTypeDef));
SPIHandle6.Instance = SPI6;
#endif
}