实现复位飞控进入isp模式,并擦除内存
This commit is contained in:
@@ -269,6 +269,17 @@ int resend_parse_data(resend_device_t *resend_device)
|
|||||||
break;
|
break;
|
||||||
case RESEND_CMD_OTA_END:
|
case RESEND_CMD_OTA_END:
|
||||||
break;
|
break;
|
||||||
|
case RESEND_CMD_FC_ISP_GET_PARAM:
|
||||||
|
//针对ISP的应答
|
||||||
|
resend_device->status.ack_flag = 0;
|
||||||
|
break;
|
||||||
|
case RESEND_CMD_FC_ISP_START:
|
||||||
|
resend_device->handle_flag = RESEND_CMD_FC_ISP_GET_PARAM;
|
||||||
|
break;
|
||||||
|
case RESEND_CMD_FC_ISP_DATA:
|
||||||
|
break;
|
||||||
|
case RESEND_CMD_FC_ISP_END:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,12 @@ typedef enum
|
|||||||
RESEND_CMD_OTA_GET_PARAM = 0x010,
|
RESEND_CMD_OTA_GET_PARAM = 0x010,
|
||||||
RESEND_CMD_OTA_START = 0x011,
|
RESEND_CMD_OTA_START = 0x011,
|
||||||
RESEND_CMD_OTA_DATA = 0x012,
|
RESEND_CMD_OTA_DATA = 0x012,
|
||||||
RESEND_CMD_OTA_END = 0x013
|
RESEND_CMD_OTA_END = 0x013,
|
||||||
|
|
||||||
|
RESEND_CMD_FC_ISP_GET_PARAM = 0x020,
|
||||||
|
RESEND_CMD_FC_ISP_START = 0x021,
|
||||||
|
RESEND_CMD_FC_ISP_DATA = 0x022,
|
||||||
|
RESEND_CMD_FC_ISP_END = 0x023
|
||||||
}resend_cmd_type_e;
|
}resend_cmd_type_e;
|
||||||
// 帧解析状态
|
// 帧解析状态
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|||||||
@@ -22,8 +22,12 @@ void sertrf_init(void)
|
|||||||
resend_init(&sertrf.resend_device, resend_send, resend_recv, resend_get_length,resend_user_parse);
|
resend_init(&sertrf.resend_device, resend_send, resend_recv, resend_get_length,resend_user_parse);
|
||||||
// stmisp协议初始化
|
// stmisp协议初始化
|
||||||
stmisp_init(&sertrf.stmisp_device,stmisp_send,stmisp_recv,stmisp_get_length);
|
stmisp_init(&sertrf.stmisp_device,stmisp_send,stmisp_recv,stmisp_get_length);
|
||||||
|
|
||||||
//OAT信息获取
|
//OAT信息获取
|
||||||
get_partition_status(&sertrf.otau);
|
get_partition_status(&sertrf.otau);
|
||||||
|
|
||||||
|
//获取飞控代码地址
|
||||||
|
sertrf.fc_address = parse_hex_or_dec(FC_ADDRESS);
|
||||||
//线程启动
|
//线程启动
|
||||||
sertrf_start();
|
sertrf_start();
|
||||||
}
|
}
|
||||||
@@ -267,6 +271,12 @@ void printf_chill_time(uint8_t chill_time, uint16_t type)
|
|||||||
last_time[chill_time] = now_time;
|
last_time[chill_time] = now_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t parse_hex_or_dec(const char *s) {
|
||||||
|
if (!s) return 0;
|
||||||
|
if (s[0] == '0' && (s[1]=='x' || s[1]=='X')) return (uint32_t)strtoul(s+2, NULL, 16);
|
||||||
|
return (uint32_t)strtoul(s, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int resend_send(void* data, uint16_t len, int timeout)
|
int resend_send(void* data, uint16_t len, int timeout)
|
||||||
{
|
{
|
||||||
return app_device_write(&sertrf.device, data, len);
|
return app_device_write(&sertrf.device, data, len);
|
||||||
@@ -320,7 +330,7 @@ void resend_user_parse(void *resend_device)
|
|||||||
break;
|
break;
|
||||||
case RESEND_CMD_OTA_START:
|
case RESEND_CMD_OTA_START:
|
||||||
{
|
{
|
||||||
|
//设置协议状态,为了后续灯颜色变化
|
||||||
protocol_set_message_status(MESSAGE_OTA);
|
protocol_set_message_status(MESSAGE_OTA);
|
||||||
// if(!sertrf.resend_device.status.resend_flag)
|
// if(!sertrf.resend_device.status.resend_flag)
|
||||||
otau_init(&sertrf.otau);
|
otau_init(&sertrf.otau);
|
||||||
@@ -329,7 +339,6 @@ void resend_user_parse(void *resend_device)
|
|||||||
break;
|
break;
|
||||||
case RESEND_CMD_OTA_DATA:
|
case RESEND_CMD_OTA_DATA:
|
||||||
{
|
{
|
||||||
|
|
||||||
memcpy(sertrf.otau.ota_buff + sertrf.otau.ota_data_cnt, sertrf.resend_device.rx_frame.payload, sertrf.resend_device.rx_frame.len);
|
memcpy(sertrf.otau.ota_buff + sertrf.otau.ota_data_cnt, sertrf.resend_device.rx_frame.payload, sertrf.resend_device.rx_frame.len);
|
||||||
|
|
||||||
sertrf.otau.ota_data_cnt += sertrf.resend_device.rx_frame.len;
|
sertrf.otau.ota_data_cnt += sertrf.resend_device.rx_frame.len;
|
||||||
@@ -361,6 +370,47 @@ void resend_user_parse(void *resend_device)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Examples_run(void)
|
||||||
|
{
|
||||||
|
//关闭其他线程中相同串口的使用
|
||||||
|
sertrf.stmisp_device.flag = 1;
|
||||||
|
// 重启飞控,并使其进入isp烧录模式
|
||||||
|
fc_reboot();
|
||||||
|
boot_set(1);
|
||||||
|
os_thread_sleep(1000);
|
||||||
|
uart_set_parity_switch(sertrf.device.embedded_device, 0x02);
|
||||||
|
os_thread_sleep(100);
|
||||||
|
// 与isp确定通讯波特率,并建立联系
|
||||||
|
if(!send_sync(&sertrf.stmisp_device, 5))
|
||||||
|
printf("stmisp: sync error\n");
|
||||||
|
else
|
||||||
|
printf("stmisp: sync ok\n");
|
||||||
|
|
||||||
|
os_thread_sleep(100);
|
||||||
|
|
||||||
|
// 解除写保护
|
||||||
|
if(!cmd_write_unprotect(&sertrf.stmisp_device))
|
||||||
|
printf("stmisp: write unprotect error\n");
|
||||||
|
else
|
||||||
|
printf("stmisp: write unprotect ok\n");
|
||||||
|
|
||||||
|
os_thread_sleep(100);
|
||||||
|
if(!send_sync(&sertrf.stmisp_device, 5))
|
||||||
|
printf("stmisp: sync error\n");
|
||||||
|
else
|
||||||
|
printf("stmisp: sync ok\n");
|
||||||
|
os_thread_sleep(100);
|
||||||
|
// 全盘擦除
|
||||||
|
if(!cmd_extended_erase_mass(&sertrf.stmisp_device))
|
||||||
|
printf("stmisp: erase mass error\n");
|
||||||
|
else
|
||||||
|
printf("stmisp: erase mass ok\n");
|
||||||
|
|
||||||
|
os_thread_sleep(10);
|
||||||
|
|
||||||
|
printf("stmisp: isp start\n");
|
||||||
|
|
||||||
|
}
|
||||||
int stmisp_send(void* data, uint16_t len, int timeout)
|
int stmisp_send(void* data, uint16_t len, int timeout)
|
||||||
{
|
{
|
||||||
return embedded_device_write(&sertrf.device, data, len);
|
return embedded_device_write(&sertrf.device, data, len);
|
||||||
@@ -372,6 +422,8 @@ int stmisp_recv(void* data, uint16_t len, int timeout)
|
|||||||
while(os_get_sys_time() - time_start < timeout)
|
while(os_get_sys_time() - time_start < timeout)
|
||||||
{
|
{
|
||||||
size = embedded_device_read(&sertrf.device, data, len, 0);
|
size = embedded_device_read(&sertrf.device, data, len, 0);
|
||||||
|
if(size > 0)
|
||||||
|
return size;
|
||||||
os_thread_sleep(1);
|
os_thread_sleep(1);
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include "ota_u.h"
|
#include "ota_u.h"
|
||||||
#include "../../config/app_config.h"
|
#include "../../config/app_config.h"
|
||||||
|
|
||||||
|
#define FC_ADDRESS "0x08000000"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
device_t device;
|
device_t device;
|
||||||
@@ -25,6 +27,7 @@ typedef struct
|
|||||||
//STMISP协议
|
//STMISP协议
|
||||||
stmisp_device_t stmisp_device;
|
stmisp_device_t stmisp_device;
|
||||||
|
|
||||||
|
uint32_t fc_address;
|
||||||
}sertrf_t;
|
}sertrf_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -82,4 +85,8 @@ void pc_link_rgb_color(device_t* device);
|
|||||||
* @brief 打印时间间隔
|
* @brief 打印时间间隔
|
||||||
*/
|
*/
|
||||||
void printf_chill_time(uint8_t chill_time, uint16_t type);
|
void printf_chill_time(uint8_t chill_time, uint16_t type);
|
||||||
|
/**
|
||||||
|
* @brief 字符串转十进制
|
||||||
|
*/
|
||||||
|
uint32_t parse_hex_or_dec(const char *s);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user