semf
semf::Stm32SpiMaster Class Reference

SpiMasterHardware implementation for STM32. More...

#include <stm32spimaster.h>

Inheritance diagram for semf::Stm32SpiMaster:
Inheritance graph
Collaboration diagram for semf::Stm32SpiMaster:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Init_HalError = 0 , Init_HalBusy , Init_HalTimeout , Deinit_HalError ,
  Deinit_HalBusy , Deinit_HalTimeout , SetFrequency_IsBusy , SetFrequency_SpiClockIsZero ,
  IsrError_Isr , SetFormatHardware_BitsNotSupported , StopWriteHardware_HalError , StopWriteHardware_HalBusy ,
  StopWriteHardware_HalTimeout , StopReadHardware_HalError , StopReadHardware_HalBusy , StopReadHardware_HalTimeout ,
  Write_HalError , Write_HalBusy , Write_HalTimeout , ReadNext_HalError ,
  ReadNext_HalBusy , ReadNext_HalTimeout , WriteReadNext_HalError , WriteReadNext_HalBusy ,
  WriteReadNext_HalTimeout
}
 
- Public Types inherited from semf::SpiMasterHardware
enum class  ErrorCode : uint8_t {
  Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Read_IsBusy ,
  Read_BufferIsNullptr , Read_BufferSizeIsZero , SetFormat_IsBusy , StopWrite_IsReadOnly ,
  StopRead_IsWriteOnly , WriteRead_IsBusy , WriteRead_WriteDataIsNullptr , WriteRead_ReadBufferIsNullptr ,
  WriteRead_SizeIsZero , SetChipSelectPin_IsBusy
}
 Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring). More...
 
- Public Types inherited from semf::Spi
enum class  TransmissionMode : uint8_t { Mode0 , Mode1 , Mode2 , Mode3 }
 
enum class  WireMode : uint8_t { FullDuplexWires , HalfDuplexWires , WriteOnlyWires , ReadOnlyWires }
 
- Public Types inherited from semf::CommunicationHardware
enum class  Type { SynchronousMaster = 1 , SynchronousSlave , Asynchronous }
 
enum class  Frame : uint8_t { First = 0x01 , Next = 0x08 , Last = 0x10 , FirstAndLast = 0x11 }
 

Public Member Functions

 Stm32SpiMaster (SPI_HandleTypeDef &hwHandle, uint32_t spiClockFrequencyHz=0)
 Constructor. More...
 
 Stm32SpiMaster (SPI_HandleTypeDef &hwHandle, Gpio &chipSelectPin, uint32_t spiClockFrequencyHz=0)
 Constructor. More...
 
 Stm32SpiMaster (const Stm32SpiMaster &other)=delete
 
virtual ~Stm32SpiMaster ()=default
 
void init () override
 
void deinit () override
 
void setFrequency (uint32_t hz) override
 Sets the speed. More...
 
void isrRead (SPI_HandleTypeDef &spi)
 Interrupt service routine for spi object receive. More...
 
void isrWritten (SPI_HandleTypeDef &spi)
 
void isrWrittenAndRead (SPI_HandleTypeDef &spi)
 Interrupt service routine for spi object receive and transmit. More...
 
void isrError (SPI_HandleTypeDef &spi)
 Interrupt service routine for spi object error. More...
 
void isrAborted (SPI_HandleTypeDef &spi)
 handles the abort callback More...
 
- Public Member Functions inherited from semf::SpiMasterHardware
 SpiMasterHardware ()=default
 
 SpiMasterHardware (Gpio &chipSelectPin)
 
virtual ~SpiMasterHardware ()=default
 
void write (const uint8_t data[], size_t dataSize) override
 For writing data, dataWritten signal will be emitted after successful write. More...
 
void read (uint8_t buffer[], size_t bufferSize) override
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
bool isBusyReading () const override
 Communication hardware is busy reading at the moment. More...
 
bool isBusyWriting () const override
 Communication hardware is busy writing at the moment. More...
 
void setFrame (CommunicationHardware::Frame frame) override
 Sets the selected usage of start and stop condition. More...
 
void setFormat (uint8_t bits, TransmissionMode transmission, WireMode wire) override
 Sets the format for the spi slave device. More...
 
void stopWrite () override
 
void stopRead () override
 
void writeRead (const uint8_t writeData[], uint8_t readBuffer[], size_t size) override
 For writing and reading data parallel through the communication hardware 1) For interrupt or one shot dma mode, dataAvailable signal will be fired after successful read/write. 2) For cyclic dma mode, do not use this function. More...
 
virtual void setChipSelectPin (Gpio &chipSelectPin)
 Sets a new chip select pin read and write operations. More...
 
