28 #define UNUSED(x) (void)(x) 30 #define USE_SPI_DEVICE_1 31 #define USE_SPI_DEVICE_2 33 #ifdef USE_SPI_DEVICE_1 36 #define SPI1_GPIO GPIOA 37 #define SPI1_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOA 38 #define SPI1_NSS_PIN GPIO_Pin_4 39 #define SPI1_NSS_PIN_SOURCE GPIO_PinSource4 40 #define SPI1_SCK_PIN GPIO_Pin_5 41 #define SPI1_SCK_PIN_SOURCE GPIO_PinSource5 42 #define SPI1_MISO_PIN GPIO_Pin_6 43 #define SPI1_MISO_PIN_SOURCE GPIO_PinSource6 44 #define SPI1_MOSI_PIN GPIO_Pin_7 45 #define SPI1_MOSI_PIN_SOURCE GPIO_PinSource7 72 #ifdef SPI1_NSS_PIN_SOURCE 81 #ifdef USE_SDCARD_SPI1 150 #ifdef USE_SDCARD_SPI1 174 #define SPI2_GPIO GPIOB 175 #define SPI2_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOB 176 #define SPI2_NSS_PIN GPIO_Pin_12 177 #define SPI2_NSS_PIN_SOURCE GPIO_PinSource12 178 #define SPI2_SCK_PIN GPIO_Pin_13 179 #define SPI2_SCK_PIN_SOURCE GPIO_PinSource13 180 #define SPI2_MISO_PIN GPIO_Pin_14 181 #define SPI2_MISO_PIN_SOURCE GPIO_PinSource14 182 #define SPI2_MOSI_PIN GPIO_Pin_15 183 #define SPI2_MOSI_PIN_SOURCE GPIO_PinSource15 233 #ifdef USE_SDCARD_SPI2 256 #if defined(USE_SPI_DEVICE_3) && defined(STM32F303xC) 259 #define SPI3_GPIO GPIOB 260 #define SPI3_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOB 261 #define SPI3_NSS_GPIO GPIOA 262 #define SPI3_NSS_PERIPHERAL RCC_AHBPeriph_GPIOA 263 #define SPI3_NSS_PIN GPIO_Pin_15 264 #define SPI3_NSS_PIN_SOURCE GPIO_PinSource15 265 #define SPI3_SCK_PIN GPIO_Pin_3 266 #define SPI3_SCK_PIN_SOURCE GPIO_PinSource3 267 #define SPI3_MISO_PIN GPIO_Pin_4 268 #define SPI3_MISO_PIN_SOURCE GPIO_PinSource4 269 #define SPI3_MOSI_PIN GPIO_Pin_5 270 #define SPI3_MOSI_PIN_SOURCE GPIO_PinSource5 296 #ifdef SPI2_NSS_PIN_SOURCE 306 #ifdef USE_SDCARD_SPI3 310 GPIO_InitStructure.
GPIO_Pin = SPI3_MOSI_PIN;
312 GPIO_Init(SPI3_GPIO, &GPIO_InitStructure);
315 GPIO_InitStructure.
GPIO_Pin = SPI3_MISO_PIN;
317 GPIO_Init(SPI3_GPIO, &GPIO_InitStructure);
320 GPIO_InitStructure.
GPIO_Pin = SPI3_SCK_PIN;
322 GPIO_Init(SPI3_GPIO, &GPIO_InitStructure);
325 GPIO_InitStructure.
GPIO_Pin = SPI3_SCK_PIN | SPI3_MISO_PIN | SPI3_MOSI_PIN;
327 GPIO_Init(SPI3_GPIO, &GPIO_InitStructure);
331 GPIO_InitStructure.
GPIO_Pin = SPI3_NSS_PIN;
337 GPIO_Init(SPI3_NSS_GPIO, &GPIO_InitStructure);
351 #ifdef USE_SDCARD_SPI3 374 #if (!(defined(USE_SPI_DEVICE_1) && defined(USE_SPI_DEVICE_2) && defined(USE_SPI_DEVICE_3))) 378 #ifdef USE_SPI_DEVICE_1 379 if (instance ==
SPI1) {
384 #ifdef USE_SPI_DEVICE_2 385 if (instance ==
SPI2) {
390 #if defined(USE_SPI_DEVICE_3) && defined(STM32F303xC) 391 if (instance ==
SPI3) {
401 uint16_t spiTimeout = 1000;
404 if ((spiTimeout--) == 0)
414 if ((spiTimeout--) == 0)
432 uint16_t spiTimeout = 1000;
437 b = in ? *(in++) : 0xFF;
439 if ((spiTimeout--) == 0)
448 if ((spiTimeout--) == 0)
462 #define BR_CLEAR_MASK 0xFFC7 464 uint16_t tempRegister;
468 tempRegister = instance->
CR1;
512 instance->
CR1 = tempRegister;
void GPIO_PinAFConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
Changes the mapping of the specified pin.
#define SPI1_NSS_PIN_SOURCE
void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Enables or disables the Low Speed APB (APB1) peripheral clock.
GPIOOType_TypeDef GPIO_OType
bool spiIsBusBusy(SPI_TypeDef *instance)
uint16_t SPI_I2S_ReceiveData(SPI_TypeDef *SPIx)
Returns the most recent received data by the SPIx/I2Sx peripheral.
uint16_t SPI_BaudRatePrescaler
void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor)
#define GPIO_AF_6
AF 6 selection.
GPIOSpeed_TypeDef GPIO_Speed
#define SPI1_SCK_PIN_SOURCE
uint16_t SPI_CRCPolynomial
void SPI_I2S_DeInit(SPI_TypeDef *SPIx)
Deinitializes the SPIx peripheral registers to their default reset values.
void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
Enables or disables the High Speed APB (APB2) peripheral clock.
#define SPI_BaudRatePrescaler_32
FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
Checks whether the specified SPI flag is set or not.
uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t data)
Serial Peripheral Interface.
void GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_InitStruct)
Initializes the GPIOx peripheral according to the specified parameters in the GPIO_InitStruct.
void gpioInit(GPIO_TypeDef *gpio, gpio_config_t *config)
#define SPI_BaudRatePrescaler_256
#define RCC_APB1Periph_SPI2
#define RCC_APB2Periph_SPI1
#define SPI_BaudRatePrescaler_16
#define GPIO_AF_5
AF 5 selection.
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
GPIO Init structure definition.
#define SPI_BaudRatePrescaler_2
SPI Init structure definition.
#define SPI_Direction_2Lines_FullDuplex
void spiTransfer(SPI_TypeDef *instance, uint8_t *out, const uint8_t *in, int len)
#define SPI_I2S_FLAG_RXNE
void SPI_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified SPI peripheral.
void SPI_Init(SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct.
GPIOMode_TypeDef GPIO_Mode
bool spiInit(SPI_TypeDef *instance)
#define SPI_BaudRatePrescaler_128
#define SPI_BaudRatePrescaler_64
void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
Forces or releases High Speed APB (APB2) peripheral reset.
#define SPI1_MOSI_PIN_SOURCE
void SPI_RxFIFOThresholdConfig(SPI_TypeDef *SPIx, uint16_t SPI_RxFIFOThreshold)
Configures the FIFO reception threshold for the selected SPI.
#define SPI1_GPIO_PERIPHERAL
void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)
Enables or disables the AHB peripheral clock.
#define SPI_RxFIFOThreshold_QF
#define RCC_APB1Periph_SPI3
void SPI_I2S_SendData(SPI_TypeDef *SPIx, uint16_t Data)
Transmits a Data through the SPIx/I2Sx peripheral.
CMSIS Cortex-M3 Device Peripheral Access Layer Header File. This file contains all the peripheral reg...
GPIOPuPd_TypeDef GPIO_PuPd
void GPIO_SetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Sets the selected data port bits.
#define SPI_BaudRatePrescaler_4
#define SPI_BaudRatePrescaler_8
#define SPI1_MISO_PIN_SOURCE