Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
SerialBase Class Reference

A base class for serial port implementations Can't be instantiated directly (use Serial or RawSerial) More...

#include <SerialBase.h>

Inheritance diagram for SerialBase:
NonCopyable< SerialBase > RawSerial Serial UARTSerial GreenteaSerial

Public Member Functions

void baud (int baudrate)
 Set the baud rate of the serial port. More...
 
void format (int bits=8, Parity parity=SerialBase::None, int stop_bits=1)
 Set the transmission format used by the serial port. More...
 
int readable ()
 Determine if there is a character available to read. More...
 
int writeable ()
 Determine if there is space available to write a character. More...
 
void attach (Callback< void()> func, IrqType type=RxIrq)
 Attach a function to call whenever a serial interrupt is generated. More...
 
template<typename T >
void attach (T *obj, void(T::*method)(), IrqType type=RxIrq)
 Attach a member function to call whenever a serial interrupt is generated. More...
 
template<typename T >
void attach (T *obj, void(*method)(T *), IrqType type=RxIrq)
 Attach a member function to call whenever a serial interrupt is generated. More...
 
void set_break ()
 Generate a break condition on the serial line NOTE: Clear break needs to run at least one frame after set_break is called. More...
 
void clear_break ()
 Clear a break condition on the serial line NOTE: Should be run at least one frame after set_break is called. More...
 
void send_break ()
 Generate a break condition on the serial line. More...
 
void set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC)
 Set the flow control type on the serial port. More...
 
int write (const uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE)
 Begin asynchronous write using 8bit buffer. More...
 
int write (const uint16_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE)
 Begin asynchronous write using 16bit buffer. More...
 
void abort_write ()
 Abort the on-going write transfer. More...
 
int read (uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_RX_COMPLETE, unsigned char char_match=SERIAL_RESERVED_CHAR_MATCH)
 Begin asynchronous reading using 8bit buffer. More...
 
int read (uint16_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_RX_COMPLETE, unsigned char char_match=SERIAL_RESERVED_CHAR_MATCH)
 Begin asynchronous reading using 16bit buffer. More...
 
void abort_read ()
 Abort the on-going read transfer. More...
 
int set_dma_usage_tx (DMAUsage usage)
 Configure DMA usage suggestion for non-blocking TX transfers. More...
 
int set_dma_usage_rx (DMAUsage usage)
 Configure DMA usage suggestion for non-blocking RX transfers. More...
 

Detailed Description

A base class for serial port implementations Can't be instantiated directly (use Serial or RawSerial)

Note
Synchronization level: Set by subclass

Definition at line 43 of file SerialBase.h.

Member Function Documentation

void abort_read ( )

Abort the on-going read transfer.

void abort_write ( )

Abort the on-going write transfer.

void attach ( Callback< void()>  func,
IrqType  type = RxIrq 
)

Attach a function to call whenever a serial interrupt is generated.

Parameters
funcA pointer to a void function, or 0 to set as none
typeWhich serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
void attach ( T *  obj,
void(T::*)()  method,
IrqType  type = RxIrq 
)

Attach a member function to call whenever a serial interrupt is generated.

Parameters
objpointer to the object to call the member function on
methodpointer to the member function to be called
typeWhich serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
Deprecated:
The attach function does not support cv-qualifiers. Replaced by attach(callback(obj, method), type).

Definition at line 118 of file SerialBase.h.

void attach ( T *  obj,
void(*)(T *)  method,
IrqType  type = RxIrq 
)

Attach a member function to call whenever a serial interrupt is generated.

Parameters
objpointer to the object to call the member function on
methodpointer to the member function to be called
typeWhich serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
Deprecated:
The attach function does not support cv-qualifiers. Replaced by attach(callback(obj, method), type).

Definition at line 136 of file SerialBase.h.

void baud ( int  baudrate)

Set the baud rate of the serial port.

Parameters
baudrateThe baudrate of the serial port (default = 9600).
void clear_break ( )

Clear a break condition on the serial line NOTE: Should be run at least one frame after set_break is called.

void format ( int  bits = 8,
Parity  parity = SerialBase::None,
int  stop_bits = 1 
)

Set the transmission format used by the serial port.

Parameters
bitsThe number of bits in a word (5-8; default = 8)
parityThe parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
stop_bitsThe number of stop bits (1 or 2; default = 1)
int read ( uint8_t *  buffer,
int  length,
const event_callback_t callback,
int  event = SERIAL_EVENT_RX_COMPLETE,
unsigned char  char_match = SERIAL_RESERVED_CHAR_MATCH 
)

Begin asynchronous reading using 8bit buffer.

The completion invokes registered RX event callback.

This function locks the deep sleep until any event has occurred

Parameters
bufferThe buffer where received data will be stored
lengthThe buffer length in bytes
callbackThe event callback function
eventThe logical OR of RX events
char_matchThe matching character
int read ( uint16_t *  buffer,
int  length,
const event_callback_t callback,
int  event = SERIAL_EVENT_RX_COMPLETE,
unsigned char  char_match = SERIAL_RESERVED_CHAR_MATCH 
)

Begin asynchronous reading using 16bit buffer.

The completion invokes registered RX event callback.

This function locks the deep sleep until any event has occurred

Parameters
bufferThe buffer where received data will be stored
lengthThe buffer length in bytes
callbackThe event callback function
eventThe logical OR of RX events
char_matchThe matching character
int readable ( )

Determine if there is a character available to read.

Returns
1 if there is a character available to read, 0 otherwise
void send_break ( )

Generate a break condition on the serial line.

void set_break ( )

Generate a break condition on the serial line NOTE: Clear break needs to run at least one frame after set_break is called.

int set_dma_usage_rx ( DMAUsage  usage)

Configure DMA usage suggestion for non-blocking RX transfers.

Parameters
usageThe usage DMA hint for peripheral
Returns
Zero if the usage was set, -1 if a transaction is on-going
int set_dma_usage_tx ( DMAUsage  usage)

Configure DMA usage suggestion for non-blocking TX transfers.

Parameters
usageThe usage DMA hint for peripheral
Returns
Zero if the usage was set, -1 if a transaction is on-going
void set_flow_control ( Flow  type,
PinName  flow1 = NC,
PinName  flow2 = NC 
)

Set the flow control type on the serial port.

Parameters
typethe flow control type (Disabled, RTS, CTS, RTSCTS)
flow1the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
flow2the second flow control pin (CTS for RTSCTS)
int write ( const uint8_t *  buffer,
int  length,
const event_callback_t callback,
int  event = SERIAL_EVENT_TX_COMPLETE 
)

Begin asynchronous write using 8bit buffer.

The completion invokes registered TX event callback

This function locks the deep sleep until any event has occurred

Parameters
bufferThe buffer where received data will be stored
lengthThe buffer length in bytes
callbackThe event callback function
eventThe logical OR of TX events
int write ( const uint16_t *  buffer,
int  length,
const event_callback_t callback,
int  event = SERIAL_EVENT_TX_COMPLETE 
)

Begin asynchronous write using 16bit buffer.

The completion invokes registered TX event callback

This function locks the deep sleep until any event has occurred

Parameters
bufferThe buffer where received data will be stored
lengthThe buffer length in bytes
callbackThe event callback function
eventThe logical OR of TX events
int writeable ( )

Determine if there is space available to write a character.

Returns
1 if there is space to write a character, 0 otherwise
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.