semf
semf::Stm32Uart Class Reference

UartHardware implemenation for STM32. More...

#include <stm32uart.h>

Inheritance diagram for semf::Stm32Uart:
Inheritance graph
Collaboration diagram for semf::Stm32Uart:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Init_HalError = 0 , Init_HalBusy , Init_HalTimeout , Deinit_HalError ,
  Deinit_HalBusy , Deinit_HalTimeout , StopWrite_HalError , StopWrite_HalBusy ,
  StopWrite_HalTimeout , StopRead_HalError , StopRead_HalBusy , StopRead_HalTimeout ,
  SetFormat_WordLengthInvalid , SetFormat_WireInvalid , SetFormat_ParityInvalid , SetFormat_StopBitsInvalid ,
  SetFormat_FlowInvalid , WriteHardware_HalError , WriteHardware_HalBusy , WriteHardware_HalTimeout ,
  ReadHardware_HalError , ReadHardware_HalBusy , ReadHardware_HalTimeout
}
 
- Public Types inherited from semf::UartHardware
enum class  ErrorCode : uint8_t {
  Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Read_IsBusy ,
  Read_BufferIsNullptr , Read_BufferSizeIsZero
}
 Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring). More...
 
- Public Types inherited from semf::Uart
enum class  FlowControl : uint8_t { NoFlowControl = 0x00 , RtsFlowControl = 0x01 , CtsFlowControl = 0x10 , RtsAndCtsFlowControl = 0x11 }
 
enum class  Parity : uint8_t { NoParity , OddParity , EvenParity }
 
enum class  StopBits : uint8_t { Stopbits_0_5 , Stopbits_1 , Stopbits_1_5 , Stopbits_2 }
 
enum class  WireMode : uint8_t { ReadWire , WriteWire , ReadAndWriteWires }
 
- 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

 Stm32Uart (UART_HandleTypeDef &hwHandle)
 Constructor. More...
 
 Stm32Uart (const Stm32Uart &other)=delete
 
virtual ~Stm32Uart ()=default
 
void init () override
 
void deinit () override
 
void stopWrite () override
 
void stopRead () override
 
void setFormat (uint8_t bits, WireMode wire, Parity par, StopBits stop, FlowControl flow) override
 Sets the format for the spi slave device. More...
 
void setBaud (uint32_t baud) override
 Sets the baud rate. More...
 
uint32_t baud () override
 Returns the currently used baud rate. More...
 
void isrRead (UART_HandleTypeDef &uart)
 Interrupt service routine for uart object receive. More...
 
void isrWritten (UART_HandleTypeDef &uart)
 Interrupt service routine for uart object transmit. More...
 
- Public Member Functions inherited from semf::UartHardware
virtual ~UartHardware ()=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...
 
- Public Member Functions inherited from semf::Uart
virtual ~Uart ()=default
 
virtual void setFormat (uint8_t bits, WireMode wire, Parity par, StopBits stop, FlowControl flow)=0
 Sets the format for the spi slave device. More...
 
virtual void setBaud (uint32_t baud)=0
 Sets the baud rate. More...
 
virtual uint32_t baud ()=0
 Returns the currently used baud rate. More...
 
- Public Member Functions inherited from semf::CommunicationHardwareAsynchronous
virtual ~CommunicationHardwareAsynchronous ()=default
 
Type type () const override
 Returns the hardware type. More...
 
void setFrame (Frame frame) final
 Sets the selected usage of start and stop condition. 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< Stm32Uart > * queue ()
 Get the list with all uarts. More...
 
static void systemIsrRead (UART_HandleTypeDef &uart)
 System-wide interrupt service routine for uart receive. More...
 
static void systemIsrWritten (UART_HandleTypeDef &uart)
 System-wide interrupt service routine for uart transmit. More...
 

Protected Member Functions

void writeHardware (const uint8_t data[], size_t dataSize) override
 Hardware will write data in interrupt mode. More...
 
void readHardware (uint8_t buffer[], size_t bufferSize) override
 Hardware will read data in interrupt mode. More...
 
- Protected Member Functions inherited from semf::UartHardware
void setBusyReading (bool isBusy)
 Sets the busy flag for reading. More...
 
void setBusyWriting (bool isBusy)
 Sets the busy flag for writing. More...
 
virtual void writeHardware (const uint8_t data[], size_t dataSize)=0
 Hardware will write data in interrupt mode. More...
 
virtual void readHardware (uint8_t buffer[], size_t bufferSize)=0
 Hardware will read data in interrupt mode. More...
 
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...
 

Additional Inherited Members

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

Detailed Description

UartHardware implemenation for STM32.

Definition at line 23 of file stm32uart.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::Stm32Uart::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 
StopWrite_HalError 
StopWrite_HalBusy 
StopWrite_HalTimeout 
StopRead_HalError 
StopRead_HalBusy 
StopRead_HalTimeout 
SetFormat_WordLengthInvalid 
SetFormat_WireInvalid 
SetFormat_ParityInvalid 
SetFormat_StopBitsInvalid 
SetFormat_FlowInvalid 
WriteHardware_HalError 
WriteHardware_HalBusy 
WriteHardware_HalTimeout 
ReadHardware_HalError 
ReadHardware_HalBusy 
ReadHardware_HalTimeout 

Definition at line 27 of file stm32uart.h.

Constructor & Destructor Documentation

◆ Stm32Uart() [1/2]

semf::Stm32Uart::Stm32Uart ( UART_HandleTypeDef &  hwHandle)
explicit

Constructor.

Parameters
hwHandleuart hardware interface

Definition at line 26 of file stm32uart.cpp.

Here is the call graph for this function:

