2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
23 #define SPI_TIMEOUT_US 10000
25 #if defined(STM32F4) || defined(STM32G4)
26 #define MAX_SPI_PIN_SEL 2
27 #elif defined(STM32F7)
28 #define MAX_SPI_PIN_SEL 4
29 #elif defined(STM32H7)
30 #define MAX_SPI_PIN_SEL 5
32 #error Unknown MCU family
35 #define BUS_SPI_FREE 0x0
37 typedef struct spiPinDef_s
{
39 #if defined(STM32F7) || defined(STM32H7) || defined(STM32G4)
44 typedef struct spiHardware_s
{
47 spiPinDef_t sckPins
[MAX_SPI_PIN_SEL
];
48 spiPinDef_t misoPins
[MAX_SPI_PIN_SEL
];
49 spiPinDef_t mosiPins
[MAX_SPI_PIN_SEL
];
55 uint8_t dmaIrqHandler
;
59 extern const spiHardware_t spiHardware
[];
61 typedef struct SPIDevice_s
{
66 #if defined(STM32F7) || defined(STM32H7) || defined(STM32G4)
73 #if defined(HAL_SPI_MODULE_ENABLED)
74 SPI_HandleTypeDef hspi
;
77 volatile uint16_t errorCount
;
80 uint8_t dmaIrqHandler
;
84 extern spiDevice_t spiDevice
[SPIDEV_COUNT
];
86 void spiInitDevice(SPIDevice device
);
87 void spiInternalInitStream(const extDevice_t
*dev
, bool preInit
);
88 void spiInternalStartDMA(const extDevice_t
*dev
);
89 void spiInternalStopDMA (const extDevice_t
*dev
);
90 void spiInternalResetStream(dmaChannelDescriptor_t
*descriptor
);
91 void spiInternalResetDescriptors(busDevice_t
*bus
);
92 void spiSequenceStart(const extDevice_t
*dev
);