From d392858cb1f8e08c4348d06cbb52faf529b93d7c Mon Sep 17 00:00:00 2001 From: Mit4el Date: Fri, 22 Nov 2024 22:45:10 +0300 Subject: [PATCH] add board ESP32-C6 4mb and 8mb --- include/Const.h | 12 +- include/DebugTrace.h | 5 +- myProfile.json | 20 ++- platformio.ini | 179 +++++++++++++++++++++++ src/DebugTrace.cpp | 8 +- src/EspFileSystem.cpp | 5 +- src/Main.cpp | 6 +- src/PeriodicTasks.cpp | 6 +- src/modules/exec/Mp3/modinfo.json | 6 + src/modules/exec/Pwm32/Pwm32.cpp | 16 +- src/modules/sensors/Ds18b20/modinfo.json | 6 + src/utils/WiFiUtils.cpp | 4 + tools/patch32c6.py | 32 ++++ 13 files changed, 284 insertions(+), 21 deletions(-) create mode 100644 tools/patch32c6.py diff --git a/include/Const.h b/include/Const.h index bc84800d..b04cccf2 100644 --- a/include/Const.h +++ b/include/Const.h @@ -52,8 +52,16 @@ #define FIRMWARE_NAME "esp32s3_16mb" #endif -#ifdef LIBRETINY -#define FIRMWARE_NAME "libretiny" +#ifdef bk7231n +#define FIRMWARE_NAME "bk7231n" +#endif + +#ifdef esp32c6_4mb +#define FIRMWARE_NAME "esp32c6_4mb" +#endif + +#ifdef esp32c6_8mb +#define FIRMWARE_NAME "esp32c6_8mb" #endif // Размер буфера json diff --git a/include/DebugTrace.h b/include/DebugTrace.h index f73bce0d..26daa463 100644 --- a/include/DebugTrace.h +++ b/include/DebugTrace.h @@ -6,9 +6,10 @@ // xtensa-esp32-elf-addr2line.exe -pfiaC -e Путь_к_файлу/firmware.elf Стэк_адресов_из_сообщения // %%USERPROFILE%/.platformio/packages/toolchain-xtensa-esp32@8.4.0+2021r2-patch5/bin xtensa-esp32-elf-addr2line.exe -pfiaC -e .pio/build/esp32_4mb3f/firmware.elf Стэк_адресов #include "Global.h" - +#if defined(ESP32) && !defined(esp32c3m_4mb) && !defined(esp32c6_4mb) && !defined(esp32c6_8mb) #define RESTART_DEBUG_INFO -#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb) +#endif +#if defined(RESTART_DEBUG_INFO) #define CONFIG_RESTART_DEBUG_STACK_DEPTH 15 typedef struct { size_t heap_total; diff --git a/myProfile.json b/myProfile.json index 0e6bc051..2ec4b43e 100644 --- a/myProfile.json +++ b/myProfile.json @@ -21,12 +21,12 @@ "pinSDA": 0, "i2cFreq": 100000, "wg": "group1", - "debugTrace": 1 + "debugTrace": 1 }, "projectProp": { "platformio": { "default_envs": "esp32_4mb3f", - "comments_default_envs": "choose from: esp8266_4mb, esp32_4mb, esp32_4mb3f, esp8266_16mb, esp32_16mb, esp32cam_4mb, esp32s2_4mb, esp32s3_16mb, esp32c3m_4mb, esp8266_1mb, esp8266_1mb_ota, esp8266_2mb, esp8266_2mb_ota, esp8285_1mb, esp8285_1mb_ota", + "comments_default_envs": "choose from: esp8266_4mb, esp32_4mb, esp32_4mb3f, esp8266_16mb, esp32_16mb, esp32cam_4mb, esp32s2_4mb, esp32s3_16mb, esp32c3m_4mb, esp8266_1mb, esp8266_1mb_ota, esp8266_2mb, esp8266_2mb_ota, esp8285_1mb, esp8285_1mb_ota, esp32c6_4mb, esp32c6_8mb, bk7231n", "envs": [ { "name": "esp8266_4mb", @@ -123,6 +123,22 @@ "firmware": "0x10000", "partitions": "0x8000", "littlefs": "0x910000" + }, + { + "name": "esp32c6_4mb", + "boot_app0": "0xe000", + "bootloader_qio_80m": "0x1000", + "firmware": "0x10000", + "partitions": "0x8000", + "littlefs": "0x310000" + }, + { + "name": "esp32c6_8mb", + "boot_app0": "0xe000", + "bootloader_qio_80m": "0x1000", + "firmware": "0x10000", + "partitions": "0x8000", + "littlefs": "0x670000" } ] } diff --git a/platformio.ini b/platformio.ini index 80839aa4..4e18d664 100644 --- a/platformio.ini +++ b/platformio.ini @@ -381,6 +381,65 @@ build_src_filter = + ${env:esp32_16mb_fromitems.build_src_filter} +[env:esp32c6_4mb] +extra_scripts = pre:tools/patch32c6.py +lib_deps = + ${common_env_data.lib_deps_external} + ${env:esp32c6_4mb_fromitems.lib_deps} +lib_ignore = LT_WebSockets +build_flags = + -Desp32c6_4mb="esp32c6_4mb" + -DARDUINO_USB_CDC_ON_BOOT=0 + -DARDUINO_USB_MODE=0 + -Wl,--wrap=esp_panic_handler +framework = arduino +board = esp32-c6-devkitm-1 +platform = espressif32 @6.9.0 +platform_packages = + platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git + platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1 +monitor_filters = esp32_exception_decoder +upload_speed = 921600 +monitor_speed = 115200 +debug_tool = esp-prog +board_build.partitions = tools/partitions_custom.csv +board_build.filesystem = littlefs +build_src_filter = + +<*.cpp> + + + + + + + ${env:esp32c6_4mb_fromitems.build_src_filter} + +[env:esp32c6_8mb] +extra_scripts = pre:tools/patch32c6.py +lib_deps = + ${common_env_data.lib_deps_external} + ${env:esp32c6_8mb_fromitems.lib_deps} +lib_ignore = LT_WebSockets +build_flags = + -Desp32c6_4mb="esp32c6_4mb" + -DARDUINO_USB_CDC_ON_BOOT=0 + -DARDUINO_USB_MODE=0 + -Wl,--wrap=esp_panic_handler +framework = arduino +board = esp32-c6-devkitc-1 +platform = espressif32 @6.9.0 +platform_packages = + platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git + platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1 +monitor_filters = esp32_exception_decoder +upload_speed = 921600 +monitor_speed = 115200 +debug_tool = esp-prog +board_build.filesystem = littlefs +build_src_filter = + +<*.cpp> + + + + + + + ${env:esp32c6_8mb_fromitems.build_src_filter} + [env:bk7231n] extra_scripts = pre:tools/lt_fsbuildscript.py lib_compat_mode = off @@ -882,6 +941,126 @@ build_src_filter = + + +[env:esp32c6_4mb_fromitems] +lib_deps = + https://github.com/enjoyneering/AHTxx.git + adafruit/Adafruit BME280 Library + adafruit/Adafruit BMP280 Library + beegee-tokyo/DHT sensor library for ESPx + https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg + robtillaart/SHT2x@^0.1.1 + WEMOS SHT3x@1.0.0 + plerup/EspSoftwareSerial + gyverlibs/EncButton @ ^2.0 + https://github.com/RoboticsBrno/ServoESP32#v1.0.3 + adafruit/Adafruit MCP23017 Arduino Library@^2.1.0 + adafruit/Adafruit BusIO @ ^1.13.2 + adafruit/Adafruit BusIO @ ^1.13.2 + https://github.com/robotclass/RobotClass_LiquidCrystal_I2C + marcoschwartz/LiquidCrystal_I2C@^1.1.4 + https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED + https://github.com/adafruit/Adafruit-GFX-Library +build_src_filter = + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[env:esp32c6_8mb_fromitems] +lib_deps = + https://github.com/enjoyneering/AHTxx.git + adafruit/Adafruit BME280 Library + adafruit/Adafruit BMP280 Library + beegee-tokyo/DHT sensor library for ESPx + https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg + robtillaart/SHT2x@^0.1.1 + WEMOS SHT3x@1.0.0 + plerup/EspSoftwareSerial + gyverlibs/EncButton @ ^2.0 + https://github.com/RoboticsBrno/ServoESP32#v1.0.3 + adafruit/Adafruit MCP23017 Arduino Library@^2.1.0 + adafruit/Adafruit BusIO @ ^1.13.2 + adafruit/Adafruit BusIO @ ^1.13.2 + https://github.com/robotclass/RobotClass_LiquidCrystal_I2C + marcoschwartz/LiquidCrystal_I2C@^1.1.4 + https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED + https://github.com/adafruit/Adafruit-GFX-Library +build_src_filter = + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [env:bk7231n_fromitems] lib_deps = build_src_filter = diff --git a/src/DebugTrace.cpp b/src/DebugTrace.cpp index e4a8e160..49cb0239 100644 --- a/src/DebugTrace.cpp +++ b/src/DebugTrace.cpp @@ -1,5 +1,5 @@ #include "DebugTrace.h" -#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb) +#if defined(RESTART_DEBUG_INFO) // #ifdef RESTART_DEBUG_INFO __NOINIT_ATTR static re_restart_debug_t _debug_info; @@ -282,12 +282,14 @@ void sendDebugTraceAndFreeMemory(bool postMsg) void printDebugTrace() {} void sendDebugTraceAndFreeMemory(bool) {} //void IRAM_ATTR debugUpdate() {} +#if !defined(esp32c6_4mb) && !defined(esp32c6_8mb) extern "C" void __wrap_esp_panic_handler(void *info) { // Call the original panic handler function to finish processing this error (creating a core dump for example...) __real_esp_panic_handler(info); } -#endif // RESTART_DEBUG_INFO +#endif //esp32c6 +#endif // !RESTART_DEBUG_INFO #if defined(ESP32) @@ -299,8 +301,10 @@ extern "C" void __wrap_esp_panic_handler(void *info) void startWatchDog() { +#if !defined(esp32c6_4mb) && !defined(esp32c6_8mb) //TODO esp32-c6 переписать esp_task_wdt_init esp_task_wdt_init(WDT_TIMEOUT, true); // enable panic so ESP32 restarts esp_task_wdt_add(NULL); // add current thread to WDT watch +#endif } extern "C" bool verifyRollbackLater() diff --git a/src/EspFileSystem.cpp b/src/EspFileSystem.cpp index 1ff8090b..cebead18 100644 --- a/src/EspFileSystem.cpp +++ b/src/EspFileSystem.cpp @@ -1,5 +1,8 @@ #include "EspFileSystem.h" #include "Global.h" +#if defined(esp32c6_4mb) || defined(esp32c6_8mb) +#include "esp_mac.h" +#endif bool fileSystemInit() { @@ -149,7 +152,7 @@ const String getMacAddress() char buf[13] = { 0 }; #if defined(ESP8266) WiFi.macAddress(mac); - sprintf(buf, MACSTR, MAC2STR(mac)); + sprintf(buf, MACSTR, MAC2STR(mac)); #elif defined(ESP32) esp_read_mac(mac, ESP_MAC_WIFI_STA); sprintf(buf, MACSTR, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); diff --git a/src/Main.cpp b/src/Main.cpp index 223f1470..bcfe6d9e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -104,7 +104,7 @@ void setup() { Serial.begin(115200); Serial.flush(); //----------- Отладка EXCEPTION (функции с заглушками для отключения) --------- -#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb) +#if defined(RESTART_DEBUG_INFO) //Привязка коллбэк функции для вызова при перезагрузке esp_register_shutdown_handler(debugUpdate); #endif // RESTART_DEBUG_INFO @@ -156,7 +156,7 @@ void setup() { #endif SerialPrint("i", "i2c", F("i2c pins overriding done")); } -#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb) +#if defined(RESTART_DEBUG_INFO) esp_reset_reason_t esp_reason = esp_reset_reason(); if (esp_reason == ESP_RST_UNKNOWN || esp_reason == ESP_RST_POWERON) bootloop_panic_count = 0; @@ -291,7 +291,7 @@ void setup() { Serial.println("--------test end---------"); stopErrorMarker(SETUPLAST_ERRORMARKER); -#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb) +#if defined(RESTART_DEBUG_INFO) bootloop_panic_count = 0; #endif // RESTART_DEBUG_INFO } diff --git a/src/PeriodicTasks.cpp b/src/PeriodicTasks.cpp index c4979963..9427a623 100644 --- a/src/PeriodicTasks.cpp +++ b/src/PeriodicTasks.cpp @@ -64,7 +64,7 @@ String ESP_getResetReason(void) { return ESP.getResetReason(); } #endif -#if defined(esp32s2_4mb) || defined(esp32s3_16mb) || defined(esp32c3m_4mb) +#if defined(esp32s2_4mb) || defined(esp32s3_16mb) || defined(esp32c3m_4mb) || defined(esp32c6_4mb) || defined(esp32c6_8mb) String ESP_getResetReason(void) { // return ESP32GetResetReason(0); // CPU 0 esp_reset_reason_t esp_reason = esp_reset_reason(); @@ -102,8 +102,8 @@ String ESP32GetResetReason(uint32_t cpu_no) { return F("Timer Group1 Watchdog reset digital core"); // 8 case RTCWDT_SYS_RESET: return F("RTC Watchdog Reset digital core"); // 9 - case INTRUSION_RESET: - return F("Instrusion tested to reset CPU"); // 10 +// case INTRUSION_RESET: +// return F("Instrusion tested to reset CPU"); // 10 case TG0WDT_CPU_RESET: return F("Time Group reset CPU"); // 11 case RTC_SW_CPU_RESET: diff --git a/src/modules/exec/Mp3/modinfo.json b/src/modules/exec/Mp3/modinfo.json index 631ba050..e64d1460 100644 --- a/src/modules/exec/Mp3/modinfo.json +++ b/src/modules/exec/Mp3/modinfo.json @@ -92,6 +92,12 @@ "esp32*": [ "dfrobot/DFRobotDFPlayerMini @ ^1.0.5" ], + "esp32c6_4mb": [ + "exclude" + ], + "esp32c6_8mb": [ + "exclude" + ], "esp82*": [ "dfrobot/DFRobotDFPlayerMini @ ^1.0.5" ] diff --git a/src/modules/exec/Pwm32/Pwm32.cpp b/src/modules/exec/Pwm32/Pwm32.cpp index 79f6eedf..875595fe 100644 --- a/src/modules/exec/Pwm32/Pwm32.cpp +++ b/src/modules/exec/Pwm32/Pwm32.cpp @@ -8,15 +8,15 @@ extern IoTGpio IoTgpio; class Pwm32 : public IoTItem { - private: +private: int _pin; - int _freq; + int _freq; int _apin, _oldValue; bool _freezVal = true; - int _ledChannel; + int _ledChannel; int _resolution; - public: +public: Pwm32(String parameters): IoTItem(parameters) { _interval = _interval / 1000; // корректируем величину интервала int, теперь он в миллисекундах @@ -24,10 +24,14 @@ class Pwm32 : public IoTItem { jsonRead(parameters, "freq", _freq); jsonRead(parameters, "ledChannel", _ledChannel); jsonRead(parameters, "PWM_resolution", _resolution); - + pinMode(_pin, OUTPUT); +#if defined(esp32c6_4mb) || defined(esp32c6_8mb) + ledcAttachChannel(_pin, _freq, _resolution, _ledChannel); +#else ledcSetup(_ledChannel, _freq, _resolution); ledcAttachPin(_pin, _ledChannel); +#endif ledcWrite(_ledChannel, value.valD); _resolution = pow(2, _resolution); // переводим биты в значение @@ -53,7 +57,7 @@ class Pwm32 : public IoTItem { } } } - + void setValue(const IoTValue& Value, bool genEvent = true) { value = Value; ledcWrite(_ledChannel, value.valD); diff --git a/src/modules/sensors/Ds18b20/modinfo.json b/src/modules/sensors/Ds18b20/modinfo.json index 85bd3c96..39639737 100644 --- a/src/modules/sensors/Ds18b20/modinfo.json +++ b/src/modules/sensors/Ds18b20/modinfo.json @@ -42,6 +42,12 @@ "esp32*": [ "https://github.com/milesburton/Arduino-Temperature-Control-Library" ], + "esp32c6_4mb": [ + "https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg" + ], + "esp32c6_8mb": [ + "https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg" + ], "esp82*": [ "https://github.com/milesburton/Arduino-Temperature-Control-Library" ] diff --git a/src/utils/WiFiUtils.cpp b/src/utils/WiFiUtils.cpp index 2973fde0..bd44849d 100644 --- a/src/utils/WiFiUtils.cpp +++ b/src/utils/WiFiUtils.cpp @@ -17,7 +17,11 @@ IPAddress stringToIp(String strIp) void routerConnect() { #if !defined LIBRETINY +#if defined(esp32c6_4mb) || defined(esp32c6_8mb) + WiFi.setAutoReconnect(false); +#else WiFi.setAutoConnect(false); +#endif WiFi.persistent(false); #endif /* String s_staip = "192.168.2.62"; diff --git a/tools/patch32c6.py b/tools/patch32c6.py new file mode 100644 index 00000000..7ab88d88 --- /dev/null +++ b/tools/patch32c6.py @@ -0,0 +1,32 @@ +import json +import os +import shutil +from sys import platform + +if platform == "linux" or platform == "linux2": + # linux + devkitm = '/home/rise/.platformio/platforms/espressif32/boards/esp32-c6-devkitm-1.json' + devkitc = '/home/rise/.platformio/platforms/espressif32/boards/esp32-c6-devkitc-1.json' +else: + # windows + devkitm = os.environ['USERPROFILE'] + '\\.platformio\\platforms\\espressif32\\boards\\esp32-c6-devkitm-1.json' + devkitc = os.environ['USERPROFILE'] + '\\.platformio\\platforms\\espressif32\\boards\\esp32-c6-devkitc-1.json' + +def add_arduino_to_frameworks(file_name): + with open(file_name, 'r+') as f: + data = json.load(f) + frameworks = data['frameworks'] + if 'arduino' not in frameworks: + frameworks.insert(frameworks.index('espidf') + 1, 'arduino') + data['frameworks'] = frameworks + f.seek(0) + json.dump(data, f, indent=4) + f.truncate() + else: + print(f"Arduino already exists in {file_name}") + +if os.path.exists(devkitm) and os.path.exists(devkitc): + add_arduino_to_frameworks(devkitm) + add_arduino_to_frameworks(devkitc) +else: + print("One or both files do not exist.") \ No newline at end of file