This commit is contained in:
Robofish 2025-09-29 03:35:01 +08:00
parent bc9628b56e
commit 5abffb4cd1
14 changed files with 1367 additions and 531 deletions

View File

@ -70,6 +70,11 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
User/device/motor.c
User/device/motor_rm.c
# User/module sources
User/module/config.c
User/module/gimbal.c
User/module/shoot.c
# User/task sources
User/task/ai.c
User/task/atti_esti.c

File diff suppressed because it is too large Load Diff

View File

@ -128,7 +128,7 @@ uart:
- instance: USART6
name: AI
- instance: USART1
name: DR16
- instance: USART3
name: REF
- instance: USART3
name: DR16
enabled: true

View File

@ -26,9 +26,9 @@ static BSP_UART_t UART_Get(UART_HandleTypeDef *huart) {
if (huart->Instance == USART6)
return BSP_UART_AI;
else if (huart->Instance == USART1)
return BSP_UART_DR16;
else if (huart->Instance == USART3)
return BSP_UART_REF;
else if (huart->Instance == USART3)
return BSP_UART_DR16;
else
return BSP_UART_ERR;
}
@ -119,9 +119,9 @@ UART_HandleTypeDef *BSP_UART_GetHandle(BSP_UART_t uart) {
switch (uart) {
case BSP_UART_AI:
return &huart6;
case BSP_UART_DR16:
return &huart1;
case BSP_UART_REF:
return &huart1;
case BSP_UART_DR16:
return &huart3;
default:
return NULL;

View File

@ -28,8 +28,8 @@ extern "C" {
/* UART实体枚举与设备对应 */
typedef enum {
BSP_UART_AI,
BSP_UART_DR16,
BSP_UART_REF,
BSP_UART_DR16,
BSP_UART_NUM,
BSP_UART_ERR,
} BSP_UART_t;

54
User/module/config.c Normal file
View File

@ -0,0 +1,54 @@
/*
*
*/
/* Includes ----------------------------------------------------------------- */
#include "module/config.h"
#include "bsp/can.h"
#include "device/motor_rm.h"
#include "component/pid.h"
#include "component/user_math.h"
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* Exported variables ------------------------------------------------------- */
// 机器人参数配置
Config_RobotParam_t robot_config = {
.shoot_param = {
.trig_motor_param = {
.can = BSP_CAN_1,
.id = 0x201,
.module = MOTOR_M2006,
.reverse = false,
.gear = true,
},
.trig_pid_param = {
.k = 12.0f,
.p = 1.0f,
.i = 0.0f,
.d = 0.0450000018f,
.i_limit = 1.0f,
.out_limit = 1.0f,
.d_cutoff_freq = -1.0f,
.range = M_2PI,
},
.num_trig_tooth = 8.0f,
.fric_radius = 0.03f,
.min_shoot_delay = (uint32_t)(1000.0f / 10.0f),
}
};
/* Private function prototypes ---------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
/**
* @brief
* @return
*/
Config_RobotParam_t* Config_GetRobotParam(void) {
return &robot_config;
}

30
User/module/config.h Normal file
View File

@ -0,0 +1,30 @@
/*
*
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "module/shoot.h"
#include "module/gimbal.h"
typedef struct {
Shoot_Params_t shoot_param; /* 射击参数 */
} Config_RobotParam_t;
/* Exported functions prototypes -------------------------------------------- */
/**
* @brief
* @return
*/
Config_RobotParam_t* Config_GetRobotParam(void);
#ifdef __cplusplus
}
#endif

0
User/module/gimbal.c Normal file
View File

0
User/module/gimbal.h Normal file
View File

201
User/module/shoot.c Normal file
View File

@ -0,0 +1,201 @@
/*
*
*/
/* Includes ----------------------------------------------------------------- */
#include "shoot.h"
#include "bsp/pwm.h"
#include "bsp/time.h"
#include "bsp/can.h"
#include "component/pid.h"
#include "component/limiter.h"
#include "component/user_math.h"
#include "device/motor_rm.h"
#include <stdint.h>
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
#define BULLET_SPEED_LIMIT_17MM (25.0)
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* Private function -------------------------------------------------------- */
/**
* \brief
*
* \param c
* \param mode
*
* \return
*/
static int8_t Shoot_SetMode(Shoot_t *s, CMD_ShootMode_t mode) {
if (s == NULL) return -1;
if (mode == s->mode) return SHOOT_OK;
/* 切换模式后重置PID和滤波器 */
// for (uint8_t i = 0; i < 2; i++) {
// PID_Reset(s->pid.fric + i);
// LowPassFilter2p_Reset(s->filter.in.fric + i, 0.0f);
// LowPassFilter2p_Reset(s->filter.out.fric + i, 0.0f);
// }
// PID_Reset(&(s->pid.trig));
// LowPassFilter2p_Reset(&(s->filter.in.trig), 0.0f);
// LowPassFilter2p_Reset(&(s->filter.out.trig), 0.0f);
PID_Reset(&(s->pid.fric[0]));
PID_Reset(&(s->pid.fric[1]));
LowPassFilter2p_Reset(&(s->filter.in.fric[0]), 0.0f);
LowPassFilter2p_Reset(&(s->filter.in.fric[1]), 0.0f);
LowPassFilter2p_Reset(&(s->filter.out.fric[0]), 0.0f);
LowPassFilter2p_Reset(&(s->filter.out.fric[1]), 0.0f);
PID_Reset(&(s->pid.trig));
LowPassFilter2p_Reset(&(s->filter.in.trig), 0.0f);
LowPassFilter2p_Reset(&(s->filter.out.trig), 0.0f);
// while (fabsf(CircleError(s->setpoint.trig_angle, s->feedback.trig_angle,
// M_2PI)) >= M_2PI / s->param->num_trig_tooth / 2.0f) {
// CircleAdd(&(s->setpoint.trig_angle), M_2PI / s->param->num_trig_tooth,
// M_2PI);
// }
if (mode == SHOOT_MODE_LOADED) s->fire_ctrl.to_shoot = 0;
s->mode = mode;
return 0;
}
// static float Shoot_CalcRPMFromSpeed(float speed, float radius, float *rpm) {
// if (rpm == NULL) return -1;
// if (radius <= 0.0f) return -2;
// /* 限制弹丸速度 */
// speed = Limit_Abs(speed, BULLET_SPEED_LIMIT_17MM);
// /* 计算转速 */
// *rpm = speed / (2.0f * M_PI * radius) * 60.0f;
// return 0;
// }
/* Exported functions ------------------------------------------------------- */
/**
* \brief
*
* \param s
* \param param
* \param target_freq
*
* \return
*/
int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq) {
if (s == NULL) return -1;
s->param = param; /* 初始化参数 */
s->mode = SHOOT_MODE_RELAX; /* 设置默认模式 */
PID_Init(&(s->pid.fric[0]), KPID_MODE_NO_D, target_freq,
&(param->fric_pid_param));
PID_Init(&(s->pid.fric[1]), KPID_MODE_NO_D, target_freq,
&(param->fric_pid_param));
PID_Init(&(s->pid.trig), KPID_MODE_CALC_D, target_freq,
&(param->trig_pid_param));
LowPassFilter2p_Init(&(s->filter.in.fric[0]), target_freq,
param->low_pass_cutoff_freq.in.fric);
LowPassFilter2p_Init(&(s->filter.in.fric[1]), target_freq,
param->low_pass_cutoff_freq.in.fric);
LowPassFilter2p_Init(&(s->filter.out.fric[0]), target_freq,
param->low_pass_cutoff_freq.out.fric);
LowPassFilter2p_Init(&(s->filter.out.fric[1]), target_freq,
param->low_pass_cutoff_freq.out.fric);
LowPassFilter2p_Init(&(s->filter.in.trig), target_freq,
param->low_pass_cutoff_freq.in.trig);
LowPassFilter2p_Init(&(s->filter.out.trig), target_freq,
param->low_pass_cutoff_freq.out.trig);
BSP_CAN_Init();
MOTOR_RM_Register(s->param->fric_motor_param[0]);
MOTOR_RM_Register(s->param->fric_motor_param[1]);
MOTOR_RM_Register(s->param->trig_motor_param);
return SHOOT_OK;
}
/**
* \brief
*
* \param s
*
* \return
*/
int8_t Shoot_UpdateFeedback(Shoot_t *s) {
if (s == NULL) return -1;
MOTOR_RM_Update(s->param->fric_motor_param[0]);
MOTOR_RM_Update(s->param->fric_motor_param[1]);
MOTOR_RM_Update(s->param->trig_motor_param);
MOTOR_RM_t *motor;
motor = MOTOR_RM_GetMotor(s->param->fric_motor_param[0]);
s->feedback.fric[0] = motor->feedback;
motor = MOTOR_RM_GetMotor(s->param->fric_motor_param[1]);
s->feedback.fric[1] = motor->feedback;
motor = MOTOR_RM_GetMotor(s->param->trig_motor_param);
s->feedback.trig = motor->feedback;
return SHOOT_OK;
}
/**
* \brief
*
* \param s
* \param s_cmd
*
* \return
*/
int8_t Shoot_Control(Shoot_t *s, Shoot_CMD_t *s_cmd) {
if (s == NULL) return -1;
if (s_cmd == NULL) return -1;
Shoot_SetMode(s, s_cmd->mode); /* 设置射击模式 */
/* 计算摩擦轮转速的目标值 */
// 根据弹丸射速计算转速,这里需要实现具体的计算逻辑
// s->setpoint.fric_rpm[0] = calculate_rpm_from_speed(s_cmd->bullet_speed);
// s->setpoint.fric_rpm[1] = -s->setpoint.fric_rpm[0];
switch (s->mode) {
case SHOOT_MODE_RELAX:
MOTOR_RM_SetOutput(s->param->fric_motor_param[0], 0.0f);
MOTOR_RM_SetOutput(s->param->fric_motor_param[1], 0.0f);
MOTOR_RM_SetOutput(s->param->trig_motor_param, 0.0f);
break;
case SHOOT_MODE_SAFE:
/*摩擦轮速度环到0拨弹位置环到设定位置*/
s->setpoint.fric_rpm[0] = 0.0f;
s->setpoint.fric_rpm[1] = 0.0f;
break;
case SHOOT_MODE_LOADED:
// TODO: 实现上膛模式的控制逻辑
break;
}
return SHOOT_OK;
}
/**
* \brief
*
* \param s
*/
void Shoot_Output(Shoot_t *s) {
if (s == NULL) return;
MOTOR_RM_Ctrl(s->param->fric_motor_param[0]);
}

