Skip to content

Commit 2c55f11

Browse files
authored
Merge pull request #3171 from ErnestChen1/master
[DeviceDrivers] add warning about overflowing by serial receiver
2 parents e1a0125 + f82d4f1 commit 2c55f11

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

components/drivers/serial/serial.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ rt_inline int _serial_int_tx(struct rt_serial_device *serial, const rt_uint8_t *
327327
return size - length;
328328
}
329329

330+
static void _serial_check_buffer_size(void)
331+
{
332+
static rt_bool_t already_output = RT_FALSE;
333+
334+
if (already_output == RT_FALSE)
335+
{
336+
LOG_W("Warning: There is no enough buffer for saving data,"
337+
" please increase the RT_SERIAL_RB_BUFSZ option.");
338+
already_output = RT_TRUE;
339+
}
340+
}
341+
330342
#if defined(RT_USING_POSIX) || defined(RT_SERIAL_USING_DMA)
331343
static rt_size_t _serial_fifo_calc_recved_len(struct rt_serial_device *serial)
332344
{
@@ -430,6 +442,7 @@ static void rt_dma_recv_update_put_index(struct rt_serial_device *serial, rt_siz
430442

431443
if(rx_fifo->is_full == RT_TRUE)
432444
{
445+
_serial_check_buffer_size();
433446
rx_fifo->get_index = rx_fifo->put_index;
434447
}
435448
}
@@ -1170,6 +1183,8 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
11701183
rx_fifo->get_index += 1;
11711184
rx_fifo->is_full = RT_TRUE;
11721185
if (rx_fifo->get_index >= serial->config.bufsz) rx_fifo->get_index = 0;
1186+
1187+
_serial_check_buffer_size();
11731188
}
11741189

11751190
/* enable interrupt */

0 commit comments

Comments
 (0)