rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
stm32_spi.cpp File Reference

Functions

static int getSpiAf (SPIDriver *driver)
 
void turnOnSpi (spi_device_e device)
 
void initSpiModule (SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, brain_pin_e mosi, int sckMode, int mosiMode, int misoMode)
 
void initSpiCsNoOccupy (SPIConfig *spiConfig, brain_pin_e csPin)
 
void initSpiCs (SPIConfig *spiConfig, brain_pin_e csPin)
 
int spiGetBaseClock (SPIDriver *spip)
 
int spiCalcClockDiv (SPIDriver *, SPIConfig *, unsigned int)
 

Variables

bool isSpiInitialized [SPI_TOTAL_COUNT+1] = { true, false, false, false, false, false, false }
 
SPIConfig mmc_hs_spicfg
 
SPIConfig mmc_ls_spicfg
 

Function Documentation

◆ getSpiAf()

static int getSpiAf ( SPIDriver *  driver)
static

Definition at line 15 of file stm32_spi.cpp.

15 {
16#if STM32_SPI_USE_SPI1
17 if (driver == &SPID1) {
18 return EFI_SPI1_AF;
19 }
20#endif
21#if STM32_SPI_USE_SPI2
22 if (driver == &SPID2) {
23 return EFI_SPI2_AF;
24 }
25#endif
26#if STM32_SPI_USE_SPI3
27 if (driver == &SPID3) {
28 return EFI_SPI3_AF;
29 }
30#endif
31#if STM32_SPI_USE_SPI4
32 if (driver == &SPID4) {
33 return EFI_SPI4_AF;
34 }
35#endif
36#if STM32_SPI_USE_SPI5
37 if (driver == &SPID5) {
38 return EFI_SPI5_AF;
39 }
40#endif
41#if STM32_SPI_USE_SPI6
42 if (driver == &SPID6) {
43 return EFI_SPI6_AF;
44 }
45#endif
46 criticalError("SPI AF not available");
47 return -1;
48}
SPIDriver SPID1
SPI0 driver identifier.
Definition hal_spi_lld.c:42
SPIDriver SPID2
SPI1 driver identifier.
Definition hal_spi_lld.c:47

Referenced by initSpiModule().

Here is the caller graph for this function:

◆ initSpiCs()

void initSpiCs ( SPIConfig *  spiConfig,
brain_pin_e  csPin 
)

Definition at line 160 of file stm32_spi.cpp.

160 {
161 /* TODO: why this is here? */
162#ifdef _CHIBIOS_RT_CONF_VER_6_1_
163 spiConfig->end_cb = nullptr;
164#else
165 spiConfig->data_cb = nullptr;
166 spiConfig->error_cb = nullptr;
167#endif
168
169 initSpiCsNoOccupy(spiConfig, csPin);
170 efiSetPadMode("chip select", csPin, PAL_STM32_MODE_OUTPUT);
171}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
void initSpiCsNoOccupy(SPIConfig *spiConfig, brain_pin_e csPin)
Here is the call graph for this function:

◆ initSpiCsNoOccupy()

void initSpiCsNoOccupy ( SPIConfig *  spiConfig,
brain_pin_e  csPin 
)

Definition at line 153 of file stm32_spi.cpp.

153 {
154 ioportid_t port = getHwPort("spi", csPin);
155 ioportmask_t pin = getHwPin("spi", csPin);
156 spiConfig->ssport = port;
157 spiConfig->sspad = pin;
158}
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
uint32_t ioportmask_t
Digital I/O port sized unsigned type.
Definition hal_pal_lld.h:78
GPIO_TypeDef * ioportid_t
Port Identifier.
brain_pin_e pin
Definition stm32_adc.cpp:15

Referenced by initSpiCs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initSpiModule()

void initSpiModule ( SPIDriver *  driver,
brain_pin_e  sck,
brain_pin_e  miso,
brain_pin_e  mosi,
int  sckMode,
int  mosiMode,
int  misoMode 
)

