当前位置: 首页 > news >正文

C# WPF读写STM32/GD32单片机Flash数据

1.安装jlink

下载你需要的Jlink版本

JLink-Windows-V792k-x86-64

JLink-Windows-V810k-x86-64

https://download.csdn.net/download/hmxm6/90178195
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.Visual Studio创建WPF项目

如果没有这个选项请看

https://blog.csdn.net/hmxm6/article/details/132914337

image-20241224220628135

创建完成后

在这里插入图片描述

添加一些界面

MainWindow.xaml

<Window x:Class="Jlink_Demo.Views.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:prism="http://prismlibrary.com/"prism:ViewModelLocator.AutoWireViewModel="True"Title="{Binding Title}" Height="350" Width="525" ><Grid><StackPanel Width="525" Height="350" HorizontalAlignment="Left"><Button Width="100"  Height="30"  Command="{Binding connectJlink}">连接Jlink</Button><Button  Width="100"  Height="30"  Command="{Binding closeJlink}">关闭Jlink连接</Button><TextBlock Width="200" Text="{Binding JLINKVersion}" FontSize="20"></TextBlock><Button Width="100" Height="30" Command="{Binding connectMCU}">连接MCU</Button><TextBlock Width="200" Text="{Binding HardwareId}" FontSize="20"></TextBlock><Button Width="100" Height="30" Command="{Binding resetMCU}">复位单片机</Button><Button Width="100" Height="30" Command="{Binding readFlash}">读取Flash</Button><Button Width="100" Height="30" Command="{Binding writeFlash}">写入Flash</Button><TextBox  Width="100" FontSize="20" Text="{Binding FlashData}"></TextBox></StackPanel></Grid>
</Window>

在这里插入图片描述

添加MVVM变量

MainWindowViewModel.cs

