Need help with SysTick interrupt on a FRDM-KL43Z board

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Need help with SysTick interrupt on a FRDM-KL43Z board

3,618 次查看
pramodchanderse
Contributor I

Hi Guys,

     I am moving to a Kinetis L series from STM32 and very confused. Hope someone can help me out.

 

     All I am trying to do is use the SysTick Interrupt to toggle an LED. I got the LED setup working. I can see it toggle using the debugger while I am stepping thru. But I just do not seem to be able to get the SysTick Interrupt to work.

     I am attaching my code. Any help is greatly appreciated.

 

 

Thanks

Pramod

 

 

 

Original Attachment has been moved to: main.c.zip

标记 (1)
0 项奖励
回复
8 回复数

1,973 次查看
pramodchanderse
Contributor I

Hi Everyone,

    I apologize for not posting this earlier - was travelling.

    It seems strange and confusing but it worked after a hard reset - I mean my original code. When I ran it with gdb, gdb first loads the codebase and then does a soft reset of some sort. At that point the Systick timer does not seem to work but after I do a hard reset with the btn on the board the systick timer starts working.

Thanks

Pramod

0 项奖励
回复

1,973 次查看
yasuhikokoumoto
Senior Contributor I

Hi Pramod,

Your main.c seems not to have strange parts.

I think there would be at least 1 check point.


Is the SysTick_Handler properly assigned to the vector?

How did you assign it to the vector table?

Do you use KDSK? Then, it would automatically assigned.

Otherwise, some procedure for it would be needed.

Best regards.

Yasuhiko Koumoto.

0 项奖励
回复

1,973 次查看
pramodchanderse
Contributor I

Hi Yasuhiko Koumoto,

     I am using the KSDK. I did verify that the SysTick_Handler is installer properly in the NVIC. I dumped the appropriate section from teh elf file and made sure that the right function pointer is installed.

     I tried both with the call to  NVIC_EnableIRQ and without. I also made sure that "cpsie i" is called before. I am lost at this point.

Thanks

Pramod

0 项奖励
回复

1,973 次查看
yasuhikokoumoto
Senior Contributor I

Hello Pramod,

the next possible thing that I can guess is that the interrupt interval is too short.

How about increasing the value of SysTick->LOAD?

Instead the value is increased, the value of (counter%1000) should be decreased.

For example,

SysTick->LOAD  = (ticks*100) - 1;

if ( (counter%10) == 0 ) {

  GPIOE_PTOR |= (0x01 << 31);

}

How do you think?

Best regards,

Yasuhiko Koumoto.


0 项奖励
回复

1,973 次查看
egoodii
Senior Contributor III

A few quick comments:

SysTick is NOT an 'NVIC' interrupt -- it is a 'basic' ARM interrupt, on vector 15.  NVIC uses vectors 16 'and up'.  Do NOT try to use the NVIC-interrupt interface routines.  Just create your ISR vector directly in the table, at #15.

.

.

.

DCDPendSV_Handler       ; PendSV Handler #14
DCDSysTick_Handler      ; SysTick Handler #15
; External Interrupts
DCDDMA0_IRQHandler      ; 0:  DMA Channel 0 transfer complete #16, NVIC #0

.

.

.

My handler, with an optional 'scope hook' on GPIOC16:

void SysTick_Handler(void)

{

    {

//  GPIOC_PSOR = 1<<16;

        tick_flag = TRUE;

        if( TST_dly != 0 )

            TST_dly--;                              //Timeouts within test state machine

//  GPIOC_PCOR = 1<<16;

    }

}

The count runs from the CPU instruction-clock, so you will need a BIG number to toggle at a rate you can see -- probably something > 10million.:

SYST_RVR = (core_clk_khz * 1000L / TICKS_PER_SECOND) - 1;
SYST_CVR = 0;
SYST_CSR = SysTick_CSR_TICKINT_MASK | SysTick_CSR_ENABLE_MASK | SysTick_CSR_CLKSOURCE_MASK;

But note that SYST_RVR (etc) is a 24-bit counter setup, so limited to about 16 million (or about 6 interrupts per second from 100MHz, at the longest).

As a final note, one need NEVER '|=' to the direct-bit-control GPIO registers -- as in this case, PTOR.  The mere existence of the proper '1' bit implements the function, and they always READ as zero -- so Read/Modify/Write is a WASTE of time.

0 项奖励
回复

1,973 次查看
mjbcswitzerland
Specialist V

Hi Pramod

You have enabled the interrupt in the NVIC but have you enabled it to the core?

__asm__("cpsie i")

With regard to the SysTick, STM32 and Kinetis code is identical.

Regards

Mark

Kinetis: µTasker Kinetis support

KL43: µTasker FRDM-KL43Z support / µTasker TWR-KL43Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 项奖励
回复

1,973 次查看
pramodchanderse
Contributor I

Mark,

       I am writing this code on top of the startup code from the Kinetis SDK. But I did verify the startup sequence and in the ResetHandler before main is called "cpsie i" is invoked.

       And I understand that since the NVIC is really on the ARM core the code should be identical hence the "I am confused" part :smileyhappy: because the same code works fine on stm.

       My next step I think would be to verify the register values directly. Could you point me to freescale documentation on the arm code. Most of the Reference manuals only talk about the peripherals but give very little detail about the ARM core.

Thanks

Pramod

0 项奖励
回复

1,973 次查看
mjbcswitzerland
Specialist V

Hi Pramod

The best source for information about the core (including SYSTICK) is on the ARM web site.

ARM Information Center

Regards

Mark

Kinetis: µTasker Kinetis support

KL43: µTasker FRDM-KL43Z support / µTasker TWR-KL43Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 项奖励
回复