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).
This commit is contained in:
Damien George 2018-02-02 19:01:11 +11:00
parent 57d2ac1300
commit 5ddd1488bd
2 changed files with 3 additions and 8 deletions

View File

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

View File

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