SPI Peripheral#

SPI Peripheral Interface driver.

Flexible SPI Peripheral driver implementation for use in an NCP scenario.

This driver will support both blocking and non-blocking operation, with LDMA backing the background transfers to support nonblocking.

Functions#

void

Initialize the configured USART peripheral for the SPI peripheral operation.

void

Disable the configured USART peripheral for the SPI operation.

int32_t
spi_peripheral_sendBuffer(uint8_t *buffer, size_t length)

Write a data buffer to the controller next time the controller starts clocking SCLK.

int32_t

Write one byte to the controller in a blocking fashion.

size_t

Get the amount of bytes left in the TX data buffer.

void

Enable/disable MISO output.

void

Enable/disable receiving bytes from the controller into the internal buffer.

size_t

Get the amount of bytes ready for reading.

int32_t
spi_peripheral_receiveBuffer(uint8_t *buffer, size_t requestedLength, size_t *receivedLength, bool blocking, uint32_t timeout)

Read from the RX buffer into a local buffer.

int32_t

Get one byte from the SPI peripheral in a blocking fashion.

void
spi_peripheral_flush(bool flushTx, bool flushRx)

Flush one or both buffers.

Function Documentation#

spi_peripheral_init#

void spi_peripheral_init (void )

Initialize the configured USART peripheral for the SPI peripheral operation.

Parameters
N/A

Also sets up GPIO settings for MOSI, MISO, SCLK and SS. After initialization, the SPI peripheral will have RX enabled.


Definition at line 45 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_deinit#

void spi_peripheral_deinit (void )

Disable the configured USART peripheral for the SPI operation.

Parameters
N/A

Definition at line 50 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_sendBuffer#

int32_t spi_peripheral_sendBuffer (uint8_t * buffer, size_t length)

Write a data buffer to the controller next time the controller starts clocking SCLK.

Parameters
[in]buffer

The data buffer to send

[in]length

Number of bytes in the buffer to send

This transfer will be non-blocking and its progress can be tracked through spi_peripheral_getTxBytesLeft.

Returns

  • BOOTLOADER_OK if successful, error code otherwise


Definition at line 62 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_sendByte#

int32_t spi_peripheral_sendByte (uint8_t byte)

Write one byte to the controller in a blocking fashion.

Parameters
[in]byte

The byte to send

Warnings

  • If the controller goes down, this will block forever.

Returns

  • BOOTLOADER_OK if successful, error code otherwise


Definition at line 74 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_getTxBytesLeft#

size_t spi_peripheral_getTxBytesLeft (void )

Get the amount of bytes left in the TX data buffer.

Parameters
N/A

Returns

  • Number of bytes in the transmit buffer still needing to go out


Definition at line 81 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_enableTransmitter#

void spi_peripheral_enableTransmitter (bool enable)

Enable/disable MISO output.

Parameters
[in]enable

True to enable the transmitter, false to disable


Definition at line 88 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_enableReceiver#

void spi_peripheral_enableReceiver (bool enable)

Enable/disable receiving bytes from the controller into the internal buffer.

Parameters
[in]enable

True to enable the receiver, false to disable

This function makes it possible to avoid filling up the buffer with 0xFF while a controller is polling for new data.


Definition at line 97 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_getRxAvailableBytes#

size_t spi_peripheral_getRxAvailableBytes (void )

Get the amount of bytes ready for reading.

Parameters
N/A

Returns


Definition at line 105 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_receiveBuffer#

int32_t spi_peripheral_receiveBuffer (uint8_t * buffer, size_t requestedLength, size_t * receivedLength, bool blocking, uint32_t timeout)

Read from the RX buffer into a local buffer.

Parameters
[out]buffer

The data buffer to receive into

[in]requestedLength

Number of bytes we'd like to read

[out]receivedLength

Number of bytes read

[in]blocking

Indicate whether we should wait for requestedLength bytes to be available and read before returning, or we can read out whatever is currently in the buffer and return.

[in]timeout

Number of milliseconds to wait for data in blocking mode

Returns

  • BOOTLOADER_OK if successful, error code otherwise


Definition at line 120 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_receiveByte#

int32_t spi_peripheral_receiveByte (uint8_t * byte)

Get one byte from the SPI peripheral in a blocking fashion.

Parameters
[out]byte

Pointer to where to put the received byte

Warnings

  • If the controller never clocks in a byte, this function will block forever.

Returns

  • BOOTLOADER_OK if successful, error code otherwise


Definition at line 136 of file platform/bootloader/driver/btl_driver_spi_peripheral.h

spi_peripheral_flush#

void spi_peripheral_flush (bool flushTx, bool flushRx)

Flush one or both buffers.

Parameters
[in]flushTx

Flush the transmit buffer when true

[in]flushRx

Flush the receive buffer when true


Definition at line 144 of file platform/bootloader/driver/btl_driver_spi_peripheral.h