added polling msp init
This commit is contained in:
parent
863dfa68a0
commit
66a7a4dbbe
@ -44,39 +44,12 @@ void hal_spi_msp_init_dma(void *spi_handle) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
hal_spi_msp_init_polling(spi_handle);
|
||||||
if (hspi->Instance == SPI1)
|
if (hspi->Instance == SPI1) {
|
||||||
{
|
// DMA setup
|
||||||
/*##-1- Enable peripherals and GPIO Clocks #################################*/
|
|
||||||
/* Enable GPIO TX/RX clock */
|
|
||||||
SPIx_SCK_GPIO_CLK_ENABLE();
|
|
||||||
SPIx_MISO_GPIO_CLK_ENABLE();
|
|
||||||
SPIx_MOSI_GPIO_CLK_ENABLE();
|
|
||||||
/* Enable SPI1 clock */
|
|
||||||
SPIx_CLK_ENABLE();
|
|
||||||
/* Enable DMA clock */
|
|
||||||
DMAx_CLK_ENABLE();
|
DMAx_CLK_ENABLE();
|
||||||
|
|
||||||
/*##-2- Configure peripheral GPIO ##########################################*/
|
// Configure the DMA
|
||||||
/* SPI SCK GPIO pin configuration */
|
|
||||||
GPIO_InitStruct.Pin = SPIx_SCK_PIN;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
||||||
GPIO_InitStruct.Alternate = SPIx_SCK_AF;
|
|
||||||
HAL_GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* SPI MISO GPIO pin configuration */
|
|
||||||
GPIO_InitStruct.Pin = SPIx_MISO_PIN;
|
|
||||||
GPIO_InitStruct.Alternate = SPIx_MISO_AF;
|
|
||||||
HAL_GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* SPI MOSI GPIO pin configuration */
|
|
||||||
GPIO_InitStruct.Pin = SPIx_MOSI_PIN;
|
|
||||||
GPIO_InitStruct.Alternate = SPIx_MOSI_AF;
|
|
||||||
HAL_GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*##-3- Configure the DMA ##################################################*/
|
|
||||||
/* Configure the DMA handler for Transmission process */
|
/* Configure the DMA handler for Transmission process */
|
||||||
hdma_tx->Instance = SPIx_TX_DMA_STREAM;
|
hdma_tx->Instance = SPIx_TX_DMA_STREAM;
|
||||||
hdma_tx->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
hdma_tx->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
||||||
@ -154,20 +127,8 @@ void hal_spi_msp_deinit_dma(void *spi_handle)
|
|||||||
if(hspi == NULL) {
|
if(hspi == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(hspi->Instance == SPIx)
|
hal_spi_msp_deinit_polling(spi_handle);
|
||||||
{
|
if(hspi->Instance == SPIx) {
|
||||||
/*##-1- Reset peripherals ##################################################*/
|
|
||||||
SPIx_FORCE_RESET();
|
|
||||||
SPIx_RELEASE_RESET();
|
|
||||||
|
|
||||||
/*##-2- Disable peripherals and GPIO Clocks ################################*/
|
|
||||||
/* Deconfigure SPI SCK */
|
|
||||||
HAL_GPIO_DeInit(SPIx_SCK_GPIO_PORT, SPIx_SCK_PIN);
|
|
||||||
/* Deconfigure SPI MISO */
|
|
||||||
HAL_GPIO_DeInit(SPIx_MISO_GPIO_PORT, SPIx_MISO_PIN);
|
|
||||||
/* Deconfigure SPI MOSI */
|
|
||||||
HAL_GPIO_DeInit(SPIx_MOSI_GPIO_PORT, SPIx_MOSI_PIN);
|
|
||||||
|
|
||||||
DMA_HandleTypeDef* hdma_tx = NULL;
|
DMA_HandleTypeDef* hdma_tx = NULL;
|
||||||
DMA_HandleTypeDef* hdma_rx = NULL;
|
DMA_HandleTypeDef* hdma_rx = NULL;
|
||||||
get_dma_handles(&hdma_tx, &hdma_rx);
|
get_dma_handles(&hdma_tx, &hdma_rx);
|
||||||
@ -190,3 +151,47 @@ void hal_spi_msp_deinit_dma(void *spi_handle)
|
|||||||
HAL_NVIC_EnableIRQ(SPIx_IRQn);
|
HAL_NVIC_EnableIRQ(SPIx_IRQn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hal_spi_msp_init_polling(void *hspi) {
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {};
|
||||||
|
/*##-1- Enable peripherals and GPIO Clocks #################################*/
|
||||||
|
/* Enable GPIO TX/RX clock */
|
||||||
|
SPIx_SCK_GPIO_CLK_ENABLE();
|
||||||
|
SPIx_MISO_GPIO_CLK_ENABLE();
|
||||||
|
SPIx_MOSI_GPIO_CLK_ENABLE();
|
||||||
|
/* Enable SPI clock */
|
||||||
|
SPIx_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*##-2- Configure peripheral GPIO ##########################################*/
|
||||||
|
/* SPI SCK GPIO pin configuration */
|
||||||
|
GPIO_InitStruct.Pin = SPIx_SCK_PIN;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = SPIx_SCK_AF;
|
||||||
|
HAL_GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* SPI MISO GPIO pin configuration */
|
||||||
|
GPIO_InitStruct.Pin = SPIx_MISO_PIN;
|
||||||
|
GPIO_InitStruct.Alternate = SPIx_MISO_AF;
|
||||||
|
HAL_GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* SPI MOSI GPIO pin configuration */
|
||||||
|
GPIO_InitStruct.Pin = SPIx_MOSI_PIN;
|
||||||
|
GPIO_InitStruct.Alternate = SPIx_MOSI_AF;
|
||||||
|
HAL_GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hal_spi_msp_deinit_polling(void *hspi) {
|
||||||
|
/*##-1- Reset peripherals ##################################################*/
|
||||||
|
SPIx_FORCE_RESET();
|
||||||
|
SPIx_RELEASE_RESET();
|
||||||
|
|
||||||
|
/*##-2- Disable peripherals and GPIO Clocks ################################*/
|
||||||
|
/* Configure SPI SCK as alternate function */
|
||||||
|
HAL_GPIO_DeInit(SPIx_SCK_GPIO_PORT, SPIx_SCK_PIN);
|
||||||
|
/* Configure SPI MISO as alternate function */
|
||||||
|
HAL_GPIO_DeInit(SPIx_MISO_GPIO_PORT, SPIx_MISO_PIN);
|
||||||
|
/* Configure SPI MOSI as alternate function */
|
||||||
|
HAL_GPIO_DeInit(SPIx_MOSI_GPIO_PORT, SPIx_MOSI_PIN);
|
||||||
|
}
|
||||||
|
@ -8,6 +8,9 @@ extern "C" {
|
|||||||
void hal_spi_msp_init_dma(void *hspi);
|
void hal_spi_msp_init_dma(void *hspi);
|
||||||
void hal_spi_msp_deinit_dma(void *hspi);
|
void hal_spi_msp_deinit_dma(void *hspi);
|
||||||
|
|
||||||
|
void hal_spi_msp_init_polling(void *hspi);
|
||||||
|
void hal_spi_msp_deinit_polling(void *hspi);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user