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

Functions

static int findAfForPin (const struct af_pairs *list, brain_pin_e pin)
 
static const struct spi_af * getAfListForSpi (SPIDriver *driver)
 
static int getSpiCsAf (SPIDriver *driver, brain_pin_e pin)
 
static int getSpiSckAf (SPIDriver *driver, brain_pin_e pin)
 
static int getSpiMisoAf (SPIDriver *driver, brain_pin_e pin)
 
static int getSpiMosiAf (SPIDriver *driver, brain_pin_e pin)
 
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 *)
 
int spiCalcClockDiv (SPIDriver *, SPIConfig *, unsigned int)
 

Variables

bool isSpiInitialized [SPI_TOTAL_COUNT+1] = { true, false, false, false, false, false, false }
 
static const struct spi_af spi1_af
 
static const struct spi_af spi2_af
 
static const struct spi_af spi3_af
 
static const struct spi_af spi4_af
 
SPIConfig mmc_hs_spicfg
 
SPIConfig mmc_ls_spicfg
 

Function Documentation

◆ findAfForPin()

static int findAfForPin ( const struct af_pairs *  list,
brain_pin_e  pin 
)
static

Definition at line 65 of file at32_spi.cpp.

66{
67 int i;
68
69 if (list == NULL) {
70 return -1;
71 }
72
73 /* scan all list or until Gpio::Invalid */
74 for (i = 0; (i < AT32_SPI_MAX_POSSIBLE_PINS_FOR_FX) && (list[i].pin != Gpio::Invalid); i++) {
75 if (list[i].pin == pin) {
76 return list[i].af;
77 }
78 }
79 return -1;
80}
@ Invalid
brain_pin_e pin
Definition stm32_adc.cpp:15

Referenced by getSpiCsAf(), getSpiMisoAf(), getSpiMosiAf(), and getSpiSckAf().

Here is the caller graph for this function:

◆ getAfListForSpi()

static const struct spi_af * getAfListForSpi ( SPIDriver *  driver)
static

Definition at line 82 of file at32_spi.cpp.

83{
84#if STM32_SPI_USE_SPI1
85 if (driver == &SPID1) {
86 return &spi1_af;
87 }
88#endif
89#if STM32_SPI_USE_SPI2
90 if (driver == &SPID2) {
91 return &spi2_af;
92 }
93#endif
94#if STM32_SPI_USE_SPI3
95 if (driver == &SPID3) {
96 return &spi3_af;
97 }
98#endif
99#if STM32_SPI_USE_SPI4
100 if (driver == &SPID4) {
101 return &spi4_af;
102 }
103#endif
104 criticalError("SPI interface is not available");
105 return NULL;
106}
static const struct spi_af spi2_af
Definition at32_spi.cpp:39
static const struct spi_af spi4_af
Definition at32_spi.cpp:57
static const struct spi_af spi1_af
Definition at32_spi.cpp:30
static const struct spi_af spi3_af
Definition at32_spi.cpp: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 getSpiCsAf(), getSpiMisoAf(), getSpiMosiAf(), and getSpiSckAf().

Here is the caller graph for this function:

◆ getSpiCsAf()

static int getSpiCsAf ( SPIDriver *  driver,
brain_pin_e  pin 
)
static

Definition at line 110 of file at32_spi.cpp.

111{
112 const struct spi_af *af = getAfListForSpi(driver);
113
114 if (af == NULL)
115 return -1;
116
117 return findAfForPin(af->cs, pin);
118}
static const struct spi_af * getAfListForSpi(SPIDriver *driver)
Definition at32_spi.cpp:82
static int findAfForPin(const struct af_pairs *list, brain_pin_e pin)
Definition at32_spi.cpp:65
Here is the call graph for this function:

◆ getSpiMisoAf()

static int getSpiMisoAf ( SPIDriver *  driver,
brain_pin_e  pin 
)
static

Definition at line 131 of file at32_spi.cpp.

