Zkus přeložit a pošli co hlásí překlad, výstup tohoto programu:
Kód: Vybrat vše
/*
CH32V307VCT6 Bring-up (CH32duino / openwch/arduino_core_ch32)
- Serial diagnostics
- LED test (PB8/PB9 + LED_BUILTIN if present)
- Ethernet "capability detection" (ETH.h / lwIP / WCHNet headers if present)
Board: "CH32V307VCT6 EVT"
FQBN: WCH:ch32v:CH32V30x_EVT
Core: WCH ch32v (example seen: 1.0.4)
Why this version:
- Your compile log shows "invalid library: no header files found" for some folders in ~/Arduino/libraries/.
That's not a compile error; it means those folders are NOT Arduino libraries.
- Ethernet on CH32V307 is MAC+10M PHY built-in (not Wiznet Ethernet.h). Arduino-style ETH.h may not exist in this core,
so we only detect what is available and tell you next steps.
*/
#pragma execution_character_set("utf-8")
#include <Arduino.h>
// ---------------- LED pin defaults ----------------
#ifndef LED_PB8
#define LED_PB8 PB8
#endif
#ifndef LED_PB9
#define LED_PB9 PB9
#endif
#ifdef LED_BUILTIN
static const int LED_BUILTIN_PIN = LED_BUILTIN;
#else
static const int LED_BUILTIN_PIN = -1;
#endif
// ---------------- Header detection helpers ----------------
#if defined(__has_include)
#define HAS_INCLUDE(x) __has_include(x)
#else
#define HAS_INCLUDE(x) 0
#endif
// 1) Arduino-style ETH wrapper (often NOT present for CH32)
#if HAS_INCLUDE(<ETH.h>)
#include <ETH.h>
#define HAS_CH32_ETH_H 1
#else
#define HAS_CH32_ETH_H 0
#endif
// 2) Try to detect lwIP headers (names differ by ports; we only detect, we don't rely on them)
#if HAS_INCLUDE(<lwip/opt.h>)
#define HAS_LWIP_OPT 1
#else
#define HAS_LWIP_OPT 0
#endif
#if HAS_INCLUDE(<lwip/init.h>)
#define HAS_LWIP_INIT 1
#else
#define HAS_LWIP_INIT 0
#endif
#if HAS_INCLUDE(<lwip/netif.h>)
#define HAS_LWIP_NETIF 1
#else
#define HAS_LWIP_NETIF 0
#endif
#if HAS_INCLUDE(<netif/ethernet.h>)
#define HAS_LWIP_ETHERNET 1
#else
#define HAS_LWIP_ETHERNET 0
#endif
// 3) Try to detect WCHNet-ish headers (names vary a lot; again detection only)
#if HAS_INCLUDE(<WCHNET.h>)
#define HAS_WCHNET_H 1
#elif HAS_INCLUDE(<wchnet.h>)
#define HAS_WCHNET_H 1
#else
#define HAS_WCHNET_H 0
#endif
// ---------------- Helpers ----------------
static void blink_pin(int pin, int times, int on_ms, int off_ms)
{
if (pin < 0) return;
pinMode(pin, OUTPUT);
for (int i = 0; i < times; i++)
{
digitalWrite(pin, HIGH); delay(on_ms);
digitalWrite(pin, LOW); delay(off_ms);
}
}
static void print_chip_info()
{
Serial.println();
Serial.println(F("=== CH32V307 Bring-up ==="));
#if defined(ARDUINO_ARCH_RISCV)
Serial.println(F("Arch: RISC-V (ARDUINO_ARCH_RISCV)"));
#else
Serial.println(F("Arch: (unknown / not ARDUINO_ARCH_RISCV)"));
#endif
#if defined(ARDUINO)
Serial.print(F("ARDUINO = "));
Serial.println(ARDUINO);
#endif
#if defined(F_CPU)
Serial.print(F("F_CPU = "));
Serial.print((unsigned long)F_CPU);
Serial.println(F(" Hz"));
#endif
#if defined(BOARD_NAME)
Serial.print(F("BOARD_NAME = "));
Serial.println(BOARD_NAME);
#endif
#if defined(VARIANT_H)
Serial.print(F("VARIANT_H = "));
Serial.println(VARIANT_H);
#endif
Serial.println(F("LED pins:"));
Serial.print(F(" PB8 = ")); Serial.println((int)LED_PB8);
Serial.print(F(" PB9 = ")); Serial.println((int)LED_PB9);
if (LED_BUILTIN_PIN >= 0)
{
Serial.print(F(" LED_BUILTIN = ")); Serial.println(LED_BUILTIN_PIN);
}
else
{
Serial.println(F(" LED_BUILTIN not defined by this board/core"));
}
Serial.println(F("========================="));
Serial.println();
}
static void print_ethernet_capabilities()
{
Serial.println(F("=== Ethernet / Stack detection ==="));
#if HAS_CH32_ETH_H
Serial.println(F("[OK] Found header: <ETH.h> (Arduino-style wrapper detected)"));
#else
Serial.println(F("[NO] <ETH.h> not found (very common on WCH ch32v core 1.0.4)"));
#endif
// lwIP detection
Serial.print(F("[lwIP] <lwip/opt.h>: ")); Serial.println(HAS_LWIP_OPT ? F("YES") : F("NO"));
Serial.print(F("[lwIP] <lwip/init.h>: ")); Serial.println(HAS_LWIP_INIT ? F("YES") : F("NO"));
Serial.print(F("[lwIP] <lwip/netif.h>: ")); Serial.println(HAS_LWIP_NETIF ? F("YES") : F("NO"));
Serial.print(F("[lwIP] <netif/ethernet.h>: "));Serial.println(HAS_LWIP_ETHERNET ? F("YES") : F("NO"));
// WCHNet detection
Serial.print(F("[WCHNet] WCHNET header: "));
Serial.println(HAS_WCHNET_H ? F("YES") : F("NO"));
Serial.println(F("----------------------------------"));
Serial.println(F("If you see Arduino build warnings like:"));
Serial.println(F(" \"invalid library: no header files found\""));
Serial.println(F("it means you placed a NON-Arduino repo into ~/Arduino/libraries/."));
Serial.println(F("Fix: move such folders out of ~/Arduino/libraries/ (e.g. to ~/src/)"));
Serial.println(F("or convert them into a real Arduino library structure (library.properties + src/*.h/*.cpp)."));
Serial.println(F("----------------------------------"));
Serial.println();
}
#if HAS_CH32_ETH_H
static void try_init_ethernet_eth_h()
{
Serial.println(F("[ETH] <ETH.h> is available -> trying ETH.begin()..."));
// Some implementations return bool, some return void.
// We'll attempt bool. If your ETH.begin() is void, compiler will complain -> paste error and I adjust.
bool ok = ETH.begin();
if (!ok)
{
Serial.println(F("[ETH] ETH.begin() failed / returned false."));
Serial.println(F("[ETH] If your core uses different init API, paste the compiler/runtime output."));
return;
}
Serial.println(F("[ETH] ETH.begin() OK, waiting for DHCP IP..."));
unsigned long t0 = millis();
while (millis() - t0 < 15000)
{
IPAddress ip = ETH.localIP();
if (ip[0] != 0)
{
Serial.print(F("[ETH] IP: ")); Serial.println(ip);
Serial.print(F("[ETH] GW: ")); Serial.println(ETH.gatewayIP());
Serial.print(F("[ETH] MASK: ")); Serial.println(ETH.subnetMask());
Serial.println(F("[ETH] Ready."));
return;
}
// blink PB9 while waiting
digitalWrite(LED_PB9, !digitalRead(LED_PB9));
delay(250);
}
Serial.println(F("[ETH] No DHCP IP within 15s (check link/router/DHCP)."));
}
#endif
void setup()
{
Serial.begin(115200);
delay(250);
Serial.println();
Serial.println(F("Booting..."));
delay(250);
pinMode(LED_PB8, OUTPUT);
pinMode(LED_PB9, OUTPUT);
digitalWrite(LED_PB8, LOW);
digitalWrite(LED_PB9, LOW);
print_chip_info();
// LED test
Serial.println(F("[TEST] Blinking PB8 (5x)"));
blink_pin(LED_PB8, 5, 120, 120);
Serial.println(F("[TEST] Blinking PB9 (5x)"));
blink_pin(LED_PB9, 5, 120, 120);
if (LED_BUILTIN_PIN >= 0)
{
Serial.println(F("[TEST] Blinking LED_BUILTIN (3x)"));
blink_pin(LED_BUILTIN_PIN, 3, 180, 180);
}
// Ethernet capability detection (based on your environment)
print_ethernet_capabilities();
#if HAS_CH32_ETH_H
try_init_ethernet_eth_h();
#else
Serial.println(F("[ETH] Skipping init because <ETH.h> is not available in this core."));
Serial.println(F("[ETH] Next step: use a CH32V307-specific LwIP/WCHNet example/port,"));
Serial.println(F(" or install a real Arduino-wrapped CH32 Ethernet library (with library.properties + src/...)."));
#endif
Serial.println(F("[DONE] setup() complete."));
}
void loop()
{
// Heartbeat: PB8 toggles every 1s
static unsigned long last = 0;
if (millis() - last >= 1000)
{
last = millis();
digitalWrite(LED_PB8, !digitalRead(LED_PB8));
}
// PB9: short pulse every 5s
static unsigned long last2 = 0;
if (millis() - last2 >= 5000)
{
last2 = millis();
digitalWrite(LED_PB9, HIGH);
delay(40);
digitalWrite(LED_PB9, LOW);
}
}