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

Cannot Fully Enable Compare Interrupts on STimer #6

Open
Wenn0101 opened this issue May 15, 2020 · 2 comments
Open

Cannot Fully Enable Compare Interrupts on STimer #6

Wenn0101 opened this issue May 15, 2020 · 2 comments

Comments

@Wenn0101
Copy link

Wenn0101 commented May 15, 2020

Quick Steps to Reproduce:

    am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
    am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ);
    am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREA);
    am_hal_stimer_compare_delta_set(0, 50000);
  • observe no interrupt fired

Description
There are 2 bits that need to be set in order to actually enable sTimer compare interrupts
One is in STCFG, the other is in STMINTEN. The HAL only provides access to STMINTEN, thus you cannot enable sTimer Compare Interrupts using just the HAL.

So for example, if you wanted to use Compare A you would need to set both bit 8 of STCFG:
stimerSTCFG
And bit 0 of STMINTEN:
stimerSTINTEN

Calling:

am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREA);

Allows user to set STMINTEN, but the HAL provides no way of setting the bit in STCFG.

void
am_hal_stimer_int_enable(uint32_t ui32Interrupt)
{
    //
    // Enable the interrupt at the module level.
    //
    CTIMERn(0)->STMINTEN |= ui32Interrupt;
}

In am_hal_stimer_compare_delta_set() we see:

CTIMER->STCFG |= cfgVal & (AM_HAL_STIMER_CFG_COMPARE_A_ENABLE << ui32CmprInstance);

However, since it is masked with its starting value, the bit is never set.

Suggestions:

  • Set the bit in am_hal_stimer_compare_delta_set() regardless of starting value
  • Set the appropriate bit in am_hal_stimer_int_enable()
@oclyke oclyke changed the title Cannot properly enable compare interrupts on sTimer Cannot Fully Enable Compare Interrupts on STimer May 15, 2020
@oclyke oclyke added the 2.5.1 label Oct 5, 2020
@oclyke
Copy link
Contributor

oclyke commented Oct 5, 2020

This issue persists in AmbiqSuite SDK 2.5.1 and does not have a patch branch

@RichardSWheatley
Copy link

RichardSWheatley commented Nov 16, 2021

The comment above is false "One is in STCFG, the other is in STMINTEN. The HAL only provides access to STMINTEN, thus you cannot enable sTimer Compare Interrupts using just the HAL."

You have access to STCFG in am_hal_stimer_config.

am_hal_stimer_config(uint32_t ui32STimerConfig) { ... CTIMER->STCFG = ui32STimerConfig;

That would mean you would need to set up the am_hal_stimer_config input parameters properly using one of these:

#define AM_HAL_STIMER_CFG_COMPARE_A_ENABLE  _VAL2FLD(CTIMER_STCFG_COMPARE_A_EN, CTIMER_STCFG_COMPARE_A_EN_ENABLE)
#define AM_HAL_STIMER_CFG_COMPARE_B_ENABLE  _VAL2FLD(CTIMER_STCFG_COMPARE_B_EN, CTIMER_STCFG_COMPARE_B_EN_ENABLE)
#define AM_HAL_STIMER_CFG_COMPARE_C_ENABLE  _VAL2FLD(CTIMER_STCFG_COMPARE_C_EN, CTIMER_STCFG_COMPARE_C_EN_ENABLE)
#define AM_HAL_STIMER_CFG_COMPARE_D_ENABLE  _VAL2FLD(CTIMER_STCFG_COMPARE_D_EN, CTIMER_STCFG_COMPARE_D_EN_ENABLE)
#define AM_HAL_STIMER_CFG_COMPARE_E_ENABLE  _VAL2FLD(CTIMER_STCFG_COMPARE_E_EN, CTIMER_STCFG_COMPARE_E_EN_ENABLE)
#define AM_HAL_STIMER_CFG_COMPARE_F_ENABLE  _VAL2FLD(CTIMER_STCFG_COMPARE_F_EN, CTIMER_STCFG_COMPARE_F_EN_ENABLE)
#define AM_HAL_STIMER_CFG_COMPARE_G_ENABLE  _VAL2FLD(CTIMER_STCFG_COMPARE_G_EN, CTIMER_STCFG_COMPARE_G_EN_ENABLE)
#define AM_HAL_STIMER_CFG_COMPARE_H_ENABLE  _VAL2FLD(CTIMER_STCFG_COMPARE_H_EN, CTIMER_STCFG_COMPARE_H_EN_ENABLE)
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ | AM_HAL_STIMER_CFG_COMPARE_A_ENABLE);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants