【问题标题】:Custom bootloader for the micro-controller微控制器的自定义引导加载程序
【发布时间】:2021-07-12 07:47:47
【问题描述】:

在此寻求帮助,以使用 PIC24FJ 系列微控制器构建自定义引导加载程序。

我打算使用 UART 来解析 .hex 文件。

你能帮忙吗?

如何解析 .hex 文件?我对 .hex 的解析一无所知

【问题讨论】:

  • 你能解释一下为什么要解析 hex 文件吗?为什么不使用二进制文件?
  • @MahendraGunawardena,是的,我可以使用二进制文件,但我想将十六进制文件数据写入闪存。但我不知道该怎么做。?我知道闪存写入方法。但是解析我什至没有尝试任何地方,所以如果出现问题我的程序将无法启动
  • 据我了解,您无法将典型的 Intel Hex 文件闪存到微控制器。我相信你可能已经意识到了这一点。因此,在将代码刷入微之前,您需要提取与微控制器相关的内容。您可以使用您用于开发与 pic24fj 微控制器相关的软件的 IDE 更新帖子吗?
  • 您能解决您的问题吗?

标签: bootloader


【解决方案1】:

为了解析十六进制文件,您需要识别相关格式。假设您使用的是 MPLAB X,很可能感兴趣的文件格式是 SQTP。下面是一些字段和相关说明。您需要进行一些研究,以验证以下信息是否与您的申请相关。

Field Description
Field 1 Start Code – 1 character This character is an ASCII colon ‘:’
Field 2 Byte Count – 2 hexadecimal digits These two digits indicate the number of bytes (HEX digit pairs) in the data field. The maximum byte count is 255 (0xFF). For example, 16 (0x10) and 32 (0x20) byte counts are commonly used.
Field 3 Address – 4 hexadecimal digits These four digits represent the 16-bit beginning memory address offset of the data. The physical address of the data is computed by adding this offset to a previously established base address. This provides memory addressing beyond the 64-kilobyte limit of 16-bit addresses. The base address, which defaults to zero, can be changed by various types of records. Base addresses and address offsets are always expressed as big endian values.
Field 4 Record Type – 2 hexadecimal digits, 00 to 05 These two digits define the meaning of the data field. For SQTP, only three types are used; 00, 01, and 04 (see Table 1-1).
Field 5 Data – a sequence of n bytes of data Data is represented by 2n hexadecimal digits. Some records omit this field (n equals zero). The meaning and interpretation of the data bytes depends on the application.
Field 6. Checksum – 2 hexadecimal digits These two digits represent a computed value that is used to verify the record has no errors by ensuring the summation of each of the bytes in the line add upChecksum – 2 hexadecimal digits These two digits represent a computed value that is used to verify the record has no errors by ensuring the summation of each of the bytes in the line add up add up to 0.

附加 UART 是一种通信协议。 UART 不会解析文件。您将开发解析 hex 文件的软件。据我所知,微控制器需要一个二进制文件。

最后,这是一个已解决的问题。有大量开源资源可以最大限度地减少您的工作量。

根据下面的评论,如果使用 Kiel 作为 IDE,您可以 fromelf 创建 bin 文件。

fromelf.exe --bin --output=user_application.bin User_Application\User_Application.axf

参考文献

【讨论】:

  • 首先让我们谈谈解析,当我看到我的应用程序的十六进制文件时,一些地址被扩展(记录字节 04),这意味着如果我有记录为 04,那么我将得到低地址字节。高位地址将是十六进制文件的下一行,我可以解析它,但让我解释一下我是否必须将十六进制数据直接写入地址? (我必须这样做)但如果出现问题,那将是应用程序的问题。
  • 我让 MCC 生成 16 位引导加载程序代码。统一引导加载程序只解析UART,就像命令和响应一样,我尝试对统一引导加载程序主机应用程序进行错误处理,但我不明白他们如何解析十六进制文件,我比较了主机应用程序日志,可以通过日志级别为 FINEST,实际加载了 hex 文件到主机应用程序,但我确实了解他们如何解析 hex 文件,因为实际 hex 文件数据的大小写不匹配。
  • 我们退一步了解一些基础知识怎么样。您用于开发微控制器软件的 IDE。您是否已经选择了一个主机应用程序来加载引导加载程序。如果是这样,主机应用程序是什么。使用这些基本问题更新帖子将有助于社区帮助您实现目标。
  • 我正在使用 PIC24FJ256GL406,带有 MPLAB IDEv5.40 的微控制器,我的应用程序代码没有引导加载程序,这是我一直由 PICKIT3 转储的,在现场我打算使用自定义引导加载程序这将使我使用 UART 升级我的框架。
  • 是否有打算在现场使用的主机应用程序?我假设主机应用程序将在 windows 或 ubuntu 平台上
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-14
  • 2019-10-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
相关资源
最近更新 更多