private void PrepareForDeploy(ArrayList blocks) { const uint c_DeploySector = _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; const uint c_SectorUsageMask = _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK; bool fEraseDeployment = false; // if vsdebug is not enabled then we cannot write/erase if (!IsClrDebuggerEnabled()) { if (OnProgress != null) { OnProgress(0, 1, Properties.Resources.StatusConnectingToTinyBooter); } // only check for signature file if we are uploading firmware if (!ConnectToTinyBooter()) { throw new MFDeviceNoResponseException(); } } _WP.Commands.Monitor_FlashSectorMap.Reply map = m_eng.GetFlashSectorMap(); if (map == null) { throw new MFDeviceNoResponseException(); } foreach (_DBG.SRecordFile.Block bl in blocks) { foreach (_WP.Commands.Monitor_FlashSectorMap.FlashSectorData sector in map.m_map) { if (sector.m_address == bl.address) { // only support writing with CLR to the deployment sector and RESERVED sector (for digi) if (c_DeploySector == (c_SectorUsageMask & sector.m_flags)) { fEraseDeployment = true; } else { if (m_eng.ConnectionSource != _DBG.ConnectionSource.TinyBooter) { if (OnProgress != null) { OnProgress(0, 1, Properties.Resources.StatusConnectingToTinyBooter); } // only check for signature file if we are uploading firmware if (!ConnectToTinyBooter()) { throw new MFDeviceNoResponseException(); } } } break; } } } if (fEraseDeployment) { this.Erase(EraseOptions.Deployment); } else if (m_eng.ConnectionSource != _DBG.ConnectionSource.TinyBooter) { //if we are not writing to the deployment sector then assure that we are talking with TinyBooter ConnectToTinyBooter(); } if (m_eng.ConnectionSource == _DBG.ConnectionSource.TinyCLR) { m_eng.PauseExecution(); } }
private bool Connect() { Disconnect(); try { _DBG.PortDefinition pd = (_DBG.PortDefinition)comboBoxPort.SelectedItem; string port = pd.Port; uint baudrate = uint.Parse( ((string)comboBoxBaud.SelectedItem) ); using(_DBG.AsyncSerialStream stream = new _DBG.AsyncSerialStream( port, baudrate )) { stream.Close(); } m_eng = new _DBG.Engine( new Microsoft.SPOT.Debugger.PortDefinition_Serial( port, port, baudrate ) ); m_eng.Silent = true; m_eng.Start(); if(m_eng.TryToConnect( 4, 250 )) { m_deviceRunning = true; m_eng.PauseExecution(); m_ranges = m_eng.MemoryMap(); if(m_ranges == null) { // // Fallback to some defaults. // m_ranges = new _DBG.WireProtocol.Commands.Monitor_MemoryMap.Range[2]; m_ranges[0] = new _DBG.WireProtocol.Commands.Monitor_MemoryMap.Range(); m_ranges[0].m_address = 0x00000000; m_ranges[0].m_length = 0x00060000; m_ranges[0].m_flags = _DBG.WireProtocol.Commands.Monitor_MemoryMap.c_RAM; m_ranges[1] = new _DBG.WireProtocol.Commands.Monitor_MemoryMap.Range(); m_ranges[1].m_address = 0x10000000; m_ranges[1].m_length = 1024*1024; m_ranges[1].m_flags = _DBG.WireProtocol.Commands.Monitor_MemoryMap.c_FLASH; } } else { m_deviceRunning = false; } m_ah = new _DBG.AbortHandler( m_eng, m_deviceRunning ); m_ah.Start(); bool connected = false; for(int tries=0; tries < 5; tries++) { if(m_ah.ReadRegisters( m_snapshot.m_registers, out m_snapshot.m_cpsr, out m_snapshot.m_BWA, out m_snapshot.m_BWC )) { connected = true; break; } Thread.Sleep( 1000 ); } if(connected) { for(int tries=0; tries < 5; tries++) { if(m_ah.ReadLayout( out m_snapshot.m_flashBase, out m_snapshot.m_flashSize, out m_snapshot.m_ramBase, out m_snapshot.m_ramSize )) { break; } Thread.Sleep( 1000 ); } return true; } if(!connected) { MessageBox.Show( "Cannot connect to device" ); } return connected; } catch(Exception ex) { MessageBox.Show( ex.Message ); return false; } }
private void ConnectToDevice(string buildPath, string exePath, ArrayList referenceList) { TestSystem.IncludesDeviceTest = true; PortDefinition port = Utils.GetPort(m_device, m_transport, exePath); try { for (int retry = 0; retry < 3; retry++) { m_engine = new Microsoft.SPOT.Debugger.Engine(port); m_engine.StopDebuggerOnConnect = true; m_engine.Start(); bool connected = false; connected = m_engine.TryToConnect(200, 500, true, ConnectionSource.TinyCLR); if (connected) { m_engine.PauseExecution(); if (!string.Equals(m_transport.ToLower(), "emulator")) { // Deploy the test files to the device. Utils.DeployToDevice(buildPath, referenceList, m_engine, m_transport, m_isDevEnvironment, m_assemblyName); // Connect to the device and execute the deployed test. m_engine.RebootDevice(Microsoft.SPOT.Debugger.Engine.RebootOption.RebootClrWaitForDebugger); // give the device some time to restart (especially for tcp/ip) Thread.Sleep(500); if (m_engine.PortDefinition is PortDefinition_Tcp) { Thread.Sleep(1000); } connected = false; connected = m_engine.TryToConnect(200, 500, true, ConnectionSource.TinyCLR); } if (!connected) { DetachFromEngine(); throw new ApplicationException("Reboot Failed"); } AttachToProcess(); m_engine.ThrowOnCommunicationFailure = true; m_engine.OnMessage += new MessageEventHandler(OnMessage); m_engine.OnCommand += new CommandEventHandler(OnCommand); m_engine.OnNoise += new NoiseEventHandler(OnNoise); Console.WriteLine("\tExecuting the device test.."); m_initialTime = DateTime.Now; m_engine.ResumeExecution(); m_deviceDone.WaitOne(); break; } else { DetachFromEngine(); //throw new ApplicationException("Connection failed"); } } } catch (Exception ex) { DetachFromEngine(); throw new ApplicationException("Connection failed: " + ex.ToString()); } }
private void ConnectToDevice(string buildPath, string exePath, ArrayList referenceList) { TestSystem.IncludesDeviceTest = true; PortDefinition port = Utils.GetPort(m_device, m_transport, exePath); try { for (int retry = 0; retry < 3; retry++) { m_engine = new Microsoft.SPOT.Debugger.Engine(port); m_engine.StopDebuggerOnConnect = true; m_engine.Start(); bool connected = false; connected = m_engine.TryToConnect(200, 500, true, ConnectionSource.TinyCLR); if (connected) { m_engine.PauseExecution(); if (!string.Equals(m_transport.ToLower(), "emulator")) { // Deploy the test files to the device. Utils.DeployToDevice(buildPath, referenceList, m_engine, m_transport, m_isDevEnvironment, m_assemblyName); // Connect to the device and execute the deployed test. m_engine.RebootDevice(Microsoft.SPOT.Debugger.Engine.RebootOption.RebootClrWaitForDebugger); // give the device some time to restart (especially for tcp/ip) Thread.Sleep(500); if (m_engine.PortDefinition is PortDefinition_Tcp) { Thread.Sleep(1000); } connected = false; connected = m_engine.TryToConnect(200, 500, true, ConnectionSource.TinyCLR); } if (!connected) { DetachFromEngine(); throw new ApplicationException("Reboot Failed"); } AttachToProcess(); m_engine.ThrowOnCommunicationFailure = true; m_engine.OnMessage += new MessageEventHandler(OnMessage); m_engine.OnCommand += new CommandEventHandler(OnCommand); m_engine.OnNoise += new NoiseEventHandler(OnNoise); Console.WriteLine("\tExecuting the device test.."); m_initialTime = DateTime.Now; m_engine.ResumeExecution(); m_deviceDone.WaitOne(); break; } else { DetachFromEngine(); //throw new ApplicationException("Connection failed"); } } } catch(Exception ex) { DetachFromEngine(); throw new ApplicationException("Connection failed: " + ex.ToString()); } }
private void buttonEraseDeployment_Click(object sender, EventArgs e) { bool bWasStarted = EnsureDebuggerConnection(); Cursor old = Cursor.Current; Cursor = Cursors.WaitCursor; buttonEraseDeployment.Text = "Erasing..."; buttonEraseDeployment.Update(); NewText("Erasing Deployment Sector...\r\n"); try { _DBG.WireProtocol.Commands.Monitor_Ping.Reply ping = m_eng.GetConnectionSource(); if (ping == null) { NewText("Unable to connect to device\r\n"); return; } bool fClrConnection = ping.m_source == _DBG.WireProtocol.Commands.Monitor_Ping.c_Ping_Source_TinyCLR; if (fClrConnection) { m_eng.PauseExecution(); } _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.Reply status = m_eng.GetFlashSectorMap() as _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.Reply; if (status == null) { NewText("Erase Deployment may Not be supported on this device build\r\n"); } else { const uint c_deployFlag = _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; const uint c_usageMask = _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK; foreach (_DBG.WireProtocol.Commands.Monitor_FlashSectorMap.FlashSectorData sector in status.m_map) { if (c_deployFlag == (c_usageMask & sector.m_flags)) { NewText(string.Format("Erasing sector at 0x{0:x08}\r\n", sector.m_address)); m_eng.EraseMemory(sector.m_address, sector.m_size); } } if (fClrConnection) { m_eng.RebootDevice(_DBG.Engine.RebootOption.RebootClrOnly); } NewText("Erase Deployment Successfull"); } } catch (Exception ex) { NewText("Exception: " + ex.Message + "\r\n"); } finally { buttonEraseDeployment.Text = "Erase Deployment"; Cursor = old; if (!bWasStarted) { m_eng.Stop(); m_eng = null; } } }
private bool Connect() { Disconnect(); try { _DBG.PortDefinition pd = (_DBG.PortDefinition)comboBoxPort.SelectedItem; string port = pd.Port; uint baudrate = uint.Parse(((string)comboBoxBaud.SelectedItem)); using (_DBG.AsyncSerialStream stream = new _DBG.AsyncSerialStream(port, baudrate)) { stream.Close(); } m_eng = new _DBG.Engine(new Microsoft.SPOT.Debugger.PortDefinition_Serial(port, port, baudrate)); m_eng.Silent = true; m_eng.Start(); if (m_eng.TryToConnect(4, 250)) { m_deviceRunning = true; m_eng.PauseExecution(); m_ranges = m_eng.MemoryMap(); if (m_ranges == null) { // // Fallback to some defaults. // m_ranges = new _DBG.WireProtocol.Commands.Monitor_MemoryMap.Range[2]; m_ranges[0] = new _DBG.WireProtocol.Commands.Monitor_MemoryMap.Range(); m_ranges[0].m_address = 0x00000000; m_ranges[0].m_length = 0x00060000; m_ranges[0].m_flags = _DBG.WireProtocol.Commands.Monitor_MemoryMap.c_RAM; m_ranges[1] = new _DBG.WireProtocol.Commands.Monitor_MemoryMap.Range(); m_ranges[1].m_address = 0x10000000; m_ranges[1].m_length = 1024 * 1024; m_ranges[1].m_flags = _DBG.WireProtocol.Commands.Monitor_MemoryMap.c_FLASH; } } else { m_deviceRunning = false; } m_ah = new _DBG.AbortHandler(m_eng, m_deviceRunning); m_ah.Start(); bool connected = false; for (int tries = 0; tries < 5; tries++) { if (m_ah.ReadRegisters(m_snapshot.m_registers, out m_snapshot.m_cpsr, out m_snapshot.m_BWA, out m_snapshot.m_BWC)) { connected = true; break; } Thread.Sleep(1000); } if (connected) { for (int tries = 0; tries < 5; tries++) { if (m_ah.ReadLayout(out m_snapshot.m_flashBase, out m_snapshot.m_flashSize, out m_snapshot.m_ramBase, out m_snapshot.m_ramSize)) { break; } Thread.Sleep(1000); } return(true); } if (!connected) { MessageBox.Show("Cannot connect to device"); } return(connected); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }