[开发工具] 使用ESP给AVR烧录固件

[复制链接]
 楼主| gejigeji521 发表于 2025-5-27 16:03 | 显示全部楼层 |阅读模式
ESP8266/ESP32 通过 WiFi 进行 AVR 在系统编程
该库允许带有 HSPI 端口的 ESP8266/32 模块成为 AVR 系统内编程器。

硬件
ESP 模块通过标准 6 针 AVR“推荐的系统内编程接口连接器布局”连接到 AVR 目标芯片,如AVR910等所示。

如果 AVR 目标板的供电 Vcc 与 ESP 芯片的供电 Vcc 不同,则必须提供电压电平转换或其他形式的缓冲器。ESP 的引脚暴露在超过 3.6V 的电压下会损坏 ESP。

连接如下:


对于 RESET,请使用 0、2 和 15(引导选择引脚)以外的 GPIO,并应用外部上拉/下拉,以便目标正常运行。


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| gejigeji521 发表于 2025-5-27 16:03 | 显示全部楼层
相关源码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| gejigeji521 发表于 2025-5-27 16:04 | 显示全部楼层
  1. #include <SPI.h>
  2. #include <ESP_AVRISP.h>
  3. #ifdef ESP8266
  4. #include <ESP8266WiFi.h>
  5. #include <ESP8266mDNS.h>
  6. #else
  7. #include <WiFi.h>
  8. #include <ESPmDNS.h>
  9. #endif

  10. const char* host = "esp-avrisp";
  11. const char* ssid = "**********";
  12. const char* pass = "**********";
  13. const uint16_t port = 328;
  14. const uint8_t reset_pin = 5;

  15. ESP_AVRISP avrprog(port, reset_pin);

  16. void setup() {
  17.     Serial.begin(115200);
  18.     Serial.println("");
  19.     Serial.println("Arduino AVR-ISP over TCP");
  20.     avrprog.setReset(false); // let the AVR run

  21.     WiFi.begin(ssid, pass);
  22.     while (WiFi.waitForConnectResult() != WL_CONNECTED);

  23.     MDNS.begin(host);
  24.     MDNS.addService("avrisp", "tcp", port);

  25.     IPAddress local_ip = WiFi.localIP();
  26.     Serial.print("IP address: ");
  27.     Serial.println(local_ip);
  28.     Serial.println("Use y**dude:");
  29.     Serial.print("avrdude -c arduino -p <device> -P net:");
  30.     Serial.print(local_ip);
  31.     Serial.print(":");
  32.     Serial.print(port);
  33.     Serial.println(" -t # or -U ...");

  34.     // listen for avrdudes
  35.     avrprog.begin();
  36. }

  37. void loop() {
  38.     static AVRISPState_t last_state = AVRISP_STATE_IDLE;
  39.     AVRISPState_t new_state = avrprog.update();
  40.     if (last_state != new_state) {
  41.         switch (new_state) {
  42.             case AVRISP_STATE_IDLE: {
  43.                 Serial.printf("[AVRISP] now idle\r\n");
  44.                 // Use the SPI bus for other purposes
  45.                 break;
  46.             }
  47.             case AVRISP_STATE_PENDING: {
  48.                 Serial.printf("[AVRISP] connection pending\r\n");
  49.                 // Clean up your other purposes and prepare for programming mode
  50.                 break;
  51.             }
  52.             case AVRISP_STATE_ACTIVE: {
  53.                 Serial.printf("[AVRISP] programming mode\r\n");
  54.                 // Stand by for completion
  55.                 break;
  56.             }
  57.         }
  58.         last_state = new_state;
  59.     }
  60.     // Serve the client
  61.     if (last_state != AVRISP_STATE_IDLE) {
  62.         avrprog.serve();
  63.     }
  64. }
 楼主| gejigeji521 发表于 2025-5-27 16:06 | 显示全部楼层
另外还有一个ESP8266自带的示例
https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266AVRISP
小灵通2018 发表于 2025-5-29 16:37 | 显示全部楼层
AVR 的烧录协议比较简单吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

195

主题

2460

帖子

8

粉丝
快速回复 在线客服 返回列表 返回顶部