From 50e40f624dbe9afc187954f46330149baab7c509 Mon Sep 17 00:00:00 2001 From: ARg Date: Wed, 11 Sep 2024 11:13:54 +0200 Subject: [PATCH 1/6] Migration of ESP32 targets from idf 4.4 to 5.3: - Added define DBG_PRINTF to AP_HAL_ESP32.h to replace various printf, in order to optimise better for release builds; - Fixed WDT in Scheduler, it was broken with idf 5.3; --- libraries/AP_HAL_ESP32/AP_HAL_ESP32.h | 6 ++ libraries/AP_HAL_ESP32/Scheduler.cpp | 145 ++++++++++++-------------- libraries/AP_HAL_ESP32/Scheduler.h | 3 +- 3 files changed, 77 insertions(+), 77 deletions(-) diff --git a/libraries/AP_HAL_ESP32/AP_HAL_ESP32.h b/libraries/AP_HAL_ESP32/AP_HAL_ESP32.h index 13c0bc6a795f16..95b20fbd33c929 100644 --- a/libraries/AP_HAL_ESP32/AP_HAL_ESP32.h +++ b/libraries/AP_HAL_ESP32/AP_HAL_ESP32.h @@ -5,3 +5,9 @@ #include "HAL_ESP32_Class.h" + +#ifndef NDEBUG + #define DBG_PRINTF(fmt, args ...) do { printf(fmt, ## args); } while(0) +#else + #define DBG_PRINTF(fmt, args ...) +#endif diff --git a/libraries/AP_HAL_ESP32/Scheduler.cpp b/libraries/AP_HAL_ESP32/Scheduler.cpp index 25ce48eeccac87..144884d857974a 100644 --- a/libraries/AP_HAL_ESP32/Scheduler.cpp +++ b/libraries/AP_HAL_ESP32/Scheduler.cpp @@ -23,14 +23,15 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "soc/rtc_wdt.h" -#include "esp_int_wdt.h" +#include "rtc_wdt.h" #include "esp_task_wdt.h" #include #include #include +#include "esp_rom_sys.h" + //#define SCHEDULERDEBUG 1 using namespace ESP32; @@ -46,31 +47,27 @@ Scheduler::Scheduler() _initialized = false; } -void disableCore0WDT() +Scheduler::~Scheduler() { - idle_0 = xTaskGetIdleTaskHandleForCPU(0); - if (idle_0 == NULL || esp_task_wdt_delete(idle_0) != ESP_OK) { - //print("Failed to remove Core 0 IDLE task from WDT"); + if (_initialized) { + esp_task_wdt_deinit(); } } -void disableCore1WDT() -{ - idle_1 = xTaskGetIdleTaskHandleForCPU(1); - if (idle_1 == NULL || esp_task_wdt_delete(idle_1) != ESP_OK) { - //print("Failed to remove Core 1 IDLE task from WDT"); - } -} -void enableCore0WDT() +void wdt_init(uint32_t timeout, uint32_t core_mask) { - if (idle_0 != NULL && esp_task_wdt_add(idle_0) != ESP_OK) { - //print("Failed to add Core 0 IDLE task to WDT"); + esp_task_wdt_config_t config = { + .timeout_ms = timeout, + .idle_core_mask = core_mask, + .trigger_panic = true + }; + + if ( ESP_OK != esp_task_wdt_init(&config) ) { + DBG_PRINTF("esp_task_wdt_init() failed\n"); } -} -void enableCore1WDT() -{ - if (idle_1 != NULL && esp_task_wdt_add(idle_1) != ESP_OK) { - //print("Failed to add Core 1 IDLE task to WDT"); + + if (ESP_OK != esp_task_wdt_add(NULL)) { + DBG_PRINTF("esp_task_wdt_add(NULL) failed"); } } @@ -78,15 +75,10 @@ void Scheduler::init() { #ifdef SCHEDDEBUG - printf("%s:%d \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d \n", __PRETTY_FUNCTION__, __LINE__); #endif - // disable wd while booting, as things like mounting the sd-card in the io thread can take a while, especially if there isn't hardware attached. - disableCore0WDT(); //FASTCPU - disableCore1WDT(); //SLOWCPU - - - hal.console->printf("%s:%d running with CONFIG_FREERTOS_HZ=%d\n", __PRETTY_FUNCTION__, __LINE__,CONFIG_FREERTOS_HZ); + DBG_PRINTF("%s:%d running with CONFIG_FREERTOS_HZ=%d\n", __PRETTY_FUNCTION__, __LINE__,CONFIG_FREERTOS_HZ); // keep main tasks that need speed on CPU 0 // pin potentially slow stuff to CPU 1, as we have disabled the WDT on that core. @@ -94,57 +86,51 @@ void Scheduler::init() #define SLOWCPU 1 // pin main thread to Core 0, and we'll also pin other heavy-tasks to core 1, like wifi-related. - if (xTaskCreatePinnedToCore(_main_thread, "APM_MAIN", Scheduler::MAIN_SS, this, Scheduler::MAIN_PRIO, &_main_task_handle,FASTCPU) != pdPASS) { + if (xTaskCreatePinnedToCore(_main_thread, "APM_MAIN", Scheduler::MAIN_SS, this, Scheduler::MAIN_PRIO, &_main_task_handle, FASTCPU) != pdPASS) { //if (xTaskCreate(_main_thread, "APM_MAIN", Scheduler::MAIN_SS, this, Scheduler::MAIN_PRIO, &_main_task_handle) != pdPASS) { - hal.console->printf("FAILED to create task _main_thread on FASTCPU\n"); + DBG_PRINTF("FAILED to create task _main_thread on FASTCPU\n"); } else { - hal.console->printf("OK created task _main_thread on FASTCPU\n"); + DBG_PRINTF("OK created task _main_thread on FASTCPU\n"); } if (xTaskCreatePinnedToCore(_timer_thread, "APM_TIMER", TIMER_SS, this, TIMER_PRIO, &_timer_task_handle,FASTCPU) != pdPASS) { - hal.console->printf("FAILED to create task _timer_thread on FASTCPU\n"); + DBG_PRINTF("FAILED to create task _timer_thread on FASTCPU\n"); } else { - hal.console->printf("OK created task _timer_thread on FASTCPU\n"); + DBG_PRINTF("OK created task _timer_thread on FASTCPU\n"); } if (xTaskCreatePinnedToCore(_rcout_thread, "APM_RCOUT", RCOUT_SS, this, RCOUT_PRIO, &_rcout_task_handle,SLOWCPU) != pdPASS) { - hal.console->printf("FAILED to create task _rcout_thread on SLOWCPU\n"); + DBG_PRINTF("FAILED to create task _rcout_thread on SLOWCPU\n"); } else { - hal.console->printf("OK created task _rcout_thread on SLOWCPU\n"); + DBG_PRINTF("OK created task _rcout_thread on SLOWCPU\n"); } if (xTaskCreatePinnedToCore(_rcin_thread, "APM_RCIN", RCIN_SS, this, RCIN_PRIO, &_rcin_task_handle,SLOWCPU) != pdPASS) { - hal.console->printf("FAILED to create task _rcin_thread on SLOWCPU\n"); + DBG_PRINTF("FAILED to create task _rcin_thread on SLOWCPU\n"); } else { - hal.console->printf("OK created task _rcin_thread on SLOWCPU\n"); + DBG_PRINTF("OK created task _rcin_thread on SLOWCPU\n"); } // pin this thread to Core 1 as it keeps all teh uart/s feed data, and we need that quick. if (xTaskCreatePinnedToCore(_uart_thread, "APM_UART", UART_SS, this, UART_PRIO, &_uart_task_handle,FASTCPU) != pdPASS) { - hal.console->printf("FAILED to create task _uart_thread on FASTCPU\n"); + DBG_PRINTF("FAILED to create task _uart_thread on FASTCPU\n"); } else { - hal.console->printf("OK created task _uart_thread on FASTCPU\n"); + DBG_PRINTF("OK created task _uart_thread on FASTCPU\n"); } - // we put thos on the SLOW core as it mounts the sd card, and that often isn't conencted. + // we put those on the SLOW core as it mounts the sd card, and that often isn't conencted. if (xTaskCreatePinnedToCore(_io_thread, "SchedulerIO:APM_IO", IO_SS, this, IO_PRIO, &_io_task_handle,SLOWCPU) != pdPASS) { - hal.console->printf("FAILED to create task _io_thread on SLOWCPU\n"); + DBG_PRINTF("FAILED to create task _io_thread on SLOWCPU\n"); } else { - hal.console->printf("OK created task _io_thread on SLOWCPU\n"); + DBG_PRINTF("OK created task _io_thread on SLOWCPU\n"); } if (xTaskCreatePinnedToCore(_storage_thread, "APM_STORAGE", STORAGE_SS, this, STORAGE_PRIO, &_storage_task_handle,SLOWCPU) != pdPASS) { //no actual flash writes without this, storage kinda appears to work, but does an erase on every boot and params don't persist over reset etc. - hal.console->printf("FAILED to create task _storage_thread\n"); + DBG_PRINTF("FAILED to create task _storage_thread\n"); } else { - hal.console->printf("OK created task _storage_thread\n"); + DBG_PRINTF("OK created task _storage_thread\n"); } - // xTaskCreatePinnedToCore(_print_profile, "APM_PROFILE", IO_SS, this, IO_PRIO, nullptr,SLOWCPU); - - hal.console->printf("OK Sched Init, enabling WD\n"); - enableCore0WDT(); //FASTCPU - //enableCore1WDT(); //we don't enable WD on SLOWCPU right now. - } template @@ -166,7 +152,7 @@ void IRAM_ATTR Scheduler::thread_create_trampoline(void *ctx) bool Scheduler::thread_create(AP_HAL::MemberProc proc, const char *name, uint32_t requested_stack_size, priority_base base, int8_t priority) { #ifdef SCHEDDEBUG - printf("%s:%d \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d \n", __PRETTY_FUNCTION__, __LINE__); #endif // take a copy of the MemberProc, it is freed after thread exits @@ -197,7 +183,7 @@ bool Scheduler::thread_create(AP_HAL::MemberProc proc, const char *name, uint32_ for (uint8_t i=0; i= ESP32_SCHEDULER_MAX_TIMER_PROCS) { - printf("Out of timer processes\n"); + DBG_PRINTF("Out of timer processes\n"); return; } _timer_sem.take_blocking(); @@ -263,7 +249,7 @@ void IRAM_ATTR Scheduler::register_timer_process(AP_HAL::MemberProc proc) void IRAM_ATTR Scheduler::register_io_process(AP_HAL::MemberProc proc) { #ifdef SCHEDDEBUG - printf("%s:%d \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d \n", __PRETTY_FUNCTION__, __LINE__); #endif _io_sem.take_blocking(); for (uint8_t i = 0; i < _num_io_procs; i++) { @@ -276,7 +262,7 @@ void IRAM_ATTR Scheduler::register_io_process(AP_HAL::MemberProc proc) _io_proc[_num_io_procs] = proc; _num_io_procs++; } else { - printf("Out of IO processes\n"); + DBG_PRINTF("Out of IO processes\n"); } _io_sem.give(); } @@ -288,7 +274,7 @@ void IRAM_ATTR Scheduler::register_timer_failsafe(AP_HAL::Proc failsafe, uint32_ void Scheduler::reboot(bool hold_in_bootloader) { - printf("Restarting now...\n"); + DBG_PRINTF("Restarting now...\n"); hal.rcout->force_safety_on(); unmount_sdcard(); esp_restart(); @@ -302,7 +288,7 @@ bool IRAM_ATTR Scheduler::in_main_thread() const void Scheduler::set_system_initialized() { #ifdef SCHEDDEBUG - printf("%s:%d \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d \n", __PRETTY_FUNCTION__, __LINE__); #endif if (_initialized) { AP_HAL::panic("PANIC: scheduler::system_initialized called more than once"); @@ -319,7 +305,7 @@ bool Scheduler::is_system_initialized() void IRAM_ATTR Scheduler::_timer_thread(void *arg) { #ifdef SCHEDDEBUG - printf("%s:%d start\n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d start\n", __PRETTY_FUNCTION__, __LINE__); #endif Scheduler *sched = (Scheduler *)arg; @@ -331,7 +317,7 @@ void IRAM_ATTR Scheduler::_timer_thread(void *arg) #endif #ifdef SCHEDDEBUG - printf("%s:%d initialised\n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d initialised\n", __PRETTY_FUNCTION__, __LINE__); #endif while (true) { sched->delay_microseconds(1000); @@ -360,13 +346,13 @@ void IRAM_ATTR Scheduler::_rcout_thread(void* arg) void IRAM_ATTR Scheduler::_run_timers() { #ifdef SCHEDULERDEBUG - printf("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); #endif if (_in_timer_proc) { return; } #ifdef SCHEDULERDEBUG - printf("%s:%d _in_timer_proc \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d _in_timer_proc \n", __PRETTY_FUNCTION__, __LINE__); #endif _in_timer_proc = true; @@ -407,13 +393,13 @@ void IRAM_ATTR Scheduler::_rcin_thread(void *arg) void IRAM_ATTR Scheduler::_run_io(void) { #ifdef SCHEDULERDEBUG - printf("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); #endif if (_in_io_proc) { return; } #ifdef SCHEDULERDEBUG - printf("%s:%d initialised \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d initialised \n", __PRETTY_FUNCTION__, __LINE__); #endif _in_io_proc = true; @@ -433,7 +419,7 @@ void IRAM_ATTR Scheduler::_run_io(void) void IRAM_ATTR Scheduler::_io_thread(void* arg) { #ifdef SCHEDDEBUG - printf("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); #endif mount_sdcard(); Scheduler *sched = (Scheduler *)arg; @@ -441,7 +427,7 @@ void IRAM_ATTR Scheduler::_io_thread(void* arg) sched->delay_microseconds(1000); } #ifdef SCHEDDEBUG - printf("%s:%d initialised \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d initialised \n", __PRETTY_FUNCTION__, __LINE__); #endif uint32_t last_sd_start_ms = AP_HAL::millis(); while (true) { @@ -465,14 +451,14 @@ void IRAM_ATTR Scheduler::_io_thread(void* arg) void Scheduler::_storage_thread(void* arg) { #ifdef SCHEDDEBUG - printf("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); #endif Scheduler *sched = (Scheduler *)arg; while (!sched->_initialized) { sched->delay_microseconds(10000); } #ifdef SCHEDDEBUG - printf("%s:%d initialised \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d initialised \n", __PRETTY_FUNCTION__, __LINE__); #endif while (true) { sched->delay_microseconds(1000); @@ -499,14 +485,14 @@ void Scheduler::_print_profile(void* arg) void IRAM_ATTR Scheduler::_uart_thread(void *arg) { #ifdef SCHEDDEBUG - printf("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d start \n", __PRETTY_FUNCTION__, __LINE__); #endif Scheduler *sched = (Scheduler *)arg; while (!sched->_initialized) { sched->delay_microseconds(2000); } #ifdef SCHEDDEBUG - printf("%s:%d initialised\n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d initialised\n", __PRETTY_FUNCTION__, __LINE__); #endif while (true) { sched->delay_microseconds(1000); @@ -534,12 +520,12 @@ void Scheduler::print_stats(void) if (AP_HAL::millis64() - last_run > 60000) { char buffer[1024]; vTaskGetRunTimeStats(buffer); - printf("\n\n%s\n", buffer); + DBG_PRINTF("\n\n%s\n", buffer); heap_caps_print_heap_info(0); last_run = AP_HAL::millis64(); } - // printf("loop_rate_hz: %d",get_loop_rate_hz()); + // DBG_PRINTF("loop_rate_hz: %d",get_loop_rate_hz()); } // Run every 10s @@ -551,14 +537,14 @@ void Scheduler::print_main_loop_rate(void) // null pointer in here... const float actual_loop_rate = AP::scheduler().get_filtered_loop_rate_hz(); const uint16_t expected_loop_rate = AP::scheduler().get_loop_rate_hz(); - hal.console->printf("loop_rate: actual: %fHz, expected: %uHz\n", actual_loop_rate, expected_loop_rate); + DBG_PRINTF("loop_rate: actual: %fHz, expected: %uHz\n", actual_loop_rate, expected_loop_rate); } } void IRAM_ATTR Scheduler::_main_thread(void *arg) { #ifdef SCHEDDEBUG - printf("%s:%d start\n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d start\n", __PRETTY_FUNCTION__, __LINE__); #endif Scheduler *sched = (Scheduler *)arg; @@ -571,8 +557,11 @@ void IRAM_ATTR Scheduler::_main_thread(void *arg) sched->set_system_initialized(); + //initialize WTD for current thread on FASTCPU, all cores will be (1 << CONFIG_FREERTOS_NUMBER_OF_CORES) - 1 + wdt_init( TWDT_TIMEOUT_MS, 1 << FASTCPU ); // 3 sec + #ifdef SCHEDDEBUG - printf("%s:%d initialised\n", __PRETTY_FUNCTION__, __LINE__); + DBG_PRINTF("%s:%d initialised\n", __PRETTY_FUNCTION__, __LINE__); #endif while (true) { sched->callbacks->loop(); @@ -581,6 +570,10 @@ void IRAM_ATTR Scheduler::_main_thread(void *arg) // run stats periodically sched->print_stats(); sched->print_main_loop_rate(); + + if (ESP_OK != esp_task_wdt_reset()) { + DBG_PRINTF("esp_task_wdt_reset() failed\n"); + }; } } diff --git a/libraries/AP_HAL_ESP32/Scheduler.h b/libraries/AP_HAL_ESP32/Scheduler.h index d2131e4b13c478..3e4252606c6a2c 100644 --- a/libraries/AP_HAL_ESP32/Scheduler.h +++ b/libraries/AP_HAL_ESP32/Scheduler.h @@ -23,7 +23,7 @@ #define ESP32_SCHEDULER_MAX_TIMER_PROCS 10 #define ESP32_SCHEDULER_MAX_IO_PROCS 10 - +#define TWDT_TIMEOUT_MS 3000 /* Scheduler implementation: */ class ESP32::Scheduler : public AP_HAL::Scheduler @@ -31,6 +31,7 @@ class ESP32::Scheduler : public AP_HAL::Scheduler public: Scheduler(); + ~Scheduler(); /* AP_HAL::Scheduler methods */ void init() override; void set_callbacks(AP_HAL::HAL::Callbacks *cb) From 4db5d065b2eaaf6c6f747eb3750cdf53b336647b Mon Sep 17 00:00:00 2001 From: ARg Date: Wed, 11 Sep 2024 11:48:14 +0200 Subject: [PATCH 2/6] Migration of ESP32 targets from idf 4.4 to 5.3: - Updated README.md to reflect changes in sdkconfig handling; - Updated idf installation packages list, according to espressif documentation; - Note: idf.py tool can't be used directly anymore, ninja should be used instead; --- libraries/AP_HAL_ESP32/README.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/libraries/AP_HAL_ESP32/README.md b/libraries/AP_HAL_ESP32/README.md index e891fa9571edad..cfd829fcde7669 100644 --- a/libraries/AP_HAL_ESP32/README.md +++ b/libraries/AP_HAL_ESP32/README.md @@ -14,11 +14,11 @@ or Tools/environment_install/install-prereqs-arch.sh ``` -3. install esp-idf python deps: +2. install esp-idf python deps: ``` # from: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/linux-setup.html -sudo apt-get install git wget flex bison gperf python-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util +sudo apt-get install git wget flex bison gperf cmake ninja-build ccache libffi-dev libssl-dev dfu-util sudo apt-get install python3 python3-pip python3-setuptools sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 @@ -61,7 +61,7 @@ TIPS: - we use toolchain and esp-idf from espressif , as a 'git submodule', so no need to preinstall etc. https://docs.espressif.com/projects/esp-idf/en/latest/get-started/ - - (note we currently use https://github.com/espressif/esp-idf/tree/release/v4.0 ) + (note we currently use https://github.com/espressif/esp-idf/tree/release/v5.3 ) - if you get compile error/s to do with CONFIG... such as @@ -69,7 +69,12 @@ in expansion of macro 'configSUPPORT_STATIC_ALLOCATION' warning: "CONFIG_SUPPORT_STATIC_ALLOCATION" is not defined this means your 'sdkconfig' file that the IDF relies on is perhaps a bit out of date or out of sync with your IDF. -So double check you are using the correct IDF version ( buzz's branch uses v3.3 , sh83's probably does not.. and then if you are sure: + +You can simply remove sdkconfig file and idf build system will recreate it using sdkconfig.defaults, which should fix the problem. + +If you need to change sdkconfig, you can edit sdkconfig manually or to use ninja menuconfig: + +So double check you are using the correct IDF version: ``` cd build/esp32{BOARD}/esp-idf_build ninja menuconfig @@ -81,11 +86,7 @@ press [tab] then enter on the [exit] box to exit the app done. the 'sdkconfig' file in this folder should have been updated cd ../../../.. -OR locate the 'libraries/AP_HAL_ESP32/targets/esp32/esp-idf/sdkconfig' and delete it, as it should call back to the 'sdkconfig.defaults' file if its not there. - -'cd libraries/AP_HAL_ESP32/targets/esp32/esp-idf ; idf.py defconfig' is the command that updates it, but that shouldn't be needed manually, we don't think. - -... try ./waf plane" +If you want to make changes to sdkconfig (sdkconfig is in git ignore list) permanent and to commit them back in git, you should edit sdkconfig.defaults manually or to use ninja save-defconfig tool after menuconfig. 5. Recommanded way to flash the firmware : ``` @@ -114,9 +115,6 @@ ESPTOOL_BAUD=921600 You can find more info here : [ESPTOOL](https://github.com/espressif/esptool) -You can also find the cmake esp-idf project at `libraries/AP_HAL_ESP32/targets/esp32/esp-idf` for idf.py command. But see next section to understand how ardupilot is compiled on ESP32. - - For flashing from another machine you need the following files: ``` build//esp-idf_build/bootloader/bootloader.bin From b5f0654ef8b99b5270a2bd4bad4b71baa160b024 Mon Sep 17 00:00:00 2001 From: ARg Date: Wed, 11 Sep 2024 11:56:18 +0200 Subject: [PATCH 3/6] Migration of ESP32 targets from idf 4.4 to 5.3: - fixed GCC 13 (which is used by idf 5.3) compilation issues; - fixed compatibility issues with idf 5.3 library; --- libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp | 4 ++-- libraries/AP_HAL_ESP32/SPIDevice.cpp | 2 +- libraries/AP_HAL_ESP32/SdCard.cpp | 8 ++------ libraries/AP_HAL_ESP32/Semaphores.cpp | 2 +- libraries/AP_HAL_ESP32/UARTDriver.cpp | 2 +- libraries/AP_HAL_ESP32/Util.cpp | 1 + libraries/AP_HAL_ESP32/WiFiDriver.cpp | 4 ++-- libraries/AP_HAL_ESP32/WiFiUdpDriver.cpp | 4 ++-- libraries/AP_HAL_ESP32/i2c_sw.c | 5 +++-- libraries/SITL/SIM_EFI_MegaSquirt.cpp | 2 +- 10 files changed, 16 insertions(+), 18 deletions(-) diff --git a/libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp b/libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp index 9cb031d86795d0..9f71c8d281be03 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp @@ -42,7 +42,7 @@ int AP_Filesystem_ESP32::close(int fd) return ::close(fd); } -ssize_t AP_Filesystem_ESP32::read(int fd, void *buf, size_t count) +int32_t AP_Filesystem_ESP32::read(int fd, void *buf, uint32_t count) { #if FSDEBUG printf("DO read \n"); @@ -50,7 +50,7 @@ ssize_t AP_Filesystem_ESP32::read(int fd, void *buf, size_t count) return ::read(fd, buf, count); } -ssize_t AP_Filesystem_ESP32::write(int fd, const void *buf, size_t count) +int32_t AP_Filesystem_ESP32::write(int fd, const void *buf, uint32_t count) { #if FSDEBUG printf("DO write \n"); diff --git a/libraries/AP_HAL_ESP32/SPIDevice.cpp b/libraries/AP_HAL_ESP32/SPIDevice.cpp index 35006a48bea88d..98e5f126198dd4 100644 --- a/libraries/AP_HAL_ESP32/SPIDevice.cpp +++ b/libraries/AP_HAL_ESP32/SPIDevice.cpp @@ -60,7 +60,7 @@ SPIDevice::SPIDevice(SPIBus &_bus, SPIDeviceDesc &_device_desc) set_device_bus(bus.bus); set_device_address(_device_desc.device); set_speed(AP_HAL::Device::SPEED_LOW); - gpio_pad_select_gpio(device_desc.cs); + esp_rom_gpio_pad_select_gpio(device_desc.cs); gpio_set_direction(device_desc.cs, GPIO_MODE_OUTPUT); gpio_set_level(device_desc.cs, 1); diff --git a/libraries/AP_HAL_ESP32/SdCard.cpp b/libraries/AP_HAL_ESP32/SdCard.cpp index 0f91711e1a9a90..4644797cf32e3a 100644 --- a/libraries/AP_HAL_ESP32/SdCard.cpp +++ b/libraries/AP_HAL_ESP32/SdCard.cpp @@ -32,8 +32,6 @@ #include #include "SPIDevice.h" -#include "soc/rtc_wdt.h" - #ifdef HAL_ESP32_SDCARD #if CONFIG_IDF_TARGET_ESP32S2 ||CONFIG_IDF_TARGET_ESP32C3 @@ -254,8 +252,8 @@ void mount_sdcard() { mount_sdcard_spi(); } -#endif // end spi +#endif // end spi bool sdcard_retry(void) { @@ -265,16 +263,14 @@ bool sdcard_retry(void) return sdcard_running; } - void unmount_sdcard() { if (card != nullptr) { - esp_vfs_fat_sdmmc_unmount(); + esp_vfs_fat_sdcard_unmount( "/SDCARD", card); } sdcard_running = false; } - #else // empty impl's void mount_sdcard() diff --git a/libraries/AP_HAL_ESP32/Semaphores.cpp b/libraries/AP_HAL_ESP32/Semaphores.cpp index d76ca820aeae18..cd4189ca1ea9ef 100644 --- a/libraries/AP_HAL_ESP32/Semaphores.cpp +++ b/libraries/AP_HAL_ESP32/Semaphores.cpp @@ -106,7 +106,7 @@ void BinarySemaphore::signal_ISR() { BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(_sem, &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + portYIELD_FROM_ISR_ARG(xHigherPriorityTaskWoken); } BinarySemaphore::~BinarySemaphore(void) diff --git a/libraries/AP_HAL_ESP32/UARTDriver.cpp b/libraries/AP_HAL_ESP32/UARTDriver.cpp index 2cf293a3504821..90befdb6cc1bf3 100644 --- a/libraries/AP_HAL_ESP32/UARTDriver.cpp +++ b/libraries/AP_HAL_ESP32/UARTDriver.cpp @@ -55,7 +55,7 @@ void UARTDriver::_begin(uint32_t b, uint16_t rxS, uint16_t txS) uart_desc[uart_num].rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); //uart_driver_install(p, 2*UART_FIFO_LEN, 0, 0, nullptr, 0); - uart_driver_install(p, 2*UART_FIFO_LEN, 0, 0, nullptr, 0); + uart_driver_install(p, 2*UART_HW_FIFO_LEN(p), 0, 0, nullptr, 0); _readbuf.set_size(RX_BUF_SIZE); _writebuf.set_size(TX_BUF_SIZE); diff --git a/libraries/AP_HAL_ESP32/Util.cpp b/libraries/AP_HAL_ESP32/Util.cpp index c5d68386686fc8..8585e23fc81516 100644 --- a/libraries/AP_HAL_ESP32/Util.cpp +++ b/libraries/AP_HAL_ESP32/Util.cpp @@ -35,6 +35,7 @@ #include "esp_heap_caps.h" #include +#include "esp_mac.h" extern const AP_HAL::HAL& hal; diff --git a/libraries/AP_HAL_ESP32/WiFiDriver.cpp b/libraries/AP_HAL_ESP32/WiFiDriver.cpp index 9d8b5cfd5c4698..f1c7eb9e972765 100644 --- a/libraries/AP_HAL_ESP32/WiFiDriver.cpp +++ b/libraries/AP_HAL_ESP32/WiFiDriver.cpp @@ -145,7 +145,7 @@ bool WiFiDriver::start_listen() bool WiFiDriver::try_accept() { struct sockaddr_in sourceAddr; - uint addrLen = sizeof(sourceAddr); + socklen_t addrLen = sizeof(sourceAddr); short i = available_socket(); if (i != WIFI_MAX_CONNECTION) { socket_list[i] = accept(accept_socket, (struct sockaddr *)&sourceAddr, &addrLen); @@ -246,7 +246,7 @@ static void _sta_event_handler(void* arg, esp_event_base_t event_base, void WiFiDriver::initialize_wifi() { #ifndef WIFI_PWD - #default WIFI_PWD "ardupilot1" + #define WIFI_PWD "ardupilot1" #endif //Initialize NVS esp_err_t ret = nvs_flash_init(); diff --git a/libraries/AP_HAL_ESP32/WiFiUdpDriver.cpp b/libraries/AP_HAL_ESP32/WiFiUdpDriver.cpp index 9348f56cc7ac89..d6a247e13c5d63 100644 --- a/libraries/AP_HAL_ESP32/WiFiUdpDriver.cpp +++ b/libraries/AP_HAL_ESP32/WiFiUdpDriver.cpp @@ -32,7 +32,7 @@ #include "lwip/sys.h" #include "lwip/netdb.h" -#include "soc/rtc_wdt.h" +#include "freertos/idf_additions.h" using namespace ESP32; @@ -215,7 +215,7 @@ static void _sta_event_handler(void* arg, esp_event_base_t event_base, void WiFiUdpDriver::initialize_wifi() { #ifndef WIFI_PWD - #default WIFI_PWD "ardupilot1" + #define WIFI_PWD "ardupilot1" #endif //Initialize NVS esp_err_t ret = nvs_flash_init(); diff --git a/libraries/AP_HAL_ESP32/i2c_sw.c b/libraries/AP_HAL_ESP32/i2c_sw.c index 6caf9e5c6064ed..e2ae274774cb44 100644 --- a/libraries/AP_HAL_ESP32/i2c_sw.c +++ b/libraries/AP_HAL_ESP32/i2c_sw.c @@ -126,8 +126,9 @@ void i2c_init(_i2c_bus_t* bus) case 160: bus->delay = _i2c_delays[bus->speed][1]; break; case 240: bus->delay = _i2c_delays[bus->speed][2]; break; default : DEBUG("i2c I2C software implementation is not " - "supported for this CPU frequency: %d MHz\n", - ets_get_cpu_frequency()); + "supported for this CPU frequency: %u MHz\n", + (unsigned int)ets_get_cpu_frequency() + ); return; } diff --git a/libraries/SITL/SIM_EFI_MegaSquirt.cpp b/libraries/SITL/SIM_EFI_MegaSquirt.cpp index 2935024ce0b0aa..2a5e7152be8a1c 100644 --- a/libraries/SITL/SIM_EFI_MegaSquirt.cpp +++ b/libraries/SITL/SIM_EFI_MegaSquirt.cpp @@ -107,7 +107,7 @@ void EFI_MegaSquirt::update() if (crc == crc2) { send_table(); } else { - printf("BAD EFI CRC: 0x%08x 0x%08x\n", crc, crc2); + printf("BAD EFI CRC: 0x%08x 0x%08x\n", (unsigned int)crc, (unsigned int)crc2); } ofs = 0; } From de3e036e1b6c99bb0f9957fc5b9f582a8ee31420 Mon Sep 17 00:00:00 2001 From: ARg Date: Fri, 13 Sep 2024 09:32:48 +0200 Subject: [PATCH 4/6] Migration of ESP32 targets from idf 4.4 to 5.3: - fixed bug in case when HAL_ESP32_WIFI defined as 0 (disable wifi) --- libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp b/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp index b00af1bc543c09..04803a38c9454b 100644 --- a/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp +++ b/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp @@ -26,19 +26,22 @@ #include "RCInput.h" #include "RCOutput.h" #include "Storage.h" + #include "AnalogIn.h" + #include "Util.h" #if AP_SIM_ENABLED #include #endif - static ESP32::UARTDriver cons(0); #ifdef HAL_ESP32_WIFI #if HAL_ESP32_WIFI == 1 static ESP32::WiFiDriver serial1Driver; //tcp, client should connect to 192.168.4.1 port 5760 #elif HAL_ESP32_WIFI == 2 static ESP32::WiFiUdpDriver serial1Driver; //udp +#else +static Empty::UARTDriver serial1Driver; #endif #else static Empty::UARTDriver serial1Driver; From be7db14611cc97f187be155e63e397257eb3e5ef Mon Sep 17 00:00:00 2001 From: arg7 <64158631+arg7@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:26:00 +0200 Subject: [PATCH 5/6] Apply suggestions from code review install-prereqs-* typo fix. Co-authored-by: Thomas Watson --- Tools/environment_install/install-prereqs-arch.sh | 2 +- .../environment_install/install-prereqs-openSUSE-Tumbleweed.sh | 2 +- Tools/environment_install/install-prereqs-ubuntu.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tools/environment_install/install-prereqs-arch.sh b/Tools/environment_install/install-prereqs-arch.sh index d2f7d9b4a025fe..9dc26acc1297b6 100755 --- a/Tools/environment_install/install-prereqs-arch.sh +++ b/Tools/environment_install/install-prereqs-arch.sh @@ -67,7 +67,7 @@ fi if [[ $DO_PYTHON_VENV_ENV -eq 1 ]]; then echo "$SOURCE_LINE" >> ~/.bashrc else - echo "Use $SOURCE_LINE to ativate Ardupilot venv" + echo "Use $SOURCE_LINE to activate Ardupilot venv" fi pip3 -q install -U $PYTHON_PKGS diff --git a/Tools/environment_install/install-prereqs-openSUSE-Tumbleweed.sh b/Tools/environment_install/install-prereqs-openSUSE-Tumbleweed.sh index 227817fb97f144..f0d034bcbeed8e 100755 --- a/Tools/environment_install/install-prereqs-openSUSE-Tumbleweed.sh +++ b/Tools/environment_install/install-prereqs-openSUSE-Tumbleweed.sh @@ -103,7 +103,7 @@ if ! grep -Fxq "$SOURCE_LINE" ~/.bashrc; then if [[ $DO_PYTHON_VENV_ENV -eq 1 ]]; then echo $SOURCE_LINE >> ~/.bashrc else - echo "Use $SOURCE_LINE to ativate Ardupilot venv" + echo "Use $SOURCE_LINE to activate Ardupilot venv" fi fi diff --git a/Tools/environment_install/install-prereqs-ubuntu.sh b/Tools/environment_install/install-prereqs-ubuntu.sh index 218d7f0985279b..8e0e7450c87562 100755 --- a/Tools/environment_install/install-prereqs-ubuntu.sh +++ b/Tools/environment_install/install-prereqs-ubuntu.sh @@ -394,7 +394,7 @@ if [[ $VENV_LOOKUP ]]; then if [[ $DO_PYTHON_VENV_ENV -eq 1 ]]; then echo $SOURCE_LINE >> ~/$SHELL_LOGIN else - echo "Use $SOURCE_LINE to ativate Ardupilot venv" + echo "Use $SOURCE_LINE to activate Ardupilot venv" fi fi From 8630972913243c3e3274d75a20e5332aaa8bd0a4 Mon Sep 17 00:00:00 2001 From: ARg Date: Mon, 16 Sep 2024 11:39:05 +0200 Subject: [PATCH 6/6] Removed unneccessary variable and white space, as suggested by code review --- Tools/scripts/esp32_get_idf.sh | 7 +++---- libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Tools/scripts/esp32_get_idf.sh b/Tools/scripts/esp32_get_idf.sh index 2637c05418f3be..10fe0dbac423b9 100755 --- a/Tools/scripts/esp32_get_idf.sh +++ b/Tools/scripts/esp32_get_idf.sh @@ -2,7 +2,6 @@ # if you have modules/esp_idf setup as a submodule, then leave it as a submodule and switch branches COMMIT="cc3203dc4f087ab41b434afff1ed7520c6d90993" -CHECKOUT="cc3203d" if [ ! -d modules ]; then echo "this script needs to be run from the root of your repo, sorry, giving up." @@ -29,7 +28,7 @@ else echo "found empty IDF, cloning" # add esp_idf as almost submodule, depths uses less space git clone -b 'release/v5.3' https://github.com/espressif/esp-idf.git esp_idf - git checkout $CHECKOUT + git checkout $COMMIT fi fi @@ -43,13 +42,13 @@ else echo "looks like an idf, but not v5.3 branch, or wrong commit , trying to switch branch and reflect upstream"; ../../Tools/gittools/submodule-sync.sh >/dev/null git fetch ; git checkout -f release/v5.3 - git checkout $CHECKOUT + git checkout $COMMIT # retry same as above echo `git rev-parse HEAD` if [ `git rev-parse HEAD` == '$COMMIT' ]; then echo "IDF version 'release/5.3' found OK, great."; - git checkout $CHECKOUT + git checkout $COMMIT fi fi cd ../.. diff --git a/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp b/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp index 04803a38c9454b..fb37729dec4446 100644 --- a/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp +++ b/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp @@ -26,9 +26,7 @@ #include "RCInput.h" #include "RCOutput.h" #include "Storage.h" - #include "AnalogIn.h" - #include "Util.h" #if AP_SIM_ENABLED #include