Merge pull request #13037 from s-hadinger/fix_psram_uninit

Fixed crash when PSRAM is absent and ``BOARD_HAS_PSRAM`` set
This commit is contained in:
s-hadinger 2021-09-01 23:22:30 +02:00 committed by GitHub
commit 6711d464ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 10 deletions

View File

@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
## [9.5.0.8]
### Fixed
- Fixed crash when PSRAM is absent and ``BOARD_HAS_PSRAM`` set
## [9.5.0.7] 20210901
### Added

View File

@ -60,12 +60,10 @@ extern "C" {
#ifndef BERRY_LOGSZ
#define BERRY_LOGSZ 700
#endif
extern "C" {
extern void *berry_malloc(size_t size);
}
static char * log_berry_buffer = nullptr;
static_block {
log_berry_buffer = (char*) berry_malloc(BERRY_LOGSZ);
log_berry_buffer = (char*) malloc(BERRY_LOGSZ);
if (log_berry_buffer) log_berry_buffer[0] = 0;
}
extern void berry_log(const char * berry_buf);

View File

@ -464,10 +464,21 @@ uint8_t* FlashDirectAccess(void) {
return data;
}
extern "C" {
bool esp_spiram_is_initialized(void);
}
// this function is a replacement for `psramFound()`.
// `psramFound()` can return true even if no PSRAM is actually installed
// This new version also checks `esp_spiram_is_initialized` to know if the PSRAM is initialized
bool FoundPSRAM(void) {
return psramFound() && esp_spiram_is_initialized();
}
// new function to check whether PSRAM is present and supported (i.e. required pacthes are present)
bool UsePSRAM(void) {
static bool can_use_psram = CanUsePSRAM();
return psramFound() && can_use_psram;
return FoundPSRAM() && can_use_psram;
}
void *special_malloc(uint32_t size) {
@ -690,6 +701,7 @@ typedef struct {
* patches are present.
*/
bool CanUsePSRAM(void) {
if (!FoundPSRAM()) return false;
#ifdef HAS_PSRAM_FIX
return true;
#endif

View File

@ -275,14 +275,17 @@ void setup(void) {
}
// AddLog(LOG_LEVEL_INFO, PSTR("ADR: Settings %p, Log %p"), Settings, TasmotaGlobal.log_buffer);
AddLog(LOG_LEVEL_INFO, PSTR("HDW: %s"), GetDeviceHardware().c_str());
#ifdef ESP32
AddLog(LOG_LEVEL_DEBUG, PSTR("HDW: psramFound=%i CanUsePSRAM=%i"), psramFound(), CanUsePSRAM());
#endif // ESP32
#if defined(ESP32) && !defined(HAS_PSRAM_FIX)
if (psramFound() && !CanUsePSRAM()) {
AddLog(LOG_LEVEL_INFO, PSTR("HDW: %s %s"), GetDeviceHardware().c_str(),
FoundPSRAM() ? (CanUsePSRAM() ? "(PSRAM)" : "(PSRAM disabled)") : "" );
AddLog(LOG_LEVEL_DEBUG, PSTR("HDW: FoundPSRAM=%i CanUsePSRAM=%i"), FoundPSRAM(), CanUsePSRAM());
#if !defined(HAS_PSRAM_FIX)
if (FoundPSRAM() && !CanUsePSRAM()) {
AddLog(LOG_LEVEL_INFO, PSTR("HDW: PSRAM is disabled, requires specific compilation on this hardware (see doc)"));
}
#endif
#else // ESP32
AddLog(LOG_LEVEL_INFO, PSTR("HDW: %s"), GetDeviceHardware().c_str());
#endif // ESP32
#ifdef USE_UFILESYS