如何设置 Atmel-ICE 以在 Windows 10 上使用 VSCode 在 PlatformIO 上对 ATmega328 进行编程

How to setup Atmel-ICE to program an ATmega328 on PlatformIO with VSCode on Windows 10

我正在尝试将我的 atmel ICE 与 platformIO 和 VS Code 一起使用,而不是 Atmel Studio,因为当我想将 Arduino.h 与库一起使用时,这个软件很痛苦。

但是我不能用我的程序员上传。我试过 32 针 ATmega328。

我首先在这个页面上使用了 PIO 关于如何使用 Atmel-ICE 的文档:https://docs.platformio.org/en/latest/plus/debug-tools/atmel-ice.html

If you would like to use this tool for firmware uploading, please change upload 

protocol:
[env:myenv]
platform = ...
board = ...
debug_tool = atmel-ice
upload_protocol = atmel-ice

所以这是我在文件中写的:

    [env:ATmega328P]
platform = atmelavr
board = ATmega328P
framework = arduino
upload_protocol = atmel-ice

我在 运行 PIO 上的上传命令时收到此消息:

DATA:    [          ]   0.4% (used 9 bytes from 2048 bytes)
PROGRAM: [          ]   1.4% (used 444 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: atmel-ice
CURRENT: upload_protocol = atmel-ice
Looking for upload port...
Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1

那时我不确定要尝试什么。我尝试了下面描述的几件事,但我不确定我是否走在正确的轨道上。例如,与 Arduino 相比,atmel ICE 编程器没有与之关联的 USB 端口号,因此我不知道应该如何在我的 .ini 文件中指定我的 upload_port 参数。

platformIO 文档中描述了一些选项 https://docs.platformio.org/en/latest/projectconf/section_env_upload.html 但我完全迷路了。我觉得我收到的信息是: 对于某些开发平台,它可以是 USB 闪存驱动器(即 /media//) 可以是一个很好的线索。知道我应该在 .ini 文件中更改什么以使我的 atmel ICE 工作吗?谢谢!


我尝试过的其他事情:我在 post 上读到(很抱歉,我再也找不到 link)添加

upload_port = usb

可以解决问题。将此行添加到我的 platformio.ini 时,我收到一条不同的错误消息:

avrdude: Can't find programmer id "atmel-ice"

Valid programmers are:
  2232HIO          = FT2232H based generic programmer
  4232h            = FT4232H based generic programmer
  arduino          = Arduino

并且清单还在继续..

我搜索并找到了这个 post,它有相同的错误信息!: https://community.platformio.org/t/atmega-328-internal-8mhz-oscillator-atmel-ice-upload-troubles/10416

这里的解决方案是添加

upload_flags = -e 

但这对我来说没有任何改变。

他还提到他对 328p8m.json 文件进行了更改,在我的情况下是 ATmega328P.json。我什至不知道在哪里可以找到它。这有关系吗?

将此粘贴到 platformio.ini

[env:ATmega328P]
platform = atmelavr
board = ATmega328P
framework = arduino
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb

board_fuses.hfuse = 0xDF    ;smallest flash section size 256 since not using a BSL w/ Atmel-ICE 
board_fuses.lfuse = 0xE2    ;int 8MHz crystal (16MHz not working with less than 5V PSU)
board_fuses.efuse = 0xFE    ;BOD at 1.8V, perfect for low power