AmbiqSuiteSDK
AmbiqSuiteSDK copied to clipboard
Cannot Fully Enable Compare Interrupts on STimer
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:
And bit 0 of STMINTEN:
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()
This issue persists in AmbiqSuite SDK 2.5.1 and does not have a patch branch
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);