void enableChipSelect ()
 
void disableChipSelect ()
 
virtual void setFrequency (uint32_t hz)=0
 Sets the speed. More...
 
- Public Member Functions inherited from semf::Spi
virtual ~Spi ()=default
 
virtual void writeRead (const uint8_t writeData[], uint8_t readBuffer[], size_t size)=0
 For writing and reading data parallel through the communication hardware 1) For interrupt or one shot dma mode, dataAvailable signal will be fired after successful read/write. 2) For cyclic dma mode, do not use this function. More...
 
virtual void setFormat (uint8_t bits, TransmissionMode transmission, WireMode wire)=0
 Sets the format for the spi slave device. More...
 
- Public Member Functions inherited from semf::CommunicationHardwareSynchronousMaster
virtual ~CommunicationHardwareSynchronousMaster ()=default
 
Type type () const override
 Returns the hardware type. More...
 
- Public Member Functions inherited from semf::CommunicationHardware
virtual ~CommunicationHardware ()=default
 
virtual void init ()=0
 
virtual void deinit ()=0
 
virtual Type type () const =0
 Returns the hardware type. More...
 
virtual void setFrame (Frame frame)=0
 Sets the selected usage of start and stop condition. More...
 
- Public Member Functions inherited from semf::app::Communication
virtual ~Communication ()=default
 
virtual void write (const uint8_t data[], size_t dataSize)=0
 For writing data, dataWritten signal will be emitted after successful write. More...
 
virtual void read (uint8_t buffer[], size_t bufferSize)=0
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
virtual void stopRead ()=0
 
virtual void stopWrite ()=0
 
virtual bool isBusyReading () const =0
 Communication hardware is busy reading at the moment. More...
 
virtual bool isBusyWriting () const =0
 Communication hardware is busy writing at the moment. More...
 
- Public Member Functions inherited from semf::LinkedQueue< T >::Node
virtual ~Node ()=default
 
T * next () const
 Returns a pointer to the next element in a queue. More...
 
void setNext (T *next)
 Sets a pointer to the next element in a list. More...
 
bool isInQueue (LinkedQueue &queue)
 Returns if a node is part of this LinkedQueue. More...
 

Static Public Member Functions

static LinkedQueue< Stm32SpiMaster > * queue ()
 Get the list with all spi. More...
 
static void systemIsrRead (SPI_HandleTypeDef &spi)
 System-wide interrupt service routine for spi receive. More...
 
static void systemIsrWritten (SPI_HandleTypeDef &spi)
 System-wide interrupt service routine for spi transmit. More...
 
static void systemIsrWrittenAndRead (SPI_HandleTypeDef &spi)
 System-wide interrupt service routine for spi receive and transmit. More...
 
static void systemIsrError (SPI_HandleTypeDef &spi)
 System-wide interrupt service routine for spi error. More...
 
static void systemIsrAbort (SPI_HandleTypeDef &spi)
 System-wide interrupt service routine for spi abort. More...
 

Protected Member Functions

void writeHardware (const uint8_t data[], size_t dataSize) override
 Hardware will write data. More...
 
void readHardware (uint8_t buffer[], size_t bufferSize) override
 Hardware will read data. More...
 
void writeReadHardware (const uint8_t writeData[], uint8_t readBuffer[], size_t size) override
 Hardware will read and write data parallel. More...
 
void setFormatHardware (uint8_t bits, TransmissionMode transmission, WireMode wire) override
 Configures the hardware for insuring the given configuration. More...
 
void stopWriteHardware () override
 
void stopReadHardware () override
 
- Protected Member Functions inherited from semf::SpiMasterHardware
void setBusy (bool isBusy)
 Sets the busy flag. More...
 
CommunicationHardware::Frame frame () const
 Returns the actual frame mode setting. More...
 
virtual void writeHardware (const uint8_t data[], size_t dataSize)=0
 Hardware will write data. More...
 
virtual void readHardware (uint8_t buffer[], size_t bufferSize)=0
 Hardware will read data. More...
 
virtual void writeReadHardware (const uint8_t writeData[], uint8_t readBuffer[], size_t size)=0
 Hardware will read and write data parallel. More...
 
virtual void setFormatHardware (uint8_t bits, TransmissionMode transmission, WireMode wire)=0
 Configures the hardware for insuring the given configuration. More...
 
virtual void stopWriteHardware ()=0
 
virtual void stopReadHardware ()=0
 
void onDataWritten ()
 
void onDataAvailable ()
 
void onError (Error thrown)
 Is called if an error occurred by hardware read or write access. Will throw error signal. More...
 
void setTransmissionMode (TransmissionMode mode)
 Sets the transmission mode. More...
 
