Skip to content

Commit

Permalink
fix(Other): Zephyr: MAX32660: add compat wrappers
Browse files Browse the repository at this point in the history
Some defines and structs are different so reconcile these here

Signed-off-by: Matthew McClintock <[email protected]>
  • Loading branch information
mattsm committed Feb 7, 2025
1 parent bacab6b commit 0a34a87
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Libraries/zephyr/MAX/Include/wrap_max32_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void max32xx_system_init(void);
* MAX32665, MAX32666 related mapping
*/
#if defined(CONFIG_SOC_MAX32665) || defined(CONFIG_SOC_MAX32666)

#define ADI_MAX32_CLK_IPO MXC_SYS_CLOCK_HIRC96
#define ADI_MAX32_CLK_ERFO MXC_SYS_CLOCK_XTAL32M
#define ADI_MAX32_CLK_IBRO MXC_SYS_CLOCK_HIRC8
Expand All @@ -57,15 +56,19 @@ static inline int Wrap_MXC_SYS_Select32KClockSource(int clock)
}

/*
* MAX32690, MAX32655 related mapping
* MAX32660, MAX32690, MAX32655 related mapping
*/
#elif defined(CONFIG_SOC_MAX32690) || defined(CONFIG_SOC_MAX32655) || \
defined(CONFIG_SOC_MAX32670) || defined(CONFIG_SOC_MAX32672) || \
defined(CONFIG_SOC_MAX32662) || defined(CONFIG_SOC_MAX32675) || \
defined(CONFIG_SOC_MAX32680) || defined(CONFIG_SOC_MAX32657) || \
defined(CONFIG_SOC_MAX78002) || defined(CONFIG_SOC_MAX78000)
defined(CONFIG_SOC_MAX78002) || defined(CONFIG_SOC_MAX78000) || defined(CONFIG_SOC_MAX32660)

#if defined(CONFIG_SOC_MAX32660)
#define ADI_MAX32_CLK_IPO MXC_SYS_CLOCK_HIRC
#else
#define ADI_MAX32_CLK_IPO MXC_SYS_CLOCK_IPO
#endif
#if defined(CONFIG_SOC_MAX78002)
#define ADI_MAX32_CLK_IPLL MXC_SYS_CLOCK_IPLL
#define ADI_MAX32_CLK_EBO MXC_SYS_CLOCK_EBO
Expand Down
19 changes: 18 additions & 1 deletion Libraries/zephyr/MAX/Include/wrap_max32_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
extern "C" {
#endif

#if defined(CONFIG_SOC_MAX32665) || defined(CONFIG_SOC_MAX32666)
#if defined(CONFIG_SOC_MAX32665) || defined(CONFIG_SOC_MAX32666) || defined(CONFIG_SOC_MAX32660)
// status flags
#define ADI_MAX32_UART_RX_EMPTY MXC_F_UART_STATUS_RX_EMPTY
#define ADI_MAX32_UART_TX_EMPTY MXC_F_UART_STATUS_TX_EMPTY
Expand All @@ -53,6 +53,19 @@ extern "C" {
#define ADI_MAX32_UART_CFG_PARITY_MARK MXC_UART_PARITY_MARK
#define ADI_MAX32_UART_CFG_PARITY_SPACE MXC_UART_PARITY_SPACE

#if defined(CONFIG_SOC_MAX32660)
#define MXC_F_UART_INT_FL_RX_FRAME_ERROR MXC_F_UART_INT_FL_FRAME
#define MXC_F_UART_INT_FL_RX_PARITY_ERROR MXC_F_UART_INT_FL_PARITY
#define MXC_F_UART_INT_FL_RX_OVERRUN MXC_F_UART_INT_FL_RX_OVR
#define MXC_F_UART_INT_EN_TX_FIFO_THRESH MXC_F_UART_INT_EN_TX_FIFO_LVL
#define MXC_F_UART_INT_EN_RX_FIFO_THRESH MXC_F_UART_INT_EN_RX_FIFO_LVL
#define MXC_F_UART_INT_EN_TX_FIFO_ALMOST_EMPTY MXC_F_UART_INT_EN_TX_FIFO_AE
#define MXC_F_UART_STATUS_TX_FULL MXC_F_UART_STAT_TX_FULL
#define MXC_F_UART_STATUS_RX_EMPTY MXC_F_UART_STAT_RX_EMPTY
#define MXC_F_UART_DMA_RXDMA_LEVEL_POS MXC_F_UART_DMA_RXDMA_LVL_POS
#define MXC_F_UART_DMA_TXDMA_LEVEL_POS MXC_F_UART_DMA_TXDMA_LVL_POS
#endif

/* Error interrupts */
#define ADI_MAX32_UART_ERROR_INTERRUPTS \
(ADI_MAX32_UART_INT_OE | ADI_MAX32_UART_INT_PE | ADI_MAX32_UART_INT_FE)
Expand All @@ -72,7 +85,11 @@ static inline int Wrap_MXC_UART_Init(mxc_uart_regs_t *uart)
return ret;
}

#if defined(CONFIG_SOC_MAX32660)
uart->ctrl0 |= MXC_F_UART_CTRL0_ENABLE;
#else
uart->ctrl |= MXC_F_UART_CTRL_ENABLE;
#endif

return ret;
}
Expand Down
135 changes: 135 additions & 0 deletions Libraries/zephyr/MAX/Source/MAX32660/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
##############################################################################
#
# Copyright (C) 2025 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.
#
##############################################################################


