#include <arch/arm.h>
#include <sys/timer.h>
#include <cfg/spi.h>
#include <cfg/arch/gpio.h>
#include <dev/spibus.h>
#include <dev/gpio.h>
#include <arch/cm3/stm/stm32f10x_rcc.h>
#include <arch/cm3/stm/stm32f10x_gpio.h>
#include <arch/cm3/stm/stm32f10x_usart.h>
#include <dev/irqreg.h>
#include <sys/event.h>
#include <sys/nutdebug.h>
#include <stdlib.h>
#include <errno.h>
Functions | |
int | Stm32UsartBusWait (NUTSPINODE *node, uint32_t tmo) |
Wait until all SPI bus transfers are done. | |
int | Stm32UsartSpiSetup (NUTSPINODE *node) |
Update SPI shadow registers. | |
int | Stm32Usart3ChipSelect (uint_fast8_t cs, uint_fast8_t hi) |
Set the specified chip select to a given level. | |
int | Stm32Usart3BusDeselect (NUTSPINODE *node) |
Deselect a device on the first SPI bus. | |
int | Stm32Usart3BusSelect (NUTSPINODE *node, uint32_t tmo) |
Select a device on the first SPI bus. | |
int | Stm32UsartBusNodeInit (NUTSPINODE *node) |
Initialize an SPI bus node. | |
int | Stm32UsartBusTransfer (NUTSPINODE *node, const void *txbuf, void *rxbuf, int xlen) |
Transfer data on the SPI bus using single buffered interrupt mode. | |
Variables | |
IRQ_HANDLER | sig_USART3 |
IRQ Handler for USART 1. | |
NUTSPIBUS | spiUsart3BusStm32 |
int Stm32UsartBusWait | ( | NUTSPINODE * | node, |
uint32_t | tmo | ||
) |
Wait until all SPI bus transfers are done.
node | Specifies the SPI bus node. |
tmo | Timeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE. |
Referenced by Stm32Usart3BusDeselect().
int Stm32UsartSpiSetup | ( | NUTSPINODE * | node | ) |
Update SPI shadow registers.
node | Specifies the SPI bus node. |
References USART_TypeDef::BRR, _NUTSPIBUS::bus_base, USART_TypeDef::CR1, USART_TypeDef::CR2, _NUTSPINODE::node_bits, _NUTSPINODE::node_bus, _NUTSPINODE::node_mode, _NUTSPINODE::node_rate, _NUTSPINODE::node_stat, NULL, NUTASSERT, NutClockGet, SPI_MODE_CPHA, SPI_MODE_CPOL, SPI_MODE_UPDATE, USART_Clock_Enable, USART_CPHA_2Edge, USART_CPOL_High, USART_LastBit_Enable, USART_Mode_Rx, USART_Mode_Tx, and USART_WordLength_9b.
Referenced by Stm32Usart3BusSelect(), and Stm32UsartBusNodeInit().
int Stm32Usart3ChipSelect | ( | uint_fast8_t | cs, |
uint_fast8_t | hi | ||
) |
Set the specified chip select to a given level.
References EIO, errno, GpioPinSetHigh, GpioPinSetLow, NUTGPIO_PORTD, and rc.
Referenced by Stm32Usart3BusDeselect(), Stm32Usart3BusSelect(), and Stm32UsartBusNodeInit().
int Stm32Usart3BusDeselect | ( | NUTSPINODE * | node | ) |
Deselect a device on the first SPI bus.
Deactivates the chip select and unlocks the bus.
node | Specifies the SPI bus node. |
References _NUTSPIBUS::bus_mutex, _NUTSPINODE::node_bus, _NUTSPINODE::node_cs, _NUTSPINODE::node_mode, NULL, NUT_WAIT_INFINITE, NUTASSERT, NutEventPost(), SPI_MODE_CSHIGH, Stm32Usart3ChipSelect(), and Stm32UsartBusWait().
int Stm32Usart3BusSelect | ( | NUTSPINODE * | node, |
uint32_t | tmo | ||
) |
Select a device on the first SPI bus.
Locks and activates the bus for the specified node.
node | Specifies the SPI bus node. |
tmo | Timeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE. |
References AFIO, USART_TypeDef::BRR, _NUTSPIBUS::bus_base, _NUTSPIBUS::bus_mutex, USART_TypeDef::CR1, USART_TypeDef::CR2, EIO, errno, GPIO_CFG_DISABLED, GPIO_CFG_OUTPUT, GPIO_FullRemap_USART3, GpioPinConfigSet(), _NUTSPINODE::node_bus, _NUTSPINODE::node_cs, _NUTSPINODE::node_mode, _NUTSPINODE::node_stat, NULL, NUTASSERT, NutEventPost(), NutEventWait(), NUTGPIO_PORTD, rc, RCC, RCC_APB1Periph_USART3, RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOD, SPI_MODE_CSHIGH, SPI_MODE_UPDATE, Stm32Usart3ChipSelect(), and Stm32UsartSpiSetup().
int Stm32UsartBusNodeInit | ( | NUTSPINODE * | node | ) |
Initialize an SPI bus node.
This routine is called for each SPI node, which is registered via NutRegisterSpiDevice().
node | Specifies the SPI bus node. |
References USART_TypeDef::BRR, USART_TypeDef::CR1, USART_TypeDef::CR2, malloc(), _NUTSPINODE::node_bus, _NUTSPINODE::node_cs, _NUTSPINODE::node_mode, _NUTSPINODE::node_stat, NULL, NUTASSERT, rc, SPI_MODE_CSHIGH, Stm32Usart3ChipSelect(), Stm32UsartSpiSetup(), USART_Clock_Enable, USART_LastBit_Enable, USART_Mode_Rx, and USART_Mode_Tx.
int Stm32UsartBusTransfer | ( | NUTSPINODE * | node, |
const void * | txbuf, | ||
void * | rxbuf, | ||
int | xlen | ||
) |
Transfer data on the SPI bus using single buffered interrupt mode.
A device must have been selected by calling At91SpiSelect().
node | Specifies the SPI bus node. |
txbuf | Pointer to the transmit buffer. If NULL, undetermined byte values are transmitted. |
rxbuf | Pointer to the receive buffer. If NULL, then incoming data is discarded. |
xlen | Number of bytes to transfer. |
References _NUTSPIBUS::bus_base, USART_TypeDef::DR, _NUTSPINODE::node_bus, NULL, NUTASSERT, USART_TypeDef::SR, and USART_FLAG_RXNE.