132{
133 const struct spi_af *af = getAfListForSpi(driver);
134
135 if (af == NULL)
136 return -1;
137
138 return findAfForPin(af->miso, pin);
139}

Referenced by initSpiModule().

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

◆ getSpiMosiAf()

static int getSpiMosiAf ( SPIDriver *  driver,
brain_pin_e  pin 
)
static

Definition at line 141 of file at32_spi.cpp.

142{
143 const struct spi_af *af = getAfListForSpi(driver);
144
145 if (af == NULL)
146 return -1;
147
148 return findAfForPin(af->mosi, pin);
149}

Referenced by initSpiModule().

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

◆ getSpiSckAf()

static int getSpiSckAf ( SPIDriver *  driver,
brain_pin_e  pin 
)
static

Definition at line 121 of file at32_spi.cpp.

122{
123 const struct spi_af *af = getAfListForSpi(driver);
124
125 if (af == NULL)
126 return -1;
127
128 return findAfForPin(af->sck, pin);
129}

Referenced by initSpiModule().

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

◆ initSpiCs()

void initSpiCs ( SPIConfig *  spiConfig,
brain_pin_e  csPin 
)

Definition at line 241 of file at32_spi.cpp.

241 {
242 /* TODO: why this is here? */
243#if !defined(HAL_LLD_SELECT_SPI_V2)
244 spiConfig->end_cb = nullptr;
245#else
246 spiConfig->data_cb = nullptr;
247 spiConfig->error_cb = nullptr;
248#endif
249
250 initSpiCsNoOccupy(spiConfig, csPin);
251 efiSetPadMode("chip select", csPin, PAL_STM32_MODE_OUTPUT);
252}
void initSpiCsNoOccupy(SPIConfig *spiConfig, brain_pin_e csPin)
Definition at32_spi.cpp:234
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)

Referenced by initPotentiometer().

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

◆ initSpiCsNoOccupy()

void initSpiCsNoOccupy ( SPIConfig *  spiConfig,
brain_pin_e  csPin 
)

Definition at line 234 of file at32_spi.cpp.

234 {
235 ioportid_t port = getHwPort("spi", csPin);
236 ioportmask_t pin = getHwPin("spi", csPin);
237 spiConfig->ssport = port;
238 spiConfig->sspad = pin;
239}
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.

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 
)

Definition at line 206 of file at32_spi.cpp.

210 {
211
212 int sckAf = getSpiSckAf(driver, sck);
213 int mosiAf = getSpiMosiAf(driver, mosi);
214 int misoAf = getSpiMisoAf(driver, miso);
215
216 if ((sckAf < 0) || (mosiAf < 0) || (misoAf < 0)) {
217 criticalError("Incorrect SPI pin configuration");
218 }
219
220 efiSetPadMode("SPI CLK ", sck,
221 PAL_MODE_ALTERNATE(sckAf) | sckMode | PAL_STM32_OSPEED_HIGHEST);
222
223 efiSetPadMode("SPI MOSI", mosi,
224 PAL_MODE_ALTERNATE(mosiAf) | mosiMode | PAL_STM32_OSPEED_HIGHEST);
225
226 // Activate the internal pullup on MISO: SD cards indicate "busy" by holding MOSI low,
227 // so in case there is no SD card installed, the line could float low and indicate that
228 // the (non existent) card is busy. We pull the line high to indicate "not busy" in case
229 // of a missing card.
230 efiSetPadMode("SPI MISO ", miso,
231 PAL_MODE_ALTERNATE(misoAf) | misoMode | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP);
232}
static int getSpiSckAf(SPIDriver *driver, brain_pin_e pin)
Definition at32_spi.cpp:121
static int getSpiMosiAf(SPIDriver *driver, brain_pin_e pin)
Definition at32_spi.cpp:141
static int getSpiMisoAf(SPIDriver *driver, brain_pin_e pin)
Definition at32_spi.cpp:131

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 260 of file at32_spi.cpp.