See https://github.com/rusefi/rusefi/pull/664/

Info on the silicon defect can be found in this document, section 2.5.2: https://www.st.com/content/ccc/resource/technical/document/errata_sheet/0a/98/58/84/86/b6/47/a2/DM00037591.pdf/files/DM00037591.pdf/jcr:content/translations/en.DM00037591.pdf

Definition at line 132 of file stm32_spi.cpp.

134 {
135
136 /**
137 * See https://github.com/rusefi/rusefi/pull/664/
138 *
139 * Info on the silicon defect can be found in this document, section 2.5.2:
140 * https://www.st.com/content/ccc/resource/technical/document/errata_sheet/0a/98/58/84/86/b6/47/a2/DM00037591.pdf/files/DM00037591.pdf/jcr:content/translations/en.DM00037591.pdf
141 */
142 efiSetPadMode("SPI CLK ", sck, PAL_MODE_ALTERNATE(getSpiAf(driver)) | sckMode | PAL_STM32_OSPEED_HIGHEST);
143
144 efiSetPadMode("SPI MOSI", mosi, PAL_MODE_ALTERNATE(getSpiAf(driver)) | mosiMode | PAL_STM32_OSPEED_HIGHEST);
145
146 // Activate the internal pullup on MISO: SD cards indicate "busy" by holding MOSI low,
147 // so in case there is no SD card installed, the line could float low and indicate that
148 // the (non existent) card is busy. We pull the line high to indicate "not busy" in case
149 // of a missing card.
150 efiSetPadMode("SPI MISO", miso, PAL_MODE_ALTERNATE(getSpiAf(driver)) | misoMode | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP);
151}
static int getSpiAf(SPIDriver *driver)
Definition stm32_spi.cpp:15

Referenced by turnOnSpi().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spiCalcClockDiv()

int spiCalcClockDiv ( SPIDriver *  spip,
SPIConfig *  spiConfig,
unsigned int  clk 
)

Definition at line 217 of file stm32_spi.cpp.

218{
219 // TODO: implement
220 return -1;
221}

◆ spiGetBaseClock()

int spiGetBaseClock ( SPIDriver *  spip)

Definition at line 173 of file stm32_spi.cpp.

174{
175#if STM32_SPI_USE_SPI1
176 if (spip == &SPID1) {
177 // APB2
178 return STM32_PCLK2;
179 }
180#endif
181#if STM32_SPI_USE_SPI2
182 if (spip == &SPID2) {
183 // APB1
184 return STM32_PCLK1;
185 }
186#endif
187#if STM32_SPI_USE_SPI3
188 if (spip == &SPID3) {
189 // APB1
190 return STM32_PCLK1;
191 }
192#endif
193#if STM32_SPI_USE_SPI4
194 if (spip == &SPID4) {
195 // APB2
196 return STM32_PCLK2;
197 }
198#endif
199#if STM32_SPI_USE_SPI5
200 if (spip == &SPID5) {
201 // APB2
202 return STM32_PCLK2;
203 }
204#endif
205#if STM32_SPI_USE_SPI6
206 if (spip == &SPID6) {
207 // APB2
208 return STM32_PCLK2;
209 }
210#endif
211
212 return 0;
213}

◆ turnOnSpi()

void turnOnSpi ( spi_device_e  device)

Definition at line 50 of file stm32_spi.cpp.

