110VCGQ/project/110VCGQV6_BOOT/user/Src/user_main.c
2024-11-18 10:09:39 +08:00

78 lines
1.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* user_main.c
*
* Created on: Sep 24, 2024
* Author: 10425
*/
#include "user.h"
void user_main()
{
uint8_t APP_flag = *(uint8_t*)app_flag;
if(APP_flag == 0xFF)
{
uint8_t parameters[18];
memset(parameters,0xFF,sizeof(parameters));
AT24C16_WriteBytes(0, parameters, sizeof(parameters));
uint64_t a = 0;
write_code(app_flag, (uint8_t*)&a, 8);
}
user_init();
uint8_t aa[2] = {0};
HAL_StatusTypeDef status;
status=AT24C16_ReadBytes(FILE_SIZE_ADDR, aa, sizeof(aa));
while(status != HAL_OK)
{
status=AT24C16_ReadBytes(FILE_SIZE_ADDR, aa, sizeof(aa));
}
uint16_t file_size = aa[0]<<8 | aa[1];
if(file_size ==0 || file_size == 0xFFFF)
{
if(( ( *(volatile uint32_t*)app2_addr )&0x2FFE0000 )==0x20000000)//检查栈顶地址是否合法.
{
if(( *(volatile uint32_t*)(app2_addr+4) )>app2_addr)
{
//关闭中断
__disable_irq();
HAL_ADC_Stop_DMA(&hadc1); //关闭adc不关闭无法正常跳转
//跳转
SCB->VTOR = app2_addr;
LoadApp loadapp;
loadapp=(LoadApp)( *(volatile uint32_t*)(app2_addr+4) ); //用户代码区第二个字为程序开始地址(复位地址)
__set_MSP(*(volatile uint32_t*)app2_addr); //初始化MSP
loadapp();
}
}
}
bsp_StartAutoTimer(0,100); //计算波形峰峰值
while(1)
{
if(bsp_CheckTimer(0))
{
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin);
}
if(usart_count >0)
{
Usart_Receive();
usart_count = 0;
}
}
}