261{
262 // TODO: implement
263 return -1;
264}

Referenced by initializeMmcBlockDevice().

Here is the caller graph for this function:

◆ spiGetBaseClock()

int spiGetBaseClock ( SPIDriver *  spip)

Definition at line 254 of file at32_spi.cpp.

255{
256 // TODO: implement
257 return 0;
258}

Referenced by sdStatistics().

Here is the caller graph for this function:

◆ turnOnSpi()

void turnOnSpi ( spi_device_e  device)

Definition at line 151 of file at32_spi.cpp.

151 {
153 return; // already initialized
154 isSpiInitialized[device] = true;
155 if (device == SPI_DEVICE_1) {
156// todo: introduce a nice structure with all fields for same SPI
157#if STM32_SPI_USE_SPI1
158// scheduleMsg(&logging, "Turning on SPI1 pins");
165#else
166 criticalError("SPI1 not available in this binary");
167#endif /* STM32_SPI_USE_SPI1 */
168 }
169 if (device == SPI_DEVICE_2) {
170#if STM32_SPI_USE_SPI2
171 //scheduleMsg(&logging, "Turning on SPI2 pins");
178#else
179 criticalError("SPI2 not available in this binary");
180#endif /* STM32_SPI_USE_SPI2 */
181 }
182 if (device == SPI_DEVICE_3) {
183#if STM32_SPI_USE_SPI3
184 //scheduleMsg(&logging, "Turning on SPI3 pins");
191#else
192 criticalError("SPI3 not available in this binary");
193#endif /* STM32_SPI_USE_SPI3 */
194 }
195 if (device == SPI_DEVICE_4) {
196#if STM32_SPI_USE_SPI4
197 //scheduleMsg(&logging, "Turning on SPI4 pins");
198 /* there are no configuration fields for SPI4 in engineConfiguration, rely on board init code
199 * it should set proper functions for SPI4 pins */
200#else
201 criticalError("SPI4 not available in this binary");
202#endif /* STM32_SPI_USE_SPI4 */
203 }
204}
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, brain_pin_e mosi, int sckMode, int mosiMode, int misoMode)
Definition at32_spi.cpp:206
bool isSpiInitialized[SPI_TOTAL_COUNT+1]
Definition at32_spi.cpp:13
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

Variable Documentation

◆ isSpiInitialized

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

Definition at line 13 of file at32_spi.cpp.

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

Referenced by turnOnSpi().

◆ mmc_hs_spicfg

SPIConfig mmc_hs_spicfg
Initial value:
= {
.circular = false,
#if !defined(HAL_LLD_SELECT_SPI_V2)
.end_cb = NULL,
#else
.slave = false,
.data_cb = NULL,
.error_cb = NULL,
#endif
.ssport = NULL,
.sspad = 0,
.cr1 = SPI_BaudRatePrescaler_2,
.cr2 = 0
}

Definition at line 273 of file at32_spi.cpp.

273 {
274 .circular = false,
275#if !defined(HAL_LLD_SELECT_SPI_V2)
276 .end_cb = NULL,
277#else
278 .slave = false,
279 .data_cb = NULL,
280 .error_cb = NULL,
281#endif
282 .ssport = NULL,
283 .sspad = 0,
284 .cr1 = SPI_BaudRatePrescaler_2,
285 .cr2 = 0
286};

Referenced by initializeMmcBlockDevice(), and sdStatistics().

◆ mmc_ls_spicfg

SPIConfig mmc_ls_spicfg
Initial value:
= {
.circular = false,
#if !defined(HAL_LLD_SELECT_SPI_V2)
.end_cb = NULL,
#else
.slave = false,
.data_cb = NULL,
.error_cb = NULL,
#endif
.ssport = NULL,
.sspad = 0,
.cr1 = SPI_BaudRatePrescaler_8,
.cr2 = 0
}

