初级会员
- 积分
- 62
- 金钱
- 62
- 注册时间
- 2015-5-2
- 在线时间
- 8 小时
|
1金钱
SDP命令如上所示
关于SDP命令的使用,尤其是使用顺序,NXP的手册上并没有太多介绍,而且有个问题很棘手搞了两天了没搞定,hid report 2的读写问题,report 1,3,4使用时没有异常,只有在需要report2的场景,比如下载文件到指定地址和下载dcd表到指定地址时总是出现问题,我已经将这个问题汇报给微软,希望能得到一些帮助,毕竟这是一个hid系统库调用的问题,我不知道其他人是怎么解决这个问题,或者说没有遇到这个问题的。
当我使用串口而不是hid方式连接时,他就没有这个问题,dcd写入没有问题,文件写入时,写入imx文件会失去响应,写入bin文件时没问题。所以我觉得还是hid系统库的问题。
下面是我自己做的一个ui程序,主要将sdp命令的可视化:
在测试的时候发现很多问题,
读取寄存器命令可以读取内部的00920000这部分内存,这部分内存实际上是内部的可以自由使用的ram,但是,他不能读取020E0000这些地址,根据如下的内存映射表:
根据以上,020E0000地址应该是IOMUXC控制寄存器地址区,应该是可以访问的,但是我试图使用sdp指令读取这些地址时imx6ull就会失去响应,同样的,0209C000等这些地址,比如这个GPIO寄存器地址,读取就不会有问题。
还有一个就是,我成功的把dcd表写入到00920000,但是好像并没有运行啊???为啥??当我使用跳转指令跳转到00920000地址运行时明显设备重启了,说明dcd表不能跳转运行,但是也没用一个指令是运行dcd表的指令啊,dcd表应该会配置ddr,我发送成功dcd表后依然无法访问87800000地址,也无法把程序复制到这个地址运行,往这个地址下载bin文件时imx6直接失去响应,啥情况?
各位,有开发过固件烧录工具的吗?讨论一下?多谢各位
如果要代码的话发一部分代码如下:
- /// <summary>
- /// 读取一系列寄存器的值
- /// </summary>
- /// <param name="addr"></param>
- /// <param name="len"></param>
- /// <param name="format"></param>
- /// <returns></returns>
- public byte[] ReadReg(uint addr, int len, SDPCommend.AccessFormat format)
- {
- if (!IsOpened) throw new Exception("设备未打开,不能操作");
- var cmd = SDPCommend.CreateReadReg(addr, format, (uint)len);
- if (ComPort is not null)
- {//串口连接情况下
- ComPort.ReadExisting();
- ComPort.BaseStream.Flush();
- ComPort.Write(cmd.SourceData, 1, cmd.SourceData.Length - 1);
- var hab = new HABSecurity(4);
- ReadDataOnCom(hab.SourceData, 1, 4);
- using var ms = new MemoryStream();
- for (int i = 0; i < len;)
- {
- var dt = new SDPResponseData(64);
- var l = ComPort.Read(dt.SourceData, 1, len > 64 ? Math.Min(64, len - 64) : len);
- ms.Write(dt.SourceData, 1, l);
- i += l;
- }
- ms.Seek(0, SeekOrigin.Begin);
- return ms.ToArray();
- }
- if (HidStream is not null)
- {
- HidStream.Flush();
- HidStream.Write(cmd.SourceData);
- var hab = new HABSecurity(InputReportSize - 1);
- HidStream.Read(hab.SourceData);
- using var ms = new MemoryStream();
- for (int i = 0; i < len;)
- {
- var dt = new SDPResponseData(InputReportSize - 1);
- var l = HidStream.Read(dt.SourceData) - 1;
- ms.Write(dt.SourceData, 1, l);
- i += l;
- }
- ms.Seek(0, SeekOrigin.Begin);
- return ms.ToArray();
- }
- //if (HidHandle is not null)
- //{
- // var hidp = HidHandle.DangerousGetHandle();
- // HID.HidD_FlushQueue(hidp);
- // var pbuf = Marshal.AllocHGlobal(OutputReportLength);
- // try
- // {
- // Marshal.Copy(cmd.SourceData, 0, pbuf, cmd.SourceData.Length);
- // if (!HID.HidD_SetOutputReport(hidp, pbuf, OutputReportLength)) throw new IOException($"无法写入数据到HID:{Kernel32.GetLastError()}");
- // var hab = new HABSecurity(InputReportLength - 1);
- // Marshal.WriteByte(pbuf, hab.SourceData[0]);
- // if (!HID.HidD_GetInputReport(hidp, pbuf, InputReportLength)) throw new IOException($"无法从HID读取数据:{Kernel32.GetLastError()}");
- // hab.SourceData = Marshal.PtrToStructure<byte[]>(pbuf) ?? hab.SourceData;
- // using var ms = new MemoryStream();
- // for (int i = 0; i < len;)
- // {
- // var dt = new SDPResponseData(InputReportLength - 1);
- // Marshal.WriteByte(pbuf, dt.SourceData[0]);
- // if (!HID.HidD_GetInputReport(hidp, pbuf, InputReportLength)) throw new IOException($"无法从HID读取数据:{Kernel32.GetLastError()}");
- // dt.SourceData = Marshal.PtrToStructure<byte[]>(pbuf) ?? hab.SourceData;
- // ms.Write(dt.SourceData, 1, InputReportLength - 1);
- // i += InputReportLength - 1;
- // }
- // ms.Seek(0, SeekOrigin.Begin);
- // return ms.ToArray();
- // }
- // finally
- // {
- // Marshal.FreeHGlobal(pbuf);
- // }
- //}
- return Array.Empty<byte>();
- }
- /// <summary>
- /// 写入一系列寄存器的值
- /// </summary>
- /// <param name="addr"></param>
- /// <param name="len"></param>
- /// <param name="format">写入寄存器数据的格式</param>
- /// <param name="data">所有寄存器只能写入同一个值</param>
- /// <returns></returns>
- public bool WriteReg(uint addr, int len, uint data, SDPCommend.AccessFormat format)
- {
- if (!IsOpened) throw new Exception("设备未打开,不能操作");
- var cmd = SDPCommend.CreateWriteReg(addr, format, (uint)len, data);
- if (ComPort is not null)
- {//串口连接情况下
- ComPort.ReadExisting();
- ComPort.BaseStream.Flush();
- ComPort.Write(cmd.SourceData, 1, cmd.SourceData.Length - 1);
- var hab = new HABSecurity(4);
- ReadDataOnCom(hab.SourceData, 1, 4);
- var dt = new SDPResponseData(4);
- ReadDataOnCom(dt.SourceData, 1, 4);
- return dt.IsWriteRegComplete;
- }
- if (HidStream is not null)
- {
- HidStream.Flush();
- HidStream.Write(cmd.SourceData);
- var hab = new HABSecurity(InputReportSize - 1);
- HidStream.Read(hab.SourceData);
- var dt = new SDPResponseData(InputReportSize - 1);
- HidStream.Read(dt.SourceData);
- return dt.IsWriteRegComplete;
- }
- return false;
- }
- /// <summary>
- /// 写入镜像文件
- /// </summary>
- /// <param name="addr"></param>
- /// <param name="fp">本地文件地址</param>
- /// <param name="prog">进度条显示,0-100f</param>
- /// <returns></returns>
- public bool WriteFile(uint addr, string fp, Action<float>? prog = null)
- {
- if (!IsOpened) throw new Exception("设备未打开,不能操作");
- if (!System.IO.File.Exists(fp)) throw new Exception("文件不存在");
- if (ComPort is not null)
- {//串口连接情况下
- using var fst = System.IO.File.OpenRead(fp);
- var cmd = SDPCommend.CreateWriteFile(addr, (uint)fst.Length);
- ComPort.ReadExisting();
- ComPort.BaseStream.Flush();
- ComPort.Write(cmd.SourceData, 1, cmd.SourceData.Length - 1);
- var cmddt = new SDPCommendData(1024);
- prog?.Invoke(0);
- for (int i = 0; i < fst.Length;)
- {
- var l = fst.Read(cmddt.SourceData, 1, cmddt.SourceData.Length - 1);
- ComPort.Write(cmddt.SourceData, 1, l);
- i += l;
- prog?.Invoke(i * 100f / fst.Length);
- }
- var hab = new HABSecurity(4);
- ReadDataOnCom(hab.SourceData, 1, 4);
- var dt = new SDPResponseData(4);
- ReadDataOnCom(dt.SourceData, 1, 4);
- return dt.IsWriteFileComplete;
- }
- if (HidStream is not null)
- {
- HidStream.Flush();
- using var fst = System.IO.File.OpenRead(fp);
- var cmd = SDPCommend.CreateWriteFile(addr, (uint)fst.Length);
- HidStream.Write(cmd.SourceData);
- var cmddt = new SDPCommendData(OutputReportSize - 1);
- prog?.Invoke(0);
- for (int i = 0; i < fst.Length;)
- {
- var l = fst.Read(cmddt.SourceData, 1, OutputReportSize - 1);
- HidStream.Write(cmddt.SourceData);
- i += l;
- prog?.Invoke(i * 100f / fst.Length);
- }
- var hab = new HABSecurity(InputReportSize - 1);
- HidStream.Read(hab.SourceData);
- var dt = new SDPResponseData(InputReportSize - 1);
- HidStream.Read(dt.SourceData);
- return dt.IsWriteFileComplete;
- }
- return false;
- }
- /// <summary>
- /// 获取设备的错误码
- /// </summary>
- /// <returns></returns>
- public int GetErrStatue()
- {
- if (!IsOpened) throw new Exception("设备未打开,不能操作");
- var cmd = SDPCommend.CreateErrorStatue();
- if (ComPort is not null)
- {//串口连接情况下
- ComPort.ReadExisting();
- ComPort.BaseStream.Flush();
- ComPort.Write(cmd.SourceData, 1, cmd.SourceData.Length - 1);
- var hab = new HABSecurity(4);
- ReadDataOnCom(hab.SourceData, 1, 4);
- var dt = new SDPResponseData(4);
- ReadDataOnCom(dt.SourceData, 1, 4);
- return dt.ResponseStatue;
- }
- if (HidStream is not null)
- {
- HidStream.Flush();
- HidStream.Write(cmd.SourceData);
- var hab = new HABSecurity(InputReportSize - 1);
- HidStream.Read(hab.SourceData);
- var dt = new SDPResponseData(InputReportSize - 1);
- HidStream.Read(dt.SourceData);
- return dt.ResponseStatue;
- }
- return 0;
- }
- /// <summary>
- /// 写入Dcd数据
- /// </summary>
- /// <param name="addr"></param>
- /// <param name="dcdarray">本地文件地址</param>
- /// <returns></returns>
- public bool WriteDCD(uint addr, byte[] dcdarray)
- {
- if (!IsOpened) throw new Exception("设备未打开,不能操作");
- if (dcdarray.Length < 4 || dcdarray.Length > 1768) throw new Exception("dcd表过大或过小");
- if (ComPort is not null)
- {//串口连接情况下
- ComPort.ReadExisting();
- ComPort.BaseStream.Flush();
- var cmd = SDPCommend.CreateDCDWrite(addr, (uint)dcdarray.Length);
- ComPort.Write(cmd.SourceData, 1, cmd.SourceData.Length - 1);
- var cmddt = new SDPCommendData(1024);
- using var fst = new MemoryStream(dcdarray);
- for (int i = 0; i < dcdarray.Length;)
- {
- var l = fst.Read(cmddt.SourceData, 1, cmddt.SourceData.Length - 1);
- ComPort.Write(cmddt.SourceData, 1, l);
- i += l;
- }
- var hab = new HABSecurity(4);
- ReadDataOnCom(hab.SourceData, 1, 4);
- var dt = new SDPResponseData(4);
- ReadDataOnCom(dt.SourceData, 1, 4);
- return dt.IsWriteDCDComplete || dt.IsWriteRegComplete;
- }
- if (HidStream is not null)
- {
- HidStream.Flush();
- var cmd = SDPCommend.CreateDCDWrite(addr, (uint)dcdarray.Length);
- HidStream.Write(cmd.SourceData);
- var cmddt = new SDPCommendData(OutputReportSize - 1);
- using var fst = new MemoryStream(dcdarray);
- for (int i = 0; i < dcdarray.Length;)
- {
- var l = fst.Read(cmddt.SourceData, 1, OutputReportSize - 1);
- HidStream.Write(cmddt.SourceData);
- i += l;
- }
- var hab = new HABSecurity(InputReportSize - 1);
- HidStream.Read(hab.SourceData);
- var dt = new SDPResponseData(InputReportSize - 1);
- HidStream.Read(dt.SourceData);
- return dt.IsWriteDCDComplete;
- }
- return false;
- }
- /// <summary>
- /// 跳过dcd命令
- /// </summary>
- /// <returns></returns>
- public bool SkipDCD()
- {
- if (!IsOpened) throw new Exception("设备未打开,不能操作");
- var cmd = SDPCommend.CreateSkipDCD();
- if (ComPort is not null)
- {//串口连接情况下
- ComPort.ReadExisting();
- ComPort.BaseStream.Flush();
- ComPort.Write(cmd.SourceData, 1, cmd.SourceData.Length - 1);
- var hab = new HABSecurity(4);
- ReadDataOnCom(hab.SourceData, 1, 4);
- var dt = new SDPResponseData(4);
- ReadDataOnCom(dt.SourceData, 1, 4);
- return dt.IsSkipDCDComplete;
- }
- if (HidStream is not null)
- {
- HidStream.Flush();
- HidStream.Write(cmd.SourceData);
- var hab = new HABSecurity(InputReportSize - 1);
- HidStream.Read(hab.SourceData);
- var dt = new SDPResponseData(InputReportSize - 1);
- HidStream.Read(dt.SourceData);
- return dt.IsSkipDCDComplete;
- }
- return false;
- }
- /// <summary>
- /// 跳到指定的地址执行代码或者验证镜像文件
- /// </summary>
- /// <returns>返回错误码</returns>
- public int JumpTo(uint addr)
- {
- if (!IsOpened) throw new Exception("设备未打开,不能操作");
- var cmd = SDPCommend.CreateJumpAddress(addr);
- if (ComPort is not null)
- {//串口连接情况下
- ComPort.ReadExisting();
- ComPort.BaseStream.Flush();
- ComPort.Write(cmd.SourceData, 1, cmd.SourceData.Length - 1);
- var hab = new HABSecurity(4);
- ReadDataOnCom(hab.SourceData, 1, 4);
- var dt = new SDPResponseData(4);
- ReadDataOnCom(dt.SourceData, 1, 4);
- return dt.ResponseStatue;
- }
- if (HidStream is not null)
- {
- HidStream.Flush();
- HidStream.Write(cmd.SourceData);
- var hab = new HABSecurity(InputReportSize - 1);
- HidStream.Read(hab.SourceData);
- var dt = new SDPResponseData(InputReportSize - 1);
- HidStream.Read(dt.SourceData);
- return dt.ResponseStatue;
- }
- return 0;
- }
复制代码
|
|