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()