// This function is to fix issue where PBL does not propery handle PIPE reset need to make sure 1 TX and 1 RX is working we may be out of sync... int Sahara::PblHack(void) { int status = 0; // Assume that we already got the hello req so send hello response status = ConnectToDevice(false, SAHARA_MODE_COMMAND); if (status != 0) { return status; } // Make sure we get command ready back execute_rsp_t cmd_rdy; uint32_t bytesRead = sizeof(cmd_rdy); sport->SetTimeout(10); status = sport->Read((unsigned char *)&cmd_rdy, &bytesRead); if (status != 0 || bytesRead == 0) { // Assume there was a data toggle issue and send the mode switch command return ModeSwitch(SAHARA_MODE_IMAGE_TX_PENDING); } else if (cmd_rdy.cmd != SAHARA_CMD_READY) { Log("PblHack: Error - cmd:%i, status:%i\n", cmd_rdy.cmd, cmd_rdy.data_len); return ERROR_INVALID_DATA; } // Successfully got the CMD_READY so now switch back to normal mode return ModeSwitch(SAHARA_MODE_IMAGE_TX_PENDING); }
int main(void) { delay_init(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); uart_init(115200); //串口初始化为115200 Uart2_Init(115200); OLED_Init(); LED_Init(); OLED_Clear(); KEY_Init();//IO初始化 TIM3_Int_Init(499,7199);//10Khz的计数频率,计数到500为50ms NET_Init(); ConnectToDevice(); delay_ms(300); LED2 = 0; delay_ms(100); LED2 = 1; EEPROM_Init(); // ReadLedStatusFromFlash(); StartToUploadFlag = 1; while(1) { MainMenuIntoSubMenu(); SwitchDetect(); } }
int Sahara::DumpDeviceInfo(pbl_info_t *pbl_info) { uint32_t dataBuf[64]; int status = 0; // Connect to the device in command mode status = ConnectToDevice(true, SAHARA_MODE_COMMAND); if( status != 0) { return status; } // Make sure we get command ready back execute_rsp_t cmd_rdy; uint32_t bytesRead = sizeof(cmd_rdy); status = sport->Read((unsigned char *)&cmd_rdy, &bytesRead); if (status != 0 || bytesRead == 0 ) { Log("No response from device after switch mode command\n"); return EINVAL; } else if (cmd_rdy.cmd != SAHARA_CMD_READY) { Log("Unexpected response for command mode %i\n", cmd_rdy.cmd); return EINVAL; } // Dump out all the device information status = ReadData(SAHARA_EXEC_CMD_SERIAL_NUM_READ, (unsigned char*)dataBuf, sizeof(dataBuf)); if ( status > 0 && status < sizeof(dataBuf)) { pbl_info->serial = dataBuf[0]; } status = ReadData(SAHARA_EXEC_CMD_MSM_HW_ID_READ, (unsigned char*)dataBuf, sizeof(dataBuf)); if (status > 0 && status < sizeof(dataBuf)) { pbl_info->msm_id = dataBuf[1]; } status = ReadData(SAHARA_EXEC_CMD_OEM_PK_HASH_READ, (unsigned char*)dataBuf, sizeof(dataBuf)); if (status > 0 && status < sizeof(dataBuf)) { memcpy(pbl_info->pk_hash, dataBuf, sizeof(pbl_info->pk_hash)); } status = ReadData(SAHARA_EXEC_CMD_GET_SOFTWARE_VERSION_SBL, (unsigned char*)dataBuf, sizeof(dataBuf)); if (status > 0 && status < sizeof(dataBuf)) { pbl_info->pbl_sw = dataBuf[0]; } ModeSwitch(SAHARA_MODE_COMMAND, false); return 0; }
int Sahara::CheckDevice(void) { hello_req_t hello_req = {0}; int status = -1; uint32_t bytesRead = sizeof(hello_req); if (sport->InputBufferCount()) { status = sport->Read((unsigned char *)&hello_req,&bytesRead); //sport->UnRead((unsigned char *)&hello_req, &bytesRead); if (hello_req.cmd == SAHARA_HELLO_REQ ) { status = ModeSwitch(SAHARA_MODE_COMMAND, false); } } else { // Assume that we already got the hello req so send hello response status = ConnectToDevice(false, SAHARA_MODE_COMMAND); if (status != 0) { return status; } // Make sure we get command ready back execute_rsp_t cmd_rdy; uint32_t bytesRead = sizeof(cmd_rdy); sport->SetTimeout(10); status = sport->Read((unsigned char *)&cmd_rdy, &bytesRead); if (status != 0 || bytesRead == 0 || (cmd_rdy.cmd == SAHARA_END_TRANSFER && cmd_rdy.data_len == SAHARA_NAK_INVALID_CMD)) { // Assume there was a data toggle issue and send the mode switch command //return ModeSwitch(SAHARA_MODE_COMMAND, false); } else if (cmd_rdy.cmd != SAHARA_CMD_READY) { Log("PblHack: Error - cmd:%i, status:%i\n", cmd_rdy.cmd, cmd_rdy.data_len); return ERROR_INVALID_DATA; } ModeSwitch(SAHARA_MODE_COMMAND, false); status = 0; } return status; }