added polling msp init

This commit is contained in:
Robin Müller 2021-06-03 21:49:16 +02:00
parent 863dfa68a0
commit 66a7a4dbbe
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C
2 changed files with 53 additions and 45 deletions

View File

@ -44,39 +44,12 @@ void hal_spi_msp_init_dma(void *spi_handle) {
return;
}
GPIO_InitTypeDef GPIO_InitStruct;
if (hspi->Instance == SPI1)
{
/*##-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 */
hal_spi_msp_init_polling(spi_handle);
if (hspi->Instance == SPI1) {
// DMA setup
DMAx_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);
/*##-3- Configure the DMA ##################################################*/
// Configure the DMA
/* Configure the DMA handler for Transmission process */
hdma_tx->Instance = SPIx_TX_DMA_STREAM;
hdma_tx->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
@ -154,20 +127,8 @@ void hal_spi_msp_deinit_dma(void *spi_handle)
if(hspi == NULL) {
return;
}
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);
hal_spi_msp_deinit_polling(spi_handle);
if(hspi->Instance == SPIx) {
DMA_HandleTypeDef* hdma_tx = NULL;
DMA_HandleTypeDef* hdma_rx = NULL;
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);
}
}
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);
}

View File

@ -8,6 +8,9 @@ extern "C" {
void hal_spi_msp_init_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
}
#endif