[Mod] 解决GCC版本,串口无法接收问题

This commit is contained in:
gaoyang3513
2024-07-24 00:05:14 +08:00
parent d39d11abad
commit 8b6fe7ef86
2 changed files with 27 additions and 21 deletions

View File

@ -147,26 +147,6 @@ void start_task(void *p_arg)
app_init(); app_init();
#endif #endif
#if defined (CONFIG_GY3513)
#if 0
printf("reading input from file... ");
fflush(stdout);
filename = "Test.txt";
LWIP_ASSERT("invalid filename", filename != NULL);
f = fopen(filename, "rb");
LWIP_ASSERT("open failed", f != NULL);
len = fread(pktbuf, 1, sizeof(pktbuf), f);
len = fwrite(pktbuf, 1, sizeof(pktbuf), f);
fclose(f);
printf("testing file: \"%s\"...\r\n", filename);
#else
fprintf(stdout, "What is your name?\r\n");
fscanf(stdin, "%s", read_buf);
fprintf(stdout, "\nHello, %s\r\n", read_buf);
#endif
#endif // CONFIG_GY3513
sys_task_delete(NULL); sys_task_delete(NULL);
} }

View File

@ -37,6 +37,7 @@ OF SUCH DAMAGE.
#include "app_cfg.h" #include "app_cfg.h"
#include "bsp_inc.h" #include "bsp_inc.h"
#include "gd32w51x_usart.h" #include "gd32w51x_usart.h"
#include "platform_def.h"
#include "uart.h" #include "uart.h"
#include "malloc.h" #include "malloc.h"
#include "wifi_netlink.h" #include "wifi_netlink.h"
@ -90,6 +91,31 @@ int _write(int fd, char *str, int len)
return i; return i;
} }
int _read(int handle, char *buffer, int size)
{
uint8_t ch = 0U;
int actualSize = 0;
/* This function only reads from "standard in", for all other file handles it returns failure. */
if (handle != 0) {
return -1;
}
/* Receive data. */
for (; size > 0; size--) {
while(RESET == usart_flag_get(LOG_UART, USART_FLAG_RBNE));
*buffer++ = (char)usart_data_receive(LOG_UART);
actualSize++;
if ((ch == 0U) || (ch == (uint8_t)'\n') || (ch == (uint8_t)'\r')) {
break;
}
}
return (actualSize > 0) ? actualSize : -1;
}
#endif #endif
/*! /*!
@ -134,7 +160,7 @@ void usart_config(uint32_t usart_periph)
usart_baudrate_set(usart_periph, 115200); usart_baudrate_set(usart_periph, 115200);
usart_receive_config(usart_periph, USART_RECEIVE_ENABLE); usart_receive_config(usart_periph, USART_RECEIVE_ENABLE);
usart_transmit_config(usart_periph, USART_TRANSMIT_ENABLE); usart_transmit_config(usart_periph, USART_TRANSMIT_ENABLE);
//usart_interrupt_enable(usart_periph, USART_INT_RBNE); usart_interrupt_enable(usart_periph, USART_INT_RBNE);
usart_enable(usart_periph); usart_enable(usart_periph);
} }