Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
# Defined behavior * serial_init initializes the serial_t * serial_init sets the default parameters for serial peripheral (9600 bps, 8N1 format) * serial_init configures the specified pins * serial_free releases the serial peripheral * serial_baud configures the baud rate * at least 9600 bps the baud rate must be supported * serial_format configures the transmission format (number of bits, parity and the number of stop bits) * at least 8N1 format must be supported * serial_irq_handler registers the interrupt handler which will be invoked when the interrupt fires. More...
Modules | |
Serial hal tests | |
The Serial HAL tests ensure driver conformance to defined behavior. | |
Functions | |
void | serial_init (serial_t *obj, PinName tx, PinName rx) |
Initialize the serial peripheral. | |
void | serial_init_direct (serial_t *obj, const serial_pinmap_t *pinmap) |
Initialize the serial peripheral. | |
void | serial_free (serial_t *obj) |
Release the serial peripheral, not currently invoked. | |
void | serial_baud (serial_t *obj, int baudrate) |
Configure the baud rate. | |
void | serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits) |
Configure the format. | |
void | serial_irq_handler (serial_t *obj, uart_irq_handler handler, uint32_t id) |
The serial interrupt handler registration. | |
void | serial_irq_set (serial_t *obj, SerialIrq irq, uint32_t enable) |
Configure serial interrupt. | |
int | serial_getc (serial_t *obj) |
Get character. | |
void | serial_putc (serial_t *obj, int c) |
Send a character. | |
int | serial_readable (serial_t *obj) |
Check if the serial peripheral is readable. | |
int | serial_writable (serial_t *obj) |
Check if the serial peripheral is writable. | |
void | serial_clear (serial_t *obj) |
Clear the serial peripheral. | |
void | serial_break_set (serial_t *obj) |
Set the break. | |
void | serial_break_clear (serial_t *obj) |
Clear the break. | |
void | serial_pinout_tx (PinName tx) |
Configure the TX pin for UART function. | |
void | serial_set_flow_control (serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) |
Configure the serial for the flow control. | |
void | serial_set_flow_control_direct (serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap) |
Configure the serial for the flow control. | |
const PinMap * | serial_tx_pinmap (void) |
Get the pins that support Serial TX. | |
const PinMap * | serial_rx_pinmap (void) |
Get the pins that support Serial RX. | |
const PinMap * | serial_cts_pinmap (void) |
Get the pins that support Serial CTS. | |
const PinMap * | serial_rts_pinmap (void) |
Get the pins that support Serial RTS. |
Detailed Description
# Defined behavior * serial_init initializes the serial_t * serial_init sets the default parameters for serial peripheral (9600 bps, 8N1 format) * serial_init configures the specified pins * serial_free releases the serial peripheral * serial_baud configures the baud rate * at least 9600 bps the baud rate must be supported * serial_format configures the transmission format (number of bits, parity and the number of stop bits) * at least 8N1 format must be supported * serial_irq_handler registers the interrupt handler which will be invoked when the interrupt fires.
* serial_irq_set enables or disables the serial RX or TX IRQ. * If `RxIrq` is enabled by serial_irq_set, serial_irq_handler will be invoked whenever Receive Data Register Full IRQ is generated. * If `TxIrq` is enabled by serial_irq_set, serial_irq_handler will be invoked whenever Transmit Data Register Empty IRQ is generated. * If the interrupt condition holds true, when the interrupt is enabled with serial_irq_set, the serial_irq_handler is called instantly. * serial_getc returns the character from serial buffer. * serial_getc is a blocking call (waits for the character). * serial_putc sends a character. * serial_putc is a blocking call (waits for a peripheral to be available). * serial_readable returns non-zero value if a character can be read, 0 otherwise. * serial_writable returns non-zero value if a character can be written, 0 otherwise. * serial_clear clears the serial_t RX/TX buffers * serial_break_set sets the break signal. * serial_break_clear clears the break signal. * serial_pinout_tx configures the TX pin as an output (to be used in half-duplex mode). * serial_set_flow_control configures serial flow control. * serial_set_flow_control sets flow control in the hardware if a serial peripheral supports it, otherwise software emulation is used. * serial_tx_asynch starts the serial asynchronous transfer. * serial_tx_asynch writes `tx_length` bytes from the `tx` to the bus. * serial_tx_asynch must support 8 data bits * The callback given to serial_tx_asynch is invoked when the transfer completes. * serial_tx_asynch specifies the logical OR of events to be registered. * The serial_tx_asynch function may use the `DMAUsage` hint to select the appropriate async algorithm. * serial_rx_asynch starts the serial asynchronous transfer. * serial_rx_asynch reads `rx_length` bytes to the `rx` buffer. * serial_rx_asynch must support 8 data bits * The callback given to serial_rx_asynch is invoked when the transfer completes. * serial_rx_asynch specifies the logical OR of events to be registered. * The serial_rx_asynch function may use the `DMAUsage` hint to select the appropriate async algorithm. * serial_rx_asynch specifies a character in range 0-254 to be matched, 255 is a reserved value. * If SERIAL_EVENT_RX_CHARACTER_MATCH event is not registered, the `char_match` is ignored. * The SERIAL_EVENT_RX_CHARACTER_MATCH event is set in the callback when SERIAL_EVENT_RX_CHARACTER_MATCH event is registered AND `char_match` is present in the received data. * serial_tx_active returns non-zero if the TX transaction is ongoing, 0 otherwise. * serial_rx_active returns non-zero if the RX transaction is ongoing, 0 otherwise. * serial_irq_handler_asynch returns event flags if a transfer termination condition was met, otherwise returns 0. * serial_irq_handler_asynch takes no longer than one packet transfer time (packet_bits / baudrate) to execute. * serial_tx_abort_asynch aborts the ongoing TX transaction. * serial_tx_abort_asynch disables the enabled interupt for TX. * serial_tx_abort_asynch flushes the TX hardware buffer if TX FIFO is used. * serial_rx_abort_asynch aborts the ongoing RX transaction. * serial_rx_abort_asynch disables the enabled interupt for RX. * serial_rx_abort_asynch flushes the TX hardware buffer if RX FIFO is used. * Correct operation guaranteed when interrupt latency is shorter than one packet transfer time (packet_bits / baudrate) if the flow control is not used. * Correct operation guaranteed regardless of interrupt latency if the flow control is used.
# Undefined behavior * Calling serial_init multiple times on the same `serial_t` without serial_free. * Passing invalid pin to serial_init, serial_pinout_tx. * Calling any function other than serial_init on am uninitialized or freed `serial_t`. * Passing an invalid pointer as `obj` to any function. * Passing an invalid pointer as `handler` to serial_irq_handler, serial_tx_asynch, serial_rx_asynch. * Calling serial_tx_abort while no async TX transfer is being processed. * Calling serial_rx_abort while no async RX transfer is being processed. * Devices behavior is undefined when the interrupt latency is longer than one packet transfer time (packet_bits / baudrate) if the flow control is not used.
Function Documentation
void serial_baud | ( | serial_t * | obj, |
int | baudrate | ||
) |
Configure the baud rate.
- Parameters:
-
obj The serial object baudrate The baud rate to be configured
void serial_break_clear | ( | serial_t * | obj ) |
Clear the break.
- Parameters:
-
obj The serial object
void serial_break_set | ( | serial_t * | obj ) |
Set the break.
- Parameters:
-
obj The serial object
void serial_clear | ( | serial_t * | obj ) |
Clear the serial peripheral.
- Parameters:
-
obj The serial object
const PinMap* serial_cts_pinmap | ( | void | ) |
Get the pins that support Serial CTS.
Return a PinMap array of pins that support Serial CTS. The array is terminated with {NC, NC, 0}.
- Returns:
- PinMap array
void serial_format | ( | serial_t * | obj, |
int | data_bits, | ||
SerialParity | parity, | ||
int | stop_bits | ||
) |
Configure the format.
Set the number of bits, parity and the number of stop bits
- Parameters:
-
obj The serial object data_bits The number of data bits parity The parity stop_bits The number of stop bits
void serial_free | ( | serial_t * | obj ) |
Release the serial peripheral, not currently invoked.
It requires further resource management.
- Parameters:
-
obj The serial object
int serial_getc | ( | serial_t * | obj ) |
Get character.
This is a blocking call, waiting for a character
- Parameters:
-
obj The serial object
void serial_init | ( | serial_t * | obj, |
PinName | tx, | ||
PinName | rx | ||
) |
Initialize the serial peripheral.
It sets the default parameters for serial peripheral, and configures its specifieds pins.
- Parameters:
-
obj The serial object tx The TX pin name rx The RX pin name
void serial_init_direct | ( | serial_t * | obj, |
const serial_pinmap_t * | pinmap | ||
) |
Initialize the serial peripheral.
It sets the default parameters for serial peripheral, and configures its specifieds pins.
- Parameters:
-
obj The serial object pinmap pointer to structure which holds static pinmap
Definition at line 64 of file static_pinmap.cpp.
void serial_irq_handler | ( | serial_t * | obj, |
uart_irq_handler | handler, | ||
uint32_t | id | ||
) |
The serial interrupt handler registration.
- Parameters:
-
obj The serial object handler The interrupt handler which will be invoked when the interrupt fires id The SerialBase object
Configure serial interrupt.
This function is used for word-approach
- Parameters:
-
obj The serial object irq The serial IRQ type (RX or TX) enable Set to non-zero to enable events, or zero to disable them
void serial_pinout_tx | ( | PinName | tx ) |
Configure the TX pin for UART function.
- Parameters:
-
tx The pin name used for TX
void serial_putc | ( | serial_t * | obj, |
int | c | ||
) |
Send a character.
This is a blocking call, waiting for a peripheral to be available for writing
- Parameters:
-
obj The serial object c The character to be sent
int serial_readable | ( | serial_t * | obj ) |
Check if the serial peripheral is readable.
- Parameters:
-
obj The serial object
- Returns:
- Non-zero value if a character can be read, 0 if nothing to read
const PinMap* serial_rts_pinmap | ( | void | ) |
Get the pins that support Serial RTS.
Return a PinMap array of pins that support Serial RTS. The array is terminated with {NC, NC, 0}.
- Returns:
- PinMap array
const PinMap* serial_rx_pinmap | ( | void | ) |
Get the pins that support Serial RX.
Return a PinMap array of pins that support Serial RX. The array is terminated with {NC, NC, 0}.
- Returns:
- PinMap array
void serial_set_flow_control | ( | serial_t * | obj, |
FlowControl | type, | ||
PinName | rxflow, | ||
PinName | txflow | ||
) |
Configure the serial for the flow control.
It sets flow control in the hardware if a serial peripheral supports it, otherwise software emulation is used.
- Parameters:
-
obj The serial object type The type of the flow control. Look at the available FlowControl types. rxflow The TX pin name txflow The RX pin name
void serial_set_flow_control_direct | ( | serial_t * | obj, |
FlowControl | type, | ||
const serial_fc_pinmap_t * | pinmap | ||
) |
Configure the serial for the flow control.
It sets flow control in the hardware if a serial peripheral supports it, otherwise software emulation is used.
- Parameters:
-
obj The serial object type The type of the flow control. Look at the available FlowControl types. pinmap Pointer to structure which holds static pinmap
Definition at line 70 of file static_pinmap.cpp.
const PinMap* serial_tx_pinmap | ( | void | ) |
Get the pins that support Serial TX.
Return a PinMap array of pins that support Serial TX. The array is terminated with {NC, NC, 0}.
- Returns:
- PinMap array
int serial_writable | ( | serial_t * | obj ) |
Check if the serial peripheral is writable.
- Parameters:
-
obj The serial object
- Returns:
- Non-zero value if a character can be written, 0 otherwise.
Generated on Tue Jul 12 2022 13:55:25 by