50 {
52 return; // already initialized
54 if (device == SPI_DEVICE_1) {
55// todo: introduce a nice structure with all fields for same SPI
56#if STM32_SPI_USE_SPI1
57// scheduleMsg(&logging, "Turning on SPI1 pins");
64#else
65 criticalError("SPI1 not available in this binary");
66#endif /* STM32_SPI_USE_SPI1 */
67 }
68 if (device == SPI_DEVICE_2) {
69#if STM32_SPI_USE_SPI2
70// scheduleMsg(&logging, "Turning on SPI2 pins");
77#else
78 criticalError("SPI2 not available in this binary");
79#endif /* STM32_SPI_USE_SPI2 */
80 }
81 if (device == SPI_DEVICE_3) {
82#if STM32_SPI_USE_SPI3
83// scheduleMsg(&logging, "Turning on SPI3 pins");
90#else
91 criticalError("SPI3 not available in this binary");
92#endif /* STM32_SPI_USE_SPI3 */
93 }
94 if (device == SPI_DEVICE_4) {
95#if STM32_SPI_USE_SPI4
102#else
103 criticalError("SPI4 not available in this binary");
104#endif /* STM32_SPI_USE_SPI4 */
105 }
106 if (device == SPI_DEVICE_5) {
107#if STM32_SPI_USE_SPI5
114#else
115 criticalError("SPI5 not available in this binary");
116#endif /* STM32_SPI_USE_SPI5 */
117 }
118 if (device == SPI_DEVICE_6) {
119#if STM32_SPI_USE_SPI6
126#else
127 criticalError("SPI6 not available in this binary");
128#endif /* STM32_SPI_USE_SPI6 */
129 }
130}
static constexpr engine_configuration_s * engineConfiguration
brain_pin_e getSckPin(spi_device_e device)
Definition hardware.cpp:126
brain_pin_e getMosiPin(spi_device_e device)
Definition hardware.cpp:106
brain_pin_e getMisoPin(spi_device_e device)
Definition hardware.cpp:86
static Lps25 device
Definition init_baro.cpp:4
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, brain_pin_e mosi, int sckMode, int mosiMode, int misoMode)
bool isSpiInitialized[SPI_TOTAL_COUNT+1]
Definition stm32_spi.cpp:13

Referenced by initSpiModules().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ isSpiInitialized

bool isSpiInitialized[SPI_TOTAL_COUNT+1] = { true, false, false, false, false, false, false }

Definition at line 13 of file stm32_spi.cpp.

13{ true, false, false, false, false, false, false };

Referenced by stopSpi(), and turnOnSpi().

◆ mmc_hs_spicfg

SPIConfig mmc_hs_spicfg
Initial value:
= {
.circular = false,
#ifdef _CHIBIOS_RT_CONF_VER_6_1_
.end_cb = NULL,
#else
.slave = false,
.data_cb = NULL,
.error_cb = NULL,
#endif
.ssport = NULL,
.sspad = 0,
.cfg1 = 7
| 0 ,
.cfg2 = 0
}

Definition at line 267 of file stm32_spi.cpp.

267 {
268 .circular = false,
269#ifdef _CHIBIOS_RT_CONF_VER_6_1_
270 .end_cb = NULL,
271#else
272 .slave = false,
273 .data_cb = NULL,
274 .error_cb = NULL,
275#endif
276 .ssport = NULL,
277 .sspad = 0,
278 .cfg1 = 7 // 8 bits per byte
279 | 0 /* MBR = 0, divider = 2 */,
280 .cfg2 = 0
281};

◆ mmc_ls_spicfg

SPIConfig mmc_ls_spicfg
Initial value:
= {
.circular = false,
#ifdef _CHIBIOS_RT_CONF_VER_6_1_
.end_cb = NULL,
#else
.slave = false,
.data_cb = NULL,
.error_cb = NULL,
#endif
.ssport = NULL,
.sspad = 0,
.cfg1 = 7
| SPI_CFG1_MBR_0 ,
.cfg2 = 0
}

Definition at line 284 of file stm32_spi.cpp.

284 {
285 .circular = false,
286#ifdef _CHIBIOS_RT_CONF_VER_6_1_
287 .end_cb = NULL,
288#else
289 .slave = false,
290 .data_cb = NULL,
291 .error_cb = NULL,
292#endif
293 .ssport = NULL,
294 .sspad = 0,
295 .cfg1 = 7 // 8 bits per byte
296 | SPI_CFG1_MBR_0 /* MBR = 001, divider = 4 */,
297 .cfg2 = 0
298};

Go to the source code of this file.