if(NOT TARGET_REV)
# Default version A1, not actively use in driver but requires to be defined.
zephyr_compile_definitions(-DTARGET_REV=0x4131)
endif()

zephyr_include_directories(
${MSDK_PERIPH_SRC_DIR}/DMA
${MSDK_PERIPH_SRC_DIR}/FLC
${MSDK_PERIPH_SRC_DIR}/GPIO
${MSDK_PERIPH_SRC_DIR}/I2C
${MSDK_PERIPH_SRC_DIR}/I2S
${MSDK_PERIPH_SRC_DIR}/ICC
${MSDK_PERIPH_SRC_DIR}/LP
${MSDK_PERIPH_SRC_DIR}/RTC
${MSDK_PERIPH_SRC_DIR}/SPI
${MSDK_PERIPH_SRC_DIR}/SYS
${MSDK_PERIPH_SRC_DIR}/TMR
${MSDK_PERIPH_SRC_DIR}/UART
${MSDK_PERIPH_SRC_DIR}/WDT
)

zephyr_library_sources(
./max32xxx_system.c

${MSDK_CMSIS_DIR}/Source/system_max32660.c

${MSDK_PERIPH_SRC_DIR}/ICC/icc_common.c
${MSDK_PERIPH_SRC_DIR}/ICC/icc_me11.c
${MSDK_PERIPH_SRC_DIR}/ICC/icc_reva.c

${MSDK_PERIPH_SRC_DIR}/LP/lp_me11.c

${MSDK_PERIPH_SRC_DIR}/SYS/mxc_assert.c
${MSDK_PERIPH_SRC_DIR}/SYS/mxc_delay.c
${MSDK_PERIPH_SRC_DIR}/SYS/mxc_lock.c
${MSDK_PERIPH_SRC_DIR}/SYS/pins_me11.c
${MSDK_PERIPH_SRC_DIR}/SYS/sys_me11.c

${MSDK_PERIPH_SRC_DIR}/DMA/dma_me11.c
${MSDK_PERIPH_SRC_DIR}/DMA/dma_reva.c
)

if (CONFIG_ADC_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/ADC/adc_me11.c
${MSDK_PERIPH_SRC_DIR}/ADC/adc_reva.c
)
endif()

if (CONFIG_UART_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/UART/uart_common.c
${MSDK_PERIPH_SRC_DIR}/UART/uart_me11.c
${MSDK_PERIPH_SRC_DIR}/UART/uart_reva.c
)
endif()

if (CONFIG_GPIO_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/GPIO/gpio_common.c
${MSDK_PERIPH_SRC_DIR}/GPIO/gpio_me11.c
${MSDK_PERIPH_SRC_DIR}/GPIO/gpio_reva.c
)
endif()

if (CONFIG_SPI_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/SPI/spi_me11.c
${MSDK_PERIPH_SRC_DIR}/SPI/spi_reva1.c
)
endif()

if (CONFIG_I2C_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/I2C/i2c_me11.c
${MSDK_PERIPH_SRC_DIR}/I2C/i2c_reva.c
)
endif()

if (CONFIG_I2S_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/I2S/i2s_me11.c
${MSDK_PERIPH_SRC_DIR}/I2S/i2s_reva.c
)
endif()

if (CONFIG_WDT_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/WDT/wdt_common.c
${MSDK_PERIPH_SRC_DIR}/WDT/wdt_me11.c
${MSDK_PERIPH_SRC_DIR}/WDT/wdt_reva.c
)
endif()

if (CONFIG_RTC_MAX32 OR CONFIG_COUNTER_RTC_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/RTC/rtc_me11.c
${MSDK_PERIPH_SRC_DIR}/RTC/rtc_reva.c
)
endif()

if (CONFIG_SOC_FLASH_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/FLC/flc_common.c
${MSDK_PERIPH_SRC_DIR}/FLC/flc_me11.c
${MSDK_PERIPH_SRC_DIR}/FLC/flc_reva.c
)
endif()

if (CONFIG_PWM_MAX32 OR CONFIG_TIMER_MAX32 OR CONFIG_COUNTER_TIMER_MAX32)
zephyr_library_sources(
${MSDK_PERIPH_SRC_DIR}/TMR/tmr_common.c
${MSDK_PERIPH_SRC_DIR}/TMR/tmr_me11.c
${MSDK_PERIPH_SRC_DIR}/TMR/tmr_reva.c
)
endif()
40 changes: 40 additions & 0 deletions Libraries/zephyr/MAX/Source/MAX32660/max32xxx_system.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/******************************************************************************
*
* Copyright (C) 2025 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.
*
******************************************************************************/

#include "max32660.h"
#include "mxc_sys.h"

/*
* This function is called during boot up.
*/
void max32xx_system_init(void) {
/* Switch system clock to HIRC */
MXC_SYS_Clock_Select(MXC_SYS_CLOCK_HIRC);

/* Disable clocks to peripherals by default to reduce power */
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_DMA);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_SPI0);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_SPI1);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_UART0);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_UART1);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_I2C0);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TMR0);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TMR1);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TMR2);
MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_I2C1);
}

0 comments on commit 0a34a87

Please sign in to comment.