波特率提升为921600,修复了和视觉通信的溢出错误以及DMA冲突.

This commit is contained in:
NeoZng 2023-03-18 14:50:50 +08:00
parent 11b401c2bc
commit 87d0a5161c
10 changed files with 34 additions and 32 deletions

View File

@ -46,7 +46,7 @@ void MX_USART1_UART_Init(void)
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.BaudRate = 921600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;

View File

@ -0,0 +1,3 @@
# referee
需要将此模块移动到module层并新建一个rtos任务以一定频率运行用于ui刷新和多机通信

View File

@ -35,7 +35,7 @@ void RobotInit()
#endif
#if defined(ONE_BOARD) || defined(CHASSIS_BOARD)
Referee_Interactive_init();
// Referee_Interactive_init();
ChassisInit();
#endif
// 初始化完成,开启中断
@ -52,6 +52,6 @@ void RobotTask()
#if defined(ONE_BOARD) || defined(CHASSIS_BOARD)
ChassisTask();
Referee_Interactive_task();
// Referee_Interactive_task();
#endif
}

View File

@ -19,7 +19,7 @@ static USARTInstance *usart_instance[DEVICE_USART_CNT] = {NULL};
/**
* @brief ,,DMA接收,IT和BLOCKING接收
*
*
* @todo ,DMA接收,IT和BLOCKING接收
* extern,使module可以控制串口的启停
*
@ -52,24 +52,22 @@ USARTInstance *USARTRegister(USART_Init_Config_s *init_config)
}
/* @todo 当前仅进行了形式上的封装,后续要进一步考虑是否将module的行为与bsp完全分离 */
void USARTSend(USARTInstance *_instance, uint8_t *send_buf, uint16_t send_size)
{
HAL_UART_Transmit_DMA(_instance->usart_handle, send_buf, send_size);
}
void USARTAbort(USARTInstance *_instance, USART_TRANSFER_MODE mode)
void USARTSend(USARTInstance *_instance, uint8_t *send_buf, uint16_t send_size, USART_TRANSFER_MODE mode)
{
switch (mode)
{
case USART_TRANSFER_TX:
// if(_instance.work_mode == USART_TX_DMA)
HAL_UART_AbortTransmit_IT(_instance->usart_handle);
case USART_TRANSFER_BLOCKING:
HAL_UART_Transmit(_instance->usart_handle, send_buf, send_size, 100);
break;
case USART_TRANSFER_RX:
// if(_instance.work_mode == USART_RX_DMA)
HAL_UART_AbortReceive_IT(_instance->usart_handle);
case USART_TRANSFER_IT:
HAL_UART_Transmit_IT(_instance->usart_handle, send_buf, send_size);
break;
case USART_TRANSFER_NONE:
case USART_TRANSFER_DMA:
HAL_UART_Transmit_DMA(_instance->usart_handle, send_buf, send_size);
break;
default:
while (1)
; // illegal mode! check your code context!
break;
}
}

View File

@ -13,8 +13,9 @@ typedef void (*usart_module_callback)();
typedef enum
{
USART_TRANSFER_NONE=0,
USART_TRANSFER_TX,
USART_TRANSFER_RX,
USART_TRANSFER_BLOCKING,
USART_TRANSFER_IT,
USART_TRANSFER_DMA,
} USART_TRANSFER_MODE;
// 串口实例结构体,每个module都要包含一个实例.
@ -52,14 +53,6 @@ USARTInstance *USARTRegister(USART_Init_Config_s *init_config);
* @param send_buf buffer
* @param send_size how many bytes to send
*/
void USARTSend(USARTInstance *_instance, uint8_t *send_buf, uint16_t send_size);
/**
* @brief ,mode参数来选择终止发送还是接收
*
* @param _instance
* @param mode
*/
void USARTAbort(USARTInstance *_instance,USART_TRANSFER_MODE mode);
void USARTSend(USARTInstance *_instance, uint8_t *send_buf, uint16_t send_size,USART_TRANSFER_MODE mode);
#endif

View File

@ -61,5 +61,8 @@ void VisionSend(Vision_Send_s *send)
// 将数据转化为seasky协议的数据包
get_protocol_send_data(0x02, flag_register, &send->yaw, 3, send_buff, &tx_len);
USARTSend(vision_usart_instance, send_buff, tx_len);
USARTSend(vision_usart_instance, send_buff, tx_len,USART_TRANSFER_IT); // 和视觉通信使用IT,防止和接收使用的DMA冲突
// 此处为HAL设计的缺陷,DMASTOP会停止发送和接收,导致再也无法进入接收中断.
// 也可在发送完成中断中重新启动DMA接收,但较为复杂.因此,此处使用IT发送.
}

View File

@ -114,7 +114,7 @@ uint16_t get_protocol_info(uint8_t *rx_buf, // 接收到的原始数据
if (CRC16_Check_Sum(&rx_buf[0], date_length))
{
*flags_register = (rx_buf[7] << 8) | rx_buf[6];
memcpy(rx_data, rx_buf + 8, 4 * sizeof(pro.header.data_length - 2));
memcpy(rx_data, rx_buf + 8, pro.header.data_length - 2);
return pro.cmd_id;
}
}

View File

@ -0,0 +1,3 @@
# referee
当前模块组织较为混乱,后续统一为多机通信+裁判系统信息接收+UI绘制。UI绘制和多机通信的发送部分在referee任务中以一定的频率运行信息的接收通过中断完成。

View File

@ -41,7 +41,7 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle)
*/
void RefereeSend(uint8_t *send, uint16_t tx_len)
{
USARTSend(referee_usart_instance, send, tx_len);
USARTSend(referee_usart_instance, send, tx_len,USART_TRANSFER_IT);
/* syhtodo DMA请求过快会导致数据发送丢失考虑数据尽可能打成一个整包以及队列发送并且发送函数添加缓冲区 */
HAL_Delay(5);
}

View File

@ -14,5 +14,7 @@
## 请给你编写的bsp和module提供详细的文档和使用示例并为接口增加安全检查
“treat your user as idot
用于调试的条件编译和log输出也是必须的。
另外“treat your user as idot