From 259c785bb4fd3619bbeb3f64268cd2267a302ce8 Mon Sep 17 00:00:00 2001 From: Michael Perkins Date: Thu, 13 Nov 2025 11:59:12 +0000 Subject: [PATCH] Fix LPWDT clock sources for MAX78002 From Aleks Kupriianov. 1. Before proposed changes, the implementation of WDT clock for 78002 put literally the enum value for clock to the corresponding register. This would be correct if the table in the page 384 of the user guide were correct. 2. However, it turns out that the clock diagram in the pdf is correct, and the sets and numbers of clocks are the same for 78000 and 78002. Henceforth, it makes sense to re-use the solution for 78000 for our case. 3. So we add 78002 to wdt_me17.c and use wdt_me17.c for 78002 as well (changing makefile). We already use it for 78000. 4. The files wdt_me17.c and wdt_ai87.c are nearly identical, except two places. One place is the function MXC_WDT_SetClockSource, where the substitution of enum is done. The other place is the function MXC_WDT_Init, which checks if the clock was enabled. It should be disabled in all chips, since LPGCR_PCLKDIS has ones for all chips. Signed-off-by: Michael Perkins --- Libraries/PeriphDrivers/Source/WDT/wdt_ai87.c | 135 ------------------ Libraries/PeriphDrivers/Source/WDT/wdt_me17.c | 2 +- Libraries/PeriphDrivers/max78002_files.mk | 2 +- 3 files changed, 2 insertions(+), 137 deletions(-) delete mode 100644 Libraries/PeriphDrivers/Source/WDT/wdt_ai87.c diff --git a/Libraries/PeriphDrivers/Source/WDT/wdt_ai87.c b/Libraries/PeriphDrivers/Source/WDT/wdt_ai87.c deleted file mode 100644 index 55686105f7c..00000000000 --- a/Libraries/PeriphDrivers/Source/WDT/wdt_ai87.c +++ /dev/null @@ -1,135 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by - * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. - * - * Licensed 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. - * - ******************************************************************************/ - -/* **** Includes **** */ -#include "mxc_device.h" -#include "mxc_errors.h" -#include "mxc_assert.h" -#include "mxc_sys.h" -#include "wdt.h" -#include "wdt_revb.h" - -/* **** Functions **** */ - -int MXC_WDT_Init(mxc_wdt_regs_t *wdt, mxc_wdt_cfg_t *cfg) -{ -#ifndef MSDK_NO_GPIO_CLK_INIT - if (wdt == MXC_WDT0) { - MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_WDT0); - } else if (wdt == MXC_WDT1) { - // This clock is enabled by default (LPWDT0) - if (!MXC_SYS_IsClockEnabled(MXC_SYS_PERIPH_CLOCK_WDT1)) { - // Handle when clock was previously disabled - MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_WDT1); - } - } else { - return E_BAD_PARAM; - } -#endif - - MXC_WDT_RevB_Init((mxc_wdt_revb_regs_t *)wdt, (mxc_wdt_revb_cfg_t *)cfg); - - return E_NO_ERROR; -} - -int MXC_WDT_Shutdown(mxc_wdt_regs_t *wdt) -{ - if (wdt == MXC_WDT0) { - MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_WDT0); - } else if (wdt == MXC_WDT1) { - MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_WDT1); - } else { - return E_BAD_PARAM; - } - - return E_NO_ERROR; -} - -void MXC_WDT_SetIntPeriod(mxc_wdt_regs_t *wdt, mxc_wdt_cfg_t *cfg) -{ - MXC_WDT_RevB_SetIntPeriod((mxc_wdt_revb_regs_t *)wdt, (mxc_wdt_revb_cfg_t *)cfg); -} - -void MXC_WDT_SetResetPeriod(mxc_wdt_regs_t *wdt, mxc_wdt_cfg_t *cfg) -{ - MXC_WDT_RevB_SetResetPeriod((mxc_wdt_revb_regs_t *)wdt, (mxc_wdt_revb_cfg_t *)cfg); -} - -void MXC_WDT_Enable(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_Enable((mxc_wdt_revb_regs_t *)wdt); -} - -void MXC_WDT_Disable(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_Disable((mxc_wdt_revb_regs_t *)wdt); -} - -void MXC_WDT_EnableInt(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_EnableInt((mxc_wdt_revb_regs_t *)wdt, MXC_WDT_REVB_ENABLE); -} - -void MXC_WDT_DisableInt(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_EnableInt((mxc_wdt_revb_regs_t *)wdt, MXC_WDT_REVB_DISABLE); -} - -void MXC_WDT_EnableReset(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_EnableReset((mxc_wdt_revb_regs_t *)wdt, MXC_WDT_REVB_ENABLE); -} - -void MXC_WDT_DisableReset(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_EnableReset((mxc_wdt_revb_regs_t *)wdt, MXC_WDT_REVB_DISABLE); -} - -void MXC_WDT_ResetTimer(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_ResetTimer((mxc_wdt_revb_regs_t *)wdt); -} - -int MXC_WDT_GetResetFlag(mxc_wdt_regs_t *wdt) -{ - return MXC_WDT_RevB_GetResetFlag((mxc_wdt_revb_regs_t *)wdt); -} - -void MXC_WDT_ClearResetFlag(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_ClearResetFlag((mxc_wdt_revb_regs_t *)wdt); -} - -int MXC_WDT_GetIntFlag(mxc_wdt_regs_t *wdt) -{ - return MXC_WDT_RevB_GetIntFlag((mxc_wdt_revb_regs_t *)wdt); -} - -void MXC_WDT_ClearIntFlag(mxc_wdt_regs_t *wdt) -{ - MXC_WDT_RevB_ClearIntFlag((mxc_wdt_revb_regs_t *)wdt); -} - -int MXC_WDT_SetClockSource(mxc_wdt_regs_t *wdt, mxc_wdt_clock_t clock_source) -{ - MXC_WDT_RevB_SetClockSource((mxc_wdt_revb_regs_t *)wdt, (int)clock_source); - - return E_NO_ERROR; -} diff --git a/Libraries/PeriphDrivers/Source/WDT/wdt_me17.c b/Libraries/PeriphDrivers/Source/WDT/wdt_me17.c index 5de8e920341..cd9ab1a68fc 100644 --- a/Libraries/PeriphDrivers/Source/WDT/wdt_me17.c +++ b/Libraries/PeriphDrivers/Source/WDT/wdt_me17.c @@ -129,7 +129,7 @@ int MXC_WDT_SetClockSource(mxc_wdt_regs_t *wdt, mxc_wdt_clock_t clock_source) uint8_t idx = 0; uint8_t instance = 0; -#if TARGET_NUM == 32655 || TARGET_NUM == 78000 +#if TARGET_NUM == 32655 || TARGET_NUM == 78000 || TARGET_NUM == 78002 mxc_wdt_clock_t clock_sources[2][8] = { { MXC_WDT_PCLK, MXC_WDT_IBRO_CLK, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, { MXC_WDT_IBRO_CLK, MXC_WDT_INRO_CLK, MXC_WDT_ERTCO_CLK, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } diff --git a/Libraries/PeriphDrivers/max78002_files.mk b/Libraries/PeriphDrivers/max78002_files.mk index 7add3b5bef2..6afd1580df2 100644 --- a/Libraries/PeriphDrivers/max78002_files.mk +++ b/Libraries/PeriphDrivers/max78002_files.mk @@ -167,7 +167,7 @@ PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/UART/uart_revb.c PERIPH_DRIVER_INCLUDE_DIR += $(SOURCE_DIR)/WDT PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/WDT/wdt_common.c -PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/WDT/wdt_ai87.c +PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/WDT/wdt_me17.c PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/WDT/wdt_revb.c PERIPH_DRIVER_INCLUDE_DIR += $(SOURCE_DIR)/WUT