void setWireMode (WireMode mode)
 Sets the wire mode. More...
 

Additional Inherited Members

- Public Attributes inherited from semf::app::Communication
Signal dataWritten
 
Signal dataAvailable
 
Signal writeStopped
 
Signal readStopped
 
Signal< Errorerror
 

Detailed Description

SpiMasterHardware implementation for STM32.

Definition at line 24 of file stm32spimaster.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::Stm32SpiMaster::ErrorCode : uint8_t
strong

Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring).

Enumerator
Init_HalError 
Init_HalBusy 
Init_HalTimeout 
Deinit_HalError 
Deinit_HalBusy 
Deinit_HalTimeout 
SetFrequency_IsBusy 
SetFrequency_SpiClockIsZero 
IsrError_Isr 
SetFormatHardware_BitsNotSupported 
StopWriteHardware_HalError 
StopWriteHardware_HalBusy 
StopWriteHardware_HalTimeout 
StopReadHardware_HalError 
StopReadHardware_HalBusy 
StopReadHardware_HalTimeout 
Write_HalError 
Write_HalBusy 
Write_HalTimeout 
ReadNext_HalError 
ReadNext_HalBusy 
ReadNext_HalTimeout 
WriteReadNext_HalError 
WriteReadNext_HalBusy 
WriteReadNext_HalTimeout 

Definition at line 28 of file stm32spimaster.h.

Constructor & Destructor Documentation

◆ Stm32SpiMaster() [1/3]

semf::Stm32SpiMaster::Stm32SpiMaster ( SPI_HandleTypeDef &  hwHandle,
uint32_t  spiClockFrequencyHz = 0 
)
explicit

Constructor.

Parameters
hwHandleHardware spi handle.
spiClockFrequencyHzFrequency of the clock running the SPI module in Hz.

Definition at line 18 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ Stm32SpiMaster() [2/3]

semf::Stm32SpiMaster::Stm32SpiMaster ( SPI_HandleTypeDef &  hwHandle,
Gpio chipSelectPin,
uint32_t  spiClockFrequencyHz = 0 
)

Constructor.

Parameters
hwHandleSPI hardware interface.
chipSelectPinGpio for chip select.
spiClockFrequencyHzFrequency of the clock running the SPI module in Hz.

Definition at line 26 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ Stm32SpiMaster() [3/3]

semf::Stm32SpiMaster::Stm32SpiMaster ( const Stm32SpiMaster other)
explicitdelete

◆ ~Stm32SpiMaster()

virtual semf::Stm32SpiMaster::~Stm32SpiMaster ( )
virtualdefault

Member Function Documentation

◆ deinit()

void semf::Stm32SpiMaster::deinit ( )
overridevirtual

Deinitializes the hardware

Exceptions
Deinit_HalErrorIf the ST-HAL returns a hal error.
Deinit_HalBusyIf the ST-HAL returns a hal busy.
Deinit_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::CommunicationHardware.

Definition at line 60 of file stm32spimaster.cpp.

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

◆ init()

void semf::Stm32SpiMaster::init ( )
overridevirtual

Initializes the hardware.

Exceptions
Init_HalErrorIf the ST-HAL returns a hal error.
Init_HalBusyIf the ST-HAL returns a hal busy.
Init_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::CommunicationHardware.

Definition at line 35 of file stm32spimaster.cpp.

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

◆ isrAborted()

void semf::Stm32SpiMaster::isrAborted ( SPI_HandleTypeDef &  spi)

handles the abort callback

Parameters
spiHardware handler.

Definition at line 244 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ isrError()

void semf::Stm32SpiMaster::isrError ( SPI_HandleTypeDef &  spi)

Interrupt service routine for spi object error.

Parameters
spiHardware handler.
Exceptions
IsrError_IsrIf an unexpected error occurres.

Definition at line 235 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ isrRead()

void semf::Stm32SpiMaster::isrRead ( SPI_HandleTypeDef &  spi)

Interrupt service routine for spi object receive.

Parameters
spiHardware handler.

Definition at line 183 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ isrWritten()

void semf::Stm32SpiMaster::isrWritten ( SPI_HandleTypeDef &  spi)

Definition at line 203 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ isrWrittenAndRead()

void semf::Stm32SpiMaster::isrWrittenAndRead ( SPI_HandleTypeDef &  spi)

Interrupt service routine for spi object receive and transmit.

Parameters
spiHardware handler.

Definition at line 214 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ queue()

LinkedQueue< Stm32SpiMaster > * semf::Stm32SpiMaster::queue ( )
static

Get the list with all spi.

Returns
The list with all spi.

Definition at line 147 of file stm32spimaster.cpp.

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