◆ Stm32Uart() [2/2]

semf::Stm32Uart::Stm32Uart ( const Stm32Uart other)
explicitdelete

◆ ~Stm32Uart()

virtual semf::Stm32Uart::~Stm32Uart ( )
virtualdefault

Member Function Documentation

◆ baud()

uint32_t semf::Stm32Uart::baud ( )
overridevirtual

Returns the currently used baud rate.

Returns
Baud rate.

Implements semf::Uart.

Definition at line 269 of file stm32uart.cpp.

Here is the caller graph for this function:

◆ deinit()

void semf::Stm32Uart::deinit ( )
overridevirtual

Deinitializes the hardware

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

Implements semf::CommunicationHardware.

Definition at line 57 of file stm32uart.cpp.

Here is the call graph for this function:

◆ init()

void semf::Stm32Uart::init ( )
overridevirtual

Initializes the hardware.

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

Implements semf::CommunicationHardware.

Definition at line 32 of file stm32uart.cpp.

Here is the call graph for this function:

◆ isrRead()

void semf::Stm32Uart::isrRead ( UART_HandleTypeDef &  uart)

Interrupt service routine for uart object receive.

Parameters
uartHardware handler.

Definition at line 292 of file stm32uart.cpp.

Here is the call graph for this function:

◆ isrWritten()

void semf::Stm32Uart::isrWritten ( UART_HandleTypeDef &  uart)

Interrupt service routine for uart object transmit.

Parameters
uartHardware handler.

Definition at line 300 of file stm32uart.cpp.

Here is the call graph for this function:

◆ queue()

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

Get the list with all uarts.

Returns
The list with all uarts.

Definition at line 274 of file stm32uart.cpp.

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

◆ readHardware()

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

Hardware will read data in interrupt mode.

Parameters
bufferdata array.
bufferSizedata array size.
Exceptions
ReadHardware_HalErrorIf the ST-HAL returns a hal error.
ReadHardware_HalBusyIf the ST-HAL returns a hal bussy.
ReadHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::UartHardware.

Definition at line 333 of file stm32uart.cpp.

Here is the call graph for this function:

◆ setBaud()

void semf::Stm32Uart::setBaud ( uint32_t  baud)
overridevirtual

Sets the baud rate.

Parameters
baudBaud rate.

Implements semf::Uart.

Definition at line 261 of file stm32uart.cpp.

Here is the call graph for this function:

◆ setFormat()

void semf::Stm32Uart::setFormat ( uint8_t  bits,
WireMode  wire,
Parity  par,
StopBits  stop,
FlowControl  flow 
)
overridevirtual

Sets the format for the spi slave device.

Parameters
bitsNumber of data bits (without parity) per frame.
wireFull duplex mode or half duplex mode.
parParity.
stopStop bits.
flowFlow control.
Note
Number of data bits differs that the number of bits to be send. i.e.: in case of sending a frame 8 bits without parity, number of data bits should be 8 bits. i.e.: in case of sending a frame of 8 bits including a parity, number of bits should be 7 bits.
Exceptions
SetFormat_WordLengthInvalidIf bits is invalid (7, 8 and 9 are possible).
SetFormat_WireInvalidIf wire is invalid.
SetFormat_ParityInvalidIf par is invalid.
SetFormat_StopBitsInvalidIf stop is invalid.
SetFormat_FlowInvalidIf flow is invalid.

Implements semf::Uart.

Definition at line 134 of file stm32uart.cpp.

Here is the call graph for this function:

◆ stopRead()

void semf::Stm32Uart::stopRead ( )
overridevirtual

Stops the read process as fast as possible without destroying anything. The readStopped Signal gets emitted if the call was successful.

Exceptions
StopRead_HalErrorIf the ST-HAL returns a hal error.
StopRead_HalBusyIf the ST-HAL returns a hal bussy.
StopRead_HalTimeoutIf the ST-HAL returns a hal timeout.
Note
This implementation is blocking and emits readStopped without stack overflow protection

Implements semf::app::Communication.

Definition at line 108 of file stm32uart.cpp.

Here is the call graph for this function:

◆ stopWrite()

void semf::Stm32Uart::stopWrite ( )
overridevirtual

Stops the write process as fast as possible without destroying anything. The writeStopped Signal gets emitted if the call was successful.

Exceptions
StopWrite_HalErrorIf the ST-HAL returns a hal error.
StopWrite_HalBusyIf the ST-HAL returns a hal bussy.
StopWrite_HalTimeoutIf the ST-HAL returns a hal timeout.
Note
This implementation is blocking and emits writeStopped without stack overflow protection

Implements semf::app::Communication.

Definition at line 82 of file stm32uart.cpp.

Here is the call graph for this function:

◆ systemIsrRead()

void semf::Stm32Uart::systemIsrRead ( UART_HandleTypeDef &  uart)
static

System-wide interrupt service routine for uart receive.

Parameters
uartHardware handler.

Definition at line 280 of file stm32uart.cpp.

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

◆ systemIsrWritten()

void semf::Stm32Uart::systemIsrWritten ( UART_HandleTypeDef &  uart)
static

System-wide interrupt service routine for uart transmit.

Parameters
uartHardware handler.

Definition at line 286 of file stm32uart.cpp.

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

◆ writeHardware()

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

Hardware will write data in interrupt mode.

Parameters
datadata array.
dataSizedata array size.
Exceptions
WriteHardware_HalErrorIf the ST-HAL returns a hal error.
WriteHardware_HalBusyIf the ST-HAL returns a hal bussy.
WriteHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::UartHardware.

Definition at line 308 of file stm32uart.cpp.

Here is the call graph for this function: