Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UARTSerial writes even if tx is disabled #14498

Merged
merged 5 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions drivers/UARTSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable<UA
bool _blocking;
bool _tx_irq_enabled;
bool _rx_irq_enabled;
bool _tx_enabled;
bool _rx_enabled;
InterruptIn *_dcd_irq;

/** Device Hanged up
Expand Down
46 changes: 22 additions & 24 deletions drivers/source/UARTSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ UARTSerial::UARTSerial(PinName tx, PinName rx, int baud) :
_blocking(true),
_tx_irq_enabled(false),
_rx_irq_enabled(false),
_tx_enabled(true),
_rx_enabled(true),
_dcd_irq(NULL)
{
/* Attatch IRQ routines to the serial device. */
Expand All @@ -41,8 +39,6 @@ UARTSerial::UARTSerial(const serial_pinmap_t &static_pinmap, int baud) :
_blocking(true),
_tx_irq_enabled(false),
_rx_irq_enabled(false),
_tx_enabled(true),
_rx_enabled(true),
_dcd_irq(NULL)
{
/* Attatch IRQ routines to the serial device. */
Expand Down Expand Up @@ -196,14 +192,7 @@ ssize_t UARTSerial::write(const void *buffer, size_t length)
data_written++;
}

core_util_critical_section_enter();
if (_tx_enabled && !_tx_irq_enabled) {
UARTSerial::tx_irq(); // only write to hardware in one place
if (!_txbuf.empty()) {
enable_tx_irq();
}
}
core_util_critical_section_exit();
enable_tx_irq();
}

api_unlock();
Expand Down Expand Up @@ -238,14 +227,7 @@ ssize_t UARTSerial::read(void *buffer, size_t length)
data_read++;
}

core_util_critical_section_enter();
if (_rx_enabled && !_rx_irq_enabled) {
UARTSerial::rx_irq(); // only read from hardware in one place
if (!_rxbuf.full()) {
enable_rx_irq();
}
}
core_util_critical_section_exit();
enable_rx_irq();

api_unlock();

Expand Down Expand Up @@ -355,8 +337,15 @@ void UARTSerial::tx_irq(void)
/* These are all called from critical section */
void UARTSerial::enable_rx_irq()
{
SerialBase::attach(callback(this, &UARTSerial::rx_irq), RxIrq);
_rx_irq_enabled = true;
core_util_critical_section_enter();
ghseb marked this conversation as resolved.
Show resolved Hide resolved
if (_rx_enabled && !_rx_irq_enabled) {
UARTSerial::rx_irq(); // only read from hardware in one place
if (!_rxbuf.full()) {
SerialBase::attach(callback(this, &UARTSerial::rx_irq), RxIrq);
_rx_irq_enabled = true;
}
}
core_util_critical_section_exit();
}

void UARTSerial::disable_rx_irq()
Expand All @@ -367,8 +356,15 @@ void UARTSerial::disable_rx_irq()

void UARTSerial::enable_tx_irq()
{
SerialBase::attach(callback(this, &UARTSerial::tx_irq), TxIrq);
_tx_irq_enabled = true;
core_util_critical_section_enter();
if (_tx_enabled && !_tx_irq_enabled) {
UARTSerial::tx_irq(); // only write to hardware in one place
if (!_txbuf.empty()) {
SerialBase::attach(callback(this, &UARTSerial::tx_irq), TxIrq);
_tx_irq_enabled = true;
}
}
core_util_critical_section_exit();
}

void UARTSerial::disable_tx_irq()
Expand All @@ -381,6 +377,7 @@ int UARTSerial::enable_input(bool enabled)
{
api_lock();
SerialBase::enable_input(enabled);
enable_rx_irq(); // Enable interrupt to handle incoming data
ghseb marked this conversation as resolved.
Show resolved Hide resolved
api_unlock();

return 0;
Expand All @@ -390,6 +387,7 @@ int UARTSerial::enable_output(bool enabled)
{
api_lock();
SerialBase::enable_output(enabled);
enable_tx_irq(); // Enable interrupt to flush buffered data
api_unlock();

return 0;
Expand Down