修复因内存对齐访问导致的硬件错误
This commit is contained in:
parent
f1301ab7de
commit
a539072052
|
@ -18,8 +18,9 @@
|
||||||
"can.h": "c",
|
"can.h": "c",
|
||||||
"bsp_can.h": "c",
|
"bsp_can.h": "c",
|
||||||
"dji_motor.h": "c",
|
"dji_motor.h": "c",
|
||||||
"master_process.h": "c"
|
"master_process.h": "c",
|
||||||
|
"seasky_protocol.h": "c",
|
||||||
|
"bsp_usart.h": "c"
|
||||||
},
|
},
|
||||||
"C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools",
|
"C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools",
|
||||||
"C_Cpp.intelliSenseEngineFallback": "enabled",
|
|
||||||
}
|
}
|
|
@ -141,14 +141,14 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||||
*/
|
*/
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_7;
|
GPIO_InitStruct.Pin = GPIO_PIN_7;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
||||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
|
@ -75,7 +75,7 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||||
if (huart == instance[i]->usart_handle)
|
if (huart == instance[i]->usart_handle)
|
||||||
{
|
{
|
||||||
instance[i]->module_callback();
|
instance[i]->module_callback();
|
||||||
memset(instance[i]->recv_buff,0,instance[i]->recv_buff_size); // 接收结束后清空buffer,对于变长数据是必要的
|
memset(instance[i]->recv_buff,0,Size); // 接收结束后清空buffer,对于变长数据是必要的
|
||||||
HAL_UARTEx_ReceiveToIdle_DMA(instance[i]->usart_handle, instance[i]->recv_buff, instance[i]->recv_buff_size);
|
HAL_UARTEx_ReceiveToIdle_DMA(instance[i]->usart_handle, instance[i]->recv_buff, instance[i]->recv_buff_size);
|
||||||
__HAL_DMA_DISABLE_IT(instance[i]->usart_handle->hdmarx, DMA_IT_HT);
|
__HAL_DMA_DISABLE_IT(instance[i]->usart_handle->hdmarx, DMA_IT_HT);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -5,17 +5,20 @@
|
||||||
* @version beta
|
* @version beta
|
||||||
* @date 2022-11-03
|
* @date 2022-11-03
|
||||||
* @todo 增加对串口调试助手协议的支持,包括vofa和serial debug
|
* @todo 增加对串口调试助手协议的支持,包括vofa和serial debug
|
||||||
* @copyright Copyright (c) 2022
|
* @copyright Copyright (c) 2022
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "Master_process.h"
|
#include "master_process.h"
|
||||||
|
#include "bsp_usart.h"
|
||||||
|
#include "usart.h"
|
||||||
|
#include "seasky_protocol.h"
|
||||||
|
|
||||||
/* use usart1 as vision communication*/
|
/* use usart1 as vision communication*/
|
||||||
static Vision_Recv_s recv_data;
|
Vision_Recv_s recv_data;
|
||||||
// @todo:由于后续需要进行IMU-Cam的硬件触发采集控制,因此可能需要将发送设置为定时任务,或由IMU采集完成产生的中断唤醒的任务,
|
// @todo:由于后续需要进行IMU-Cam的硬件触发采集控制,因此可能需要将发送设置为定时任务,或由IMU采集完成产生的中断唤醒的任务,
|
||||||
// 使得时间戳对齐. 因此,在send_data中设定其他的标志位数据,让ins_task填充姿态值.
|
// 使得时间戳对齐. 因此,在send_data中设定其他的标志位数据,让ins_task填充姿态值.
|
||||||
// static Vision_Send_s send_data;
|
// static Vision_Send_s send_data;
|
||||||
static usart_instance* vision_usart_instance;
|
static usart_instance *vision_usart_instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 接收解包回调函数,将在bsp_usart.c中被usart rx callback调用
|
* @brief 接收解包回调函数,将在bsp_usart.c中被usart rx callback调用
|
||||||
|
@ -25,18 +28,18 @@ static usart_instance* vision_usart_instance;
|
||||||
static void DecodeVision()
|
static void DecodeVision()
|
||||||
{
|
{
|
||||||
static uint16_t flag_register;
|
static uint16_t flag_register;
|
||||||
get_protocol_info(vision_usart_instance->recv_buff, &flag_register, &recv_data.pitch);
|
get_protocol_info(vision_usart_instance->recv_buff, &flag_register, (uint8_t*)&recv_data.pitch);
|
||||||
// TODO: code to resolve flag_register;
|
// TODO: code to resolve flag_register;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 视觉通信初始化 */
|
/* 视觉通信初始化 */
|
||||||
Vision_Recv_s* VisionInit(UART_HandleTypeDef *handle)
|
Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle)
|
||||||
{
|
{
|
||||||
USART_Init_Config_s conf;
|
USART_Init_Config_s conf;
|
||||||
conf.module_callback = DecodeVision;
|
conf.module_callback = DecodeVision;
|
||||||
conf.recv_buff_size = VISION_RECV_SIZE;
|
conf.recv_buff_size = VISION_RECV_SIZE;
|
||||||
conf.usart_handle = handle;
|
conf.usart_handle = _handle;
|
||||||
vision_usart_instance=USARTRegister(&conf);
|
vision_usart_instance = USARTRegister(&conf);
|
||||||
return &recv_data;
|
return &recv_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +63,7 @@ void VisionSend(Vision_Send_s *send)
|
||||||
USARTSend(vision_usart_instance, send_buff, tx_len);
|
USARTSend(vision_usart_instance, send_buff, tx_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vision_Recv_s *VisionGetcmd()
|
||||||
Vision_Recv_s* VisionGetcmd()
|
|
||||||
{
|
{
|
||||||
return &recv_data;
|
return &recv_data;
|
||||||
}
|
}
|
|
@ -2,7 +2,6 @@
|
||||||
#define MASTER_PROCESS_H
|
#define MASTER_PROCESS_H
|
||||||
|
|
||||||
#include "bsp_usart.h"
|
#include "bsp_usart.h"
|
||||||
#include "usart.h"
|
|
||||||
#include "seasky_protocol.h"
|
#include "seasky_protocol.h"
|
||||||
|
|
||||||
#define VISION_RECV_SIZE 36u
|
#define VISION_RECV_SIZE 36u
|
||||||
|
@ -13,7 +12,7 @@
|
||||||
*
|
*
|
||||||
* @param handle 用于和视觉通信的串口handle(C板上一般为USART1,丝印为USART2,4pin)
|
* @param handle 用于和视觉通信的串口handle(C板上一般为USART1,丝印为USART2,4pin)
|
||||||
*/
|
*/
|
||||||
Vision_Recv_s *VisionInit(UART_HandleTypeDef *handle);
|
Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 发送视觉视觉
|
* @brief 发送视觉视觉
|
||||||
|
@ -22,11 +21,4 @@ Vision_Recv_s *VisionInit(UART_HandleTypeDef *handle);
|
||||||
*/
|
*/
|
||||||
void VisionSend(Vision_Send_s *send);
|
void VisionSend(Vision_Send_s *send);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 返回所需的上位机数据
|
|
||||||
*
|
|
||||||
* @return Vision_Recv_s* 数据结构体指针
|
|
||||||
*/
|
|
||||||
Vision_Recv_s* VisionGetcmd();
|
|
||||||
|
|
||||||
#endif // !MASTER_PROCESS_H
|
#endif // !MASTER_PROCESS_H
|
|
@ -13,39 +13,32 @@
|
||||||
#include "seasky_protocol.h"
|
#include "seasky_protocol.h"
|
||||||
#include "crc8.h"
|
#include "crc8.h"
|
||||||
#include "crc16.h"
|
#include "crc16.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
/*获取CRC8校验码*/
|
|
||||||
uint8_t Get_CRC8_Check(uint8_t *pchMessage, uint16_t dwLength)
|
|
||||||
{
|
|
||||||
return crc_8(pchMessage, dwLength);
|
|
||||||
}
|
|
||||||
/*检验CRC8数据段*/
|
/*检验CRC8数据段*/
|
||||||
uint8_t CRC8_Check_Sum(uint8_t *pchMessage, uint16_t dwLength)
|
static uint8_t CRC8_Check_Sum(uint8_t *pchMessage, uint16_t dwLength)
|
||||||
{
|
{
|
||||||
uint8_t ucExpected = 0;
|
uint8_t ucExpected = 0;
|
||||||
if ((pchMessage == 0) || (dwLength <= 2))
|
if ((pchMessage == 0) || (dwLength <= 2))
|
||||||
return 0;
|
return 0;
|
||||||
ucExpected = Get_CRC8_Check(pchMessage, dwLength - 1);
|
ucExpected = crc_8(pchMessage, dwLength - 1);
|
||||||
return (ucExpected == pchMessage[dwLength - 1]);
|
return (ucExpected == pchMessage[dwLength - 1]);
|
||||||
}
|
}
|
||||||
/*获取CRC16校验码*/
|
|
||||||
uint16_t Get_CRC16_Check(uint8_t *pchMessage, uint32_t dwLength)
|
|
||||||
{
|
|
||||||
return crc_16(pchMessage, dwLength);
|
|
||||||
}
|
|
||||||
/*检验CRC16数据段*/
|
/*检验CRC16数据段*/
|
||||||
uint16_t CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength)
|
static uint16_t CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength)
|
||||||
{
|
{
|
||||||
uint16_t wExpected = 0;
|
uint16_t wExpected = 0;
|
||||||
if ((pchMessage == 0) || (dwLength <= 2))
|
if ((pchMessage == 0) || (dwLength <= 2))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
wExpected = Get_CRC16_Check(pchMessage, dwLength - 2);
|
wExpected = crc_16(pchMessage, dwLength - 2);
|
||||||
return (((wExpected & 0xff) == pchMessage[dwLength - 2]) && (((wExpected >> 8) & 0xff) == pchMessage[dwLength - 1]));
|
return (((wExpected & 0xff) == pchMessage[dwLength - 2]) && (((wExpected >> 8) & 0xff) == pchMessage[dwLength - 1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*检验数据帧头*/
|
/*检验数据帧头*/
|
||||||
uint8_t protocol_heade_Check(protocol_rm_struct *pro,uint8_t *rx_buf)
|
static uint8_t protocol_heade_Check(protocol_rm_struct *pro,uint8_t *rx_buf)
|
||||||
{
|
{
|
||||||
if (rx_buf[0] == PROTOCOL_CMD_ID)
|
if (rx_buf[0] == PROTOCOL_CMD_ID)
|
||||||
{
|
{
|
||||||
|
@ -61,15 +54,6 @@ uint8_t protocol_heade_Check(protocol_rm_struct *pro,uint8_t *rx_buf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float float_protocol(uint8_t *dat_t)
|
|
||||||
{
|
|
||||||
uint8_t f_data[4];
|
|
||||||
f_data[0] = *(dat_t + 0);
|
|
||||||
f_data[1] = *(dat_t + 1);
|
|
||||||
f_data[2] = *(dat_t + 2);
|
|
||||||
f_data[3] = *(dat_t + 3);
|
|
||||||
return *(float *)f_data;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
此函数根据待发送的数据更新数据帧格式以及内容,实现数据的打包操作
|
此函数根据待发送的数据更新数据帧格式以及内容,实现数据的打包操作
|
||||||
后续调用通信接口的发送函数发送tx_buf中的对应数据
|
后续调用通信接口的发送函数发送tx_buf中的对应数据
|
||||||
|
@ -118,24 +102,19 @@ void get_protocol_send_data(uint16_t send_id, //信号id
|
||||||
*/
|
*/
|
||||||
uint16_t get_protocol_info(uint8_t *rx_buf, //接收到的原始数据
|
uint16_t get_protocol_info(uint8_t *rx_buf, //接收到的原始数据
|
||||||
uint16_t *flags_register, //接收数据的16位寄存器地址
|
uint16_t *flags_register, //接收数据的16位寄存器地址
|
||||||
float *rx_data) //接收的float数据存储地址
|
uint8_t *rx_data) //接收的float数据存储地址
|
||||||
{
|
{
|
||||||
static protocol_rm_struct pro;
|
static protocol_rm_struct pro;
|
||||||
static uint16_t date_length;
|
static uint16_t date_length;
|
||||||
|
volatile size_t s=sizeof(pro);
|
||||||
|
volatile size_t aa=sizeof(Vision_Recv_s);
|
||||||
if (protocol_heade_Check(&pro, rx_buf))
|
if (protocol_heade_Check(&pro, rx_buf))
|
||||||
{
|
{
|
||||||
date_length = OFFSET_BYTE + pro.header.data_length;
|
date_length = OFFSET_BYTE + pro.header.data_length;
|
||||||
while (CRC16_Check_Sum(&rx_buf[0], date_length))
|
if (CRC16_Check_Sum(&rx_buf[0], date_length))
|
||||||
{
|
{
|
||||||
*flags_register = (rx_buf[7] << 8) | rx_buf[6];
|
*flags_register = (rx_buf[7] << 8) | rx_buf[6];
|
||||||
for (int i = 0; i < (pro.header.data_length - 2) / 4; i++)
|
memcpy(rx_data,rx_buf+8,4*sizeof(pro.header.data_length - 2));
|
||||||
{
|
|
||||||
rx_data[i] = float_protocol(&rx_buf[8 + 4 * i]);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < date_length; i++)
|
|
||||||
{
|
|
||||||
rx_buf[i] = 0;
|
|
||||||
}
|
|
||||||
return pro.cmd_id;
|
return pro.cmd_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define __SEASKY_PROTOCOL_H
|
#define __SEASKY_PROTOCOL_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint-gcc.h>
|
||||||
|
|
||||||
#define PROTOCOL_CMD_ID 0XA5
|
#define PROTOCOL_CMD_ID 0XA5
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ typedef struct
|
||||||
Target_State_e target_state;
|
Target_State_e target_state;
|
||||||
Target_Type_e target_type;
|
Target_Type_e target_type;
|
||||||
|
|
||||||
float yaw;
|
|
||||||
float pitch;
|
float pitch;
|
||||||
|
float yaw;
|
||||||
} Vision_Recv_s;
|
} Vision_Recv_s;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -92,6 +92,7 @@ typedef struct
|
||||||
uint16_t frame_tail; // 帧尾CRC校验
|
uint16_t frame_tail; // 帧尾CRC校验
|
||||||
} protocol_rm_struct;
|
} protocol_rm_struct;
|
||||||
|
|
||||||
|
|
||||||
/*更新发送数据帧,并计算发送数据帧长度*/
|
/*更新发送数据帧,并计算发送数据帧长度*/
|
||||||
void get_protocol_send_data(uint16_t send_id, // 信号id
|
void get_protocol_send_data(uint16_t send_id, // 信号id
|
||||||
uint16_t flags_register, // 16位寄存器
|
uint16_t flags_register, // 16位寄存器
|
||||||
|
@ -103,6 +104,6 @@ void get_protocol_send_data(uint16_t send_id, // 信号id
|
||||||
/*接收数据处理*/
|
/*接收数据处理*/
|
||||||
uint16_t get_protocol_info(uint8_t *rx_buf, // 接收到的原始数据
|
uint16_t get_protocol_info(uint8_t *rx_buf, // 接收到的原始数据
|
||||||
uint16_t *flags_register, // 接收数据的16位寄存器地址
|
uint16_t *flags_register, // 接收数据的16位寄存器地址
|
||||||
float *rx_data); // 接收的float数据存储地址
|
uint8_t *rx_data); // 接收的float数据存储地址
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue