Browse Source

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).
pull/3599/head
Damien George 7 years ago
parent
commit
5ddd1488bd
  1. 2
      ports/stm32/main.c
  2. 9
      ports/stm32/spi.c

2
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.

9
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
}

Loading…
Cancel
Save