Definition at line 288 of file at32_spi.cpp.

288 {
289 .circular = false,
290#if !defined(HAL_LLD_SELECT_SPI_V2)
291 .end_cb = NULL,
292#else
293 .slave = false,
294 .data_cb = NULL,
295 .error_cb = NULL,
296#endif
297 .ssport = NULL,
298 .sspad = 0,
299 .cr1 = SPI_BaudRatePrescaler_8,
300 .cr2 = 0
301};

Referenced by initializeMmcBlockDevice(), and sdStatistics().

◆ spi1_af

const struct spi_af spi1_af
static
Initial value:
= {
.cs = {{Gpio::A4, 5}, {Gpio::A15, 5}, {Gpio::E12, 4}, {Gpio::Invalid, 0}},
.sck = {{Gpio::A5, 5}, {Gpio::B3, 5}, {Gpio::E13, 4}, {Gpio::Invalid, 0}},
.miso = {{Gpio::A6, 5}, {Gpio::B4, 5}, {Gpio::E14, 4}, {Gpio::G0, 5}, {Gpio::Invalid, 0}},
.mosi = {{Gpio::A7, 5}, {Gpio::B5, 5}, {Gpio::E15, 4}, {Gpio::G1, 5}, {Gpio::Invalid, 0}}
}

Definition at line 30 of file at32_spi.cpp.

30 {
31 .cs = {{Gpio::A4, 5}, {Gpio::A15, 5}, {Gpio::E12, 4}, {Gpio::Invalid, 0}},
32 .sck = {{Gpio::A5, 5}, {Gpio::B3, 5}, {Gpio::E13, 4}, {Gpio::Invalid, 0}},
33 .miso = {{Gpio::A6, 5}, {Gpio::B4, 5}, {Gpio::E14, 4}, {Gpio::G0, 5}, {Gpio::Invalid, 0}},
34 .mosi = {{Gpio::A7, 5}, {Gpio::B5, 5}, {Gpio::E15, 4}, {Gpio::G1, 5}, {Gpio::Invalid, 0}}
35};

Referenced by getAfListForSpi().

◆ spi2_af

const struct spi_af spi2_af
static
Initial value:
= {
.cs = {{Gpio::A11, 5}, {Gpio::B9, 5}, {Gpio::B12, 5}, {Gpio::D1, 7}, {Gpio::D2, 7}, {Gpio::Invalid, 0}},
.sck = {{Gpio::A9, 5}, {Gpio::B1, 6}, {Gpio::B10, 5}, {Gpio::B13, 5}, {Gpio::C7, 5}, {Gpio::D1, 6}, {Gpio::D3, 5}, {Gpio::Invalid, 0}},
.miso = {{Gpio::A12, 5}, {Gpio::B14, 5}, {Gpio::C2, 5}, {Gpio::D3, 6}, {Gpio::Invalid, 0}},
.mosi = {{Gpio::A10, 5}, {Gpio::B15, 5}, {Gpio::C1, 7}, {Gpio::C3, 5}, {Gpio::D4, 6}, {Gpio::Invalid, 0}}
}

Definition at line 39 of file at32_spi.cpp.

39 {
40 .cs = {{Gpio::A11, 5}, {Gpio::B9, 5}, {Gpio::B12, 5}, {Gpio::D1, 7}, {Gpio::D2, 7}, {Gpio::Invalid, 0}},
41 .sck = {{Gpio::A9, 5}, {Gpio::B1, 6}, {Gpio::B10, 5}, {Gpio::B13, 5}, {Gpio::C7, 5}, {Gpio::D1, 6}, {Gpio::D3, 5}, {Gpio::Invalid, 0}},
42 .miso = {{Gpio::A12, 5}, {Gpio::B14, 5}, {Gpio::C2, 5}, {Gpio::D3, 6}, {Gpio::Invalid, 0}},
43 .mosi = {{Gpio::A10, 5}, {Gpio::B15, 5}, {Gpio::C1, 7}, {Gpio::C3, 5}, {Gpio::D4, 6}, {Gpio::Invalid, 0}}
44};

