Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(serial): add timeout support to flush()#2124

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fpistm merged 2 commits intostm32duino:mainfromfpistm:Serial_flush_timeout
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
25 changes: 15 additions & 10 deletionscores/arduino/HardwareSerial.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -441,7 +441,7 @@ void HardwareSerial::begin(unsigned long baud, byte config)
void HardwareSerial::end()
{
// wait for transmission of outgoing data
flush();
flush(TX_TIMEOUT);

uart_deinit(&_serial);

Expand DownExpand Up@@ -487,20 +487,25 @@ int HardwareSerial::availableForWrite(void)
return tail - head - 1;
}

void HardwareSerial::flush()
void HardwareSerial::flush(uint32_t timeout)
{
// If we have never written a byte, no need to flush. This special
// case is needed since there is no way to force the TXC (transmit
// complete) bit to 1 during initialization
if (!_written) {
return;
}

while ((_serial.tx_head != _serial.tx_tail)) {
// nop, the interrupt handler will free up space for us
if (_written) {
uint32_t tickstart = HAL_GetTick();
while ((_serial.tx_head != _serial.tx_tail)) {
// the interrupt handler will free up space for us
// Only manage timeout if any
if ((timeout != 0) && ((HAL_GetTick() - tickstart) >= timeout)) {
// clear any transmit data
_serial.tx_head = _serial.tx_tail;
break;
}
}
// If we get here, nothing is queued anymore (DRIE is disabled) and
// the hardware finished transmission (TXC is set).
}
// If we get here, nothing is queued anymore (DRIE is disabled) and
// the hardware finished transmission (TXC is set).
}

size_t HardwareSerial::write(const uint8_t *buffer, size_t size)
Expand Down
2 changes: 1 addition & 1 deletioncores/arduino/HardwareSerial.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -125,7 +125,7 @@ class HardwareSerial : public Stream {
virtual int peek(void);
virtual int read(void);
int availableForWrite(void);
virtual void flush(void);
virtual void flush(uint32_t timeout = 0);
virtual size_t write(uint8_t);
inline size_t write(unsigned long n)
{
Expand Down
2 changes: 2 additions & 0 deletionscores/arduino/stm32/uart.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,7 +86,9 @@ struct serial_s {
};

/* Exported constants --------------------------------------------------------*/
#ifndef TX_TIMEOUT
#define TX_TIMEOUT 1000
#endif

#if !defined(RCC_USART1CLKSOURCE_HSI)
/* Some series like C0 have 2 derivated clock from HSI: HSIKER (for peripherals)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp