21ic问答首页 - bootload中断异常
bootload中断异常
xh11440394672021-08-07
本帖最后由 tyw 于 2021-8-7 16:34 编辑
下面是跳转程序
void IAP_Load_APP(uint32_t appxaddr)
{
RCC->APB1RST = 0xFFFFFFFF;
RCC->APB2RST = 0xFFFFFFFF;
RCC->APB1RST = 0x00000000;
RCC->APB2RST = 0x00000000;
if (((*(uint32_t *)appxaddr) & 0x2FFF8000) == 0x20000000) //检查栈顶地址是否合法.
{
jump2app = (iapfun) * (vu32 *)(appxaddr + 4); //用户代码区第二个字为程序开始地址(复位地址)
__set_MSP(*(vu32 *)appxaddr); //初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址)
//MSR_MSP(*(vu32*)appxaddr);
//SCB->VTOR = appxaddr;
jump2app(); //跳转到APP.
}
}
下面是APP串口中断测试函数void USART1_IRQHandler(void)
{
//AT32_LEDn_ON(LED2);
intrupt_NUM++;
if (USART_GetITStatus(USART1, USART_INT_RDNE) != RESET)
{
/* Read one byte from the receive data register */
//RxBuffer1[1] = USART_ReceiveData(USART1);//需要读取数据清除空闲标志位,否则会循环中断
USART_ClearFlag(USART1, USART_FLAG_RDNE);
// AT32_LEDn_Toggle(LED2);
RxBuffer1[USART_INT_RDNE_NUM] = USART_ReceiveData(USART1);
USART_INT_RDNE_NUM++;
if (USART_INT_RDNE_NUM > 98)
USART_INT_RDNE_NUM = 98;
}
if (USART_GetITStatus(USART1, USART_INT_IDLEF) != RESET)
{
/* Read one byte from the receive data register */
// RxBuffer1[2] = USART1 -> STS;
RxBuffer1[USART_INT_RDNE_NUM - 1] = USART_ReceiveData(USART1); //需要读取数据用于清除空闲标志位,否则会死机
USART_INT_RDNE_NUM = 0;
USART_INT_IDLEF_NUM++;
USART1_END = 0;
}
//printf(" %d %d %d", intrupt_NUM, USART_INT_RDNE_NUM, USART_INT_IDLEF_NUM);
if (USART_GetITStatus(USART1, USART_INT_TRAC) != RESET)
{
USART_INT_TRAC_NUM++;
}
}
int main(void)
{
AT32_Board_Init();
MX_USART1_UART_Init();
printf("Tset OTA APP !!!! \n\r");
extern uint8_t USART1_END, intrupt_NUM, USART_INT_RDNE_NUM, USART_INT_IDLEF_NUM, USART_INT_TRAC_NUM;
extern uint8_t RxBuffer1[100];
while (1)
{
if (USART1_END == 0)
{
printf("RxBuffer1:%s", RxBuffer1);
USART1_END = 1;
if (strstr((char *)RxBuffer1, "LED_ON"))
{
AT32_LEDn_ON(LED2);
}
if (strstr((char *)RxBuffer1, "LED_OFF"))
{
AT32_LEDn_OFF(LED2);
}
memset(RxBuffer1, 0, sizeof(RxBuffer1));
}
AT32_LEDn_Toggle(LED3);
Delay_ms(100);
}
}
说明一下 APP函数单独下载到MCU中是可以运行的通过OTA后就出现不正常的情况OTA后的日志[16:19:17.371]收←◆Go to updata ^_^Tset OTA APP !!!! [16:19:19.462]发→◇LED_ON□[16:19:19.474]收←◆RxBuffer1:[16:19:20.727]发→◇LED_ON□[16:19:20.775]收←◆RxBuffer1:[16:19:21.721]发→◇LED_ON□[16:19:21.776]收←◆RxBuffer1:[16:19:22.375]发→◇LED_ON□[16:19:22.378]收←◆RxBuffer1:[16:19:22.846]发→◇LED_ON□[16:19:22.878]收←◆RxBuffer1:[16:19:23.279]发→◇LED_ON□[16:19:23.379]收←◆RxBuffer1:[16:19:23.854]发→◇LED_ON□[16:19:23.880]收←◆RxBuffer1:不能正常的打印出接收到的数据
下面是跳转程序
void IAP_Load_APP(uint32_t appxaddr)
{
RCC->APB1RST = 0xFFFFFFFF;
RCC->APB2RST = 0xFFFFFFFF;
RCC->APB1RST = 0x00000000;
RCC->APB2RST = 0x00000000;
if (((*(uint32_t *)appxaddr) & 0x2FFF8000) == 0x20000000) //检查栈顶地址是否合法.
{
jump2app = (iapfun) * (vu32 *)(appxaddr + 4); //用户代码区第二个字为程序开始地址(复位地址)
__set_MSP(*(vu32 *)appxaddr); //初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址)
//MSR_MSP(*(vu32*)appxaddr);
//SCB->VTOR = appxaddr;
jump2app(); //跳转到APP.
}
}
下面是APP串口中断测试函数void USART1_IRQHandler(void)
{
//AT32_LEDn_ON(LED2);
intrupt_NUM++;
if (USART_GetITStatus(USART1, USART_INT_RDNE) != RESET)
{
/* Read one byte from the receive data register */
//RxBuffer1[1] = USART_ReceiveData(USART1);//需要读取数据清除空闲标志位,否则会循环中断
USART_ClearFlag(USART1, USART_FLAG_RDNE);
// AT32_LEDn_Toggle(LED2);
RxBuffer1[USART_INT_RDNE_NUM] = USART_ReceiveData(USART1);
USART_INT_RDNE_NUM++;
if (USART_INT_RDNE_NUM > 98)
USART_INT_RDNE_NUM = 98;
}
if (USART_GetITStatus(USART1, USART_INT_IDLEF) != RESET)
{
/* Read one byte from the receive data register */
// RxBuffer1[2] = USART1 -> STS;
RxBuffer1[USART_INT_RDNE_NUM - 1] = USART_ReceiveData(USART1); //需要读取数据用于清除空闲标志位,否则会死机
USART_INT_RDNE_NUM = 0;
USART_INT_IDLEF_NUM++;
USART1_END = 0;
}
//printf(" %d %d %d", intrupt_NUM, USART_INT_RDNE_NUM, USART_INT_IDLEF_NUM);
if (USART_GetITStatus(USART1, USART_INT_TRAC) != RESET)
{
USART_INT_TRAC_NUM++;
}
}
int main(void)
{
AT32_Board_Init();
MX_USART1_UART_Init();
printf("Tset OTA APP !!!! \n\r");
extern uint8_t USART1_END, intrupt_NUM, USART_INT_RDNE_NUM, USART_INT_IDLEF_NUM, USART_INT_TRAC_NUM;
extern uint8_t RxBuffer1[100];
while (1)
{
if (USART1_END == 0)
{
printf("RxBuffer1:%s", RxBuffer1);
USART1_END = 1;
if (strstr((char *)RxBuffer1, "LED_ON"))
{
AT32_LEDn_ON(LED2);
}
if (strstr((char *)RxBuffer1, "LED_OFF"))
{
AT32_LEDn_OFF(LED2);
}
memset(RxBuffer1, 0, sizeof(RxBuffer1));
}
AT32_LEDn_Toggle(LED3);
Delay_ms(100);
}
}
说明一下 APP函数单独下载到MCU中是可以运行的通过OTA后就出现不正常的情况OTA后的日志[16:19:17.371]收←◆Go to updata ^_^Tset OTA APP !!!! [16:19:19.462]发→◇LED_ON□[16:19:19.474]收←◆RxBuffer1:[16:19:20.727]发→◇LED_ON□[16:19:20.775]收←◆RxBuffer1:[16:19:21.721]发→◇LED_ON□[16:19:21.776]收←◆RxBuffer1:[16:19:22.375]发→◇LED_ON□[16:19:22.378]收←◆RxBuffer1:[16:19:22.846]发→◇LED_ON□[16:19:22.878]收←◆RxBuffer1:[16:19:23.279]发→◇LED_ON□[16:19:23.379]收←◆RxBuffer1:[16:19:23.854]发→◇LED_ON□[16:19:23.880]收←◆RxBuffer1:不能正常的打印出接收到的数据
您需要登录后才可以回复 登录 | 注册