Well, 24 or more clock cycles do not concern me either.
But you are right, looks like not even IDLE is an option.
While looking around I found this:
https://microchipdeveloper.com/32arm:samd21-systickI currently have the datasheets for SAM C2x, E5x and D21 open and these have close to no information about SysTick.
All three say that SysTick is clocked by CLK_CPU while the page above says it is clocked by AHBCLK for the SAM D21.
CLK_CPU makes more sense though since SysTick is part of the core.
And CLK_CPU is stopped in all modes except ACTIVE.
There is no indication in the datasheets what would happen if the clocksource bit is not set.
So I just changed my SAM E51 code to this:
void init_systick(uint32_t ticks)
{
SysTick->CTRL = 0;
SysTick->LOAD = ticks - 1U; /* set the reload register */
SysTick->VAL = 0; /* clear current counter value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; /* enable systick */
}
int main(void)
{
uint8_t led_delay = 0;
init_clock();
init_io();
init_systick(120000000 / 200); /* configure and enable Systick for 5ms ticks */
CMCC->CTRL.bit.CEN = 1; /* enable Cache-Controller */
while (1)
{
if(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)
{
// system_tick = 0;
led_delay++;
It works and also replacing SysTick_Config() to not even enable the systick interrupt saves 32 bytes of program memory in total.
There really is no argument to make for saving 32 bytes out of 128 kiB, 256 kiB or even 512 kiB flash.
I am even compiling with -O2 now as my software runs faster while the binary is a little bigger.
A few clock cycles also do not make any difference for me now.
Well, my argument to be able to use sleep this way seems to be invalid.
Hmm, I got nothing to argue against this minor improvement so I might just keep it. :-)
Thanks for the tip and the oportunity to have a closer look at this!