176
User/module/shoot.h Normal file
View File

@ -0,0 +1,176 @@
/*
*
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include "component/filter.h"
#include "component/pid.h"
#include "device/motor_rm.h"
#include "device/motor.h"
/* Exported constants ------------------------------------------------------- */
#define SHOOT_OK (0) /* 运行正常 */
#define SHOOT_ERR (-1) /* 运行时发现了其他错误 */
#define SHOOT_ERR_NULL (-2) /* 运行时发现NULL指针 */
#define SHOOT_ERR_MODE (-3) /* 运行时配置了错误的CMD_ShootMode_t */
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */
typedef enum {
SHOOT_MODE_RELAX = 0, /* 放松模式,电机不工作 */
SHOOT_MODE_SAFE = 1, /* 安全模式,电机工作但不允许射击 */
SHOOT_MODE_LOADED = 2 /* 上膛模式,电机工作并允许射击 */
}Shoot_Mode_t;
typedef struct {
Shoot_Mode_t mode; /*射击模式*/
float bullet_speed; /*弹丸射速*/
uint32_t bullet_num; /*要发射的弹丸数*/
}Shoot_CMD_t;
/* 射击参数的结构体包含所有初始化用的参数通常是const存好几组。*/
typedef struct {
MOTOR_RM_Param_t fric_motor_param[2]; /* 摩擦轮电机参数 */
MOTOR_RM_Param_t trig_motor_param; /* 拨弹电机参数 */
KPID_Params_t fric_pid_param; /* 摩擦轮电机控制PID的参数 */
KPID_Params_t trig_pid_param; /* 扳机电机控制PID的参数 */
/* 低通滤波器截止频率 */
struct {
/* 输入 */
struct {
float fric; /* 摩擦轮电机 */
float trig; /* 扳机电机 */
} in;
/* 输出 */
struct {
float fric; /* 摩擦轮电机 */
float trig; /* 扳机电机 */
} out;
} low_pass_cutoff_freq;
float num_trig_tooth; /* 拨弹盘中一圈能存储几颗弹丸 */
float fric_radius; /* 摩擦轮半径,单位:米 */
float cover_open_duty; /* 弹舱盖打开时舵机PWM占空比 */
float cover_close_duty; /* 弹舱盖关闭时舵机PWM占空比 */
float bullet_speed; /* 弹丸初速度 */
uint32_t min_shoot_delay; /* 通过设置最小射击间隔来设置最大射频 */
} Shoot_Params_t;
typedef struct {
uint32_t last_shoot; /* 上次射击时间 单位ms */
bool last_fire; /* 上次开火状态 */
bool first_fire; /* 第一次收到开火指令 */
uint32_t shooted; /* 已经发射的弹丸 */
uint32_t to_shoot; /* 计划发射的弹丸 */
float bullet_speed; /* 弹丸初速度 */
uint32_t period_ms; /* 弹丸击发延迟 */
} Shoot_FireCtrl_t;
/*
*
*
*/
typedef struct {
uint64_t lask_wakeup;
float dt;
const Shoot_Params_t *param; /* 射击的参数用Shoot_Init设定 */
Shoot_FireCtrl_t fire_ctrl;
/* 模块通用 */
Shoot_Mode_t mode; /* 当前模式 */
/* 反馈信息 */
struct {
MOTOR_Feedback_t fric[2]; /* 摩擦轮电机反馈 */
MOTOR_Feedback_t trig; /* 拨弹电机反馈 */
} feedback;
/* PID计算的目标值 */
struct {
float fric_rpm[2]; /* 摩擦轮电机转速单位RPM */
float trig_angle; /* 拨弹电机角度,单位:弧度 */
} setpoint;
/* 反馈控制用的PID */
struct {
KPID_t fric[2]; /* 控制摩擦轮 */
KPID_t trig; /* 控制拨弹电机 */
} pid;
/* 过滤器 */
struct {
/* 反馈值滤波器 */
struct {
LowPassFilter2p_t fric[2]; /* 过滤摩擦轮 */
LowPassFilter2p_t trig; /* 过滤拨弹电机 */
} in;
/* 输出值滤波器 */
struct {
LowPassFilter2p_t fric[2]; /* 过滤摩擦轮 */
LowPassFilter2p_t trig; /* 过滤拨弹电机 */
} out;
} filter;
} Shoot_t;
/* Exported functions prototypes -------------------------------------------- */
/**
* \brief
*
* \param s
* \param param
* \param target_freq
*
* \return
*/
int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq);
/**
* \brief
*
* \param s
* \param can CAN设备结构体
*
* \return
*/
int8_t Shoot_UpdateFeedback(Shoot_t *s);
/**
* \brief
*
* \param s
* \param s_cmd
* \param s_ref
* \param dt_sec
*
* \return
*/
int8_t Shoot_Control(Shoot_t *s,Shoot_CMD_t *s_cmd);
/**
* \brief
*
* \param s
* \param out CAN设备射击输出结构体
*/
void Shoot_Output(Shoot_t *s);
#ifdef __cplusplus
}
#endif

