Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M487: Fix crash on WDT reset from power-down (5.15) #14502

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,7 @@ void Reset_Handler_1(void)
{
/* Disable register write-protection function */
SYS_UnlockReg();

/* Disable Power-on Reset function */
SYS_DISABLE_POR();


/**
* NOTE 1: Some register accesses require unlock.
* NOTE 2: Because EBI (external SRAM) init is done in SystemInit(), SystemInit() must be called at the very start.
Expand Down
27 changes: 24 additions & 3 deletions targets/TARGET_NUVOTON/TARGET_M480/mbed_overrides.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +59,7 @@ void mbed_sdk_init(void)

/* Set PCLK0/PCLK1 to HCLK/2 */
CLK->PCLKDIV = (CLK_PCLKDIV_PCLK0DIV2 | CLK_PCLKDIV_PCLK1DIV2); // PCLK divider set 2

#if DEVICE_ANALOGIN
/* Vref connect to internal */
SYS->VREFCTL = (SYS->VREFCTL & ~SYS_VREFCTL_VREFCTL_Msk) | SYS_VREFCTL_VREF_3_0V;
Expand All @@ -69,4 +71,23 @@ void mbed_sdk_init(void)

/* Lock protected registers */
SYS_LockReg();

/* Get around h/w limit with WDT reset from PD */
if (SYS_IS_WDT_RST()) {
/* Re-unlock protected clock setting */
SYS_UnlockReg();

/* Set up DPD power down mode */
CLK->PMUSTS |= CLK_PMUSTS_CLRWK_Msk;
CLK->PMUSTS |= CLK_PMUSTS_TMRWK_Msk;
CLK_SetPowerDownMode(CLK_PMUCTL_PDMSEL_DPD);

CLK_SET_WKTMR_INTERVAL(CLK_PMUCTL_WKTMRIS_256);
CLK_ENABLE_WKTMR();

CLK_PowerDown();

/* Lock protected registers */
SYS_LockReg();
}
}
24 changes: 21 additions & 3 deletions targets/TARGET_NUVOTON/TARGET_M480/reset_reason.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2017-2018 Nuvoton
/*
* Copyright (c) 2017-2018, Nuvoton Technology Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +39,12 @@ reset_reason_t hal_reset_reason_get(void)
reset_reason_t reset_reason_cast;
uint32_t reset_reason_count = 0;

/* Get around h/w limit with WDT reset from PD */
if (CLK->PMUSTS & CLK_PMUSTS_TMRWK_Msk) {
/* Per test, these reset reason flags will set with WKT reset. Clear them for this resolution. */
SYS_CLEAR_RST_SOURCE(SYS_RSTSTS_PINRF_Msk | SYS_RSTSTS_PORF_Msk);
}

if (SYS_IS_POR_RST()) {
reset_reason_cast = RESET_REASON_POWER_ON;
reset_reason_count ++;
Expand All @@ -47,7 +55,8 @@ reset_reason_t hal_reset_reason_get(void)
reset_reason_count ++;
}

if (SYS_IS_WDT_RST()) {
/* Get around h/w limit with WDT reset from PD */
if (SYS_IS_WDT_RST() || (CLK->PMUSTS & CLK_PMUSTS_TMRWK_Msk)) {
reset_reason_cast = RESET_REASON_WATCHDOG;
reset_reason_count ++;
}
Expand Down Expand Up @@ -101,6 +110,15 @@ uint32_t hal_reset_reason_get_raw(void)
void hal_reset_reason_clear(void)
{
SYS_CLEAR_RST_SOURCE(SYS->RSTSTS);

/* Re-unlock protected clock setting */
SYS_UnlockReg();

/* Get around h/w limit with WDT reset from PD */
CLK->PMUSTS |= (CLK_PMUSTS_CLRWK_Msk | CLK_PMUSTS_TMRWK_Msk);

/* Lock protected registers */
SYS_LockReg();
}

#endif