cmake - C可执行文件到十六进制

标签 cmake hex avr clion avrdude

我正在使用 CLion 作为 IDE。构建输出后是一个可执行文件 example。我想要实现的是从中制作 .hex 文件并通过 avrdude 将其上传到我的 AVR。我阅读并尝试了一些 possible solutions here

xxd -p example | tr -d '\n' > example.hex

avrdude -u -c usbasp-clone -p atmega8 -P /dev/bus/usb/001/006 -U flash:w:example.hex

但是 avrdude 输出

avrdude: input file example.hex auto detected as invalid format
avrdude: invalid input file format: -1
avrdude: read from file 'example.hex' failed

这里有什么想法吗?

最佳答案

从可执行文件中提取部分并将其转换为另一种格式的工具是 objcopy

avr-objcopy -j .text -j .data -O ihex example example.hex

或者,如果您的 avrdude 是使用 ELF 支持构建的,那么您可以直接使用可执行文件。

avrdude -c usbasp-clone -p atmega8 -U flash:w:example

关于cmake - C可执行文件到十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34038604/

相关文章:

c++ - 已安装 ExternalProject 后避免使用 CMake 子命令

c++ - 为什么 cmake 选错了库?

c++ - C++ 十六进制输出到字符串

c++ - 将十六进制字节发送到串行端口

c - 用于维护状态的 void*...(C 编程)

c - 如何从 C 代码调用汇编函数?

c++ - CMake add_custom_command 没有输出

c++ - 将 aws-iot-device-sdk-cpp-v2 与 CMake 结合使用

javascript - 从像素的十六进制获取 rgb 值(0..255)

c - 使用枚举设置标志时的 AVR C 随机行为