View File

@ -1,12 +1,14 @@
/*
monitor Task
*/
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#include "bsp/time.h"
#include "bsp/pwm.h"
#include "component/user_math.h"
#include <math.h>
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
@ -14,7 +16,7 @@
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
float led = 0.0f;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
@ -30,13 +32,15 @@ void Task_monitor(void *argument) {
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
BSP_PWM_SetComp(BSP_PWM_LED_G, led);
BSP_PWM_Start(BSP_PWM_LED_G);
/* USER CODE INIT END */
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
led = fAbs(sinf(BSP_TIME_Get_ms()/1000.0f));
BSP_PWM_SetComp(BSP_PWM_LED_G, led);
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}

View File

@ -6,7 +6,7 @@
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#include "device/dr16.h"
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
@ -14,7 +14,7 @@
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
DR16_t dr16;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
@ -26,12 +26,17 @@ void Task_rc(void *argument) {
osDelay(RC_INIT_DELAY); /* 延时一段时间再开启任务 */
/* USER CODE INIT BEGIN */
DR16_Init(&dr16);
/* USER CODE INIT END */
while (1) {
/* USER CODE BEGIN */
DR16_StartDmaRecv(&dr16);
if (DR16_WaitDmaCplt(20)) {
DR16_ParseData(&dr16);
} else {
DR16_Offline(&dr16);
}
/* USER CODE END */
}

361
debug.jdebug Normal file
View File

@ -0,0 +1,361 @@
/*********************************************************************
* (c) SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
File : /Users/lvzucheng/Documents/R/balance_infantry/debug.jdebug
Created : 28 Sep 2025 16:36
Ozone Version : V3.38d
*/
/*********************************************************************
*
* OnProjectLoad
*
* Function description
* Project load routine. Required.
*
**********************************************************************
*/
void OnProjectLoad (void) {
//
// Dialog-generated settings
//
Project.AddPathSubstitute ("/Users/lvzucheng/Documents/R/balance_infantry", "$(ProjectDir)");
Project.AddPathSubstitute ("/users/lvzucheng/documents/r/balance_infantry", "$(ProjectDir)");
Project.SetDevice ("STM32F407IG");
Project.SetHostIF ("USB", "207400620");
Project.SetTargetIF ("SWD");
Project.SetTIFSpeed ("4 MHz");
Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M4F.svd");
//
// User settings
//
File.Open ("$(ProjectDir)/build/Debug/DevC.elf");
}
/*********************************************************************
*
* OnStartupComplete
*
* Function description
* Called when program execution has reached/passed
* the startup completion point. Optional.
*
**********************************************************************
*/
//void OnStartupComplete (void) {
//}
/*********************************************************************
*
* TargetReset
*
* Function description
* Replaces the default target device reset routine. Optional.
*
* Notes
* This example demonstrates the usage when
* debugging an application in RAM on a Cortex-M target device.
*
**********************************************************************
*/
//void TargetReset (void) {
//
// unsigned int SP;
// unsigned int PC;
// unsigned int VectorTableAddr;
//
// VectorTableAddr = Elf.GetBaseAddr();
// //
// // Set up initial stack pointer
// //
// if (VectorTableAddr != 0xFFFFFFFF) {
// SP = Target.ReadU32(VectorTableAddr);
// Target.SetReg("SP", SP);
// }
// //
// // Set up entry point PC
// //
// PC = Elf.GetEntryPointPC();
//
// if (PC != 0xFFFFFFFF) {
// Target.SetReg("PC", PC);
// } else if (VectorTableAddr != 0xFFFFFFFF) {
// PC = Target.ReadU32(VectorTableAddr + 4);
// Target.SetReg("PC", PC);
// } else {
// Util.Error("Project file error: failed to set entry point PC", 1);
// }
//}
/*********************************************************************
*
* BeforeTargetReset
*
* Function description
* Event handler routine. Optional.
*
**********************************************************************
*/
//void BeforeTargetReset (void) {
//}
/*********************************************************************
*
* AfterTargetReset
*
* Function description
* Event handler routine. Optional.
* The default implementation initializes SP and PC to reset values.
**
**********************************************************************
*/
void AfterTargetReset (void) {
_SetupTarget();
}
/*********************************************************************
*
* DebugStart
*
* Function description
* Replaces the default debug session startup routine. Optional.
*
**********************************************************************
*/
//void DebugStart (void) {
//}
/*********************************************************************
*
* TargetConnect
*
* Function description
* Replaces the default target IF connection routine. Optional.
*
**********************************************************************
*/
//void TargetConnect (void) {
//}
/*********************************************************************
*
* BeforeTargetConnect
*
* Function description
* Event handler routine. Optional.
*
**********************************************************************
*/
//void BeforeTargetConnect (void) {
//}
/*********************************************************************
*
* AfterTargetConnect
*
* Function description
* Event handler routine. Optional.
*
**********************************************************************
*/
//void AfterTargetConnect (void) {
//}
/*********************************************************************
*
* TargetDownload
*
* Function description
* Replaces the default program download routine. Optional.
*
**********************************************************************
*/
//void TargetDownload (void) {
//}
/*********************************************************************
*
* BeforeTargetDownload
*
* Function description
* Event handler routine. Optional.
*
**********************************************************************
*/
//void BeforeTargetDownload (void) {
//}
/*********************************************************************
*
* AfterTargetDownload
*
* Function description
* Event handler routine. Optional.
* The default implementation initializes SP and PC to reset values.
*
**********************************************************************
*/
void AfterTargetDownload (void) {
_SetupTarget();
}
/*********************************************************************
*
* BeforeTargetDisconnect
*
* Function description
* Event handler routine. Optional.
*
**********************************************************************
*/
//void BeforeTargetDisconnect (void) {
//}
/*********************************************************************
*
* AfterTargetDisconnect
*
* Function description
* Event handler routine. Optional.
*
**********************************************************************
*/
//void AfterTargetDisconnect (void) {
//}
/*********************************************************************
*
* AfterTargetHalt
*
* Function description
* Event handler routine. Optional.
*
**********************************************************************
*/
//void AfterTargetHalt (void) {
//}
/*********************************************************************
*
* BeforeTargetResume
*
* Function description
* Event handler routine. Optional.
*
**********************************************************************
*/
//void BeforeTargetResume (void) {
//}
/*********************************************************************
*
* OnSnapshotLoad
*
* Function description
* Called upon loading a snapshot. Optional.
*
* Additional information
* This function is used to restore the target state in cases
* where values cannot simply be written to the target.
* Typical use: GPIO clock needs to be enabled, before
* GPIO is configured.
*
**********************************************************************
*/
//void OnSnapshotLoad (void) {
//}
/*********************************************************************
*
* OnSnapshotSave
*
* Function description
* Called upon saving a snapshot. Optional.
*
* Additional information
* This function is usually used to save values of the target
* state which can either not be trivially read,
* or need to be restored in a specific way or order.
* Typically use: Memory Mapped Registers,
* such as PLL and GPIO configuration.
*
**********************************************************************
*/
//void OnSnapshotSave (void) {
//}
/*********************************************************************
*
* OnError
*
* Function description
* Called when an error ocurred. Optional.
*
**********************************************************************
*/
//void OnError (void) {
//}
/*********************************************************************
*
* AfterProjectLoad
*
* Function description
* After Project load routine. Optional.
*
**********************************************************************
*/
//void AfterProjectLoad (void) {
//}
/*********************************************************************
*
* OnDebugStartBreakSymbolReached
*
* Function description
* Called when program execution has reached/passed
* the symbol to be breaked at during debug start. Optional.
*
**********************************************************************
*/
//void OnDebugStartBreakSymReached (void) {
//}
/*********************************************************************
*
* _SetupTarget
*
* Function description
* Setup the target.
* Called by AfterTargetReset() and AfterTargetDownload().
*
* Auto-generated function. May be overridden by Ozone.
*
**********************************************************************
*/
void _SetupTarget(void) {
unsigned int SP;
unsigned int PC;
unsigned int VectorTableAddr;
VectorTableAddr = Elf.GetBaseAddr();
//
// Set up initial stack pointer
//
SP = Target.ReadU32(VectorTableAddr);
if (SP != 0xFFFFFFFF) {
Target.SetReg("SP", SP);
}
//
// Set up entry point PC
//
PC = Elf.GetEntryPointPC();
if (PC != 0xFFFFFFFF) {
Target.SetReg("PC", PC);
} else {
Util.Error("Project script error: failed to set up entry point PC", 1);
}
}