| | |
| | | |
| | | UART_PushFrame(send_frame, data_length+9); |
| | | } |
| | | |
| | | void CheckUsartRec(uint8_t index,uint8_t value) |
| | | { |
| | | if(index==2*CNT_UPDATE&&value==1) |
| | | { |
| | | 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); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | if(index ==2*CNT_REBOOT&&value==1) |
| | | { |
| | | ReturnFactory(); |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | if(index==2*CNT_RESTART&&value==1) |
| | | { |
| | | 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长度的字节,放到全局变量中 |
| | | CheckUsartRec(pack_index,mUsartReceivePack[0]); |
| | | memcpy((uint8_t*)&g_com_map + pack_index, mUsartReceivePack, pack_datalen); |
| | | //返回一个error状态 |
| | | //SendComMap(pack_datalen,pack_index); |