Skip to content

Commit

Permalink
ESP32: sporadic crash debugging and had to disable SPI mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
cruwaller committed Jun 23, 2024
1 parent 8d62590 commit dfb64e4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/src/esp32/HwSpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
SPIClass DRAM_ATTR SpiBus;

#if !USE_ARDUINO_SPI
#include "soc/rtc_wdt.h"
#include "soc/spi_reg.h"
#include "soc/spi_struct.h"

Expand Down Expand Up @@ -74,7 +75,8 @@ __spiTransfer(struct spi_struct_t * const spi, const uint8_t * out, uint8_t * in
if (!spi || !spi->dev) {
return;
}
SPI_MUTEX_LOCK();
//rtc_wdt_feed();
//SPI_MUTEX_LOCK();
taskDISABLE_INTERRUPTS();
#if 1
while (size) {
Expand Down Expand Up @@ -102,7 +104,7 @@ __spiTransfer(struct spi_struct_t * const spi, const uint8_t * out, uint8_t * in
}
#endif
taskENABLE_INTERRUPTS();
SPI_MUTEX_UNLOCK();
//SPI_MUTEX_UNLOCK();
}
#endif // !USE_ARDUINO_SPI

Expand Down
38 changes: 34 additions & 4 deletions src/src/esp32/esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//#include <soc/rtc_cntl_reg.h>
#include <esp_task_wdt.h>

#include <soc/rtc_wdt.h>

#include <soc/timer_group_struct.h>
#include <soc/timer_group_reg.h>

Expand Down Expand Up @@ -58,15 +60,41 @@ void feedTheDog(void)
TIMERG1.wdt_wprotect = 0; // write protect
}

void initVariant(void)
static void configure_wdt(void)
{
/* Disable watchdogs to precent unwanted resets */
disableCore0WDT();
disableCore1WDT();
#if 0
rtc_wdt_protect_off();
rtc_wdt_disable();
#endif
#if 1
// Set WDT timeout to 250ms
rtc_wdt_set_length_of_reset_signal(RTC_WDT_SYS_RESET_SIG, RTC_WDT_LENGTH_3_2us);
rtc_wdt_set_stage(RTC_WDT_STAGE0, RTC_WDT_STAGE_ACTION_RESET_SYSTEM);
rtc_wdt_set_time(RTC_WDT_STAGE0, 250);
#endif

/* Disable watchdogs to precent unwanted resets */
//disableCore0WDT();
//disableCore1WDT();
#if 0
TIMERG1.wdt_wprotect = TIMG_WDT_WKEY_VALUE; // Unlock timer config.
TIMERG1.wdt_feed = 1; // Reset feed count.
TIMERG1.wdt_config0.en = 0; // Disable timer.
TIMERG1.wdt_wprotect = 0; // Lock timer config.

TIMERG0.wdt_wprotect = TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed = 1;
TIMERG0.wdt_config0.en = 0;
TIMERG0.wdt_wprotect = 0;
#endif
//WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
}

void initVariant(void)
{
//configure_wdt();
}

/******************* CONFIG *********************/
int8_t platform_config_load(struct platform_config &config)
{
Expand Down Expand Up @@ -111,6 +139,8 @@ int8_t platform_config_save(struct platform_config &config)
/******************* SETUP *********************/
void platform_setup(void)
{
configure_wdt();

// Set higher task priority
vTaskPrioritySet(NULL, 10);

Expand Down

0 comments on commit dfb64e4

Please sign in to comment.