| | |
| | | |
| | | void EnterUWBUpdateMode(void) |
| | | { |
| | | uint32_t result = 0; |
| | | uint16_t tmp = 0xCCCC; |
| | | __disable_irq(); |
| | | result = FLASH_Prepare(0x8004A38, 128); |
| | | if(result) |
| | | result = FLASH_Write(0x8004A38, (const uint8_t*)&tmp, 2); |
| | | __enable_irq(); |
| | | printf("进入升级模式\r\n"); |
| | | g_com_map[CNT_UPDATE]=0; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | // STMFLASH_Write_NoCheck(0x8004A38,0xAAAA); |
| | | // Delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | uint32_t result = 0; |
| | | uint16_t tmp = 0xCCCC; |
| | | __disable_irq(); |
| | | result = FLASH_Prepare(0x8004A38, 128); |
| | | if(result) |
| | | result = FLASH_Write(0x8004A38, (const uint8_t*)&tmp, 2); |
| | | __enable_irq(); |
| | | printf("进入升级模式\r\n"); |
| | | g_com_map[CNT_UPDATE]=0; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | // STMFLASH_Write_NoCheck(0x8004A38,0xAAAA); |
| | | // Delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | uint32_t save_com_map_to_flash(void) |
| | | { |
| | | uint32_t result = 0; |
| | | uint32_t result = 0; |
| | | |
| | | __disable_irq(); |
| | | result = FLASH_Prepare(FLASH_IAP_CTRL_MAP, (COM_MAP_SIZE<<1)); |
| | | if(result) |
| | | result = FLASH_Write(FLASH_IAP_CTRL_MAP, (const uint8_t*)g_com_map, (COM_MAP_SIZE<<1)); |
| | | __enable_irq(); |
| | | __disable_irq(); |
| | | result = FLASH_Prepare(FLASH_IAP_CTRL_MAP, (COM_MAP_SIZE<<1)); |
| | | if(result) |
| | | result = FLASH_Write(FLASH_IAP_CTRL_MAP, (const uint8_t*)g_com_map, (COM_MAP_SIZE<<1)); |
| | | __enable_irq(); |
| | | memcpy(g_com_map2,g_com_map,COM_MAP_SIZE); |
| | | return result; |
| | | return result; |
| | | } |
| | | void ReturnFactorySettings(void) |
| | | { |
| | | |
| | | g_com_map[0] = 0x55AA; |
| | | g_com_map[DEV_ID] =0x04;//DEFAULT_DEV_ID; //默认设备ID |
| | | g_com_map[COM_INTERVAL]=1000; |
| | | g_com_map[MAX_REPORT_ANC_NUM]=10; |
| | | g_com_map[GROUP_ID]=0; |
| | | g_com_map[DIST_OFFSET]=-31; |
| | | |
| | | g_com_map[DEV_ROLE] =0x1; //标签 |
| | | |
| | | g_com_map[NEARBASE_NUM]=0; |
| | | g_com_map[ANC_POLL]=0; |
| | | g_com_map[ALARM_DEV] = 0; |
| | | g_com_map[ALARM_DISTANCE1] = 0; //默认报警距离50cm |
| | | g_com_map[ALARM_DISTANCE2] = 0; //默认报警距离50cm |
| | | g_com_map[ALARM_DISTANCE3] = 0; //默认报警距离50cm |
| | | g_com_map[HEARTBEAT]=0; |
| | | |
| | | g_com_map[POWER]=67; |
| | | g_com_map[IMU_THRES]=2; |
| | | g_com_map[STATIONARY_TIME] = 10; |
| | | g_com_map[NOMOVESLEEP_TIME]=120; |
| | | g_com_map[MOTOR_ENABLE]=1; |
| | | g_com_map[IMU_ENABLE]=0; |
| | | |
| | | g_com_map[ACTIVE_INDEX]=0; |
| | | g_com_map[CNT_RESTART]=0; |
| | | g_com_map[CNT_REBOOT]=0; |
| | | g_com_map[CNT_UPDATE]=0; |
| | | g_com_map[MODBUS_MODE]=0; |
| | | // g_com_map[LORA_SEND_INDEX] = 1; |
| | | // g_com_map[NEARBASE_ID1]=0x470; |
| | | g_com_map[LORA_POWER]=22; |
| | | save_com_map_to_flash(); |
| | | } |
| | | void parameter_init(void) |
| | | { |
| | | FLASH_Read(FLASH_IAP_CTRL_MAP, (uint8_t*)&g_com_map, (COM_MAP_SIZE<<1)); |
| | | if(g_com_map[0] != 0x55AA) |
| | | { |
| | | g_com_map[0] = 0x55AA; |
| | | g_com_map[DEV_ID] =0x04;//DEFAULT_DEV_ID; //默认设备ID |
| | | |
| | | g_com_map[COM_INTERVAL]=500; |
| | | g_com_map[MAX_REPORT_ANC_NUM]=10; |
| | | g_com_map[GROUP_ID]=0; |
| | | g_com_map[DIST_OFFSET]=-31; |
| | | |
| | | g_com_map[DEV_ROLE] =0x1; //标签 |
| | | |
| | | g_com_map[NEARBASE_NUM]=0; |
| | | g_com_map[ANC_POLL]=0; |
| | | g_com_map[ALARM_DEV] = 0; |
| | | g_com_map[ALARM_DISTANCE1] = 0; //默认报警距离50cm |
| | | g_com_map[ALARM_DISTANCE2] = 0; //默认报警距离50cm |
| | | g_com_map[ALARM_DISTANCE3] = 0; //默认报警距离50cm |
| | | g_com_map[HEARTBEAT]=0; |
| | | |
| | | g_com_map[POWER]=67; |
| | | g_com_map[IMU_THRES]=2; |
| | | g_com_map[STATIONARY_TIME] = 10; |
| | | g_com_map[NOMOVESLEEP_TIME]=120; |
| | | g_com_map[MOTOR_ENABLE]=1; |
| | | g_com_map[IMU_ENABLE]=0; |
| | | |
| | | g_com_map[ACTIVE_INDEX]=0; |
| | | g_com_map[CNT_RESTART]=0; |
| | | g_com_map[CNT_REBOOT]=0; |
| | | g_com_map[CNT_UPDATE]=0; |
| | | g_com_map[MODBUS_MODE]=0; |
| | | |
| | | g_com_map[NEARBASE_ID1]=0x470; |
| | | g_com_map[LORA_POWER]=22; |
| | | save_com_map_to_flash(); |
| | | } |
| | | FLASH_Read(FLASH_IAP_CTRL_MAP, (uint8_t*)&g_com_map, (COM_MAP_SIZE<<1)); |
| | | if(g_com_map[MAP_SIGN_INDEX] !=0x55AA) |
| | | { |
| | | ReturnFactorySettings(); |
| | | } |
| | | } |
| | | |