As reported yesterday in this topic: viewtopic.php?f=2&t=7690#p32365
I used the technique described in this answer from ESP_igrr: viewtopic.php?t=6855#p29440.
I implemented it as follows:
Code: Select all
//CONFIG_BROWNOUT_DET_LVL_SEL_3
#ifdef CONFIG_BROWNOUT_DET_LVL
#define BROWNOUT_DET_LVL CONFIG_BROWNOUT_DET_LVL
#else
#define BROWNOUT_DET_LVL 4
#endif //CONFIG_BROWNOUT_DET_LVL
#define TAG "Brownout.c"
static void BOD_BrownoutIsrHandler()
{
/* Normally RTC ISR clears the interrupt flag after the application-supplied
* handler returns. Since restart is called here, the flag needs to be
* cleared manually.
*/
REG_WRITE ( RTC_CNTL_INT_CLR_REG, RTC_CNTL_BROWN_OUT_INT_CLR );
/* Stall the other CPU to make sure the code running there doesn't use UART
* at the same time as the following ets_printf.
*/
esp_cpu_stall ( !xPortGetCoreID () );
EvLog_WriteEntry( TAG, "Brownout detector was triggered!" );
// Wait for 2 seconds to allow any NVS storage to finish
vTaskDelay ( 2000/portTICK_PERIOD_MS );
ets_printf("\r\nBrownout detector was triggered\r\n\r\n");
LCD_ShowText ( "BAT");
Sleep_StartDeepSleep ( ON );
}
void BOD_BrownoutInit( void )
{
esp_err_t espError;
REG_WRITE
(
RTC_CNTL_BROWN_OUT_REG,
RTC_CNTL_BROWN_OUT_ENA /* Enable BOD */
| RTC_CNTL_BROWN_OUT_PD_RF_ENA /* Automatically power down RF */
| (2 << RTC_CNTL_BROWN_OUT_RST_WAIT_S) /* Reset timeout must be set to >1 even if BOR feature is not used */
| ( BROWNOUT_DET_LVL << RTC_CNTL_DBROWN_OUT_THRES_S )
);
espError = rtc_isr_register ( BOD_BrownoutIsrHandler, NULL, RTC_CNTL_BROWN_OUT_INT_ENA_M ) ;
if ( espError == ESP_OK )
{
REG_SET_BIT ( RTC_CNTL_INT_ENA_REG, RTC_CNTL_BROWN_OUT_INT_ENA_M );
ESP_LOGI ( TAG, "Registered brownout ISR");
}
else
{
EvLog_WriteEntry( TAG, "Could not register BOD_BrownoutIsrHandler !!" );
}
}
However: When I use my regulated power supply to lower the voltage the registered ISR is not executing as I do not get the "Brownout detector was triggered" message. Instead I get this:
(08:57:33.720) abort() was called at PC 0x40082ddd on core 0<CR>
(08:57:53.050) <CR>
(08:57:53.050) Backtrace: 0x4008ff5c:0x3ffb0000 0x40090133:0x3ffb0020 0x40082ddd:0x3ffb0040 0x40082efd:0x3ffb0070 0x400da4ba:0x3ffb0090 0x400dd715:0x3ffb03a0 0x40082d0d:0x3ffb03d0 0x400e431a:0x3ffb0420 0x400e31c7:0x3ffb05d0 0x400ea22e:0x3ffb05f0 0x400826a9:0x3ffb0610 0x4014baf3:0x00000000<CR>
(08:57:53.081) <CR>
(08:57:53.081) Rebooting...<CR>
(08:57:53.097) ets Jun 8 2016 00:22:57<CR>
(08:57:53.097) <CR>
(08:57:53.097) rst:0xc (SW_CPU_RESET),boot:0x37 (SPI_FAST_FLASH_BOOT)<CR>
...
..
.
The reboot keeps repeating until I increase the supply voltage again. Also: I have tried with various values for BROWNOUT_DET_LVL and it does not make the slightest difference. The abort() call always occurs at the same voltage.
Obviously I must be doing something wrong but for now I have no idea what.
Edit: Analysis of the map file shows that the call to abort() at PC 0x40082ddd is somewhere within file "locks.c"