35 #error "ChibiOS operates only in SPI_MASTER mode"
39 #error "ChibiOS architectures don't have SPI0"
57 #endif // USE_SPI_SLAVE0
62 #endif //USE_SPI_SLAVE1
67 #endif //USE_SPI_SLAVE2
72 #endif //USE_SPI_SLAVE3
77 #endif //USE_SPI_SLAVE4
82 #endif //USE_SPI_SLAVE5
104 #endif // USE_SPI_SLAVE0
109 #endif //USE_SPI_SLAVE1
114 #endif //USE_SPI_SLAVE2
119 #endif //USE_SPI_SLAVE3
124 #endif //USE_SPI_SLAVE4
129 #endif //USE_SPI_SLAVE5
151 #if defined(__STM32F10x_H) || defined(__STM32F4xx_H)
156 CR1 |= SPI_CR1_LSBFIRST;
175 CR1 |= SPI_CR1_BR_1 | SPI_CR1_BR_0;
181 CR1 |= SPI_CR1_BR_2 | SPI_CR1_BR_0;
184 CR1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1;
217 SPIConfig spi_cfg = {
225 static size_t t_length;
233 spiStart((SPIDriver *)p->
reg_addr, &spi_cfg);
234 spiSelect((SPIDriver *)p->
reg_addr);
246 spiUnselect((SPIDriver *)p->
reg_addr);
276 static __attribute__((noreturn)) void
thd_spi1(
void *arg)
279 chRegSetThreadName(
"spi1");
290 spi1.reg_addr = &SPID1;
291 spi1.init_struct = &spi1_sem;
293 chThdCreateStatic(wa_thd_spi1,
sizeof(wa_thd_spi1),
300 static __attribute__((noreturn)) void
thd_spi2(
void *arg)
303 chRegSetThreadName(
"spi2");
314 spi2.reg_addr = &SPID2;
315 spi2.init_struct = &spi2_sem;
317 chThdCreateStatic(wa_thd_spi2,
sizeof(wa_thd_spi2),
324 static __attribute__((noreturn)) void thd_spi3(
void *arg)
327 chRegSetThreadName(
"spi3");
336 void spi3_arch_init(
void)
338 spi3.reg_addr = &SPID3;
339 spi3.init_struct = &spi3_sem;
341 chThdCreateStatic(wa_thd_spi3,
sizeof(wa_thd_spi3),
342 NORMALPRIO+1, thd_spi3, NULL);
404 #endif // USE_SPI_SLAVE0
409 #endif //USE_SPI_SLAVE1
414 #endif //USE_SPI_SLAVE2
419 #endif //USE_SPI_SLAVE3
424 #endif //USE_SPI_SLAVE4
429 #endif //USE_SPI_SLAVE5
446 #endif // USE_SPI_SLAVE0
451 #endif //USE_SPI_SLAVE1
456 #endif //USE_SPI_SLAVE2
461 #endif //USE_SPI_SLAVE3
466 #endif //USE_SPI_SLAVE4
471 #endif //USE_SPI_SLAVE5
484 if (slave < 254 && p->suspend == 0) {
enum SPIClockPolarity cpol
clock polarity control
static uint16_t spi_resolve_slave_pin(uint8_t slave)
Resolve slave pin.
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
uint16_t output_length
number of data words to write
#define SPI_SELECT_SLAVE4_PORT
process_rx_dma_interrupt & spi2
receive transferred over DMA
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
void spi1_arch_init(void)
Architecture dependent SPI1 initialization.
static uint16_t spi_resolve_CR1(struct spi_transaction *t)
Resolve CR1.
Some architecture independent helper functions for GPIOs.
SPI transaction structure.
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
static void handle_spi_thd(struct spi_periph *p)
main thread function
enum SPIBitOrder bitorder
MSB/LSB order.
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
volatile uint8_t suspend
control for stop/resume of the fifo
static SEMAPHORE_DECL(spi1_sem, 0)
Configure SPI peripherals.
Architecture independent SPI (Serial Peripheral Interface) API.
#define SPI_SELECT_SLAVE5_PIN
#define SPI_SELECT_SLAVE1_PORT
enum SPIClockPhase cpha
clock phase control
bool spi_lock(struct spi_periph *p, uint8_t slave)
spi_lock() function
SPI peripheral structure.
#define SPI_SELECT_SLAVE0_PIN
void spi_slave_unselect(uint8_t slave)
spi_slave_unselect() function
#define SPI_SELECT_SLAVE2_PORT
SPICallback after_cb
NULL or function called after the transaction.
#define SPI_SELECT_SLAVE0_PORT
void spi2_arch_init(void)
Architecture dependent SPI2 initialization.
#define SPI_SELECT_SLAVE1_PIN
static ioportid_t spi_resolve_slave_port(uint8_t slave)
Resolve slave port.
#define SPI_SELECT_SLAVE2_PIN
uint16_t input_length
number of data words to read
enum SPIStatus status
internal state of the peripheral
#define SPI_SELECT_SLAVE3_PIN
#define SPI_SELECT_SLAVE4_PIN
bool spi_resume(struct spi_periph *p, uint8_t slave)
spi_resume() function
uint8_t trans_extract_idx
enum SPIDataSizeSelect dss
data transfer word size
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
static void thd_spi1(void *arg)
volatile uint8_t * input_buf
pointer to receive buffer for DMA
SPICallback before_cb
NULL or function called before the transaction.
#define SPI_TRANSACTION_QUEUE_LEN
SPI transaction queue length.
static void thd_spi2(void *arg)
void spi_init_slaves(void)
spi_init_slaves() function
void spi_slave_select(uint8_t slave)
spi_slave_select() function
#define SPI_SELECT_SLAVE5_PORT
#define SPI_SELECT_SLAVE3_PORT
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
struct spi_transaction * trans[SPI_TRANSACTION_QUEUE_LEN]
circular buffer holding transactions
process_rx_dma_interrupt & spi1
receive transferred over DMA
static THD_WORKING_AREA(wa_thd_spi1, 1024)
enum SPITransactionStatus status