예제 #1
0
파일: spi_api.c 프로젝트: allankliu/mbed
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));
}
예제 #2
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);
}
예제 #3
0
void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)
{

	if (hi2s->Instance == SPI2)
	{
		__SPI3_CLK_DISABLE();


		/**I2S3 GPIO Configuration    		    
		PA4      ------> I2S3_WS
		PC7      ------> I2S2_MCK
		PC10     ------> I2S3_CK
		PC12     ------> I2S3_SD 
		*/
		HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4);
		HAL_GPIO_DeInit(GPIOC, GPIO_PIN_7 | GPIO_PIN_10 | GPIO_PIN_12);

		/* Peripheral DMA DeInit*/
		//HAL_DMA_DeInit(hi2s->hdmatx);
		//HAL_DMA_DeInit(hi2s->hdmarx);
	}
} 
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);
  }
}
예제 #5
0
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
{

  if(hspi->Instance==SPI3)
  {
  /* USER CODE BEGIN SPI3_MspDeInit 0 */

  /* USER CODE END SPI3_MspDeInit 0 */
    /* Peripheral clock disable */
    __SPI3_CLK_DISABLE();
  
    /**SPI3 GPIO Configuration    
    PC10     ------> SPI3_SCK
    PC11     ------> SPI3_MISO
    PC12     ------> SPI3_MOSI 
    */
    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);

  }
  /* USER CODE BEGIN SPI3_MspDeInit 1 */

  /* USER CODE END SPI3_MspDeInit 1 */
}