diff --git a/Firmware/LogicAnalyzer_V2/LogicAnalyzer.c b/Firmware/LogicAnalyzer_V2/LogicAnalyzer.c index 91c791c..0bdab48 100644 --- a/Firmware/LogicAnalyzer_V2/LogicAnalyzer.c +++ b/Firmware/LogicAnalyzer_V2/LogicAnalyzer.c @@ -15,6 +15,8 @@ #include "hardware/structs/syscfg.h" #include "hardware/structs/systick.h" #include "tusb.h" +#include "pico/unique_id.h" +#include "pico/bootrom.h" #ifdef WS2812_LED #include "LogicAnalyzer_W2812.h" @@ -359,6 +361,13 @@ void processData(uint8_t* data, uint length, bool fromWiFi) #endif + case 4: + + sendResponse("RESTARTING_BOOTLOADER\n", fromWiFi); + sleep_ms(1000); + reset_usb_boot(0, 0); + break; + default: sendResponse("ERR_UNKNOWN_MSG\n", fromWiFi); //Unknown message @@ -540,6 +549,18 @@ int main() //Enable systick using CPU clock systick_hw->csr = 0x05; + pico_unique_board_id_t id; + pico_get_unique_board_id(&id); + + uint16_t delay = 0; + + for(int buc = 0; buc < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; buc++) + delay += id.id[buc]; + + delay = (delay & 0x3ff) + ((delay & 0xFC00) >> 6); + + sleep_ms(delay); + //Initialize USB stdio stdio_init_all(); diff --git a/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml b/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml index fafbc7e..02e3e3e 100644 --- a/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml +++ b/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml @@ -36,6 +36,7 @@ <TextBlock VerticalAlignment="Center" Margin="10,0,10,0">Current device:</TextBlock> <TextBlock VerticalAlignment="Center" Name="lblConnectedDevice">< None ></TextBlock> <TextBlock Name="lblInfo" VerticalAlignment="Center" FontFamily="avares://LogicAnalyzer/Assets/Fonts#Font Awesome 6 Free" Margin="10,0,0,0"></TextBlock> + <TextBlock Name="lblBootloader" VerticalAlignment="Center" FontFamily="avares://LogicAnalyzer/Assets/Fonts#Font Awesome 6 Free" Margin="10,0,0,0"></TextBlock> </StackPanel> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Stretch" Grid.Column="1" Margin="0,0,10,0"> <Button Name="btnRepeat" IsEnabled="False" Margin="10,0,10,0">Repeat last capture</Button> diff --git a/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml.cs b/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml.cs index fb3263e..efe898f 100644 --- a/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml.cs +++ b/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml.cs @@ -85,7 +85,7 @@ namespace LogicAnalyzer samplePreviewer.PointerWheelChanged += ScrSamplePos_PointerWheelChanged; lblInfo.PointerPressed += LblInfo_PointerPressed; - + lblBootloader.PointerPressed += LblBootloader_PointerPressed; channelViewer.ChannelClick += ChannelViewer_ChannelClick; channelViewer.ChannelVisibilityChanged += ChannelViewer_ChannelVisibilityChanged; tkInScreen.PropertyChanged += tkInScreen_ValueChanged; @@ -150,6 +150,37 @@ namespace LogicAnalyzer } } + private async void LblBootloader_PointerPressed(object? sender, PointerPressedEventArgs e) + { + if (driver != null && !driver.IsCapturing) + { + + if (await this.ShowConfirm("Bootloader", "Are you sure you want to put the device in bootloader mode?")) + { + + if (driver.EnterBootloader()) + { + driver.Dispose(); + driver = null; + lblConnectedDevice.Text = "< None >"; + ddPorts.IsEnabled = true; + btnRefresh.IsEnabled = true; + btnOpenClose.Content = "Open device"; + RefreshPorts(); + btnCapture.IsEnabled = false; + btnRepeat.IsEnabled = false; + mnuSettings.IsEnabled = false; + tmrPower.Change(Timeout.Infinite, Timeout.Infinite); + await this.ShowInfo("Bootloader", "Device entered bootloader mode."); + } + else + { + await this.ShowError("Bootloader", "Error entering bootloader mode. Device may need to be disconnected."); + } + } + } + } + private async void LblInfo_PointerPressed(object? sender, PointerPressedEventArgs e) { if(driver != null) diff --git a/Software/LogicAnalyzer/PythonInitLog.txt b/Software/LogicAnalyzer/PythonInitLog.txt index 63b630f..68e0118 100644 --- a/Software/LogicAnalyzer/PythonInitLog.txt +++ b/Software/LogicAnalyzer/PythonInitLog.txt @@ -62,3 +62,35 @@ 24/11/2024 11:46 -> Stablished path: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll 24/11/2024 11:46 -> Initializing decoders... 24/11/2024 11:46 -> Python initialization completed. +26/11/2024 6:42 -> Initializing python system... +26/11/2024 6:42 -> Initializing python installation detection... +26/11/2024 6:42 -> Target Interpreter: python, Initializing Python Installation Detection... +26/11/2024 6:42 -> Target Interpreter: python, Python version found: 312 +26/11/2024 6:42 -> Target Interpreter: python, Python version parsed: 3.12 +26/11/2024 6:42 -> Target Interpreter: python, Finding python library on Windows... +26/11/2024 6:42 -> Target Interpreter: python, Script output: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll +26/11/2024 6:42 -> Target Interpreter: python, Final python path: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll +26/11/2024 6:42 -> Target Interpreter: python, Python path found: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll +26/11/2024 6:42 -> Target Interpreter: python3, Initializing Python Installation Detection... +26/11/2024 6:42 -> Target Interpreter: python3, Python version not found, aborting. +26/11/2024 6:42 -> Valid installations found: 1 +26/11/2024 6:42 -> Selected version: 3.12 +26/11/2024 6:42 -> Stablished path: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll +26/11/2024 6:42 -> Initializing decoders... +26/11/2024 6:42 -> Python initialization completed. +26/11/2024 6:44 -> Initializing python system... +26/11/2024 6:44 -> Initializing python installation detection... +26/11/2024 6:44 -> Target Interpreter: python, Initializing Python Installation Detection... +26/11/2024 6:44 -> Target Interpreter: python, Python version found: 312 +26/11/2024 6:44 -> Target Interpreter: python, Python version parsed: 3.12 +26/11/2024 6:44 -> Target Interpreter: python, Finding python library on Windows... +26/11/2024 6:44 -> Target Interpreter: python, Script output: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll +26/11/2024 6:44 -> Target Interpreter: python, Final python path: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll +26/11/2024 6:44 -> Target Interpreter: python, Python path found: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll +26/11/2024 6:44 -> Target Interpreter: python3, Initializing Python Installation Detection... +26/11/2024 6:44 -> Target Interpreter: python3, Python version not found, aborting. +26/11/2024 6:44 -> Valid installations found: 1 +26/11/2024 6:44 -> Selected version: 3.12 +26/11/2024 6:44 -> Stablished path: C:\Users\geniw\AppData\Local\Programs\Python\Python312\Python312.dll +26/11/2024 6:44 -> Initializing decoders... +26/11/2024 6:44 -> Python initialization completed. diff --git a/Software/LogicAnalyzer/SharedDriver/AnalyzerDriverBase.cs b/Software/LogicAnalyzer/SharedDriver/AnalyzerDriverBase.cs index a1800d5..239a08a 100644 --- a/Software/LogicAnalyzer/SharedDriver/AnalyzerDriverBase.cs +++ b/Software/LogicAnalyzer/SharedDriver/AnalyzerDriverBase.cs @@ -29,6 +29,7 @@ namespace SharedDriver #region Capture Methods public abstract CaptureError StartCapture(CaptureSession Session, Action<CaptureEventArgs>? CaptureCompletedHandler = null); public abstract bool StopCapture(); + public abstract bool EnterBootloader(); #endregion #region Device info diff --git a/Software/LogicAnalyzer/SharedDriver/EmulatedAnalyzerDriver.cs b/Software/LogicAnalyzer/SharedDriver/EmulatedAnalyzerDriver.cs index c357d67..4d592f0 100644 --- a/Software/LogicAnalyzer/SharedDriver/EmulatedAnalyzerDriver.cs +++ b/Software/LogicAnalyzer/SharedDriver/EmulatedAnalyzerDriver.cs @@ -54,7 +54,10 @@ namespace SharedDriver return false; } - + public override bool EnterBootloader() + { + return false; + } public override CaptureMode GetCaptureMode(int[] Channels) { var split = SplitChannelsPerDevice(Channels); diff --git a/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs b/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs index 4c744b0..78ca18e 100644 --- a/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs +++ b/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs @@ -270,7 +270,6 @@ namespace SharedDriver #region Capture code - public override CaptureError StartCapture(CaptureSession Session, Action<CaptureEventArgs>? CaptureCompletedHandler = null) { try @@ -669,6 +668,28 @@ namespace SharedDriver #endregion + #region Bootloader-related functions + public override bool EnterBootloader() + { + try + { + if (capturing || baseStream == null || readResponse == null) + return false; + + OutputPacket pack = new OutputPacket(); + pack.AddByte(4); + baseStream.Write(pack.Serialize()); + baseStream.Flush(); + + baseStream.ReadTimeout = 10000; + var result = readResponse.ReadLine(); + + return result == "RESTARTING_BOOTLOADER"; + } + catch { return false; } + } + #endregion + #region Network-related functions public override unsafe bool SendNetworkConfig(string AccesPointName, string Password, string IPAddress, ushort Port) { diff --git a/Software/LogicAnalyzer/SharedDriver/MultiAnalyzerDriver.cs b/Software/LogicAnalyzer/SharedDriver/MultiAnalyzerDriver.cs index d6862b7..df76fde 100644 --- a/Software/LogicAnalyzer/SharedDriver/MultiAnalyzerDriver.cs +++ b/Software/LogicAnalyzer/SharedDriver/MultiAnalyzerDriver.cs @@ -315,6 +315,20 @@ namespace SharedDriver #endregion + #region Bootloader-related functions + public override bool EnterBootloader() + { + try + { + if (capturing) + return false; + + return connectedDevices.All(d => d.EnterBootloader()); + } + catch { return false; } + } + #endregion + #region Device information functions public override CaptureMode GetCaptureMode(int[] Channels) { diff --git a/Software/LogicAnalyzer/publish.ps1 b/Software/LogicAnalyzer/publish.ps1 index 6fca0eb..d49788e 100644 --- a/Software/LogicAnalyzer/publish.ps1 +++ b/Software/LogicAnalyzer/publish.ps1 @@ -1,4 +1,5 @@ param ( + [Parameter(Mandatory=$true)] [string]$packageName )