use memmove to improve recive buff

This commit is contained in:
graduateDesign 2021-09-26 13:07:22 +08:00
parent 1a3cbcb7eb
commit 56b8bf4fd2
2 changed files with 11 additions and 7 deletions

View File

@ -16,7 +16,7 @@
<TargetCommonOption>
<Device>STM32G030C8Tx</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32G0xx_DFP.1.2.0</PackID>
<PackID>Keil.STM32G0xx_DFP.1.3.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000-0x20001FFF) IROM(0x8000000-0x800FFFF) CLOCK(8000000) CPUTYPE("Cortex-M0+") TZ</Cpu>
<FlashUtilSpec></FlashUtilSpec>

View File

@ -405,13 +405,17 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
return;
}
}
/* recive next char, avoid recive buff overflow */
if (pika_uart->rxBuffOffset + 2 < RX_BUFF_LENGTH) {
pika_uart->rxBuffOffset++;
pika_uart->rxBuff[pika_uart->rxBuffOffset] = 0;
/* avoid recive buff overflow */
if (pika_uart->rxBuffOffset + 2 > RX_BUFF_LENGTH) {
memmove(pika_uart->rxBuff, pika_uart->rxBuff + 1, RX_BUFF_LENGTH);
UART_Start_Receive_IT(
huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
return;
}
/* recive next char */
pika_uart->rxBuffOffset++;
pika_uart->rxBuff[pika_uart->rxBuffOffset] = 0;
UART_Start_Receive_IT(
huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
}