void spi_free(spi_t *obj) { // Reset SPI and disable clock if (obj->spi == SPI_1) { __SPI1_FORCE_RESET(); __SPI1_RELEASE_RESET(); __SPI1_CLK_DISABLE(); } if (obj->spi == SPI_2) { __SPI2_FORCE_RESET(); __SPI2_RELEASE_RESET(); __SPI2_CLK_DISABLE(); } if (obj->spi == SPI_3) { __SPI3_FORCE_RESET(); __SPI3_RELEASE_RESET(); __SPI3_CLK_DISABLE(); } // Configure GPIOs pin_function(obj->pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); pin_function(obj->pin_mosi, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); pin_function(obj->pin_sclk, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); pin_function(obj->pin_ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); }
void spi_free(spi_t *obj) { // Reset SPI and disable clock switch(obj->spi.module) { case 0: __SPI1_FORCE_RESET(); __SPI1_RELEASE_RESET(); __SPI1_CLK_DISABLE(); break; case 1: __SPI2_FORCE_RESET(); __SPI2_RELEASE_RESET(); __SPI2_CLK_DISABLE(); break; case 2: __SPI3_FORCE_RESET(); __SPI3_RELEASE_RESET(); __SPI3_CLK_DISABLE(); break; #if MODULES_SIZE_SPI > 3 case 3: __SPI4_FORCE_RESET(); __SPI4_RELEASE_RESET(); __SPI4_CLK_DISABLE(); break; #endif #if MODULES_SIZE_SPI > 4 case 4: __SPI5_FORCE_RESET(); __SPI5_RELEASE_RESET(); __SPI5_CLK_DISABLE(); break; #endif #if MODULES_SIZE_SPI > 5 case 5: __SPI6_FORCE_RESET(); __SPI6_RELEASE_RESET(); __SPI6_CLK_DISABLE(); break; #endif default: break; } // Configure GPIOs pin_function(obj->spi.pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); pin_function(obj->spi.pin_mosi, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); pin_function(obj->spi.pin_sclk, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); DEBUG_PRINTF("SPI%u: Free\n", obj->spi.module+1); }
void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) { if (hspi->Instance == SPI3) { __SPI3_FORCE_RESET(); __SPI3_RELEASE_RESET(); __SPI3_CLK_DISABLE(); HAL_GPIO_DeInit(SPI3_MOSI_PORT, SPI3_MOSI_PIN); HAL_GPIO_DeInit(SPI3_MISO_PORT, SPI3_MISO_PIN); HAL_GPIO_DeInit(SPI3_SCK_PORT, SPI3_SCK_PIN); } else if (hspi->Instance == SPI2) { __SPI2_FORCE_RESET(); __SPI2_RELEASE_RESET(); __SPI2_CLK_DISABLE(); HAL_GPIO_DeInit(SPI2_MOSI_PORT, SPI2_MOSI_PIN); HAL_GPIO_DeInit(SPI2_MISO_PORT, SPI2_MISO_PIN); HAL_GPIO_DeInit(SPI2_SCK_PORT, SPI2_SCK_PIN); } }