| | |
| | | |
| | | UART_PushFrame(send_frame, data_length+9); |
| | | } |
| | | void UpdateProcess(uint8_t index) |
| | | { |
| | | if(index == 2*CNT_UPDATE) |
| | | { |
| | | uint32_t result = 0; |
| | | uint16_t tmp = 0xAAAA; |
| | | __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 |
| | | } |
| | | if(index == 2*CNT_REBOOT) |
| | | { |
| | | g_com_map[CNT_REBOOT]=0; |
| | | g_com_map[MAP_SIGN_INDEX]=0; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | if(index == 2*CNT_RESTART) |
| | | { |
| | | g_com_map[CNT_RESTART]=0; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | |
| | | } |
| | | void UsartParseDataHandler(uint8_t data) |
| | | { |
| | | static UsartRecvPackState usart_receive_state = UsartReceiveWaitHead0; |
| | |
| | | { |
| | | case CMD_WRITE: |
| | | //从mUsartReceivePack中读取pack_length长度的字节,放到全局变量中 |
| | | if(mUsartReceivePack[0]==1) |
| | | UpdateProcess(pack_index); |
| | | memcpy((uint8_t*)&g_com_map + pack_index, mUsartReceivePack, pack_datalen); |
| | | //返回一个error状态 |
| | | //SendComMap(pack_datalen,pack_index); |