using Prism.Mvvm;namespace Jlink_Demo.ViewModels
{public class MainWindowViewModel : BindableBase{// 标题 MVVMprivate string _title = "Prism Application";public string Title{get { return _title; }set { SetProperty(ref _title, value); }}// Jlink版本 MVVMprivate string _JLINKVersion = "Jlink版本:";public string JLINKVersion{get { return _JLINKVersion; }set { SetProperty(ref _JLINKVersion, value); }}// 硬件ID MVVMprivate string _HardwareId = "硬件ID:";public string HardwareId{get { return _HardwareId; }set { SetProperty(ref _HardwareId, value); }}// Flash数据 MVVMprivate int _FlashData = 0;public int FlashData{get { return _FlashData; }set { SetProperty(ref _FlashData, value); }}public MainWindowViewModel(){}}
}

3.加入jlink dll

在Jlink安装目录下有两个dll文件,请选择对应dll文件

image-20241224224842885

把文件放入项目

在这里插入图片描述

文件属性中,选择始终复制

在这里插入图片描述

4.添加jlink工具类

在这里插入图片描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;namespace Jlink_Demo.utils
{public static partial class JLink{/// <summary>/// 打开JLINK设备/// </summary>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_Open();/// <summary>/// 关闭JLINK设备/// </summary>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_Close();/// <summary>/// 连接设备/// </summary>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_Connect();/// <summary>/// 开启RTT/// </summary>/// <param name="terminal"></param>/// <param name="size"></param>[DllImport("JLink_x64.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt32 JLINK_RTTERMINAL_Control(UInt32 CMD, UInt32 size);/// <summary>/// 从RTT回读数据/// </summary>/// <param name="terminal"></param>/// <param name="rxBuffer"></param>/// <param name="len"></param>[DllImport("JLink_x64.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]public static extern void JLINK_RTTERMINAL_Read(int terminal, [Out(), MarshalAs(UnmanagedType.LPArray)] byte[] rxBuffer, UInt32 size);static string gbk_ansi(string str){string keyword;byte[] buffer = Encoding.GetEncoding("GB2312").GetBytes(str);keyword = Encoding.UTF8.GetString(buffer);return keyword;}public static string JLINKARM_ReadRTT_String(){try{byte[] aa = new byte[1000];JLINK_RTTERMINAL_Read(0, aa, 1000);ASCIIEncoding kk = new ASCIIEncoding();//使用UTF-8编码UTF8Encoding uu = new UTF8Encoding();string ss = uu.GetString(aa);if (ss.Length > 1){Console.Write(ss);}return ss;}catch (Exception ex){}return String.Empty;}/// <summary>/// 写数据到RTT/// </summary>/// <param name="terminal"></param>/// <param name="txBuffer"></param>/// <param name="len"></param>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINK_RTTERMINAL_Write(int terminal, [In(), MarshalAs(UnmanagedType.LPArray)] byte[] txBuffer, UInt32 size);/// <summary>/// 系统复位/// </summary>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_Reset();[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_GoAllowSim();/// <summary>/// 执行程序/// </summary>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_Go();/// <summary>/// 中断程序执行/// </summary>/// <returns></returns>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern bool JLINKARM_Halt();/// <summary>/// 单步执行/// </summary>/// <returns></returns>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern bool JLINKARM_Step();/// <summary>/// 清除错误信息/// </summary>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_ClrError();/// <summary>/// 设置JLINK接口速度/// </summary>/// <param name="speed"></param>/// <remarks>0为自动调整</remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_SetSpeed(int speed);/// <summary>/// 设置JTAG为最高速度/// </summary>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_SetMaxSpeed();[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt16 JLINKARM_GetSpeed();[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt32 JLINKARM_GetVoltage();/// <summary>/// 当前MCU是否处于停止状态/// </summary>/// <returns></returns>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern bool JLINKARM_IsHalted();[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern bool JLINKARM_IsConnected();/// <summary>/// JLINK是否已经可以操作了/// </summary>/// <returns></returns>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern bool JLINKARM_IsOpen();/// <summary>/// 取消程序断点/// </summary>/// <param name="index">断点序号</param>/// <remarks>配合JLINKARM_SetBP()使用</remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_ClrBP(UInt32 index);/// <summary>/// 设置程序断点/// </summary>/// <param name="index">断点序号</param>/// <param name="addr">目标地址</param>/// <remarks>建议使用JLINKARM_SetBPEx()替代</remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_SetBP(UInt32 index, UInt32 addr);/// <summary>/// 取消程序断点/// </summary>/// <param name="handle"></param>/// <remarks>配合JLINKARM_SetBPEx()使用</remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_ClrBPEx(int handle);[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]private static extern int JLINKARM_SetWP(UInt32 addr, UInt32 addrmark, UInt32 dat, UInt32 datmark, byte ctrl, byte ctrlmark);/// <summary>/// 取消数据断点/// </summary>/// <param name="handle"></param>/// <remarks>配合JLINKARM_SetWP()使用</remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_ClrWP(int handle);/// <summary>/// 写入一段数据/// </summary>/// <param name="addr"></param>/// <param name="size"></param>/// <param name="buf"></param>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_WriteMem(UInt32 addr, UInt32 size, byte[] buf);/// <summary>/// 读取一段数据/// </summary>/// <param name="addr"></param>/// <param name="size"></param>/// <param name="buf"></param>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_ReadMem(UInt32 addr, UInt32 size, [Out(), MarshalAs(UnmanagedType.LPArray)] byte[] buf);/// <summary>/// 从调试通道获取一串数据/// </summary>/// <param name="buf"></param>/// <param name="size">需要获取的数据长度</param>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_ReadDCCFast([Out(), MarshalAs(UnmanagedType.LPArray)] UInt32[] buf, UInt32 size);/// <summary>/// 从调试通道获取一串数据/// </summary>/// <param name="buf"></param>/// <param name="size">希望获取的数据长度</param>/// <param name="timeout"></param>/// <returns>实际获取的数据长度</returns>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt32 JLINKARM_ReadDCC([Out(), MarshalAs(UnmanagedType.LPArray)] UInt32[] buf, UInt32 size, int timeout);/// <summary>/// 向调试通道写入一串数据/// </summary>/// <param name="buf"></param>/// <param name="size">需要写入的数据长度</param>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_WriteDCCFast(UInt32[] buf, UInt32 size);/// <summary>/// 向调试通道写入一串数据/// </summary>/// <param name="buf"></param>/// <param name="size">希望写入的数据长度</param>/// <param name="timeout"></param>/// <returns>实际写入的数据长度</returns>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt32 JLINKARM_WriteDCC(UInt32[] buf, UInt32 size, int timeout);/// <summary>/// 获取JLINK的DLL版本号/// </summary>/// <returns></returns>/// <remarks>使用10进制数表示</remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt32 JLINKARM_GetDLLVersion();/// <summary>/// 执行命令/// </summary>/// <param name="oBuffer"></param>/// <param name="a"></param>/// <param name="b"></param>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_ExecCommand([In(), MarshalAs(UnmanagedType.LPArray)] byte[] oBuffer, int a, int b);/// <summary>/// 选择接口,0是JTAG 1是SWD/// </summary>/// <param name="type"></param>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_TIF_Select(int type);/// <summary>/// 获取JLINK的固件版本号/// </summary>/// <returns></returns>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt32 JLINKARM_GetHardwareVersion();[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]private static extern void JLINKARM_GetFeatureString([Out(), MarshalAs(UnmanagedType.LPArray)] byte[] oBuffer);[DllImport("JLink_x64.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]private static extern void JLINKARM_GetOEMString([Out(), MarshalAs(UnmanagedType.LPArray)] byte[] oBuffer);[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_SetLogFile([In(), MarshalAs(UnmanagedType.LPArray)] byte[] oBuffer)
;[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern StringBuilder JLINKARM_GetCompileDateTime();[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt32 JLINKARM_GetSN();/// <summary>/// 获取当前MCU的ID号/// </summary>/// <returns></returns>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern UInt32 JLINKARM_GetId();[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_ReadMemU32(UInt32 addr, UInt32 leng, ref UInt32 buf, ref byte status);/// <summary>/// 写入32位的数据/// </summary>/// <param name="addr"></param>/// <param name="dat"></param>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_WriteU32(UInt32 addr, UInt32 dat);[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]private static extern void JLINKARM_ReadMemU16(UInt32 addr, UInt32 leng, ref UInt16 buf, ref byte status);/// <summary>/// 写入16位的数据/// </summary>/// <param name="addr"></param>/// <param name="dat"></param>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_WriteU16(UInt32 addr, UInt16 dat);[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]private static extern void JLINKARM_ReadMemU8(UInt32 addr, UInt32 leng, ref byte buf, ref byte status)
;/// <summary>/// 写入8位的数据/// </summary>/// <param name="addr"></param>/// <param name="dat"></param>/// <remarks></remarks>[DllImport("JLink_x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]public static extern void JLINKARM_WriteU8(UInt32 addr, byte dat);}
}

5.编写按钮事件

MainWindowViewModel.cs

连接c并读取JLink版本号
private DelegateCommand _connectJlink;
public DelegateCommand connectJlink => _connectJlink ?? (_connectJlink = new DelegateCommand(ExecuteConnectJlink));void ExecuteConnectJlink()
{// 1.打开jlinkJLink.JLINKARM_Open();// 读取jlink版本号var dllVersion = JLink.JLINKARM_GetDLLVersion();var hardVersion = JLink.JLINKARM_GetHardwareVersion();this.JLINKVersion = "JLink版本号:" + hardVersion;
}
关闭连接JLink
private DelegateCommand _closeJlink;
public DelegateCommand closeJlink => _closeJlink ?? (_closeJlink = new DelegateCommand(ExecuteCloseJlink));void ExecuteCloseJlink()
{JLink.JLINKARM_Close();// 关闭jlinkthis.JLINKVersion = "";this.HardwareId = "";
}
连接单片机
private DelegateCommand _connectMCU;
public DelegateCommand connectMCU => _connectMCU ?? (_connectMCU = new DelegateCommand(ExecuteConnectMCU));void ExecuteConnectMCU()
{if (JLink.JLINKARM_IsOpen() == true){JLink.JLINKARM_TIF_Select(1);// SWD连接方式// 连接STM32F407VGJLink.JLINKARM_ExecCommand(System.Text.Encoding.UTF8.GetBytes("device = STM32F407VG"), 0, 0);JLink.JLINKARM_SetSpeed(4000);Thread.Sleep(100);//休眠时间var id = JLink.JLINKARM_GetId();// 判断单片机连接状态if (JLink.JLINKARM_IsConnected() == true){// 通过MVVM设置界面上的单片机IDthis.HardwareId = "SUCCESS id:" + id;}else{this.HardwareId = "ERROR";}}else{MessageBox.Show("请先打开烧录器");}
}
复位单片机
private DelegateCommand _resetMCU;
public DelegateCommand resetMCU => _resetMCU ?? (_resetMCU = new DelegateCommand(ExecuteResetMCU));void ExecuteResetMCU()
{JLink.JLINKARM_Reset();JLink.JLINKARM_Go();
}
读取Flash数据
private DelegateCommand _readFlash;
public DelegateCommand readFlash => _readFlash ?? (_readFlash = new DelegateCommand(ExecuteReadFlash));void ExecuteReadFlash()
{UInt32 dataBuff = 0;byte status = 0;if (JLink.JLINKARM_IsConnected() == true){// 读取Flash数据JLink.JLINKARM_ReadMemU32(0x080F0000, 1, ref dataBuff, ref status);// 判断读取状态if (status == 0){// 通过MVVM设置界面上的值this.FlashData = (int)dataBuff;}else{this.FlashData = 0;}}}
写入Flash数据
private DelegateCommand _writeFlash;
public DelegateCommand writeFlash => _writeFlash ?? (_writeFlash = new DelegateCommand(ExecuteWriteFlash));void ExecuteWriteFlash()
{if (JLink.JLINKARM_IsConnected() == true){JLink.JLINKARM_WriteU32(0x080D0000, (uint)this.FlashData);}
}

完整代码MainWindowViewModel.cs

using Jlink_Demo.utils;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Threading;
using System.Windows;namespace Jlink_Demo.ViewModels
{public class MainWindowViewModel : BindableBase{private string _title = "Prism Application";public string Title{get { return _title; }set { SetProperty(ref _title, value); }}private string _JLINKVersion = "Jlink版本:";public string JLINKVersion{get { return _JLINKVersion; }set { SetProperty(ref _JLINKVersion, value); }}private string _HardwareId = "硬件ID:";public string HardwareId{get { return _HardwareId; }set { SetProperty(ref _HardwareId, value); }}private int _FlashData = 0;public int FlashData{get { return _FlashData; }set { SetProperty(ref _FlashData, value); }}public MainWindowViewModel(){}private DelegateCommand _connectJlink;public DelegateCommand connectJlink => _connectJlink ?? (_connectJlink = new DelegateCommand(ExecuteConnectJlink));void ExecuteConnectJlink(){// 1.打开jlinkJLink.JLINKARM_Open();// 读取jlink版本号var dllVersion = JLink.JLINKARM_GetDLLVersion();var hardVersion = JLink.JLINKARM_GetHardwareVersion();this.JLINKVersion = "JLink版本号:" + hardVersion;}private DelegateCommand _closeJlink;public DelegateCommand closeJlink => _closeJlink ?? (_closeJlink = new DelegateCommand(ExecuteCloseJlink));void ExecuteCloseJlink(){JLink.JLINKARM_Close();// 关闭jlinkthis.JLINKVersion = "";this.HardwareId = "";}private DelegateCommand _resetMCU;public DelegateCommand resetMCU => _resetMCU ?? (_resetMCU = new DelegateCommand(ExecuteResetMCU));void ExecuteResetMCU(){JLink.JLINKARM_Reset();JLink.JLINKARM_Go();}private DelegateCommand _connectMCU;public DelegateCommand connectMCU => _connectMCU ?? (_connectMCU = new DelegateCommand(ExecuteConnectMCU));void ExecuteConnectMCU(){if (JLink.JLINKARM_IsOpen() == true){JLink.JLINKARM_TIF_Select(1);// SWD连接方式// 连接STM32F407VGJLink.JLINKARM_ExecCommand(System.Text.Encoding.UTF8.GetBytes("device = STM32F407VG"), 0, 0);JLink.JLINKARM_SetSpeed(4000);Thread.Sleep(100);//休眠时间var id = JLink.JLINKARM_GetId();// 判断单片机连接状态if (JLink.JLINKARM_IsConnected() == true){this.HardwareId = "SUCCESS id:" + id;}else{this.HardwareId = "ERROR";}}else{MessageBox.Show("请先打开烧录器");}}private DelegateCommand _readFlash;public DelegateCommand readFlash => _readFlash ?? (_readFlash = new DelegateCommand(ExecuteReadFlash));void ExecuteReadFlash(){UInt32 dataBuff = 0;byte status = 0;if (JLink.JLINKARM_IsConnected() == true){JLink.JLINKARM_ReadMemU32(0x080D0000, 1, ref dataBuff, ref status);if (status == 0){this.FlashData = (int)dataBuff;}else{this.FlashData = 0;}}}private DelegateCommand _writeFlash;public DelegateCommand writeFlash => _writeFlash ?? (_writeFlash = new DelegateCommand(ExecuteWriteFlash));void ExecuteWriteFlash(){if (JLink.JLINKARM_IsConnected() == true){JLink.JLINKARM_WriteU32(0x080D0000, (uint)this.FlashData);}}}
}

代码示例
https://download.csdn.net/download/hmxm6/90185267

相关文章:

C# WPF读写STM32/GD32单片机Flash数据

1.安装jlink 下载你需要的Jlink版本 JLink-Windows-V792k-x86-64 JLink-Windows-V810k-x86-64 https://download.csdn.net/download/hmxm6/90178195 2.Visual Studio创建WPF项目 如果没有这个选项请看 https://blog.csdn.net/hmxm6/article/details/132914337 创建完…...

[图形渲染]【Unity Shader】【游戏开发】 Shader数学基础17-法线变换基础与应用

在计算机图形学中,法线(normal) 是表示表面方向的向量。它在光照、阴影、碰撞检测等领域有着重要作用。本文将介绍如何在模型变换过程中正确变换法线,确保其在光照计算中的正确性,特别是法线与顶点的变换问题。 1. 法线与切线的基本概念 法线(Normal Vector) 法线(或…...

MySQL外键类型与应用场景总结:优缺点一目了然

前言&#xff1a; MySQL的外键简介&#xff1a;在 MySQL 中&#xff0c;外键 (Foreign Key) 用于建立和强制表之间的关联&#xff0c;确保数据的一致性和完整性。外键的作用主要是限制和维护引用完整性 (Referential Integrity)。 主要体现在引用操作发生变化时的处理方式&…...

Axure10

如果还是不行就将字体图标安装在控制面板–字体下 打开原型了之后&#xff0c;icon没有 一定要将字体库放到–》控制面板\外观和个性化\字体 里面...

数据结构(单向循环链表)

循环单向链表 所谓的循环&#xff0c;指得是将链表末尾节点的后继指针指向头结点。比如&#xff0c;单向链表变成循环链表的示意 图如下所示&#xff1a; 循环链表的操作跟普通链表操作基本上是一致的&#xff0c;只要针对循环特性稍作修改即可。 sclist.h #ifndef __SCLIST_…...

springboot项目搭建

springboot搭建 问题描述不够清晰&#xff0c;无法提供具体的代码解决方案。"springboot搭" 这个表述不明确是要进行什么操作&#xff0c;比如搭建项目、搭建环境、搭建服务等。 如果你是想要创建一个基本的Spring Boot项目&#xff0c;可以使用Spring Initializr&…...

五模型对比!Transformer-GRU、Transformer、CNN-GRU、GRU、CNN五模型多变量时间序列预测

目录 预测效果基本介绍程序设计参考资料 预测效果 基本介绍 光伏功率预测&#xff01;五模型对比&#xff01;Transformer-GRU、Transformer、CNN-GRU、GRU、CNN五模型多变量时间序列预测(Matlab2023b 多输入单输出) 1.程序已经调试好&#xff0c;替换数据集后&#xff0c;仅运…...

02-18.python入门基础一基础算法

&#xff08;一&#xff09;排序算法 简述&#xff1a; 在 Python 中&#xff0c;有多种常用的排序算法&#xff0c;下面为你详细介绍几种常见的排序算法及其原理、实现代码、时间复杂度以及稳定性等特点&#xff0c;并对比它们适用的场景。 冒泡排序&#xff08;Bubble Sor…...

条款19 对共享资源使用std::shared_ptr

目录 一、std::shared_ptr 二、std::shared_ptr性能问题 三、control block的生成时机 四、std::shared_ptr可能存在的问题 五、使用this指针作为std::shared_ptr构造函数实参 六、std::shared_ptr不支持数组 一、std::shared_ptr<T> shared_ptr的内存模型如下图&…...

TCP-UDP调试工具推荐:Socket通信测试教程(附详细图解)

前言 在网络编程与应用开发中&#xff0c;调试始终是一项不可忽视的重要环节。尤其是在涉及TCP/IP、UDP等底层网络通信协议时&#xff0c;如何确保数据能够准确无误地在不同节点间传输&#xff0c;是许多开发者关注的核心问题。 调试的难点不仅在于定位连接建立、数据流控制及…...

算法练习——模拟题

前言&#xff1a;模拟题的特点在于没有什么固定的技巧&#xff0c;完全考验自己的代码能力&#xff0c;因此有助于提升自己的代码水平。如果说一定有什么技巧的话&#xff0c;那就是有的模拟题能够通过找规律来简化算法。 一&#xff1a;替换所有问号 题目要求&#xff1a; 解…...

Windows下播放文件作为麦克风声源的一种方式

近期测试一种外语的ASR识别成功率&#xff0c;样本素材是懂这门语言的同事录制的mp3文件。测试client端原本是从麦克风拾音生成媒体流的。 这样&#xff0c;就需要想办法把mp3文件转换为测试client的输入声音。物理方式上&#xff0c;可以用一根音频线&#xff0c;把电…...

微信流量主挑战:用户数30!新增文档转化功能,解决docker运行jar包报错SimSun找不到的问题(新纪元5)

哎呀&#xff0c;今天忙到飞起&#xff0c;文章晚点更新啦&#xff01;不过好消息是&#xff0c;我们的小程序用户终于突破30啦&#xff0c;感谢大家的支持&#xff01;而且&#xff0c;大家期待已久的文档转化功能明天就要上线啦&#xff0c;目前支持word转pdf&#xff0c;pdf…...

BUU LFI COURSE 1

BUU LFI COURSE 1 启动环境 isset函数检查输入是否为空&#xff0c;使用GET传参file&#xff0c;然后赋值给$str 在调用传参内容 我们是找flag那我们输入?file/flag试试 输入后就得到了flag flag{8c108da2-a579-4ec4-b447-92d9265b8dd4}...

Spark SQL DML语句

【图书介绍】《Spark SQL大数据分析快速上手》-CSDN博客 《Spark SQL大数据分析快速上手》【摘要 书评 试读】- 京东图书 Spark本地模式安装_spark3.2.2本地模式安装-CSDN博客 DML&#xff08;Data Manipulation Language&#xff0c;数据操作语言&#xff09;操作主要用来对…...

逻辑控制语句

一、逻辑控制语句 条件判断 if循环 for、while 二、条件判断 if 1、语法 if 条件:条件为真的操作条件为真的操作 else:条件为假的操作条件为假的操作 data_01 int(input("数字: "))if data_01 > 10:print("ok!!!")print("正确!!!")prin…...

PlasmidFinder:质粒复制子的鉴定和分型

质粒&#xff08;Plasmid&#xff09;是一种细菌染色体外的线性或环状DNA分子&#xff0c;也是一种重要的遗传元素&#xff0c;它们具有自主复制能力&#xff0c;可以在细菌之间传播&#xff0c;并携带多种重要的基因(如耐药基因与毒力基因等)功能。根据质粒传播的特性&#xf…...

OSCP打靶大冒险之Solidstate:多端口获取信息,shell逃逸,计划任务提权

声明&#xff01; 学习资源来自B站up主 **泷羽sec** 有兴趣的师傅可以关注一下&#xff0c;如涉及侵权马上删除文章&#xff0c;笔记只是方便各位师傅的学习和探讨&#xff0c;文章所提到的网站以及内容&#xff0c;只做学习交流&#xff0c;其他均与本人以及泷羽sec团队无关&a…...

【Java-tesseract】OCR图片文本识别

文章目录 一、需求二、概述三、部署安装四、技术细节五、总结 一、需求 场景需求:是对识别常见的PNG,JPEG,TIFF,GIF图片识别&#xff0c;环境为离线内网。组件要求开源免费&#xff0c;并且可以集成Java生成接口服务。 二、概述 我不做选型对比了,我筛选测试了下Tesseract(v…...

sqlserver 数据库误删-用mdf和ldf文件恢复

1.准备好需要恢复的文件 2.安装sqlserver数据库&#xff0c;安装设置的实例目录要记清 3.将需要恢复的文件拷到实例所在目录下的DATA文件夹下 D:\安装时的实例目录\MSSQL10_50.MSSQLSERVER\MSSQL\DATA 4.打开 SQL Server Management Stadio执行以下命令 CREATE DATABASE 数…...

机器学习算法基础知识1:决策树

机器学习算法基础知识1&#xff1a;决策树 一、本文内容与前置知识点1. 本文内容2. 前置知识点 二、场景描述三、决策树的训练1. 决策树训练方式&#xff08;1&#xff09;分类原则-Gini&#xff08;2&#xff09;分类原则-entropy&#xff08;3&#xff09;加权系数-样本量&am…...

使用EasyExcel来动态生成表头

本文记录下使用EasyExcel来动态生成表头 文章目录 概述 概述...

梳理你的思路(从OOP到架构设计)_介绍Android的Java层应用框架03

目录 1、认识Android框架的实践技术 4个嫡系基类 誰來創建子類的對象呢? 2、Intent-based Programming 技术 嫡系应用子类之间如何互相沟通呢&#xff1f; 1、认识Android框架的实践技术 4个嫡系基类 • Android框架里提供了4个嫡系的基类&#xff0c;包括&#xff1a;…...

Html——10 关键字和描述

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title>淘宝网</title><meta name"keywords" content"我要自学网,自学HTML,自学CSS"/><meta name"description" content"要设置…...

汇编学习笔记

汇编 1. debug指令 -R命令(register) 查看、改变CPU寄存器的内容 r ax 修改AX中的内容 -D命令(display) 查看内存中的内容 -E命令(enter) 改写内存中的内容 -U命令(unassenble反汇编) 将内存中的机器指令翻译成汇编指令 -T命令(trace跟踪) 执行一条机器指令 -A命令…...

【C++】统计正整数的位数:题目解析与代码优化

博客主页&#xff1a; [小ᶻ☡꙳ᵃⁱᵍᶜ꙳] 本文专栏: C 文章目录 &#x1f4af;前言&#x1f4af;题目描述**题目要求&#xff1a;统计正整数的位数** &#x1f4af;我的代码实现**核心逻辑解析** &#x1f4af;老师的代码实现**老师代码逻辑解析** &#x1f4af;我的代码…...

CF2043b-B. Digits

题目链接 题意&#xff1a;给定两个整数n、d&#xff0c;要求找出排列成n!个d之后的数可以被1-9中奇数整除的数 题解&#xff1a; 主要是考察分类讨论&#xff1a; 被3整除&#xff0c;当d能被3整除时一定成立或者n > 3&#xff0c;当n > 3时n!一定包含因数3 被5整除&a…...

[文献阅读]ReAct: Synergizing Reasoning and Acting in Language Models

文章目录 摘要Abstract:思考与行为协同化Reason(Chain of thought)ReAct ReAct如何协同推理 响应Action&#xff08;动作空间&#xff09;协同推理 结果总结 摘要 ReAct: Synergizing Reasoning and Acting in Language Models [2210.03629] ReAct: Synergizing Reasoning an…...

React 高阶组件(HOC)

文章目录 一. 高阶组件&#xff08;HOC&#xff09;的定义二. HOC 的作用和优势三. HOC 的使用方式四. HOC 的注意事项和潜在问题五. 应用场景1. 权限控制与认证2. 数据获取与预加载3. 样式和主题管理4. 性能优化 - 缓存数据或组件渲染结果5. 日志记录与调试辅助 六. 总结 一. …...

module ‘django.db.models‘ has no attribute ‘FieldDoesNotExist‘

module ‘django.db.models’ has no attribute ‘FieldDoesNotExist’ xadmin报错 原因 django与xadmin版本不匹配。 django==3.2.7 xadmin-django==3.0.2解决方案 在xadmin/view/edit.py的388行改为 from django.core import exceptions if self.request_method ==...

仓颉语言实战——1. 类型

仓颉语言实战——1. 类型 仓颉语言&#xff08;Cangjie Language&#xff09;是一个现代化的、简洁而强大的编程语言&#xff0c;它的类型系统为高效开发提供了极大的支持。本篇文章将围绕仓颉语言中的类型系统展开&#xff0c;结合实战代码&#xff0c;帮助开发者快速掌握这一…...

大数据平台开发学习路线及技能

背景 最近项目涉及这方面&#xff0c;特地整理学习路线方便后续学习。 必备技能 一、编程语言 Java&#xff1a;大数据开发的基础语言&#xff0c;具有跨平台能力&#xff0c;可用于编写各种应用。 Python&#xff1a;机器学习和数据分析领域广泛使用的语言&#xff0c;易于…...

python报错ModuleNotFoundError: No module named ‘visdom‘

在用虚拟环境跑深度学习代码时&#xff0c;新建的环境一般会缺少一些库&#xff0c;而一般解决的方法就是直接conda install&#xff0c;但是我在conda install visdom之后&#xff0c;安装是没有任何报错的&#xff0c;conda list里面也有visdom的信息&#xff0c;但是再运行代…...

python-Flask:SQLite数据库路径不正确但是成功访问到了数据库,并对表进行了操作

出现了这个问题&#xff0c;就好像是我要去找在南方的人&#xff0c;然后我刚好不分南北&#xff0c;我认为的方向错了&#xff0c;实则方向对了。 在我针对复盘解决&#xff1a;sqlite3.OperationalError: unrecognized token: “{“-CSDN博客这个内容的时候&#xff0c;又出现…...

阿里云人工智能ACA(七)——计算机视觉基础

一、自然语言处理基本介绍 1. 自然语言处理的定义 1-1 自然语言 人类使用的在社会生活中自然形成的语言 1-2 自然语言处理 目标是让计算机能够理解、解析、生成和处理人类的自然语言 包含自然语言理解和自然语言生成两部分组成 2. 自然语言处理的发展趋势 3.自然语言处理…...

计算机组成(1)——CPU与存储器的连接

目录 CPU与存储器的连接 1.内存条的设计思路 如何读取存储元上是0还是1 存储数据1010 系统的将这些存储元连接起来 2.译码器的原理 3.加入控制电路 4.位扩展 5.字扩展 CPU与存储器的连接 1.内存条的设计思路 内存条&#xff1a;存储体、MAR&#xff08;地址寄存器&am…...

MySQL学习之表查询操作

MySQL学习之表查询操作 准备数据 创建数据表和导入数据 CREATE TABLE user (id INT COMMENT 编号,name VARCHAR (10) COMMENT 姓名,gender CHAR(1) COMMENT 性别,age TINYINT UNSIGNED COMMENT 年龄,phone VARCHAR(11) COMMENT 手机号,idcard CHAR(18) COMMENT 身份证号,addre…...

GitHub 桌面版配置 |可视化界面进行上传到远程仓库 | gitLab 配置【把密码存在本地服务器】

&#x1f947; 版权: 本文由【墨理学AI】原创首发、各位读者大大、敬请查阅、感谢三连 &#x1f389; 声明: 作为全网 AI 领域 干货最多的博主之一&#xff0c;❤️ 不负光阴不负卿 ❤️ 文章目录 桌面版安装包下载clone 仓库操作如下GitLab 配置不再重复输入账户和密码的两个方…...

六十:HTTP/2与gRPC框架

随着互联网技术的发展&#xff0c;应用程序之间的通信需求日益复杂和多样化。传统的HTTP/1.x协议虽然广泛应用&#xff0c;但在性能和功能方面已经难以满足现代应用的需求。为了解决这些问题&#xff0c;HTTP/2协议和基于其之上的gRPC框架应运而生。本文将介绍HTTP/2协议的特点…...

普通的树形数据primevue的treetable组件的treetable[ ]

1&#xff0c;核心思想就是缺什么属性加什么属性 1.原始数据 原始数据本身就是树状&#xff0c;只是不是TreeNode类型的数组&#xff0c;这样的数据&#xff0c;primevue的treetable组件是展示不出来的&#xff0c;自己把这个数组转成node类型的&#xff0c;会有一个难解决的…...

数据库设计问题记录

唯一性约束和逻辑删除的冲突 问题描述 如果一张表中&#xff0c;存在唯一性约束&#xff0c;比如一些数据中的code&#xff0c;且数据表使用逻辑删除。当删除某行数据的时候&#xff0c;以后再次插入相同code的数据&#xff0c;数据库会报错。 问题分析 在逻辑删除中&#…...

基于springboot的汽车租赁系统丨源码+数据库+万字文档+PPT

作者简介&#xff1a; 作者&#xff1a;学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等 文末获取“源码数据库万字文档PPT”&#xff0c;支持远程部署调试、运行安装。 技术框架 开发语言&#xff1a;Java 框架&#xff1a;spring…...

计算机毕业设计hadoop+spark+hive民宿推荐系统 酒店推荐系统 民宿价格预测 酒店价格 预测 机器学习 深度学习 Python爬虫 HDFS集群

温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 作者简介&#xff1a;Java领…...

从0入门自主空中机器人-2-2【无人机硬件选型-PX4篇】

1. 常用资料以及官方网站 无人机飞控PX4用户使用手册&#xff08;无人机基本设置、地面站使用教程、软硬件搭建等&#xff09;&#xff1a;https://docs.px4.io/main/en/ PX4固件开源地址&#xff1a;https://github.com/PX4/PX4-Autopilot 飞控硬件、数传模块、GPS、分电板等…...

渗透测试常用术语总结

一、攻击篇 1&#xff0e;攻击工具 肉鸡 所谓“肉鸡”是一种很形象的比喻&#xff0c;比喻那些可以被攻击者控制的电脑、手机、服务器或者其他摄像头、路由器等智能设备&#xff0c;用于发动网络攻击。 例如在2016年美国东海岸断网事件中&#xff0c;黑客组织控制了大…...

Spring Boot 介绍与应用

什么是 Spring Boot&#xff1f; Spring Boot 是一个用于简化 Spring 应用程序开发和部署的框架&#xff0c;它建立在 Spring 框架的基础之上&#xff0c;但去除了繁琐的配置。Spring Boot 采用“约定优于配置”的原则&#xff0c;默认启用了大量自动配置&#xff0c;使得开发…...

前端:改变鼠标点击物体的颜色

需求&#xff1a; 需要改变图片中某一物体的颜色&#xff0c;该物体是纯色&#xff1b; 鼠标点击哪个物体&#xff0c;哪个物体的颜色变为指定的颜色&#xff0c;利用canvas实现。 演示案例 代码Demo <!DOCTYPE html> <html lang"en"><head>&l…...

基于Android的校园导航系统

基于Android的校园导航系统是一种专为校园环境设计的移动应用程序&#xff0c;旨在帮助学生、教职工及访客快速、准确地找到校园内的目的地。以下是对基于Android的校园导航系统的详细介绍&#xff1a; 一、系统概述 基于Android的校园导航系统通常包括客户端&#xff08;移动…...

ipad如何做副屏(Windows/Mac Moonlight Sunshine)

Windows 被连接主机&#xff08;Windows&#xff09; 要使用的话需要固定ip&#xff0c;不然ip会换来换去&#xff0c;固定ip方法本人博客有记载Github下载Sunshine Sunshine下载地址除了安装路径需要改一下&#xff0c;其他一路点安装完成后会打开Sunshine的Web UI&#xff…...

微信小程序页面传参长度问题

需求&#xff1a;a页面传递参数到b页面&#xff0c;传递的参数是一个对象&#xff0c;需要进行json转换&#xff0c;但在小程序中传递的参数长度是有限制的&#xff0c;因此我们传递的时候可以&#xff0c;但是接收的时候&#xff0c;往往会被自动截取掉超出的部分&#xff0c;…...