Инициализация SPI перенесена в отдельные файлы
This commit is contained in:
@@ -42,66 +42,34 @@ uint8_t sector_buff[MEMSPI_SECTOR_SIZE];
|
||||
*/
|
||||
void MEMSPI_Base_Init(MEMSPI_HandleTypeDef *hmemspi)
|
||||
{
|
||||
SPI_SettingsTypeDef sspi;
|
||||
|
||||
// SPI PERIPH INIT
|
||||
if(hmemspi->hspi.Instance == NULL)
|
||||
hmemspi->hspi.Instance = SPI1;
|
||||
if(hmemspi->sspi.hspi.Instance == NULL)
|
||||
hmemspi->sspi.hspi.Instance = SPI1;
|
||||
|
||||
hmemspi->hspi.Init.Mode = SPI_MODE_MASTER;
|
||||
hmemspi->hspi.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hmemspi->hspi.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hmemspi->hspi.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hmemspi->hspi.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hmemspi->hspi.Init.NSS = SPI_NSS_SOFT;
|
||||
hmemspi->hspi.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hmemspi->hspi.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hmemspi->hspi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hmemspi->hspi.Init.CRCPolynomial = 10;
|
||||
|
||||
// CLOCK
|
||||
if(hmemspi->hspi.Instance == SPI1)
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
else if (hmemspi->hspi.Instance == SPI2)
|
||||
__HAL_RCC_SPI2_CLK_ENABLE();
|
||||
else if (hmemspi->hspi.Instance == SPI3)
|
||||
__HAL_RCC_SPI3_CLK_ENABLE();
|
||||
hmemspi->sspi.hspi.Init.Mode = SPI_MODE_MASTER;
|
||||
hmemspi->sspi.hspi.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hmemspi->sspi.hspi.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hmemspi->sspi.hspi.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hmemspi->sspi.hspi.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hmemspi->sspi.hspi.Init.NSS = SPI_NSS_SOFT;
|
||||
hmemspi->sspi.hspi.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hmemspi->sspi.hspi.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hmemspi->sspi.hspi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
|
||||
// SPI INIT
|
||||
HAL_SPI_Init(&hmemspi->hspi);
|
||||
SPI_Base_Init(&hmemspi->sspi);
|
||||
|
||||
// GPIO INIT
|
||||
GPIO_Clock_Enable(hmemspi->GPIOs.CS_GPIOx);
|
||||
GPIO_Clock_Enable(hmemspi->GPIOs.CLK_GPIOx);
|
||||
GPIO_Clock_Enable(hmemspi->GPIOs.MISO_GPIOx);
|
||||
GPIO_Clock_Enable(hmemspi->GPIOs.MOSI_GPIOx);
|
||||
GPIO_Clock_Enable(hmemspi->CS_GPIOx);
|
||||
// CHIP SELECT PIN INIT
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
GPIO_InitStruct.Pin = hmemspi->GPIOs.CS_PIN;
|
||||
GPIO_InitStruct.Pin = hmemspi->CS_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
HAL_GPIO_Init(hmemspi->GPIOs.CS_GPIOx, &GPIO_InitStruct);
|
||||
// CLK PIN INIT
|
||||
GPIO_InitStruct.Pin = hmemspi->GPIOs.CLK_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(hmemspi->GPIOs.CLK_GPIOx, &GPIO_InitStruct);
|
||||
// MISO PIN INIT
|
||||
GPIO_InitStruct.Pin = hmemspi->GPIOs.MISO_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(hmemspi->GPIOs.MISO_GPIOx, &GPIO_InitStruct);
|
||||
// MOSI PIN INIT
|
||||
GPIO_InitStruct.Pin = hmemspi->GPIOs.MOSI_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(hmemspi->GPIOs.MOSI_GPIOx, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(hmemspi->CS_GPIOx, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user