generated from hulk/gd32e23x_template_cmake_vscode
add mcu flash size detect and auto config usart
This commit is contained in:
38
Src/uart.c
38
Src/uart.c
@@ -3,7 +3,7 @@
|
||||
#include "gd32e23x_rcu.h"
|
||||
#include "gd32e23x_gpio.h"
|
||||
#include "board_config.h"
|
||||
|
||||
#include "uart_ring_buffer.h"
|
||||
|
||||
void rs485_init(void) {
|
||||
|
||||
@@ -37,7 +37,7 @@ void rs485_init(void) {
|
||||
|
||||
usart_enable(RS485_PHY);
|
||||
|
||||
nvic_irq_enable(USART0_IRQn, 0);
|
||||
nvic_irq_enable(RS485_IRQ, 0);
|
||||
usart_interrupt_enable(RS485_PHY, USART_INT_RBNE);
|
||||
// usart_interrupt_enable(RS485_PHY, USART_INT_IDLE);
|
||||
|
||||
@@ -70,3 +70,37 @@ void rs485_init(void) {
|
||||
|
||||
#endif // RS485_MAX13487
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* 具体的中断处理函数实现 */
|
||||
/******************************************************************************/
|
||||
|
||||
void usart0_irq_handler(void) {
|
||||
// 处理USART0的接收中断
|
||||
if(usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE)) {
|
||||
uint8_t data = usart_data_receive(USART0);
|
||||
// 使用原有的环形缓冲区处理逻辑
|
||||
(void)uart_ring_buffer_put(data); // 缓冲满时丢弃,返回值可用于统计
|
||||
}
|
||||
|
||||
// 处理USART0的空闲中断
|
||||
if(usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) {
|
||||
usart_interrupt_flag_clear(USART0, USART_INT_FLAG_IDLE);
|
||||
// 在这里添加空闲中断处理逻辑
|
||||
}
|
||||
}
|
||||
|
||||
void usart1_irq_handler(void) {
|
||||
// 处理USART1的接收中断
|
||||
if(usart_interrupt_flag_get(USART1, USART_INT_FLAG_RBNE)) {
|
||||
uint8_t data = usart_data_receive(USART1);
|
||||
// 使用原有的环形缓冲区处理逻辑
|
||||
(void)uart_ring_buffer_put(data); // 缓冲满时丢弃,返回值可用于统计
|
||||
}
|
||||
|
||||
// 处理USART1的空闲中断
|
||||
if(usart_interrupt_flag_get(USART1, USART_INT_FLAG_IDLE)) {
|
||||
usart_interrupt_flag_clear(USART1, USART_INT_FLAG_IDLE);
|
||||
// 在这里添加空闲中断处理逻辑
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user