From 87405d98b60216d81d00395923e56ae205b0d438 Mon Sep 17 00:00:00 2001 From: radityankn Date: Tue, 3 Dec 2024 22:26:54 +0700 Subject: [PATCH] hwconfig for ESP32S3 SAFMC --- libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp | 2 +- libraries/AP_HAL_ESP32/boards/esp32s3devkit.h | 63 +++++++++++-------- libraries/AP_Logger/AP_Logger_Block.cpp | 6 +- libraries/AP_Logger/AP_Logger_Flash_JEDEC.cpp | 4 +- libraries/AP_Logger/AP_Logger_W25NXX.cpp | 4 +- libraries/AP_Scheduler/PerfInfo.cpp | 2 +- 6 files changed, 46 insertions(+), 35 deletions(-) diff --git a/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp b/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp index c0b039e386e16..7b1414c0b316c 100644 --- a/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp +++ b/libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp @@ -17,6 +17,7 @@ #include #include "HAL_ESP32_Class.h" +#include "AnalogIn.h" #include "Scheduler.h" #include "I2CDevice.h" #include "SPIDevice.h" @@ -27,7 +28,6 @@ #include "RCOutput.h" #include "GPIO.h" #include "Storage.h" -#include "AnalogIn.h" #include "Util.h" #if AP_SIM_ENABLED #include diff --git a/libraries/AP_HAL_ESP32/boards/esp32s3devkit.h b/libraries/AP_HAL_ESP32/boards/esp32s3devkit.h index 07b6e8055c1dc..a22e184f96757 100644 --- a/libraries/AP_HAL_ESP32/boards/esp32s3devkit.h +++ b/libraries/AP_HAL_ESP32/boards/esp32s3devkit.h @@ -43,8 +43,8 @@ //#define HAL_BOARD_ESP32 12 #define AP_INERTIALSENSOR_ENABLED 1 //INS choices: -#define HAL_INS_DEFAULT HAL_INS_MPU9250_SPI -//#define HAL_INS_MPU9250_NAME "MPU9250" +#define HAL_INS_DEFAULT HAL_INS_MPU6500_SPI +#define HAL_INS_MPU6500_NAME "mpu6500" // or this: //#define HAL_INS_DEFAULT HAL_INS_ICM20XXX_I2C @@ -53,36 +53,38 @@ // BARO choices: #define HAL_BARO_DEFAULT HAL_BARO_BMP280_I2C -#define HAL_BARO_BMP280_NAME "BMP280" +#define HAL_BARO_BMP280_NAME "bmp280" // or one of these: //#define HAL_BARO_DEFAULT HAL_BARO_MS5837_I2C // or: GPIO 34 //#define HAL_BARO_ANALOG_PIN (6) // MAG/COMPASS choices: -#define HAL_COMPASS_DEFAULT HAL_COMPASS_AK8963_MPU9250 +//#define HAL_COMPASS_DEFAULT HAL_COMPASS_AK8963_MPU9250 // or others: -//#define HAL_COMPASS_ICM20948_I2C_ADDR (0x68) -//#define HAL_COMPASS_AK09916_I2C_BUS 0 +#define AP_COMPASS_QMC5883L_ENABLED TRUE +#define HAL_COMPASS_QMC5883L_I2C_ADDR (0xD0) +#define HAL_COMPASS_AK09916_I2C_BUS 0 //#define HAL_COMPASS_AK09916_I2C_ADDR (0x0C) //#define HAL_COMPASS_MAX_SENSORS 3 // IMU probing: -//#define HAL_INS_PROBE_LIST PROBE_IMU_I2C(Invensensev2, 0, 0x68, ROTATION_YAW_270) +#define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensense, HAL_INS_MPU6500_NAME, ROTATION_NONE) // MAG/COMPASS probing: -//#define HAL_MAG_PROBE_LIST ADD_BACKEND(DRIVER_ICM20948, AP_Compass_AK09916::probe_ICM20948_I2C(0, ROTATION_NONE)); +#define HAL_MAG_PROBE_LIST ADD_BACKEND(DRIVER_QMC5883L, AP_Compass_QMC5883L::probe(GET_I2C_DEVICE(0, 0xD0), 0, ROTATION_NONE)) //#define HAL_MAG_PROBE_LIST PROBE_MAG_SPI(Invensense, "mpu9250") // BARO probing: -#define HAL_BARO_PROBE_LIST PROBE_BARO_I2C(BMP280, 0, 0x77) +#define HAL_BARO_PROBE_LIST PROBE_BARO_I2C(BMP280, 0, 0x76) +//#define HAL_BARO_PROBE_LIST PROBE_BARO_SPI(BMP280, "bmp280") // allow boot without a baro #define HAL_BARO_ALLOW_INIT_NO_BARO 1 // ADC is available on lots of pints on the esp32, but adc2 cant co-exist with wifi we choose to allow ADC on : -//#define HAL_DISABLE_ADC_DRIVER 1 +#define HAL_DISABLE_ADC_DRIVER 1 #define TRUE 1 -#define HAL_USE_ADC TRUE +//#define HAL_USE_ADC TRUE // the pin number, the gain/multiplier associated with it, the ardupilot name for the pin in parameter/s. // @@ -101,9 +103,7 @@ } // pick one: //#define HAL_ESP32_ADC_PINS HAL_ESP32_ADC_PINS_OPTION1 -#define HAL_ESP32_ADC_PINS HAL_ESP32_ADC_PINS_OPTION1 - -#define HAL_INS_MPU9250_NAME "mpu9250" +#define HAL_ESP32_ADC_PINS HAL_ESP32_ADC_PINS_OPTION2 // uncommenting one or more of these will give more console debug in certain areas.. //#define INSEDEBUG 1 @@ -112,15 +112,13 @@ //#define FSDEBUG 1 //#define BUSDEBUG 1 -#define HAL_INS_PROBE_LIST PROBE_IMU_SPI( Invensense, HAL_INS_MPU9250_NAME, ROTATION_NONE) +//#define HAL_INS_PROBE_LIST PROBE_IMU_SPI( Invensense, HAL_INS_MPU9250_NAME, ROTATION_NONE) //#define HAL_INS_PROBE_LIST PROBE_IMU_SPI( Invensense, HAL_INS_MPU9250_NAME, ROTATION_ROLL_180) // MAG/COMPASS probing: -#define AP_COMPASS_AK8963_ENABLED TRUE -#define HAL_MAG_PROBE_LIST ADD_BACKEND(DRIVER_AK8963, AP_Compass_AK8963::probe_mpu9250(0, ROTATION_NONE)) +//#define AP_COMPASS_AK8963_ENABLED TRUE +//#define HAL_MAG_PROBE_LIST ADD_BACKEND(DRIVER_AK8963, AP_Compass_AK8963::probe(0, ROTATION_NONE)) #define HAL_PROBE_EXTERNAL_I2C_COMPASSES 1 -//#define HAL_BARO_PROBE_LIST PROBE_BARO_SPI(BMP280, "bmp280") - // 2 use udp, 1 use tcp... for udp,client needs to connect as UDPCL in missionplanner etc to 192.168.4.1 port 14550 #define HAL_ESP32_WIFI 1 @@ -147,13 +145,13 @@ // SPI BUS setup, including gpio, dma, etc // note... we use 'vspi' for the bmp280 and mpu9250 #define HAL_ESP32_SPI_BUSES \ - {.host=SPI3_HOST, .dma_ch=SPI_DMA_CH_AUTO, .mosi=GPIO_NUM_36, .miso=GPIO_NUM_37, .sclk=GPIO_NUM_35} + {.host=SPI3_HOST, .dma_ch=SPI_DMA_CH_AUTO, .mosi=GPIO_NUM_18, .miso=GPIO_NUM_17, .sclk=GPIO_NUM_46} // tip: VSPI_HOST is an alternative name for esp's SPI3 //#define HAL_ESP32_SPI_BUSES {} // SPI per-device setup, including speeds, etc. #define HAL_ESP32_SPI_DEVICES \ - {.name="mpu9250", .bus=0, .device=0, .cs=GPIO_NUM_34, .mode = 0, .lspeed=2*MHZ, .hspeed=8*MHZ} + {.name="mpu6500", .bus=0, .device=0, .cs=GPIO_NUM_9, .mode = 0, .lspeed=2*MHZ, .hspeed=8*MHZ} //#define HAL_ESP32_SPI_DEVICES {} //I2C bus list @@ -163,12 +161,14 @@ // rcin on what pin? -#define HAL_ESP32_RCIN GPIO_NUM_14 +// #define HAL_ESP32_RCIN GPIO_NUM_40 //HARDWARE UARTS #define HAL_ESP32_UART_DEVICES \ - {.port=UART_NUM_0, .rx=GPIO_NUM_44, .tx=GPIO_NUM_43 },{.port=UART_NUM_1, .rx=GPIO_NUM_17, .tx=GPIO_NUM_18 } + {.port=UART_NUM_0, .rx=GPIO_NUM_44, .tx=GPIO_NUM_43 }, \ + {.port=UART_NUM_1, .rx=GPIO_NUM_13, .tx=GPIO_NUM_12 }, \ + {.port=UART_NUM_2, .rx=GPIO_NUM_20, .tx=GPIO_NUM_21} #define HAVE_FILESYSTEM_SUPPORT 1 @@ -180,11 +180,22 @@ #define HAL_ESP32_SDCARD 1 #define LOGGER_MAVLINK_SUPPORT 1 -#define HAL_BOARD_LOG_DIRECTORY "/SDCARD/APM/LOGS" -#define HAL_BOARD_TERRAIN_DIRECTORY "/SDCARD/APM/TERRAIN" -#define HAL_BOARD_STORAGE_DIRECTORY "/SDCARD/APM/STORAGE" #define HAL_OS_POSIX_IO 1 // this becomes the default value for the ardupilot param LOG_BACKEND_TYPE, which most ppl want to be 1, for log-to-flash // setting to 2 means log-over-mavlink to a companion computer etc. #define HAL_LOGGING_BACKENDS_DEFAULT 1 + +#define HAL_LOGGING_FILESYSTEM_ENABLED 1 +#define HAL_LOGGING_DATAFLASH_ENABLED 0 +#define HAL_LOGGING_MAVLINK_ENABLED 1 + +#define HAL_BOARD_LOG_DIRECTORY "/SDCARD/APM/LOGS" +#define HAL_BOARD_STORAGE_DIRECTORY "/SDCARD/APM/STORAGE" +#define HAL_BOARD_TERRAIN_DIRECTORY "/SDCARD/APM/TERRAIN" + +#define AP_RCPROTOCOL_ENABLED 1 + +#define AP_FILESYSTEM_ESP32_ENABLED 1 +#define AP_SCRIPTING_ENABLED 0 +//#define HAL_USE_EMPTY_STORAGE 1 \ No newline at end of file diff --git a/libraries/AP_Logger/AP_Logger_Block.cpp b/libraries/AP_Logger/AP_Logger_Block.cpp index 7ebf38c8c025a..33e47f1c7332c 100644 --- a/libraries/AP_Logger/AP_Logger_Block.cpp +++ b/libraries/AP_Logger/AP_Logger_Block.cpp @@ -929,14 +929,14 @@ void AP_Logger_Block::flash_test() const uint32_t pages_to_check = 128; for (uint32_t i=1; i<=pages_to_check; i++) { if ((i-1) % df_PagePerBlock == 0) { - printf("Block erase %u\n", get_block(i)); + printf("Block erase %lu\n", get_block(i)); SectorErase(get_block(i)); } memset(buffer, uint8_t(i), df_PageSize); if (i<5) { printf("Flash fill 0x%x\n", uint8_t(i)); } else if (i==5) { - printf("Flash fill pages 5-%u\n", pages_to_check); + printf("Flash fill pages 5-%lu\n", pages_to_check); } BufferToPage(i); } @@ -944,7 +944,7 @@ void AP_Logger_Block::flash_test() if (i<5) { printf("Flash check 0x%x\n", uint8_t(i)); } else if (i==5) { - printf("Flash check pages 5-%u\n", pages_to_check); + printf("Flash check pages 5-%lu\n", pages_to_check); } PageToBuffer(i); uint32_t bad_bytes = 0; diff --git a/libraries/AP_Logger/AP_Logger_Flash_JEDEC.cpp b/libraries/AP_Logger/AP_Logger_Flash_JEDEC.cpp index 025c53e3093ca..65915c3f51ba8 100644 --- a/libraries/AP_Logger/AP_Logger_Flash_JEDEC.cpp +++ b/libraries/AP_Logger/AP_Logger_Flash_JEDEC.cpp @@ -156,7 +156,7 @@ bool AP_Logger_Flash_JEDEC::getSectorCount(void) break; default: hal.scheduler->delay(2000); - printf("Unknown SPI Flash 0x%08x\n", id); + printf("Unknown SPI Flash 0x%08lx\n", id); return false; } @@ -164,7 +164,7 @@ bool AP_Logger_Flash_JEDEC::getSectorCount(void) df_NumPages = blocks * df_PagePerBlock; erase_cmd = JEDEC_BLOCK64_ERASE; - printf("SPI Flash 0x%08x found pages=%u erase=%uk\n", + printf("SPI Flash 0x%08lx found pages=%lu erase=%uk\n", id, df_NumPages, (df_PagePerBlock * (uint32_t)df_PageSize)/1024); return true; diff --git a/libraries/AP_Logger/AP_Logger_W25NXX.cpp b/libraries/AP_Logger/AP_Logger_W25NXX.cpp index df3e8bcea2d89..1bb347ce443c9 100644 --- a/libraries/AP_Logger/AP_Logger_W25NXX.cpp +++ b/libraries/AP_Logger/AP_Logger_W25NXX.cpp @@ -147,13 +147,13 @@ bool AP_Logger_W25NXX::getSectorCount(void) default: hal.scheduler->delay(2000); - printf("Unknown SPI Flash 0x%08x\n", id); + printf("Unknown SPI Flash 0x%08lx\n", id); return false; } df_NumPages = flash_blockNum * df_PagePerBlock; - printf("SPI Flash 0x%08x found pages=%u\n", id, df_NumPages); + printf("SPI Flash 0x%08lx found pages=%lu\n", id, df_NumPages); return true; } diff --git a/libraries/AP_Scheduler/PerfInfo.cpp b/libraries/AP_Scheduler/PerfInfo.cpp index 42ad17d7313cc..01045ebd5801d 100644 --- a/libraries/AP_Scheduler/PerfInfo.cpp +++ b/libraries/AP_Scheduler/PerfInfo.cpp @@ -152,7 +152,7 @@ void AP::PerfInfo::check_loop_time(uint32_t time_in_micros) // helpful for bringup of other boards too #if CONFIG_HAL_BOARD == HAL_BOARD_ESP32 #ifdef SCHEDDEBUG - DEV_PRINTF("way overtime: %dus\n", loop_time_us); + DEV_PRINTF("way overtime: %lu us\n", loop_time_us); #endif #endif }