mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-06 11:36:51 +03:00
fix_soc_sdmmc_and_add_soc_temperature_for_s3_support
This commit is contained in:
@@ -33,6 +33,10 @@ extern "C"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "../sdmmc_common.h"
|
||||
|
||||
#ifdef CONFIG_SOC_TEMP_SENSOR_SUPPORTED
|
||||
#include "driver/temperature_sensor.h"
|
||||
#endif
|
||||
|
||||
static const char *TAG = "HELPER";
|
||||
|
||||
using namespace std;
|
||||
@@ -613,11 +617,62 @@ string toLower(string in)
|
||||
return in;
|
||||
}
|
||||
|
||||
// CPU Temp
|
||||
extern "C" uint8_t temprature_sens_read();
|
||||
// SOC temperature sensor
|
||||
#if defined(CONFIG_SOC_TEMP_SENSOR_SUPPORTED)
|
||||
static float socTemperature = -1;
|
||||
|
||||
void taskSocTemp(void *pvParameter)
|
||||
{
|
||||
temperature_sensor_handle_t socTempSensor = NULL;
|
||||
temperature_sensor_config_t socTempSensorConfig = TEMPERATURE_SENSOR_CONFIG_DEFAULT(20, 100);
|
||||
temperature_sensor_install(&socTempSensorConfig, &socTempSensor);
|
||||
temperature_sensor_enable(socTempSensor);
|
||||
|
||||
while (1) {
|
||||
if (temperature_sensor_get_celsius(socTempSensor, &socTemperature) != ESP_OK) {
|
||||
socTemperature = -1;
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
}
|
||||
}
|
||||
|
||||
void initTemperatureSensor()
|
||||
{
|
||||
// Create a dedicated task to ensure access temperature ressource only from a single source
|
||||
BaseType_t xReturned = xTaskCreate(&taskSocTemp, "taskSocTemp", 2048, NULL, tskIDLE_PRIORITY + 1, NULL);
|
||||
|
||||
if (xReturned != pdPASS) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create taskSocTemp");
|
||||
}
|
||||
}
|
||||
|
||||
float temperatureRead()
|
||||
{
|
||||
return (temprature_sens_read() - 32) / 1.8;
|
||||
return socTemperature;
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32) // Inofficial support of vanilla ESP32. Value might be unreliable
|
||||
extern "C" uint8_t temprature_sens_read();
|
||||
|
||||
float temperatureRead()
|
||||
{
|
||||
return (temprature_sens_read() - 32) / 1.8;
|
||||
}
|
||||
|
||||
#else
|
||||
#warning "SOC temperature sensor not supported"
|
||||
float temperatureRead()
|
||||
{
|
||||
return -1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string intToHexString(int _valueInt)
|
||||
{
|
||||
char valueHex[33];
|
||||
sprintf(valueHex, "0x%02x", _valueInt);
|
||||
return std::string(valueHex);
|
||||
}
|
||||
|
||||
time_t addDays(time_t startTime, int days)
|
||||
|
||||
@@ -38,8 +38,13 @@ int removeFolder(const char* folderPath, const char* logTag);
|
||||
string toLower(string in);
|
||||
string toUpper(string in);
|
||||
|
||||
#ifdef CONFIG_SOC_TEMP_SENSOR_SUPPORTED
|
||||
void initTemperatureSensor();
|
||||
#endif
|
||||
|
||||
float temperatureRead();
|
||||
|
||||
std::string intToHexString(int _valueInt);
|
||||
time_t addDays(time_t startTime, int days);
|
||||
|
||||
void memCopyGen(uint8_t* _source, uint8_t* _target, int _size);
|
||||
|
||||
@@ -79,10 +79,10 @@
|
||||
static heap_trace_record_t trace_record[NUM_RECORDS]; // This buffer must be in internal RAM
|
||||
#endif
|
||||
|
||||
extern const char* GIT_TAG;
|
||||
extern const char* GIT_REV;
|
||||
extern const char* GIT_BRANCH;
|
||||
extern const char* BUILD_TIME;
|
||||
extern const char *GIT_TAG;
|
||||
extern const char *GIT_REV;
|
||||
extern const char *GIT_BRANCH;
|
||||
extern const char *BUILD_TIME;
|
||||
|
||||
extern std::string getFwVersion(void);
|
||||
extern std::string getHTMLversion(void);
|
||||
@@ -109,27 +109,51 @@ bool Init_NVS_SDCard()
|
||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
|
||||
|
||||
// For SoCs where the SD power can be supplied both via an internal or external (e.g. on-board LDO) power supply.
|
||||
// When using specific IO pins (which can be used for ultra high-speed SDMMC) to connect to the SD card
|
||||
// and the internal LDO power supply, we need to initialize the power supply first.
|
||||
#if SD_PWR_CTRL_LDO_INTERNAL_IO
|
||||
sd_pwr_ctrl_ldo_config_t ldo_config = {
|
||||
.ldo_chan_id = CONFIG_EXAMPLE_SD_PWR_CTRL_LDO_IO_ID,
|
||||
};
|
||||
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
|
||||
|
||||
ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to create a new on-chip LDO power control driver");
|
||||
return ret;
|
||||
}
|
||||
host.pwr_ctrl_handle = pwr_ctrl_handle;
|
||||
#endif
|
||||
|
||||
// This initializes the slot without card detect (CD) and write protect (WP) signals.
|
||||
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
|
||||
#ifdef CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
|
||||
sdmmc_slot_config_t slot_config = {
|
||||
.cd = SDMMC_SLOT_NO_CD,
|
||||
.wp = SDMMC_SLOT_NO_WP,
|
||||
};
|
||||
#else
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
#endif
|
||||
|
||||
// Set bus width to use:
|
||||
#ifdef __SD_USE_ONE_LINE_MODE__
|
||||
slot_config.width = 1;
|
||||
#ifdef SOC_SDMMC_USE_GPIO_MATRIX
|
||||
#ifdef CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
|
||||
slot_config.clk = GPIO_SDCARD_CLK;
|
||||
slot_config.cmd = GPIO_SDCARD_CMD;
|
||||
slot_config.d0 = GPIO_SDCARD_D0;
|
||||
#endif
|
||||
|
||||
#else
|
||||
#endif // end CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
|
||||
#else // else __SD_USE_ONE_LINE_MODE__
|
||||
slot_config.width = 4;
|
||||
#ifdef SOC_SDMMC_USE_GPIO_MATRIX
|
||||
#ifdef CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
|
||||
slot_config.d1 = GPIO_SDCARD_D1;
|
||||
slot_config.d2 = GPIO_SDCARD_D2;
|
||||
slot_config.d3 = GPIO_SDCARD_D3;
|
||||
#endif
|
||||
#endif
|
||||
#endif // end CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
|
||||
#endif // end __SD_USE_ONE_LINE_MODE__
|
||||
|
||||
// Enable internal pullups on enabled pins. The internal pullups
|
||||
// are insufficient however, please make sure 10k external pullups are
|
||||
@@ -350,6 +374,12 @@ extern "C" void app_main(void)
|
||||
// ********************************************
|
||||
setupTime(); // NTP time service: Status of time synchronization will be checked after every round (server_tflite.cpp)
|
||||
|
||||
// Init SOC temperature sensor (if supported by hardware)
|
||||
// ********************************************
|
||||
#if defined(CONFIG_SOC_TEMP_SENSOR_SUPPORTED)
|
||||
initTemperatureSensor();
|
||||
#endif
|
||||
|
||||
// Set CPU Frequency
|
||||
// ********************************************
|
||||
setCpuFrequency();
|
||||
|
||||
Reference in New Issue
Block a user