Referenced by getAfListForSpi().

◆ spi3_af

const struct spi_af spi3_af
static
Initial value:
= {
.cs = {{Gpio::A4, 6}, {Gpio::A15, 6}, {Gpio::Invalid, 0}},
.sck = {{Gpio::B3, 6}, {Gpio::B12, 7}, {Gpio::C10, 6}, {Gpio::Invalid, 0}},
.miso = {{Gpio::A13, 6}, {Gpio::B4, 6}, {Gpio::C11, 6}, {Gpio::Invalid, 0}},
.mosi = {{Gpio::A14, 6}, {Gpio::B0, 7}, {Gpio::B2, 7}, {Gpio::B5, 6}, {Gpio::C1, 5}, {Gpio::C12, 6}, {Gpio::D0, 6}, {Gpio::D6, 5}, {Gpio::Invalid, 0}}
}

Definition at line 48 of file at32_spi.cpp.

48 {
49 .cs = {{Gpio::A4, 6}, {Gpio::A15, 6}, {Gpio::Invalid, 0}},
50 .sck = {{Gpio::B3, 6}, {Gpio::B12, 7}, {Gpio::C10, 6}, {Gpio::Invalid, 0}},
51 .miso = {{Gpio::A13, 6}, {Gpio::B4, 6}, {Gpio::C11, 6}, {Gpio::Invalid, 0}},
52 .mosi = {{Gpio::A14, 6}, {Gpio::B0, 7}, {Gpio::B2, 7}, {Gpio::B5, 6}, {Gpio::C1, 5}, {Gpio::C12, 6}, {Gpio::D0, 6}, {Gpio::D6, 5}, {Gpio::Invalid, 0}}
53};

Referenced by getAfListForSpi().

◆ spi4_af

const struct spi_af spi4_af
static
Initial value:
= {
.cs = {{Gpio::B6, 6}, {Gpio::B12, 6}, {Gpio::E4, 5}, {Gpio::E11, 5}, {Gpio::G14, 6}, {Gpio::Invalid, 0}},
.sck = {{Gpio::B7, 6}, {Gpio::B13, 6}, {Gpio::E2, 5}, {Gpio::E12, 5}, {Gpio::G11, 6}, {Gpio::Invalid, 0}},
.miso = {{Gpio::A11, 6}, {Gpio::B8, 6}, {Gpio::D0, 5}, {Gpio::E5, 5}, {Gpio::E13, 5}, {Gpio::G12, 6}, {Gpio::Invalid, 0}},
.mosi = {{Gpio::A1, 5}, {Gpio::B9, 6}, {Gpio::E6, 5}, {Gpio::E14, 5}, {Gpio::G13, 6}, {Gpio::Invalid, 0}}
}

Definition at line 57 of file at32_spi.cpp.

57 {
58 .cs = {{Gpio::B6, 6}, {Gpio::B12, 6}, {Gpio::E4, 5}, {Gpio::E11, 5}, {Gpio::G14, 6}, {Gpio::Invalid, 0}},
59 .sck = {{Gpio::B7, 6}, {Gpio::B13, 6}, {Gpio::E2, 5}, {Gpio::E12, 5}, {Gpio::G11, 6}, {Gpio::Invalid, 0}},
60 .miso = {{Gpio::A11, 6}, {Gpio::B8, 6}, {Gpio::D0, 5}, {Gpio::E5, 5}, {Gpio::E13, 5}, {Gpio::G12, 6}, {Gpio::Invalid, 0}},
61 .mosi = {{Gpio::A1, 5}, {Gpio::B9, 6}, {Gpio::E6, 5}, {Gpio::E14, 5}, {Gpio::G13, 6}, {Gpio::Invalid, 0}}
62};

Referenced by getAfListForSpi().

Go to the source code of this file.