I think I understand that CTLR is the control register, CNT in the counter (64 bit) and CMP is a comparison timestamp that can trigger an interrupt at some point. please tell me if I’m wrong
however, when I tried reading the lower half of CNT, I just consistently outputs a value of 1111 1111 1111 1111 ... 1110 without changing
Do I need to do anything with the control register? Any help is appreciated!
The WCH none os SDK does not set the SysTick to be counting continously. It is only setup in the delay() function, where the the SysTick is programmed to count up to the specified delay value (converted to ticks), after which the timer is started and it is waited to be reached.
This is not the way it would normally be setup in the e.g. Arduino core. Usually it set to trigger in one millisecond intervals, after which a variable is counted up in an interrupt.
If you want to use the SysTick in that regard (as a regular 64-bit counter), you might find the ch32fun code for it interesting, that sets it up properly and ever-counting, just shifting the target “CMP” value for the next trigger.. Of course, once you setup SysTick that way, you need to write your own correct Delay_Ms() function that does not just reset SysTick however it wants.
Thanks for the information! You’re a lifesaver. That is a pretty interesting implementation, making it so that systick will be overwritten by delay_ms(). I’m writing a HAL for luos on my CH32X035. Do you think it makes more sense to write a new delay_ms() with systick in constant operation, or just configure TIM2 to be the constant timer and just crank up it’s speed.
If you don’t want to forbid users to call the original SDK’s Delay_Ms() and Delay_Us function, it’s safer to start a new timer for timestamping. There are even one place in the SDK where they call the function themselves: