xtensa/esp32s2: Disable wdt and wrap it.

This commit is contained in:
Sara Souza 2021-07-16 17:42:00 -03:00 committed by Xiang Xiao
parent 0794991a07
commit 400d927011
5 changed files with 94 additions and 5 deletions

View File

@ -22,7 +22,7 @@
HEAD_ASRC = xtensa_vectors.S xtensa_window_vector.S xtensa_windowspill.S
HEAD_ASRC += xtensa_int_handlers.S xtensa_user_handler.S
HEAD_CSRC = esp32s2_start.c
HEAD_CSRC = esp32s2_start.c esp32s2_wdt.c
# Common XTENSA files (arch/xtensa/src/common)

View File

@ -38,6 +38,7 @@
#include "esp32s2_region.h"
#include "esp32s2_start.h"
#include "esp32s2_lowputc.h"
#include "esp32s2_wdt.h"
/****************************************************************************
* Pre-processor Definitions
@ -78,11 +79,9 @@ void IRAM_ATTR __start(void)
uint32_t regval;
uint32_t sp;
/* Kill the watchdog timer */
/* Disable any wdt enabled by bootloader */
regval = getreg32(RTC_CNTL_WDTCONFIG0_REG);
regval &= ~RTC_CNTL_WDT_FLASHBOOT_MOD_EN;
putreg32(regval, RTC_CNTL_WDTCONFIG0_REG);
esp32s2_wdt_early_deinit();
regval = getreg32(DR_REG_BB_BASE + 0x48); /* DR_REG_BB_BASE+48 */
regval &= ~(1 << 14);

View File

@ -0,0 +1,50 @@
/****************************************************************************
* arch/xtensa/src/esp32s2/esp32s2_wdt.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "xtensa.h"
#include "hardware/esp32s2_rtccntl.h"
#include "esp32s2_wdt.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32s2_wdt_early_deinit
*
* Description:
* Disable the WDT(s) that was/were enabled by the bootloader.
*
****************************************************************************/
void esp32s2_wdt_early_deinit(void)
{
uint32_t regval;
putreg32(RTC_CNTL_WDT_WKEY_VALUE, RTC_CNTL_WDTWPROTECT_REG);
regval = getreg32(RTC_CNTL_WDTCONFIG0_REG);
regval &= ~RTC_CNTL_WDT_EN;
putreg32(regval, RTC_CNTL_WDTCONFIG0_REG);
putreg32(0, RTC_CNTL_WDTWPROTECT_REG);
}

View File

@ -0,0 +1,34 @@
/****************************************************************************
* arch/xtensa/src/esp32s2/esp32s2_wdt.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_WDT_H
#define __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_WDT_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
void esp32s2_wdt_early_deinit(void);
#endif /* __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_WDT_H */

View File

@ -31,6 +31,12 @@
* Pre-processor Definitions
****************************************************************************/
/* The value that needs to be written to RTC_CNTL_WDT_WKEY to
* write-enable the wdt registers
*/
#define RTC_CNTL_WDT_WKEY_VALUE 0x50d83aa1
#define DPORT_CPUPERIOD_SEL_80 0
#define DPORT_CPUPERIOD_SEL_160 1
#define DPORT_CPUPERIOD_SEL_240 2