◆ readHardware()

void semf::Stm32SpiMaster::readHardware ( uint8_t  buffer[],
size_t  bufferSize 
)
overrideprotectedvirtual

Hardware will read data.

Parameters
bufferdata array
bufferSizedata array size

Implements semf::SpiMasterHardware.

Definition at line 280 of file stm32spimaster.cpp.

◆ setFormatHardware()

void semf::Stm32SpiMaster::setFormatHardware ( uint8_t  bits,
Stm32SpiMaster::TransmissionMode  transmission,
Stm32SpiMaster::WireMode  wire 
)
overrideprotectedvirtual

Configures the hardware for insuring the given configuration.

Parameters
bitsNumber of bits per frame.
transmissionTransmission mode (polarity and phase setting).
wireWire transmission setting.
Exceptions
SetFormatHardware_BitsNotSupportedIf value for bit is not supported (8 and 16 are allowed).

Implements semf::SpiMasterHardware.

Definition at line 299 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ setFrequency()

void semf::Stm32SpiMaster::setFrequency ( uint32_t  hz)
overridevirtual

Sets the speed.

Parameters
hzFrequency in hz.
Exceptions
SetFrequency_IsBusyIf this is busy.
SetFrequency_SpiClockIsZeroIf spiClockFrequencyHz is not initialized.

Implements semf::SpiMasterHardware.

Definition at line 85 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ stopReadHardware()

void semf::Stm32SpiMaster::stopReadHardware ( )
overrideprotectedvirtual

Forces the hardware to stop a reading process

Exceptions
StopReadHardware_HalErrorIf the ST-HAL returns a hal error.
StopReadHardware_HalBusyIf the ST-HAL returns a hal busy.
StopReadHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::SpiMasterHardware.

Definition at line 372 of file stm32spimaster.cpp.

◆ stopWriteHardware()

void semf::Stm32SpiMaster::stopWriteHardware ( )
overrideprotectedvirtual

Forces the hardware to stop a writing process.

Exceptions
StopWriteHardware_HalErrorIf the ST-HAL returns a hal error.
StopWriteHardware_HalBusyIf the ST-HAL returns a hal busy.
StopWriteHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::SpiMasterHardware.

Definition at line 347 of file stm32spimaster.cpp.

◆ systemIsrAbort()

void semf::Stm32SpiMaster::systemIsrAbort ( SPI_HandleTypeDef &  spi)
static

System-wide interrupt service routine for spi abort.

Parameters
spiHardware handler.

Definition at line 177 of file stm32spimaster.cpp.

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

◆ systemIsrError()

void semf::Stm32SpiMaster::systemIsrError ( SPI_HandleTypeDef &  spi)
static

System-wide interrupt service routine for spi error.

Parameters
spiHardware handler.

Definition at line 171 of file stm32spimaster.cpp.

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

◆ systemIsrRead()

void semf::Stm32SpiMaster::systemIsrRead ( SPI_HandleTypeDef &  spi)
static

System-wide interrupt service routine for spi receive.

Parameters
spiHardware handler.

Definition at line 153 of file stm32spimaster.cpp.

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

◆ systemIsrWritten()

void semf::Stm32SpiMaster::systemIsrWritten ( SPI_HandleTypeDef &  spi)
static

System-wide interrupt service routine for spi transmit.

Parameters
spiHardware handler.

Definition at line 159 of file stm32spimaster.cpp.

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

◆ systemIsrWrittenAndRead()

void semf::Stm32SpiMaster::systemIsrWrittenAndRead ( SPI_HandleTypeDef &  spi)
static

System-wide interrupt service routine for spi receive and transmit.

Parameters
spiHardware handler.

Definition at line 165 of file stm32spimaster.cpp.

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

◆ writeHardware()

void semf::Stm32SpiMaster::writeHardware ( const uint8_t  data[],
size_t  dataSize 
)
overrideprotectedvirtual

Hardware will write data.

Parameters
datadata array
dataSizedata array size
Exceptions
Write_HalErrorIf the ST-HAL returns a hal error.
Write_HalBusyIf the ST-HAL returns a hal busy.
Write_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::SpiMasterHardware.

Definition at line 254 of file stm32spimaster.cpp.

Here is the call graph for this function:

◆ writeReadHardware()

void semf::Stm32SpiMaster::writeReadHardware ( const uint8_t  writeData[],
uint8_t  readBuffer[],
size_t  size 
)
overrideprotectedvirtual

Hardware will read and write data parallel.

Parameters
writeDatamemory where to write from
readBuffermemory where to store read data
sizedata array size

Implements semf::SpiMasterHardware.

Definition at line 289 of file stm32spimaster.cpp.