Called function with SysTick and Current Value Register?

Thread Starter

abcmann

Joined Apr 7, 2021
10
Hello guys,
Im trying to use the timer registers of my ARM Cortex M0 while using my pga970EVM. Unfortionally there aren't any files/Commands refering to using the 3 registers SYST_CSR, SYST_RVR, SYST_CVR. I figured out how these registers are working quite easily: SYST_CVR is set to the Reload Value which is defined by SYST_RVR. When SYST_CSR is enabled, SYST_CVR gets lowered periodically and when reaching 0 its Value is reset to the reload Value. Normally there should be a function which is called as soon as the Current Value Register hits 0 but there is none in my generic firmware. The link provides the information I have on these registers.

Cortex-M0 Devices Generic User Guide (arm.com)

Do I have to write a function my own? If so how can i do it?
I already tried checking the CVR hitting 0 with an if-function: if(SYST_CVR==0x00000000) but everything if this loop never got triggered.
Regards, Paul
 

mckenney

Joined Nov 10, 2018
125
Somewhere in your source base there should be an array which serves as the Interrupt Vector Table. [Clues: The first word is the initial stack and the second the Reset entry point.] One of those entries, probably the 16th, is the function that's called for a SysTick interrupt -- you can just define a function by that name. It might also be 0, in which case you should invent a name and use that.

One of the small joys of the Cortex-M is that ISRs aren't special at a C-code level. They're coded like ordinary functions, and the return point stored in the stack tells the CPU that it's an ISR so it can do the RETI stuff.

Your other thread referred to a function "SYST_Handler". This name has the "look" of a designated interrupt handler.
[Edit: I got mixed up -- the RETI indicator is stored in LR, not the stack.]
 
Last edited:

Thread Starter

abcmann

Joined Apr 7, 2021
10
Somewhere in your source base there should be an array which serves as the Interrupt Vector Table. [Clues: The first word is the initial stack and the second the Reset entry point.] One of those entries, probably the 16th, is the function that's called for a SysTick interrupt -- you can just define a function by that name. It might also be 0, in which case you should invent a name and use that.

One of the small joys of the Cortex-M is that ISRs aren't special at a C-code level. They're coded like ordinary functions, and the return point stored in the stack tells the CPU that it's an ISR so it can do the RETI stuff.

Your other thread referred to a function "SYST_Handler". This name has the "look" of a designated interrupt handler.
[Edit: I got mixed up -- the RETI indicator is stored in LR, not the stack.]
Thank you for your answer,
I've experimented with the SYST_Handler function but the function only executes when called. But using the Timer it should be called periodically without mecalling it in main myself.
Searching for the Interrupt Vector Table which i wasn't able to find, I discovered these registers. Their values seem to be static and are never refferenced to in the whole programm.

ISER 0x000000FD Interrupt Set-Enable Register [Memory Mapped]
ICER 0x000000FD Interrupt Clear-Enable Register [Memory Mapped]
ISPR 0x00000003 Interrupt Set-Pending Register [Memory Mapped]
ICPR 0x00000003 Interrupt Clear-Pending Register [Memory Mapped]
IPR0 0x80400000 Interrupt Priority Register [Memory Mapped]
IPR1 0xC0C0C0C0 Interrupt Priority Register [Memory Mapped]

When i wrote this post, I updated the generic firmware from 1.5 to 1.6, but the update dispenses completly on any Sys_timer functions leaving me with nothing but the SySTick Registers :
SYST_CSR 0x00010001 SysTick Control and Status Register [Memory Mapped]
SYST_RVR 0x0000FFFF SysTick Reload Value Register [Memory Mapped]
SYST_CVR 0x0000FCDD SysTick Current Value Register [Memory Mapped]
These Registers work as desired but I am searching for a function which is called everytime SYST_CVR resets.
 

mckenney

Joined Nov 10, 2018
125
How are you starting the SysTick? I.e. what values do you put into the registers?

As I recall, there's no separate ISER bit for SysTick, rather setting TICKINT enables the IRQ (through the NVIC). A typical startup would set CSR=7 (CLKSOURCE=1 [sysclock], TICKINT=1 [IRQ enable], ENABLE=1 [timer enable]).

Poking around at TI, I was a bit surprised how thin the support was for the Cortex-M0 in the PGA970. Were you able to find a set of CMSIS header files? (E.g. core_m0.h, cmsis_gcc.h) Those would make things a lot easier.
 

Thread Starter

abcmann

Joined Apr 7, 2021
10
I've started the Timer with the default/typical start value if 0x00000007 as you said. For RVR I chose a smaller value of 0x0000FFFF.
I attachedthe startup_ccs.c since there are some informations on the SysTick function and there is another sysTick function declared. Sadly I couldn't get that one to work as well, as replacing the introduced IntDefaultHandler (which is decalred to be the M0 System timer handler in this file) with my own handler lead to several Errors (The file doesn't seem to be included in the project somehow). I also built in a counter to see if the IntDefaultHandler is executed sometime but CCS isn't able to show me the value of variables used in that file(even when defined global).

I also attached the arm_m0.h but had to rename it as TXT since I wasn't allowed to upload .h files. Searching for CMSIS didn't lead to any results.
 

Attachments

mckenney

Joined Nov 10, 2018
125
with my own handler lead to several Errors
Did you remember to declare "extern void SYST_Handler(void);"?

That startup_ccs.c looks like what you want, but if you're concerned you didn't get the right copy you can check your .MAP file to see what file was loaded at 0x08000000 (or maybe 0x00000000).

The arm_m0.h does look pretty thin. Are you using CCS to build this?
 

Thread Starter

abcmann

Joined Apr 7, 2021
10
Yes I did remember that. I was missing the declaration of that function in my main.h, I can build the code now but my Counter remains at 0 all the time...

Yeah I thought so too, I feel likeI am so close to the solution yet so far.
Yes I am using CCS.
 

mckenney

Joined Nov 10, 2018
125
A couple of things to try:
1) Set COUNTFLAG=1 (CSR=0x10007) and see if it "sticks". If it does, the addresses in arm_m0.h might be wrong.
2) Set CLKSOURCE=0 (alternate clock). I vaguely recall seeing one Cortex-M configured so only the "alternate" worked.
 

Thread Starter

abcmann

Joined Apr 7, 2021
10
1)The Countflag doesn't have to be put in manually since its getting set by my code. But it appears to never be reset. Any guesses on what could be wrong in arm_m0.h?
2) tried alternate clock before but in both cases nothing happens
 

mckenney

Joined Nov 10, 2018
125
The point was that COUNTFLAG is read-only so if you write 0x10007 you should read back 0x00007. If that's not what happens, that suggests you're not actually writing the SysTick CSR.

I put in a request at TI for the full datasheet yesterday, but I haven't heard anything so I'm not optimistic.
 

Thread Starter

abcmann

Joined Apr 7, 2021
10
When writing 0x10007 it stays at excatly the same value.
Since resetting the Countflag seems to be the problem, I wrote:
if(SYST_CSR==0x10007)
{
DoSomething();
SYST_CSR=0x00007;
}
I don't really know how much accuracy im losing to this but when set into an interrupt it shouldn't be too much does is?
 
Top