Skip to content

Commit

Permalink
hwconfig for ESP32S3 SAFMC
Browse files Browse the repository at this point in the history
  • Loading branch information
radityankn committed Dec 3, 2024
1 parent eaf20db commit 87405d9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion libraries/AP_HAL_ESP32/HAL_ESP32_Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <AP_HAL_Empty/AP_HAL_Empty_Private.h>

#include "HAL_ESP32_Class.h"
#include "AnalogIn.h"
#include "Scheduler.h"
#include "I2CDevice.h"
#include "SPIDevice.h"
Expand All @@ -27,7 +28,6 @@
#include "RCOutput.h"
#include "GPIO.h"
#include "Storage.h"
#include "AnalogIn.h"
#include "Util.h"
#if AP_SIM_ENABLED
#include <AP_HAL/SIMState.h>
Expand Down
63 changes: 37 additions & 26 deletions libraries/AP_HAL_ESP32/boards/esp32s3devkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
//
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
6 changes: 3 additions & 3 deletions libraries/AP_Logger/AP_Logger_Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,22 +929,22 @@ 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);
}
for (uint32_t i=1; i<=pages_to_check; i++) {
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;
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_Logger/AP_Logger_Flash_JEDEC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ 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;
}

df_PageSize = 256;
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;

Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_Logger/AP_Logger_W25NXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Scheduler/PerfInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 87405d9

Please sign in to comment.