Skip to content

feat(PeriphDrivers): Add Clock Setter APIs for MAX32690 & MAX78002 Peripherals, Add Dual Mode TMR Support, Add MAX32690 Clock Calibration API for IPO, Add MAX32690 RISCV Clock Setter, CFS Support Functions #1108

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

Merged
merged 37 commits into from
Aug 9, 2024

Conversation

Jake-Carter
Copy link
Contributor

@Jake-Carter Jake-Carter commented Aug 9, 2024

Description

This PR adds various APIs and features to support CFS clock config code generation.

Primarily, this includes clock setter APIs.

Since many of the peripheral's Init APIs also configure the clock source, a locking mechanism was developed to allow the CFS config to take precedence. This is a temporary solution until CFS can perform full peripheral configuration, which is in the roadmap.

Additionally, it adds the weak ClockInit() function to the system startup code. CFS will override this function.

This PR also adds dual-mode TMR support. The process involves initializing the TMR instance twice, once with the 16A bit-mode config, and once with the 16B bit-mode config.

Dual-Mode Example
/******************************************************************************
 *
 * Copyright (C) 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.
 *
 ******************************************************************************/

// Dual mode timer configuration example for MAX78002.

/***** Includes *****/
#include <stdio.h>
#include <stdint.h>
#include "mxc_device.h"
#include "led.h"
#include "board.h"
#include "tmr.h"
#include "nvic_table.h"

/***** Definitions *****/

/***** Globals *****/

/***** Functions *****/
void TMR_ISR(void)
{
    uint32_t flags = MXC_TMR_GetFlags(MXC_TMR0);
    if (flags & MXC_F_TMR_INTFL_IRQ_A) {
        LED_Toggle(0);
        MXC_TMR0->intfl |= MXC_F_TMR_INTFL_IRQ_A;
    }
    
    if (flags & MXC_F_TMR_INTFL_IRQ_B) {
        LED_Toggle(1);
        MXC_TMR0->intfl |= MXC_F_TMR_INTFL_IRQ_B;
    }
}

// *****************************************************************************
int main(void)
{
    mxc_tmr_cfg_t tmr0a_cfg = {
        .bitMode = MXC_TMR_BIT_MODE_16A,
        .clock = MXC_TMR_APB_CLK,
        .cmp_cnt = MXC_TMR_GetPeriod(MXC_TMR0, MXC_TMR_ISO_CLK, 128, 1),
        .mode = MXC_TMR_MODE_CONTINUOUS,
        .pol = 0,
        .pres = MXC_TMR_PRES_128
    };

    mxc_tmr_cfg_t tmr0b_cfg = {
        .bitMode = MXC_TMR_BIT_MODE_16B,
        .clock = MXC_TMR_APB_CLK,  
        .cmp_cnt = MXC_TMR_GetPeriod(MXC_TMR0, MXC_TMR_ISO_CLK, 128, 2),
        .mode = MXC_TMR_MODE_CONTINUOUS,
        .pol = 0,
        .pres = MXC_TMR_PRES_128
    };

    MXC_TMR_Init(MXC_TMR0, &tmr0a_cfg, false);
    MXC_TMR_Init(MXC_TMR0, &tmr0b_cfg, false);

    MXC_TMR_EnableInt(MXC_TMR0);
    NVIC_EnableIRQ(TMR0_IRQn);
    MXC_NVIC_SetVector(TMR0_IRQn, TMR_ISR);

    MXC_TMR_Start(MXC_TMR0);
}

This RISCV system clock input can now also be set with MXC_SYS_RISCVClockSelect.

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

- Remove mismatched clock source options
- Fix MXC_UART_SetClockSource implementation to actually work
- Fix and simplify MXC_UART_SetFrequency
- Improve RevB abstraction of clock options.  RevB does not have any
  knowledge of what the top-level clock frequencies are.
- Add MXC_UART_Enable to turn on the peripheral clock.  The peripheral
  clock must be turned on before writing to any of the UART registers is
possible.
- Add lock/unlock APIs for locking the UART clock source after setting
  with MXC_UART_SetClockSource.
- Add MXC_UART_GetClockSource for retrieving the actual value of the
  UART clock at run-time.  Required to get the initialization working
properly with the lockers.
- Prescalar offset was incorrect for bitmode 16B
- Disabled automatic start of 16B on Init.  TMR_Start now starts 16A
  and 16B if they are enabled
- TMR_Stop now stops both 16A and 16B
- Avoid resetting for 16A/16B modes, since those modes require two
  separate Init calls.  A full peripheral reset would wipe the previous
initalizations
@github-actions github-actions bot added MAX32690 Related to the MAX32690 (ME18) MAX78002 Related to the MAX78002 (AI87) labels Aug 9, 2024
Comment on lines +156 to +157
* @note (Developers): "mxc_usb_clock_t" should be defined as a macro in the top-level "max32xxx.h" file
* so that the pre-processor can check for its existence. Ex:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this note to the header device files (max32690.h)? Some developers only pull the CMSIS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jake-Carter Jake-Carter changed the title feat(PeriphDrivers): Add Clock Setter APIs for MAX32690 & MAX78002 Peripherals, Add Dual Mode TMR Support, Add MAX32690 Clock Calibration API for IPO, Add MAX32690 RISCV Clock Setter feat(PeriphDrivers): Add Clock Setter APIs for MAX32690 & MAX78002 Peripherals, Add Dual Mode TMR Support, Add MAX32690 Clock Calibration API for IPO, Add MAX32690 RISCV Clock Setter, CFS Support Functions Aug 9, 2024
@Jake-Carter Jake-Carter merged commit 3f96590 into analogdevicesinc:main Aug 9, 2024
10 checks passed
sihyung-maxim pushed a commit to analogdevicesinc/hal_adi that referenced this pull request Aug 9, 2024
ozersa pushed a commit to analogdevicesinc/hal_adi that referenced this pull request Sep 11, 2024
ozersa pushed a commit to analogdevicesinc/hal_adi that referenced this pull request Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MAX32690 Related to the MAX32690 (ME18) MAX78002 Related to the MAX78002 (AI87)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants