mirror of
https://github.com/armfly/H7-TOOL_STM32H7_App.git
synced 2024-08-09 10:05:34 +08:00
Merge pull request #31 from armfly/origin/armfly
适配RT1052, 支持Hyper Flash 和 QSPI Flash.
This commit is contained in:
commit
c07ccccac9
@ -1,3 +1,11 @@
|
||||
----------------------------------------------------------------------------
|
||||
2020-09-20 V1.31
|
||||
1. 适配RT1052, 支持Hyper Flash 和 QSPI Flash.
|
||||
2. 打印FLM文件时,显示第1个扇区的大小
|
||||
3. lua文件中增加 RESET_DELAY 变量,缺省20ms,可通过lua修改。硬件复位后的延迟时间
|
||||
4. lua文件中增加 RESET_MODE 变量,缺省0 表示自动. 1表示软件复位
|
||||
5. FLM擦除扇区超时时间,没有按照FLM中的执行. RT1052擦除256KB扇区,超时3秒
|
||||
6. 在线传送文件功能,提高效率。缓存16KB后再写入.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
2020-09-10 V1.30 【重大更新】
|
||||
|
9
Project/MDK-ARM(uV5)/EventRecorderStub.scvd
Normal file
9
Project/MDK-ARM(uV5)/EventRecorderStub.scvd
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
|
||||
|
||||
<component name="EventRecorderStub" version="1.0.0"/> <!--name and version of the component-->
|
||||
<events>
|
||||
</events>
|
||||
|
||||
</component_viewer>
|
3601
Project/MDK-ARM(uV5)/project.uvguix.ASUS
Normal file
3601
Project/MDK-ARM(uV5)/project.uvguix.ASUS
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -1535,6 +1535,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\User\modbus\modbus_file.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>modbus_swd.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\User\modbus\modbus_swd.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -68,7 +68,7 @@ __Vectors DCD __initial_sp ; Top of Stack
|
||||
DCD MemManage_Handler ; MPU Fault Handler
|
||||
DCD BusFault_Handler ; Bus Fault Handler
|
||||
DCD UsageFault_Handler ; Usage Fault Handler
|
||||
DCD 0x00000130 ; Reserved H7-TOOL APP 固件版本
|
||||
DCD 0x00000131 ; Reserved H7-TOOL APP 固件版本
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
|
BIN
Project/h7_tool_app(V1.31).bin
Normal file
BIN
Project/h7_tool_app(V1.31).bin
Normal file
Binary file not shown.
Binary file not shown.
@ -33,7 +33,7 @@ FATFS fs;
|
||||
#pragma location = 0x24001000
|
||||
FIL file;
|
||||
#pragma location = 0x24002000
|
||||
char FsReadBuf[8*1024];
|
||||
char FsReadBuf[16*1024];
|
||||
#pragma location = 0x24003000
|
||||
char FsWriteBuf[8*1024] = {"FatFS Write Demo \r\n www.armfly.com \r\n"};
|
||||
#pragma location = 0x24004000
|
||||
|
@ -365,6 +365,39 @@ static void MPU_Config(void)
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
|
||||
// uint16_t *aADCH1ConvertedData = (uint16_t *)0x38000000;
|
||||
// uint16_t *aADCH2ConvertedData = (uint16_t *)(0x38000000 + 32 * 1024);
|
||||
|
||||
// /* 0x20000000 128KB */
|
||||
// float *g_Ch1WaveBuf = (float *)0x20000000;
|
||||
// float *g_Ch2WaveBuf = (float *)(0x20000000 + 64 * 1024);
|
||||
/* 配置ADC 空间的属性为Write through */
|
||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||
MPU_InitStruct.BaseAddress = 0x38000000;
|
||||
MPU_InitStruct.Size = ARM_MPU_REGION_SIZE_64KB;
|
||||
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
|
||||
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
||||
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE; /* 不要CASHE */
|
||||
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
|
||||
MPU_InitStruct.Number = MPU_REGION_NUMBER5;
|
||||
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
|
||||
MPU_InitStruct.SubRegionDisable = 0x00;
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
|
||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||
MPU_InitStruct.BaseAddress = 0x20000000;
|
||||
MPU_InitStruct.Size = ARM_MPU_REGION_SIZE_128KB;
|
||||
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
|
||||
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
||||
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE; /* 不要CASHE */
|
||||
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
|
||||
MPU_InitStruct.Number = MPU_REGION_NUMBER6;
|
||||
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
|
||||
MPU_InitStruct.SubRegionDisable = 0x00;
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
|
||||
/*使能 MPU */
|
||||
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
||||
}
|
||||
|
@ -310,6 +310,11 @@ static float AdcSumAvg(uint8_t _AdcNo, uint8_t _Offset);
|
||||
void bsp_StopAdcCH1(void);
|
||||
void bsp_StopAdcCH2(void);
|
||||
|
||||
void __DSO_EnableDog(void);
|
||||
void __DSO_DisableDog(void);
|
||||
|
||||
void DSO_SetTrigerToggle(uint8_t _TrigEdge);
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: DSO_TrigFinished
|
||||
@ -344,10 +349,15 @@ void IRQ_WatchDog(void)
|
||||
uint8_t triged = 0;
|
||||
uint16_t *pAdcBuf;
|
||||
ADC_HandleTypeDef *hadc;
|
||||
static uint8_t s_TrigToggle = 0;
|
||||
|
||||
// HAL_ADC_IRQHandler(&AdcHandle1);
|
||||
// HAL_ADC_IRQHandler(&AdcHandle2);
|
||||
|
||||
// __DSO_DisableDog();
|
||||
|
||||
|
||||
|
||||
/* CH1 触发 */
|
||||
tmp_isr = AdcHandle1.Instance->ISR;
|
||||
tmp_ier = AdcHandle1.Instance->IER;
|
||||
@ -362,6 +372,20 @@ void IRQ_WatchDog(void)
|
||||
triged = 1;
|
||||
}
|
||||
|
||||
// if (s_TrigToggle == 1)
|
||||
// {
|
||||
// if (g_tDSO.TrigEdge == TRIG_EDGE_FALLING)
|
||||
// {
|
||||
// DSO_SetTrigerToggle(TRIG_EDGE_FALLING); /* 切换触发方向 */
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// DSO_SetTrigerToggle(TRIG_EDGE_RISING); /* 切换触发方向 */
|
||||
// }
|
||||
// s_TrigToggle = 0;
|
||||
// return;
|
||||
// }
|
||||
|
||||
/* CH2 触发*/
|
||||
tmp_isr = AdcHandle2.Instance->ISR;
|
||||
tmp_ier = AdcHandle2.Instance->IER;
|
||||
@ -458,9 +482,25 @@ void IRQ_WatchDog(void)
|
||||
BeginPos = ADC_BUFFER_SIZE + BeginPos;
|
||||
}
|
||||
|
||||
g_tDSO.DmaPos = BeginPos; /* 保存触发前的位置 */
|
||||
g_tDSO.DmaPos = BeginPos; /* 保存触发前的位置 */
|
||||
|
||||
s_TrigToggle = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_tDSO.TrigEdge == TRIG_EDGE_FALLING)
|
||||
{
|
||||
DSO_SetTrigerToggle(TRIG_EDGE_RISING); /* 切换触发方向 */
|
||||
}
|
||||
else
|
||||
{
|
||||
DSO_SetTrigerToggle(TRIG_EDGE_FALLING); /* 切换触发方向 */
|
||||
}
|
||||
|
||||
s_TrigToggle = 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void ADC_IRQHandler(void)
|
||||
@ -687,6 +727,12 @@ void __DSO_EnableDog(void)
|
||||
HAL_NVIC_EnableIRQ(ADC3_IRQn);
|
||||
}
|
||||
|
||||
void __DSO_DisableDog(void)
|
||||
{
|
||||
HAL_NVIC_DisableIRQ(ADC_IRQn);
|
||||
HAL_NVIC_DisableIRQ(ADC3_IRQn);
|
||||
}
|
||||
|
||||
void DSO_SetTriger(void)
|
||||
{
|
||||
ADC_AnalogWDGConfTypeDef WdgCfg;
|
||||
@ -795,6 +841,123 @@ void DSO_SetTriger(void)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: DSO_SetTrigerToggle
|
||||
* 功能说明: 切换触发方向
|
||||
* 形 参: _TrigEdge : 触发边沿模式
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void DSO_SetTrigerToggle(uint8_t _TrigEdge)
|
||||
{
|
||||
ADC_AnalogWDGConfTypeDef WdgCfg;
|
||||
|
||||
|
||||
/* ADC 通道1模拟看门狗配置 */
|
||||
WdgCfg.WatchdogNumber = ADC_ANALOGWATCHDOG_1;
|
||||
WdgCfg.Channel = ADCH1_CHANNEL;
|
||||
WdgCfg.WatchdogMode = ADC_ANALOGWATCHDOG_ALL_REG; // ADC_ANALOGWATCHDOG_ALL_REG;
|
||||
if (g_tDSO.TrigChan == 0)
|
||||
{
|
||||
WdgCfg.ITMode = ENABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
WdgCfg.ITMode = DISABLE;
|
||||
}
|
||||
|
||||
if (g_tDSO.TrigMode == TRIG_MODE_NORMAL || g_tDSO.TrigMode == TRIG_MODE_SINGLE)
|
||||
{
|
||||
if (_TrigEdge == TRIG_EDGE_RISING)
|
||||
{
|
||||
WdgCfg.HighThreshold = g_tDSO.TrigLevel;
|
||||
WdgCfg.LowThreshold = 0;
|
||||
}
|
||||
else if (_TrigEdge == TRIG_EDGE_FALLING)
|
||||
{
|
||||
WdgCfg.HighThreshold = 65535;
|
||||
WdgCfg.LowThreshold = g_tDSO.TrigLevel;
|
||||
}
|
||||
}
|
||||
else /* 自动触发,关闭看门狗 */
|
||||
{
|
||||
WdgCfg.HighThreshold = 65535;
|
||||
WdgCfg.LowThreshold = 0;
|
||||
}
|
||||
|
||||
HAL_ADC_AnalogWDGConfig(&AdcHandle1, &WdgCfg);
|
||||
|
||||
/* ADC 通道2模拟看门狗配置 */
|
||||
WdgCfg.WatchdogNumber = ADC_ANALOGWATCHDOG_1;
|
||||
WdgCfg.Channel = ADCH2_CHANNEL;
|
||||
WdgCfg.WatchdogMode = ADC_ANALOGWATCHDOG_ALL_REG; // ADC_ANALOGWATCHDOG_ALL_REG;
|
||||
if (g_tDSO.TrigChan == 1)
|
||||
{
|
||||
WdgCfg.ITMode = ENABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
WdgCfg.ITMode = DISABLE;
|
||||
}
|
||||
if (g_tDSO.TrigMode == TRIG_MODE_NORMAL || g_tDSO.TrigMode == TRIG_MODE_SINGLE)
|
||||
{
|
||||
if (_TrigEdge == TRIG_EDGE_RISING)
|
||||
{
|
||||
WdgCfg.HighThreshold = g_tDSO.TrigLevel;
|
||||
WdgCfg.LowThreshold = 0;
|
||||
}
|
||||
else if (_TrigEdge == TRIG_EDGE_FALLING)
|
||||
{
|
||||
WdgCfg.HighThreshold = 65535;
|
||||
WdgCfg.LowThreshold = g_tDSO.TrigLevel;
|
||||
}
|
||||
}
|
||||
else /* 自动触发,关闭看门狗 */
|
||||
{
|
||||
WdgCfg.HighThreshold = 65535;
|
||||
WdgCfg.LowThreshold = 0;
|
||||
}
|
||||
HAL_ADC_AnalogWDGConfig(&AdcHandle2, &WdgCfg);
|
||||
|
||||
// /* NVIC configuration for ADC interrupt */
|
||||
// /* Priority: high-priority */
|
||||
// HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
|
||||
// HAL_NVIC_DisableIRQ(ADC_IRQn);
|
||||
//
|
||||
// HAL_NVIC_SetPriority(ADC3_IRQn, 0, 0);
|
||||
// HAL_NVIC_DisableIRQ(ADC3_IRQn);
|
||||
|
||||
// {
|
||||
// uint32_t TransBuffSize; /* 通信传输的采样深度- PC软件设置的 */
|
||||
// int32_t pre_time;
|
||||
//
|
||||
// if (g_tDSO.TrigMode == TRIG_MODE_NORMAL || g_tDSO.TrigMode == TRIG_MODE_SINGLE)
|
||||
// {
|
||||
// /* 采样深度 */
|
||||
// if (g_tDSO.SampleSizeID < BUFF_SIZE_NUM)
|
||||
// {
|
||||
// TransBuffSize = TabelBufSize[g_tDSO.SampleSizeID];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// TransBuffSize = 1 * 1024;
|
||||
// }
|
||||
//
|
||||
// /* 计算预采集时间 us单位 */
|
||||
// pre_time = ((int64_t)(TransBuffSize * (g_tDSO.TrigPos) / 100) * 1000000) / TabelFreq[g_tDSO.FreqID];
|
||||
// if (pre_time == 0)
|
||||
// {
|
||||
// __DSO_EnableDog();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// bsp_StartHardTimer(2, pre_time, __DSO_EnableDog);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: DSO_CloseTriger
|
||||
@ -2123,9 +2286,10 @@ void DSO_LockWave(void)
|
||||
uint32_t i;
|
||||
uint32_t pos;
|
||||
uint32_t TransSize;
|
||||
|
||||
SCB_InvalidateDCache_by_Addr((uint32_t *)aADCH1ConvertedData, 2 * ADC_BUFFER_SIZE);
|
||||
SCB_InvalidateDCache_by_Addr((uint32_t *)aADCH2ConvertedData, 2 * ADC_BUFFER_SIZE);
|
||||
|
||||
// ADC缓冲区已禁止CASHE
|
||||
// SCB_InvalidateDCache_by_Addr((uint32_t *)aADCH1ConvertedData, 2 * ADC_BUFFER_SIZE);
|
||||
// SCB_InvalidateDCache_by_Addr((uint32_t *)aADCH2ConvertedData, 2 * ADC_BUFFER_SIZE);
|
||||
|
||||
pos = g_tDSO.DmaPos;
|
||||
TransSize = TabelBufSize[g_tDSO.SampleSizeID];
|
||||
@ -2164,6 +2328,8 @@ void DSO_LockWave(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SCB_InvalidateDCache_by_Addr((uint32_t *)g_Ch1WaveBuf, 128 * 1024);
|
||||
}
|
||||
|
||||
|
||||
|
@ -307,6 +307,29 @@ void MUL_SWD_GPIOConfig(void)
|
||||
EIO_D9_Config(ES_GPIO_SWD_OUT); /* 用FMC口线做GPIO。因此FMC功能失效 */
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MUL_PORT_SWD_SETUP
|
||||
* 功能说明: MUL_swd_init()调用该函数。初始化4路SWD硬件GPIO,并设置初始状态
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void MUL_PORT_SWD_SETUP(void)
|
||||
{
|
||||
// Set SWCLK HIGH
|
||||
// Set SWDIO HIGH
|
||||
// Set RESET LOW 转接板有反相器三极管
|
||||
MUL_SWD_GPIOConfig();
|
||||
MUL_RefreshGpioParam();
|
||||
|
||||
MUL_PIN_SWDIO_OUT_ENABLE();
|
||||
MUL_PIN_SWDIO_OUT(1);
|
||||
MUL_PIN_SWCLK_SET();
|
||||
|
||||
//EIO_SetOutLevel(0, 0); /* D0输出0V, 转接板RESET输出高 */
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MUL_RefreshGpioParam
|
||||
|
@ -49,6 +49,8 @@ void MUL_SWD_GPIOConfig(void);
|
||||
void MUL_RefreshGpioParam(void);
|
||||
void MUL_SEND_32BIT(uint32_t val);
|
||||
|
||||
void MUL_PORT_SWD_SETUP(void);
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//}
|
||||
//#endif
|
||||
|
@ -67,6 +67,8 @@ SWD_CONNECT_TYPE reset_connect = CONNECT_NORMAL; // CONNECT_NORMAL;CONNECT_UND
|
||||
static DAP_STATE dap_state;
|
||||
static uint32_t soft_reset = SYSRESETREQ;
|
||||
|
||||
static uint8_t s_reset_state = 0;
|
||||
|
||||
#if 0 // armfly debug
|
||||
__attribute__((weak)) void swd_set_target_reset(uint8_t asserted)
|
||||
{
|
||||
@ -78,11 +80,14 @@ void swd_set_target_reset(uint8_t asserted)
|
||||
// (asserted) ? PIN_nRESET_OUT(0) : PIN_nRESET_OUT(1);
|
||||
if (asserted)
|
||||
{
|
||||
s_reset_state = 1;
|
||||
//printf("reset gpio = 0\r\n");
|
||||
PIN_nRESET_OUT(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_reset_state = 0;
|
||||
|
||||
//printf("reset gpio = 1\r\n");
|
||||
PIN_nRESET_OUT(1);
|
||||
}
|
||||
@ -93,6 +98,11 @@ void swd_set_target_reset(uint8_t asserted)
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t swd_get_target_reset(void)
|
||||
{
|
||||
return s_reset_state;
|
||||
}
|
||||
|
||||
uint32_t target_get_apsel()
|
||||
{
|
||||
// if (g_target_family && g_target_family->apsel) {
|
||||
@ -150,16 +160,25 @@ void swd_set_soft_reset(uint32_t soft_reset_type)
|
||||
|
||||
uint8_t swd_init(void)
|
||||
{
|
||||
static uint8_t s_first_run = 0;
|
||||
//TODO - DAP_Setup puts GPIO pins in a hi-z state which can
|
||||
// cause problems on re-init. This needs to be investigated
|
||||
// and fixed.
|
||||
DAP_Setup();
|
||||
PORT_SWD_SETUP();
|
||||
|
||||
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
|
||||
PORT_SWD_SETUP(); /* V1.31内部已取消reset硬件设置 */
|
||||
|
||||
// Set RESET HIGH
|
||||
//pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit);//TODO - fix reset logic
|
||||
//BSP_SET_GPIO_1(nRESET_PIN_PORT, nRESET_PIN);
|
||||
|
||||
if (s_first_run == 0)
|
||||
{
|
||||
MUL_SWD_GPIOConfig();
|
||||
s_first_run = 1;
|
||||
BSP_SET_GPIO_1(nRESET_PIN_PORT, nRESET_PIN);
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1166,7 +1185,7 @@ uint8_t swd_init_debug(void)
|
||||
int8_t retries = 4;
|
||||
int8_t do_abort = 0;
|
||||
do {
|
||||
if (do_abort == 1)
|
||||
if (do_abort != 0)
|
||||
{
|
||||
//do an abort on stale target, then reset the device
|
||||
swd_write_dp(DP_ABORT, DAPABORT);
|
||||
@ -1174,37 +1193,38 @@ uint8_t swd_init_debug(void)
|
||||
swd_set_target_reset(1);
|
||||
osDelay(20);
|
||||
swd_set_target_reset(0);
|
||||
osDelay(20);
|
||||
//printf("reset, delay %dms\r\n", g_tProg.SwdResetDelay);
|
||||
osDelay(g_tProg.SwdResetDelay);
|
||||
do_abort = 0;
|
||||
}
|
||||
|
||||
swd_init();
|
||||
|
||||
if (!JTAG2SWD()) {
|
||||
do_abort = 1;
|
||||
do_abort = 1; /* 这种情况返回,有可能是用户程序禁止了SWD口 */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!swd_clear_errors()) {
|
||||
do_abort = 1;
|
||||
do_abort = 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!swd_write_dp(DP_SELECT, 0)) {
|
||||
do_abort = 1;
|
||||
do_abort = 3;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
// Power up
|
||||
if (!swd_write_dp(DP_CTRL_STAT, CSYSPWRUPREQ | CDBGPWRUPREQ)) {
|
||||
do_abort = 1;
|
||||
do_abort = 4;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 0; i < timeout; i++) {
|
||||
if (!swd_read_dp(DP_CTRL_STAT, &tmp)) {
|
||||
do_abort = 1;
|
||||
do_abort = 5;
|
||||
break;
|
||||
}
|
||||
if ((tmp & (CDBGPWRUPACK | CSYSPWRUPACK)) == (CDBGPWRUPACK | CSYSPWRUPACK)) {
|
||||
@ -1214,17 +1234,17 @@ uint8_t swd_init_debug(void)
|
||||
}
|
||||
if ((i == timeout) || (do_abort == 1)) {
|
||||
// Unable to powerup DP
|
||||
do_abort = 1;
|
||||
do_abort = 6;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!swd_write_dp(DP_CTRL_STAT, CSYSPWRUPREQ | CDBGPWRUPREQ | TRNNORMAL | MASKLANE)) {
|
||||
do_abort = 1;
|
||||
do_abort = 7;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!swd_write_dp(DP_SELECT, 0)) {
|
||||
do_abort = 1;
|
||||
do_abort = 8;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1642,24 +1662,29 @@ uint8_t swd_enter_debug_program(void)
|
||||
{
|
||||
uint32_t val;
|
||||
|
||||
//osDelay(200);
|
||||
|
||||
/* 拉低RESET */
|
||||
|
||||
/* 进入编程状态,先复位一次,应对已看门狗低功耗程序的片子 */
|
||||
swd_set_target_reset(1);
|
||||
osDelay(20);
|
||||
osDelay(10);
|
||||
swd_set_target_reset(0);
|
||||
|
||||
if (swd_init_debug() == 0)
|
||||
{
|
||||
printf("error 1: swd_init_debug()\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (swd_freeze_dog() == 0) /* 如果冻结看门狗时钟失败(STM32H7)*/
|
||||
{
|
||||
swd_set_target_reset(0); /* 退出硬件复位 */
|
||||
osDelay(20);
|
||||
if (swd_get_target_reset() == 0)
|
||||
{
|
||||
swd_set_target_reset(1); /* 硬件复位 */
|
||||
osDelay(g_tProg.SwdResetDelay);
|
||||
}
|
||||
|
||||
if (swd_init_debug() == 0)
|
||||
{
|
||||
printf("error 2: swd_init_debug()\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1677,7 +1702,7 @@ uint8_t swd_enter_debug_program(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
if (swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT) != 0)
|
||||
{
|
||||
@ -1686,10 +1711,43 @@ uint8_t swd_enter_debug_program(void)
|
||||
swd_set_target_reset(1);
|
||||
osDelay(20);
|
||||
swd_set_target_reset(0);
|
||||
osDelay(i * 5); /* 硬件复位退出后立即写指令 */
|
||||
osDelay(i * 5); /* 硬件复位退出后 立即写指令 */
|
||||
}
|
||||
}
|
||||
|
||||
// Enable halt on reset
|
||||
if (!swd_write_word(DBG_EMCR, VC_CORERESET)) {
|
||||
printf("error 3: swd_write_word(DBG_EMCR, VC_CORERESET)\r\n");
|
||||
return 0; /* 超时 */
|
||||
}
|
||||
|
||||
swd_read_word(DBG_HCSR, &val);
|
||||
if ((val & S_HALT) == 0)
|
||||
{
|
||||
if (swd_get_target_reset() == 0)
|
||||
{
|
||||
swd_set_target_reset(1);
|
||||
osDelay(20);
|
||||
}
|
||||
|
||||
if (swd_get_target_reset() == 1)
|
||||
{
|
||||
swd_set_target_reset(0); /* 退出硬件复位 */
|
||||
osDelay(g_tProg.SwdResetDelay);
|
||||
}
|
||||
}
|
||||
|
||||
// // Perform a soft reset
|
||||
// if (!swd_read_word(NVIC_AIRCR, &val)) {
|
||||
// printf("error 2: swd_read_word(NVIC_AIRCR, &val)\r\n");
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// if (!swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)) {
|
||||
// printf("error 3: swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)\r\n");
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
/* 2020-01-18 armfly 增加退出机制 */
|
||||
{
|
||||
uint32_t i;
|
||||
@ -1697,7 +1755,7 @@ uint8_t swd_enter_debug_program(void)
|
||||
for (i = 0; i < 100000; i++)
|
||||
{
|
||||
if (!swd_read_word(DBG_HCSR, &val)) {
|
||||
printf("error: swd_read_word(DBG_HCSR, &val) --1 i = %d\r\n", i);
|
||||
printf("error 4: swd_read_word(DBG_HCSR, &val) i = %d\r\n", i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1709,59 +1767,15 @@ uint8_t swd_enter_debug_program(void)
|
||||
|
||||
if (i == 100000)
|
||||
{
|
||||
printf("error: swd_read_word(DBG_HCSR, &val) --1\r\n");
|
||||
printf("error 5: swd_read_word(DBG_HCSR, &val)\r\n");
|
||||
return 0; /* 超时 */
|
||||
}
|
||||
}
|
||||
|
||||
// Enable halt on reset
|
||||
if (!swd_write_word(DBG_EMCR, VC_CORERESET)) {
|
||||
printf("error: swd_write_word(DBG_EMCR, VC_CORERESET)\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
swd_set_target_reset(0); /* 退出硬件复位 */
|
||||
osDelay(20);
|
||||
|
||||
// Perform a soft reset
|
||||
if (!swd_read_word(NVIC_AIRCR, &val)) {
|
||||
printf("error: swd_read_word(NVIC_AIRCR, &val)\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)) {
|
||||
printf("error: swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
osDelay(2);
|
||||
|
||||
/* 增加超时退出机制 */
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < 100000; i++)
|
||||
{
|
||||
if (!swd_read_word(DBG_HCSR, &val)) {
|
||||
printf("error: swd_read_word(DBG_HCSR, &val) --2 i = %d\r\n", i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((val & S_HALT) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 100000)
|
||||
{
|
||||
printf("error: swd_read_word(DBG_HCSR, &val) --2\r\n");
|
||||
return 0; /* 超时 */
|
||||
}
|
||||
}
|
||||
|
||||
// Disable halt on reset
|
||||
if (!swd_write_word(DBG_EMCR, 0)) {
|
||||
printf("error 6: swd_write_word(DBG_EMCR, 0)\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,8 @@ extern const char * swd_arm_core_info(uint32_t cpuid);
|
||||
static DAP_STATE dap_state;
|
||||
static uint32_t soft_reset = SYSRESETREQ;
|
||||
|
||||
static uint8_t s_reset_state = 0;
|
||||
|
||||
/*
|
||||
判断ACK = DAP_TRANSFER_OK
|
||||
*/
|
||||
@ -110,19 +112,26 @@ void MUL_swd_set_target_reset(uint8_t asserted)
|
||||
// swd_write_word((uint32_t)&SCB->AIRCR, ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |(SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | SCB_AIRCR_SYSRESETREQ_Msk));
|
||||
// }
|
||||
//
|
||||
if (asserted == 0)
|
||||
if (asserted)
|
||||
{
|
||||
// printf("reset gpio = %d\r\n", 1);
|
||||
EIO_SetOutLevel(EIO_D0, 0); /* 转接板NRESET 反相 */
|
||||
s_reset_state = 1;
|
||||
// printf("reset gpio = %d\r\n", 0);
|
||||
EIO_SetOutLevel(EIO_D0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("reset gpio = %d\r\n", 0);
|
||||
EIO_SetOutLevel(EIO_D0, 1);
|
||||
s_reset_state = 0;
|
||||
// printf("reset gpio = %d\r\n", 1);
|
||||
EIO_SetOutLevel(EIO_D0, 0); /* 转接板NRESET 反相 */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t MUL_swd_get_target_reset(void)
|
||||
{
|
||||
return s_reset_state;
|
||||
}
|
||||
|
||||
uint32_t MUL_target_get_apsel()
|
||||
{
|
||||
// if (g_target_family && g_target_family->apsel) {
|
||||
@ -246,17 +255,25 @@ void MUL_swd_set_soft_reset(uint32_t soft_reset_type)
|
||||
|
||||
uint8_t MUL_swd_init(void)
|
||||
{
|
||||
static uint8_t s_first_run = 0;
|
||||
|
||||
//TODO - DAP_Setup puts GPIO pins in a hi-z state which can
|
||||
// cause problems on re-init. This needs to be investigated
|
||||
// and fixed.
|
||||
DAP_Setup();
|
||||
PORT_SWD_SETUP();
|
||||
|
||||
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
|
||||
|
||||
// Set SWCLK HIGH
|
||||
// Set SWDIO HIGH
|
||||
// Set RESET LOW 转接板有反相器三极管
|
||||
MUL_PORT_SWD_SETUP();
|
||||
|
||||
if (s_first_run == 0)
|
||||
{
|
||||
MUL_SWD_GPIOConfig();
|
||||
MUL_RefreshGpioParam();
|
||||
s_first_run = 1;
|
||||
EIO_SetOutLevel(0, 0); /* D0输出0V, 转接板RESET输出高 */
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1499,36 +1516,28 @@ uint8_t MUL_swd_init_debug(void)
|
||||
g_gMulSwd.CoreID[2] = 0;
|
||||
g_gMulSwd.CoreID[3] = 0;
|
||||
do {
|
||||
if (do_abort == 1) {
|
||||
if (do_abort != 0)
|
||||
{
|
||||
//do an abort on stale target, then reset the device
|
||||
MUL_swd_write_dp(DP_ABORT, DAPABORT);
|
||||
|
||||
MUL_swd_set_target_reset(1);
|
||||
osDelay(20);
|
||||
MUL_swd_set_target_reset(0);
|
||||
osDelay(20);
|
||||
osDelay(g_tProg.SwdResetDelay);
|
||||
do_abort = 0;
|
||||
}
|
||||
|
||||
MUL_swd_init();
|
||||
|
||||
#if 0 // armfly debug
|
||||
// call a target dependant function
|
||||
// this function can do several stuff before really
|
||||
// initing the debug
|
||||
if (g_target_family && g_target_family->target_before_init_debug) {
|
||||
g_target_family->target_before_init_debug();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (do_abort == 2) /* 维持RESET = 0 */
|
||||
if (!MUL_JTAG2SWD())
|
||||
{
|
||||
MUL_swd_set_target_reset(1);
|
||||
osDelay(10);
|
||||
}
|
||||
|
||||
if (!MUL_JTAG2SWD()) {
|
||||
do_abort = 1;
|
||||
continue;
|
||||
osDelay(2); //调试RT1052 需要再次访问
|
||||
if (!MUL_JTAG2SWD())
|
||||
{
|
||||
do_abort = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@ -1547,25 +1556,25 @@ uint8_t MUL_swd_init_debug(void)
|
||||
|
||||
if (err == 1)
|
||||
{
|
||||
do_abort = 1;
|
||||
do_abort = 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!MUL_swd_clear_errors()) {
|
||||
do_abort = 1;
|
||||
do_abort = 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!MUL_swd_write_dp(DP_SELECT, 0)) {
|
||||
do_abort = 1;
|
||||
do_abort = 3;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
// Power up
|
||||
if (!MUL_swd_write_dp(DP_CTRL_STAT, CSYSPWRUPREQ | CDBGPWRUPREQ)) {
|
||||
do_abort = 1;
|
||||
do_abort = 4;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1614,7 +1623,7 @@ uint8_t MUL_swd_init_debug(void)
|
||||
}
|
||||
|
||||
if (!MUL_swd_write_dp(DP_CTRL_STAT, CSYSPWRUPREQ | CDBGPWRUPREQ | TRNNORMAL | MASKLANE)) {
|
||||
do_abort = 1;
|
||||
do_abort = 7;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1628,194 +1637,10 @@ uint8_t MUL_swd_init_debug(void)
|
||||
#endif
|
||||
|
||||
if (!MUL_swd_write_dp(DP_SELECT, 0)) {
|
||||
do_abort = 1;
|
||||
do_abort = 8;
|
||||
continue;
|
||||
}
|
||||
|
||||
// /* 识别进入调试状态异常,可能和用户程序启用看门狗或低功耗模式有关 */
|
||||
// {
|
||||
// uint32_t cpuid[4];
|
||||
//
|
||||
// if (do_abort == 0)
|
||||
// {
|
||||
// /* NVIC_CPUID = 0xE000ED00 */
|
||||
// if (!MUL_swd_read_word(NVIC_CPUID, cpuid))
|
||||
// {
|
||||
// do_abort = 1;
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if (g_gMulSwd.MultiMode >= 1)
|
||||
// {
|
||||
// printf("NVIC_CPUID1 = %08X, %s\r\n", cpuid[0], swd_arm_core_info(cpuid[0]));
|
||||
// }
|
||||
// if (g_gMulSwd.MultiMode >= 2)
|
||||
// {
|
||||
// printf("NVIC_CPUID2 = %08X, %s\r\n", cpuid[1], swd_arm_core_info(cpuid[1]));
|
||||
// }
|
||||
// if (g_gMulSwd.MultiMode >= 3)
|
||||
// {
|
||||
// printf("NVIC_CPUID3 = %08X, %s\r\n", cpuid[2], swd_arm_core_info(cpuid[2]));
|
||||
// }
|
||||
// if (g_gMulSwd.MultiMode >= 4)
|
||||
// {
|
||||
// printf("NVIC_CPUID4 = %08X, %s\r\n", cpuid[3], swd_arm_core_info(cpuid[3]));
|
||||
// }
|
||||
// {
|
||||
// uint8_t err = 0;
|
||||
//
|
||||
// for (i = 0; i < 4; i++)
|
||||
// {
|
||||
// if (g_gMulSwd.Active[i] == 1)
|
||||
// {
|
||||
// if ((cpuid[i] & 0xFF000000) != 0x41000000)
|
||||
// {
|
||||
// err = 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (err == 1)
|
||||
// {
|
||||
// do_abort = 2;
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (do_abort == 2) /* RESET == 0时进来, 调试期间关闭看门狗,禁止低功耗待机停机模式 */
|
||||
// {
|
||||
// const char *ret_str;
|
||||
//
|
||||
// lua_do("ret = InitUnderReset()");
|
||||
// lua_getglobal(g_Lua, "ret");
|
||||
// if (lua_isstring(g_Lua, -1))
|
||||
// {
|
||||
// ret_str = lua_tostring(g_Lua, -1);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ret_str = "";
|
||||
// }
|
||||
// lua_pop(g_Lua, 1);
|
||||
|
||||
// // [0xE000EDF0] = 0xA05F0003, remove C_MASKINTS
|
||||
// if (!MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT))
|
||||
// {
|
||||
// do_abort = 2;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // [0xE000EDFC] = 0x00000001
|
||||
// if (!MUL_swd_write_word(DBG_EMCR, VC_CORERESET))
|
||||
// {
|
||||
// do_abort = 2;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// MUL_swd_set_target_reset(0); // 退出复位
|
||||
// osDelay(50);
|
||||
|
||||
// /* 等待复位后停机 */
|
||||
// {
|
||||
// uint32_t i;
|
||||
// uint32_t val[4];
|
||||
// uint8_t err = 0;
|
||||
|
||||
// for (i = 0; i < 500; i++)
|
||||
// {
|
||||
// uint8_t errflag;
|
||||
//
|
||||
// if (!MUL_swd_read_word(DBG_HCSR, val)) {
|
||||
// err = 1;
|
||||
// break;
|
||||
// }
|
||||
// errflag = 0;
|
||||
// if (g_gMulSwd.Active[0] == 1 && ((val[0] & S_HALT) == 0))
|
||||
// {
|
||||
// errflag = 1;
|
||||
// }
|
||||
// if (g_gMulSwd.Active[1] == 1 && ((val[1] & S_HALT) == 0))
|
||||
// {
|
||||
// errflag = 1;
|
||||
// }
|
||||
// if (g_gMulSwd.Active[2] == 1 && ((val[2] & S_HALT) == 0))
|
||||
// {
|
||||
// errflag = 1;
|
||||
// }
|
||||
// if (g_gMulSwd.Active[3] == 1 && ((val[3] & S_HALT) == 0))
|
||||
// {
|
||||
// errflag = 1;
|
||||
// }
|
||||
// if (errflag == 0)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// bsp_DelayUS(1000);
|
||||
// }
|
||||
|
||||
// if (err > 0)
|
||||
// {
|
||||
// do_abort = 2;
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /* 解锁后重读 NVIC_CPUID */
|
||||
// {
|
||||
// /* NVIC_CPUID = 0xE000ED00 */
|
||||
// if (!MUL_swd_read_word(NVIC_CPUID, cpuid))
|
||||
// {
|
||||
// do_abort = 1;
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if (g_gMulSwd.MultiMode >= 1)
|
||||
// {
|
||||
// printf(".NVIC_CPUID1 = %08X, %s\r\n", cpuid[0], swd_arm_core_info(cpuid[0]));
|
||||
// }
|
||||
// if (g_gMulSwd.MultiMode >= 2)
|
||||
// {
|
||||
// printf(".NVIC_CPUID2 = %08X, %s\r\n", cpuid[1], swd_arm_core_info(cpuid[1]));
|
||||
// }
|
||||
// if (g_gMulSwd.MultiMode >= 3)
|
||||
// {
|
||||
// printf(".NVIC_CPUID3 = %08X, %s\r\n", cpuid[2], swd_arm_core_info(cpuid[2]));
|
||||
// }
|
||||
// if (g_gMulSwd.MultiMode >= 4)
|
||||
// {
|
||||
// printf(".NVIC_CPUID4 = %08X, %s\r\n", cpuid[3], swd_arm_core_info(cpuid[3]));
|
||||
// }
|
||||
// {
|
||||
// uint8_t err = 0;
|
||||
//
|
||||
// for (i = 0; i < 4; i++)
|
||||
// {
|
||||
// if (g_gMulSwd.Active[i] == 1)
|
||||
// {
|
||||
// if ((cpuid[i] & 0xFF000000) != 0x41000000)
|
||||
// {
|
||||
// err = 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (err == 1)
|
||||
// {
|
||||
// do_abort = 2;
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (strcmp(ret_str, "OK") != 0)
|
||||
// {
|
||||
// do_abort = 2;
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return 1;
|
||||
|
||||
} while (--retries > 0);
|
||||
@ -2256,22 +2081,30 @@ uint8_t MUL_swd_enter_debug_program(void)
|
||||
uint32_t val[4];
|
||||
uint32_t i;
|
||||
|
||||
/* 拉低RESET */
|
||||
/* 进入编程状态,先复位一次,应对已看门狗低功耗程序的片子 */
|
||||
MUL_swd_set_target_reset(1);
|
||||
osDelay(20);
|
||||
osDelay(10);
|
||||
MUL_swd_set_target_reset(0);
|
||||
|
||||
if (MUL_swd_init_debug() == 0)
|
||||
{
|
||||
printf("error 1: MUL_swd_init_debug()\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
osDelay(5);
|
||||
|
||||
if (swd_freeze_dog() == 0) /* 如果冻结看门狗时钟失败(STM32H7)*/
|
||||
{
|
||||
MUL_swd_set_target_reset(0); /* 退出硬件复位 */
|
||||
osDelay(20);
|
||||
if (MUL_swd_get_target_reset() == 0)
|
||||
{
|
||||
MUL_swd_set_target_reset(1); /* 硬件复位 */
|
||||
osDelay(g_tProg.SwdResetDelay);
|
||||
}
|
||||
|
||||
if (MUL_swd_init_debug() == 0)
|
||||
{
|
||||
printf("error 2: MUL_swd_init_debug()\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2281,15 +2114,8 @@ uint8_t MUL_swd_enter_debug_program(void)
|
||||
}
|
||||
}
|
||||
|
||||
MUL_swd_set_target_reset(0); /* 退出硬件复位 */
|
||||
osDelay(20);
|
||||
|
||||
// if (!MUL_swd_init_debug()) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// Enable debug and halt the core (DHCSR <- 0xA05F0003)
|
||||
for (i = 0; i < 4; i++)
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
if (MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT) != 0)
|
||||
{
|
||||
@ -2299,14 +2125,36 @@ uint8_t MUL_swd_enter_debug_program(void)
|
||||
MUL_swd_set_target_reset(1);
|
||||
osDelay(20);
|
||||
MUL_swd_set_target_reset(0);
|
||||
osDelay(20);
|
||||
osDelay(i * 5);
|
||||
}
|
||||
if (i == 4)
|
||||
if (i == 10)
|
||||
{
|
||||
printf("MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT) Timeout0\r\n");
|
||||
printf("error 3: MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT)\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Enable halt on reset
|
||||
if (!MUL_swd_write_word(DBG_EMCR, VC_CORERESET)) {
|
||||
printf("error 4: MUL_swd_write_word(DBG_EMCR, VC_CORERESET)\r\n");
|
||||
return 0; /* 超时 */
|
||||
}
|
||||
|
||||
MUL_swd_read_word(DBG_HCSR, val);
|
||||
if ((val[0] & S_HALT) == 0)
|
||||
{
|
||||
if (MUL_swd_get_target_reset() == 0)
|
||||
{
|
||||
MUL_swd_set_target_reset(1); /* 硬件复位 */
|
||||
osDelay(20);
|
||||
}
|
||||
|
||||
if (MUL_swd_get_target_reset() == 1)
|
||||
{
|
||||
MUL_swd_set_target_reset(0); /* 退出硬件复位 */
|
||||
osDelay(g_tProg.SwdResetDelay);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until core is halted
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
@ -2314,6 +2162,7 @@ uint8_t MUL_swd_enter_debug_program(void)
|
||||
|
||||
if (!MUL_swd_read_word(DBG_HCSR, val))
|
||||
{
|
||||
printf("error 5: MUL_swd_read_word(DBG_HCSR, val)\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2344,66 +2193,25 @@ uint8_t MUL_swd_enter_debug_program(void)
|
||||
}
|
||||
if (i == 1000)
|
||||
{
|
||||
printf("MUL_swd_read_word(DBG_HCSR, val) Timeout1\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Enable halt on reset
|
||||
if (!MUL_swd_write_word(DBG_EMCR, VC_CORERESET)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Perform a soft reset
|
||||
if (!MUL_swd_read_word(NVIC_AIRCR, val)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!MUL_swd_write_word(NVIC_AIRCR, VECTKEY | (val[0] & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
osDelay(2);
|
||||
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
uint8_t err;
|
||||
|
||||
if (!MUL_swd_read_word(DBG_HCSR, val))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = 0;
|
||||
if (g_gMulSwd.Active[0] == 1 && ((val[0] & S_HALT) == 0))
|
||||
{
|
||||
err = 1;
|
||||
}
|
||||
if (g_gMulSwd.Active[1] == 1 && ((val[1] & S_HALT) == 0))
|
||||
{
|
||||
err = 1;
|
||||
}
|
||||
if (g_gMulSwd.Active[2] == 1 && ((val[2] & S_HALT) == 0))
|
||||
{
|
||||
err = 1;
|
||||
}
|
||||
if (g_gMulSwd.Active[3] == 1 && ((val[3] & S_HALT) == 0))
|
||||
{
|
||||
err = 1;
|
||||
}
|
||||
if (err == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
bsp_DelayUS(1000);
|
||||
}
|
||||
if (i == 1000)
|
||||
{
|
||||
printf("MUL_swd_read_word(DBG_HCSR, val) Timeout2\r\n");
|
||||
printf("error 6: MUL_swd_read_word(DBG_HCSR, val)\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Perform a soft reset
|
||||
// if (!swd_read_word(NVIC_AIRCR, &val)) {
|
||||
// printf("error 2: swd_read_word(NVIC_AIRCR, &val)\r\n");
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// if (!swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)) {
|
||||
// printf("error 3: swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)\r\n");
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// Disable halt on reset
|
||||
if (!MUL_swd_write_word(DBG_EMCR, 0)) {
|
||||
if (!MUL_swd_write_word(DBG_EMCR, 0))
|
||||
{
|
||||
printf("error 7: MUL_swd_write_word(DBG_EMCR, 0)\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ static __inline void PORT_SWD_SETUP(void)
|
||||
|
||||
// Set RESET HIGH
|
||||
//pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit);//TODO - fix reset logic
|
||||
BSP_SET_GPIO_1(nRESET_PIN_PORT, nRESET_PIN);
|
||||
//BSP_SET_GPIO_1(nRESET_PIN_PORT, nRESET_PIN);
|
||||
}
|
||||
|
||||
/** Disable JTAG/SWD I/O Pins.
|
||||
|
@ -452,17 +452,21 @@ static void MODS64_WriteFile(void)
|
||||
uint32_t package_len; /* 本包数据长度 */
|
||||
uint8_t err = 0;
|
||||
uint8_t *pData;
|
||||
static char s_FileName[256 + 1];
|
||||
|
||||
static char s_FileName[256 + 1];
|
||||
static uint32_t s_FileOffset; /* 文件已写的数据偏移 */
|
||||
static uint32_t s_FileRxLen; /* 文件已接收的长度 */
|
||||
static uint32_t s_HeaderLen; /* 头部长度 */
|
||||
static uint32_t s_LastPackaOffsetAddr; /* 上一包的偏移地址, 用于重复帧识别 */
|
||||
|
||||
func = BEBufToUint16(&g_tModS.RxBuf[2]);
|
||||
total_len = BEBufToUint32(&g_tModS.RxBuf[4]);
|
||||
total_len = BEBufToUint32(&g_tModS.RxBuf[4]); /* 文件总长度 */
|
||||
offset_addr = BEBufToUint32(&g_tModS.RxBuf[8]);
|
||||
package_len = BEBufToUint32(&g_tModS.RxBuf[12]);
|
||||
|
||||
pData = &g_tModS.RxBuf[16];
|
||||
|
||||
/* 文件大小(4字节) + MD5 (16字节) + 文件名长度 + 文件名字符串 + 文件数据 */
|
||||
if (offset_addr == 0)
|
||||
if (offset_addr == 0) /* 第1包数据 */
|
||||
{
|
||||
uint16_t NameLen;
|
||||
uint32_t NewFileSize;
|
||||
@ -470,26 +474,26 @@ static void MODS64_WriteFile(void)
|
||||
uint16_t i;
|
||||
uint32_t OldFileSize;
|
||||
char OldMD5[16];
|
||||
uint32_t DataLen;
|
||||
uint32_t DataLen;
|
||||
|
||||
s_HeaderLen = 0; /* 头部长度 */
|
||||
s_LastPackaOffsetAddr = 0;
|
||||
|
||||
NewFileSize = BEBufToUint32(pData); pData += 4;
|
||||
NewFileSize = BEBufToUint32(pData); pData += 4; s_HeaderLen += 4;
|
||||
|
||||
NewMD5 = (char *)pData; pData += 16;
|
||||
NewMD5 = (char *)pData; pData += 16; s_HeaderLen += 16;
|
||||
|
||||
NameLen = *pData; pData++;
|
||||
NameLen = *pData; pData++; s_HeaderLen++;
|
||||
for (i = 0; i < NameLen; i++)
|
||||
{
|
||||
s_FileName[i] = *pData++;
|
||||
s_FileName[i] = *pData++; s_HeaderLen++;
|
||||
}
|
||||
s_FileName[NameLen] = 0;
|
||||
s_FileOffset = 0;
|
||||
s_FileRxLen = 0;
|
||||
|
||||
// printf(s_FileName); printf("\r\n");
|
||||
|
||||
#if 0 /* 测试代码,用来验证通信速度 */
|
||||
err = 1;
|
||||
#else
|
||||
OldFileSize = GetFileMD5(s_FileName, OldMD5); /* 获得本地文件的长度和MD5 */
|
||||
|
||||
|
||||
/* 文件长度和MD5码均相等,则不重复写入 */
|
||||
if (NewFileSize == OldFileSize && memcmp(OldMD5, NewMD5, 16) == 0)
|
||||
{
|
||||
@ -497,35 +501,93 @@ static void MODS64_WriteFile(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
DataLen = package_len - NameLen - 21;
|
||||
memcpy(FsReadBuf, (char *)pData, DataLen);
|
||||
if (WriteFile(s_FileName, 0, (char *)FsReadBuf, DataLen) == 0)
|
||||
DataLen = package_len - NameLen - 21;
|
||||
if (DataLen > 0)
|
||||
{
|
||||
err = 0; /* 文件写入OK */
|
||||
memcpy(FsReadBuf, (char *)pData, DataLen);
|
||||
s_FileRxLen = DataLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = 2; /* 文件写入失败 */
|
||||
err = 0; /* 文件写入OK */
|
||||
}
|
||||
|
||||
/* 第1包就文件结束 */
|
||||
if (s_FileOffset + s_FileRxLen >= total_len)
|
||||
{
|
||||
if (WriteFile(s_FileName, s_FileOffset, (char *)FsReadBuf, s_FileRxLen) == 0)
|
||||
{
|
||||
s_FileOffset = s_FileRxLen;
|
||||
|
||||
err = 0; /* 文件写入OK */
|
||||
}
|
||||
else
|
||||
{
|
||||
err = 2; /* 文件写入失败 */
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
else /* 第2包以后的数据 */
|
||||
{
|
||||
uint32_t DataLen;
|
||||
uint32_t offset;
|
||||
|
||||
offset = offset_addr;
|
||||
DataLen = package_len;
|
||||
memcpy(FsReadBuf, (char *)pData, DataLen);
|
||||
if (WriteFile(s_FileName, offset, (char *)FsReadBuf, DataLen) == 0)
|
||||
DataLen = package_len;
|
||||
|
||||
if (s_LastPackaOffsetAddr != offset_addr) /* 不是重复帧 */
|
||||
{
|
||||
err = 0; /* 文件写入OK */
|
||||
s_LastPackaOffsetAddr = offset_addr;
|
||||
|
||||
if (s_FileRxLen + DataLen < sizeof(FsReadBuf))
|
||||
{
|
||||
memcpy(&FsReadBuf[s_FileRxLen], (char *)pData, DataLen);
|
||||
s_FileRxLen += DataLen;
|
||||
err = 0; /* 文件写入OK */
|
||||
}
|
||||
else /* 超过16KB了 */
|
||||
{
|
||||
uint32_t len0;
|
||||
uint32_t len1;
|
||||
|
||||
len0 = sizeof(FsReadBuf) - s_FileRxLen; /* 补齐16KB需要的字节数. 本次将保存的 */
|
||||
/* 复制一部分数据,筹齐16KB */
|
||||
memcpy(&FsReadBuf[s_FileRxLen], (char *)pData, len0);
|
||||
if (WriteFile(s_FileName, s_FileOffset, (char *)FsReadBuf, sizeof(FsReadBuf)) == 0)
|
||||
{
|
||||
s_FileOffset += sizeof(FsReadBuf);
|
||||
err = 0; /* 文件写入OK */
|
||||
}
|
||||
else
|
||||
{
|
||||
err = 2; /* 文件写入失败 */
|
||||
}
|
||||
|
||||
len1 = DataLen - len0; /* 剩余未保存的 */
|
||||
|
||||
/* 将未保存的数据继续缓存 */
|
||||
memcpy(FsReadBuf, (char *)pData + len0, len1);
|
||||
s_FileRxLen = len1;
|
||||
}
|
||||
|
||||
/* 文件数据传输完毕 */
|
||||
if (s_FileOffset + s_FileRxLen >= total_len - s_HeaderLen)
|
||||
{
|
||||
if (WriteFile(s_FileName, s_FileOffset, (char *)FsReadBuf, s_FileRxLen) == 0)
|
||||
{
|
||||
s_FileOffset += s_FileRxLen;
|
||||
|
||||
err = 0; /* 文件写入OK */
|
||||
}
|
||||
else
|
||||
{
|
||||
err = 2; /* 文件写入失败, 立即终止 */
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else /* 重复帧 */
|
||||
{
|
||||
err = 2; /* 文件写入失败 */
|
||||
}
|
||||
err = 0;
|
||||
}
|
||||
}
|
||||
|
||||
g_tModS.TxCount = 0;
|
||||
|
@ -11,15 +11,9 @@
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MODBUS_IAP_H_
|
||||
#define __MODBUS_IAP_H_
|
||||
#ifndef __MODBUS_FILE_H_
|
||||
#define __MODBUS_FILE_H_
|
||||
|
||||
/* 06H boot波特率寄存器 和 程序升级寄存器 */
|
||||
#define SYS_RESET 0x9100
|
||||
#define BOOT_BAUD 0x9101
|
||||
#define BOOT_UPGRADE_FLAG 0x9102
|
||||
|
||||
void MODS_15H(void);
|
||||
uint8_t IAP_Write06H(uint16_t reg_addr, uint16_t reg_value);
|
||||
|
||||
#endif
|
||||
|
@ -39,6 +39,7 @@ static void MODS_65H(void);
|
||||
static void MODS_60H(void);
|
||||
|
||||
extern void MODS_64H(void);
|
||||
extern void MODS_66H(void);
|
||||
|
||||
void MODS_ReciveNew(uint8_t _byte);
|
||||
|
||||
@ -252,7 +253,7 @@ static void MODS_AnalyzeApp(void)
|
||||
MODS_0FH(); /* 强制多个线圈(对应D01/D02/D03) */
|
||||
break;
|
||||
|
||||
case 0x60: /* 读取波形数据专用功能码 */
|
||||
case 0x60: /* 读取波形数据专用功能码 */
|
||||
MODS_60H();
|
||||
break;
|
||||
|
||||
@ -260,10 +261,14 @@ static void MODS_AnalyzeApp(void)
|
||||
MODS_64H();
|
||||
break;
|
||||
|
||||
case 0x65: /* 临时执行小程序-废弃 */
|
||||
case 0x65: /* 临时执行小程序-废弃 */
|
||||
MODS_65H();
|
||||
break;
|
||||
|
||||
case 0x66: /* SWD操作指令(读内存,写内存等) */
|
||||
MODS_66H();
|
||||
break;
|
||||
|
||||
default:
|
||||
g_tModS.RspCode = RSP_ERR_CMD;
|
||||
MODS_SendAckErr(g_tModS.RspCode); /* 告诉主机命令错误 */
|
||||
|
340
User/modbus/modbus_swd.c
Normal file
340
User/modbus/modbus_swd.c
Normal file
@ -0,0 +1,340 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : modbus脱机烧录操作模块
|
||||
* 文件名称 : modbus_swd.c
|
||||
* 版 本 : V1.0
|
||||
* 说 明 :
|
||||
*
|
||||
* 修改记录 :
|
||||
* 版本号 日期 作者 说明
|
||||
* V1.0 2020-08-06 armfly 正式发布
|
||||
*
|
||||
* Copyright (C), 2020-2030, 安富莱电子 www.armfly.com
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
#include "bsp.h"
|
||||
#include "main.h"
|
||||
#include "modbus_file.h"
|
||||
#include "param.h"
|
||||
#include "modbus_slave.h"
|
||||
#include "lua_if.h"
|
||||
#include "prog_if.h"
|
||||
#include "swd_flash.h"
|
||||
#include "SW_DP_Multi.h"
|
||||
#include "swd_host.h"
|
||||
#include "swd_host_multi.h"
|
||||
#include "stm8_flash.h"
|
||||
#include "stm8_swim.h"
|
||||
|
||||
/* 64H帧子功能码定义 */
|
||||
enum
|
||||
{
|
||||
H66_READ_MEM = 0, /* 读内存, */
|
||||
H66_WRITE_MEM = 1, /* 写内存 */
|
||||
};
|
||||
|
||||
static void MODS66_ReadMem(void);
|
||||
static void MODS66_WriteMem(void);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODS_64H
|
||||
* 功能说明: 文件操作通信接口
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void MODS_66H(void)
|
||||
{
|
||||
/*
|
||||
主机发送: 小程序数据
|
||||
01 ; 站号
|
||||
66 ; 功能码
|
||||
0000 ; 子功能,
|
||||
- 0表示读内存
|
||||
- 1表示写内存
|
||||
0000 0000 : 偏移地址 4字节
|
||||
0020 0000 : 数据长度 4字节
|
||||
CCCC : CRC16
|
||||
|
||||
从机应答:
|
||||
01 ; 从机地址
|
||||
66 ; 功能码
|
||||
0000 ; 子功能
|
||||
|
||||
00 ; 执行结果,0表示OK 1表示错误
|
||||
CCCC : CRC16
|
||||
*/
|
||||
uint16_t func; /* 子功能代码 */
|
||||
|
||||
g_tModS.RspCode = RSP_OK;
|
||||
|
||||
if (g_tModS.RxCount < 11)
|
||||
{
|
||||
g_tModS.RspCode = RSP_ERR_VALUE; /* 数据值域错误 */
|
||||
goto err_ret;
|
||||
}
|
||||
|
||||
func = BEBufToUint16(&g_tModS.RxBuf[2]);
|
||||
|
||||
if (func == H66_READ_MEM) /* 下载lua程序 */
|
||||
{
|
||||
MODS66_ReadMem();
|
||||
}
|
||||
else if (func >= H66_WRITE_MEM)
|
||||
{
|
||||
MODS66_WriteMem();
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModS.RspCode = RSP_ERR_VALUE; /* 数据值域错误 */
|
||||
}
|
||||
|
||||
err_ret:
|
||||
if (g_tModS.RxBuf[0] != 0x00) /* 00广播地址不应答, FF地址应答g_tParam.Addr485 */
|
||||
{
|
||||
if (g_tModS.RspCode == RSP_OK) /* 正确应答 */
|
||||
{
|
||||
MODS_SendWithCRC();
|
||||
}
|
||||
else
|
||||
{
|
||||
MODS_SendAckErr(g_tModS.RspCode); /* 告诉主机命令错误 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODS66_ReadMem
|
||||
* 功能说明: 读内存
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
static void MODS66_ReadMem(void)
|
||||
{
|
||||
/*
|
||||
主机发送: 小程序数据
|
||||
01 ; 站号
|
||||
66 ; 功能码
|
||||
0000 ; 子功能,
|
||||
- 0表示读内存
|
||||
- 1表示写内存
|
||||
0000 0000 : 偏移地址 4字节
|
||||
0020 0000 : 数据长度 4字节
|
||||
CCCC : CRC16
|
||||
|
||||
从机应答:
|
||||
01 ; 从机地址
|
||||
66 ; 功能码
|
||||
0000 ; 子功能
|
||||
0000 0000 : 偏移地址 4字节
|
||||
0020 0000 : 数据长度 4字节
|
||||
|
||||
00 ; 执行结果,0表示OK 1表示错误
|
||||
|
||||
CCCC : CRC16
|
||||
*/
|
||||
uint16_t func; /* 子功能代码 */
|
||||
uint32_t offset_addr;
|
||||
uint32_t package_len; /* 本包数据长度 */
|
||||
uint8_t ch_num;
|
||||
|
||||
|
||||
func = BEBufToUint16(&g_tModS.RxBuf[2]);
|
||||
offset_addr = BEBufToUint32(&g_tModS.RxBuf[4]);
|
||||
package_len = BEBufToUint32(&g_tModS.RxBuf[8]);
|
||||
|
||||
{
|
||||
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
|
||||
{
|
||||
ch_num = g_gMulSwd.MultiMode;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch_num = 1;
|
||||
}
|
||||
|
||||
if (ch_num * package_len > 1024)
|
||||
{
|
||||
g_tModS.RspCode = RSP_ERR_VALUE; /* 数据值域错误 */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* SWD接口,读内存 */
|
||||
g_tModS.TxCount = 0;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tParam.Addr485; /* 本机地址 */
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x66; /* 功能码 */
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = func >> 8;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = func;
|
||||
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = offset_addr >> 24;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = offset_addr >> 16;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = offset_addr >> 8;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = offset_addr >> 0;
|
||||
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = package_len >> 24;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = package_len >> 16;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = package_len >> 8;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = package_len >> 0;
|
||||
|
||||
if (g_tProg.ChipType == CHIP_SWD_ARM)
|
||||
{
|
||||
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
|
||||
{
|
||||
if (MUL_swd_read_memory(offset_addr, s_lua_read_buf, package_len) == 0)
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x01; /* 出错 */
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x00; /* 执行结果 00 */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (swd_read_memory(offset_addr, s_lua_read_buf, package_len) == 0)
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x01; /* 出错 */
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x00; /* 执行结果 00 */
|
||||
}
|
||||
}
|
||||
memcpy((char *)&g_tModS.TxBuf[g_tModS.TxCount], s_lua_read_buf, package_len * ch_num);
|
||||
g_tModS.TxCount += package_len * ch_num;
|
||||
}
|
||||
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
|
||||
{
|
||||
if (SWIM_ReadBuf(offset_addr, s_lua_read_buf, package_len) == 0)
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x01; /* 出错 */
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x00; /* 执行结果 00 */
|
||||
}
|
||||
|
||||
memcpy(&g_tModS.TxBuf[g_tModS.TxCount], s_lua_read_buf, package_len);
|
||||
g_tModS.TxCount += package_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODS66_WriteMem
|
||||
* 功能说明: 写内存
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
static void MODS66_WriteMem(void)
|
||||
{
|
||||
/*
|
||||
主机发送: 小程序数据
|
||||
01 ; 站号
|
||||
66 ; 功能码
|
||||
0001 ; 子功能,
|
||||
- 0表示读内存
|
||||
- 1表示写内存
|
||||
0000 0000 : 偏移地址 4字节
|
||||
0020 0000 : 数据长度 4字节
|
||||
... 数据
|
||||
CCCC : CRC16
|
||||
|
||||
从机应答:
|
||||
01 ; 从机地址
|
||||
66 ; 功能码
|
||||
0000 ; 子功能
|
||||
|
||||
00 ; 执行结果,0表示OK 1表示错误
|
||||
CCCC : CRC16
|
||||
*/
|
||||
uint16_t func; /* 子功能代码 */
|
||||
uint32_t offset_addr;
|
||||
uint32_t package_len; /* 本包数据长度 */
|
||||
uint8_t ch_num;
|
||||
uint8_t *pData;
|
||||
|
||||
func = BEBufToUint16(&g_tModS.RxBuf[2]);
|
||||
offset_addr = BEBufToUint32(&g_tModS.RxBuf[4]);
|
||||
package_len = BEBufToUint32(&g_tModS.RxBuf[8]);
|
||||
|
||||
pData = &g_tModS.RxBuf[12];
|
||||
{
|
||||
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
|
||||
{
|
||||
ch_num = g_gMulSwd.MultiMode;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch_num = 1;
|
||||
}
|
||||
|
||||
if (ch_num * package_len > 1024)
|
||||
{
|
||||
g_tModS.RspCode = RSP_ERR_VALUE; /* 数据值域错误 */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* SWD接口,读内存 */
|
||||
g_tModS.TxCount = 0;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tParam.Addr485; /* 本机地址 */
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x66; /* 功能码 */
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = func >> 8;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = func;
|
||||
|
||||
if (g_tProg.ChipType == CHIP_SWD_ARM)
|
||||
{
|
||||
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
|
||||
{
|
||||
if (MUL_swd_write_memory(offset_addr, pData, package_len) == 0)
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x01; /* 出错 */
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x00; /* 执行结果 00 */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (swd_read_memory(offset_addr, pData, package_len) == 0)
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x01; /* 出错 */
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x00; /* 执行结果 00 */
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
|
||||
{
|
||||
if (SWIM_WriteBuf(offset_addr, pData, package_len) == 0)
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x01; /* 出错 */
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x00; /* 执行结果 00 */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
17
User/modbus/modbus_swd.h
Normal file
17
User/modbus/modbus_swd.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : RS485 MODEBUS 通信模块
|
||||
* 文件名称 : modbus_swd.h
|
||||
* 版 本 : V1.0
|
||||
* 说 明 : 头文件
|
||||
*
|
||||
* Copyright (C), 2014-2015, 安富莱电子 www.armfly.com
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MODBUS_SWD_H_
|
||||
#define __MODBUS_SWD_H_
|
||||
|
||||
#endif
|
@ -461,7 +461,9 @@ static uint8_t ELF_FillToAlgo(char *_path, program_target_t *_algo)
|
||||
printf(" Reserved : 0x%08X\r\n", g_tFLM.Device.Res);
|
||||
printf(" Erased Content : 0x%02X\r\n", g_tFLM.Device.valEmpty);
|
||||
printf(" Program Page TimeOut : %d\r\n", g_tFLM.Device.toProg);
|
||||
printf(" Erase Sector TimeOut : %d\r\n", g_tFLM.Device.toErase);
|
||||
printf(" Erase Sector TimeOut : %d\r\n", g_tFLM.Device.toErase);
|
||||
printf(" Erase Sector Size : %08X, %dKB (0x%X)\r\n",
|
||||
g_tFLM.Device.sectors[0].AddrSector, g_tFLM.Device.sectors[0].szSector / 1024, g_tFLM.Device.sectors[0].szSector);
|
||||
|
||||
/* 算法函数偏移地址 */
|
||||
printf(" ----Algo function offset ---------------\r\n");
|
||||
|
@ -234,7 +234,6 @@ void PG_ReloadLuaVar(void)
|
||||
|
||||
/* SwdClockDelay; SWD接口时序延迟 */
|
||||
{
|
||||
/* 读取复位类型: 软件还是硬件复位 */
|
||||
lua_getglobal(g_Lua, "SWD_CLOCK_DELAY");
|
||||
if (lua_isinteger(g_Lua, -1))
|
||||
{
|
||||
@ -247,6 +246,35 @@ void PG_ReloadLuaVar(void)
|
||||
lua_pop(g_Lua, 1);
|
||||
}
|
||||
|
||||
/* 复位延迟 */
|
||||
{
|
||||
lua_getglobal(g_Lua, "RESET_DELAY");
|
||||
if (lua_isinteger(g_Lua, -1))
|
||||
{
|
||||
g_tProg.SwdResetDelay = lua_tointeger(g_Lua, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tProg.SwdResetDelay = 20;
|
||||
}
|
||||
lua_pop(g_Lua, 1);
|
||||
}
|
||||
|
||||
/* 读取复位类型: 软件还是硬件复位 */
|
||||
{
|
||||
|
||||
lua_getglobal(g_Lua, "RESET_MODE");
|
||||
if (lua_isinteger(g_Lua, -1))
|
||||
{
|
||||
g_tProg.ResetMode = lua_tointeger(g_Lua, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tProg.ResetMode = 0;
|
||||
}
|
||||
lua_pop(g_Lua, 1);
|
||||
}
|
||||
|
||||
}
|
||||
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
|
||||
{
|
||||
|
@ -60,6 +60,11 @@ typedef struct
|
||||
uint8_t VerifyOptionByteDisalbe; /* 1 表示芯片设置读保护时,不校验 (STM32F207VC设置读保护后会即可生效导致无法校验) */
|
||||
|
||||
uint32_t SwdClockDelay; /* SWD时钟延迟,0表示最快,值越大速度越慢 */
|
||||
|
||||
uint32_t SwdResetDelay; /* 硬件复位后的延迟时间,ms */
|
||||
uint32_t ResetMode; /* 复位延迟 */
|
||||
|
||||
|
||||
}OFFLINE_PROG_T;
|
||||
|
||||
/* lua脚本fix_data_begin()返回一个table,用于通知C程序哪些内存地址需要填充数据 */
|
||||
|
@ -243,6 +243,8 @@ uint16_t PG_SWD_ProgFile(char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, ui
|
||||
{
|
||||
/* 恢复芯片厂家的FLM算法代码到目标机内存 */
|
||||
LoadAlgoToTarget();
|
||||
|
||||
|
||||
}
|
||||
|
||||
PG_PrintPercent(100, _FlashAddr);
|
||||
@ -265,7 +267,7 @@ uint16_t PG_SWD_ProgFile(char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, ui
|
||||
waittime = 5;
|
||||
|
||||
bsp_DelayMS(20);
|
||||
}
|
||||
}
|
||||
|
||||
PG_PrintText("正在擦除扇区...");
|
||||
PG_PrintPercent(0, 0xFFFFFFFF);
|
||||
|
Loading…
x
Reference in New Issue
Block a user