Baremetal SysTick_Handler based on KSDK_CMSIS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Baremetal SysTick_Handler based on KSDK_CMSIS

2,362 Views
michaelbubestin
Contributor I

Hi Community,

 

Im starting a project with an KL26Z4 controller. I don't want to use the whole KSDK or PE environment.

I created simple C project including the CMSIS part, startup and linker files provided with the KSDK. I've configured my clock setup in system_MKL26Z4.h and at least the debugger and a LED works .

Next step was to integrate a SysTick_Handler, i thougt it would be an easy task...it is not .

 

There must be some kind of configuration error...but i cant figure it out, maybe you can help.

 

Here is my code (which isnt much..but should be enough for a SysTick Interrupt:

 

main.c:

 

#include "MKL26Z4.h"

#include "board_setup.h"

 

void SysTick_Handler(void){

    /* toogle Led...we are alive */

    GPIOA_PTOR |= (1<<1);

}

 

void main(void){

    board_init(); // Setups PORT_PCR1 and SIMSCGC5

    SysTick_Config(48000000/10000);

    for(;;);

}

 

Attached you can find the files from the KSDK...

Original Attachment has been moved to: startup_MKL26Z4.S.zip

Original Attachment has been moved to: MKL26Z64xxx4_flash.ld.zip

Original Attachment has been moved to: system_MKL26Z4.h.zip

Labels (1)
0 Kudos
9 Replies

1,322 Views
hunter18
Contributor II

Hi Michael,

I have a question. How did you make an interrupt between ON and OFF of the LED? I'm currently have a problem of blinking my led because i cannot execute a delay. Please help me.

Thank you very much!

Best Regards,

Ken

0 Kudos

1,322 Views
michaelbubestin
Contributor I

Hi Community!


Thank you for your support...It was completly my mistake :smileysad:

Code is fine and everything works as expected, since friday. But only after disconnecting a component from the board using the NMI Pin as GPIO. I didn't realized it because in Singlestep Mode, the code works and it seems like the NMI is ignored.

Thank you for your response!

0 Kudos

1,322 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Michael Bubestinger,

    That's good to hear you find the root problem.

    If you connect the NMI pin, and when the NMI have low signal, the mcu will enter in NMI interrupt, and it will break your systick, then your systick will not correct.

    You should use other GPIO pin, unless you disable the NMI pin function from the internal flash.

    Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,322 Views
michaelbubestin
Contributor I

Hi Jingjing,

Thats right! But I never realized that it was a NMI Interrupt because of a break point at for(;;)...In singlestep the NMI didn't trigger..neither the Systick. In Freeruning-Mode and with a correct NMI_Handler the problem was obvious.

0 Kudos

1,322 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Michael Bubestinger,

    When you in full speed run, and set a breakpoint in the NMI_Hander, you will find it enter the NMI interrupt?

    And when you run in single step, you can't find it?

    This is because, if you in single step debug, when the NMI interrupt happens, you didn't run, when you do the next step debug, the NMI interrupt already return, then you won't find it.

    You should work in full speed run with breakpoint, if you want to check the NMI interrupt entering.

  Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,322 Views
yasuhikokoumoto
Senior Contributor I

Hello Michael,

I checked the source code of SysTick_Config() of KSDK1.0.0.

The error case is only that the input parameter is greater than 0x1000000.

Therefore, almost all cases will succeed and it will always cause the SysTick interrupt.

However, the interrupt priority is set to 240.

If a higher priority interrupt than 240 exits, the SysTick interrupt will not be invoked.

But it would not be considered.

From these facts, I think that your GPIO toggling method would be wrong.

Please check it.

Or, is the interrupt really enabled?

I think that it would be no problem because there is 'cpsie i' in the startup routine.

F.Y.I.

#define __NVIC_PRIO_BITS               4

__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) {   if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk)  return (1);      /* Reload value impossible */

  SysTick->LOAD  = ticks - 1;                                  /* set reload register */   NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Systick Interrupt */   SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */   SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |                    SysTick_CTRL_TICKINT_Msk   |                    SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */   return (0);                                                  /* Function successful */ } __STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) {   if(IRQn < 0) {     SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M  System Interrupts */   else {     NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff);    }        /* set Priority for device specific Interrupts  */ }

Best regards,

Yasuhiko Koumoto.

0 Kudos

1,322 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Michael Bubestinger,

    How did you judge your code can't work? Check whether PTA1 is toggling with oscilloscope?

    What the details in your SysTick_Config(48000000/10000);?

    48000000/10000 is what? The systick  reload value? If yes,  and your core clock is 48Mhz, your systick counter period is just about 100us.

  Please give us more details about your question.

  Besides, I have CW KL26_systick project, you can refer to it.

    Wish it helps you!

If you still have question, please contact me!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,322 Views
yasuhikokoumoto
Senior Contributor I

Hello Michael,

what is the return value of SysTick_Config()?

If you would like to use CMSIS API, you should check it.

Is it "0"? Otherwise, some errors might occur.

Anyway, I think you should check whether "GPIOA_PTOR |= (1<<1)" will work without SysTick Interrupt.

Best regards,

Yasuhiko Koumoto.

0 Kudos

1,322 Views
mjbcswitzerland
Specialist V

Hi Michael

I think that you need to show the SysTick_Config() code and/or refer to CMSIS in case of problems - eg. Systick Timer (SYSTICK)

Below is the code from the uTasker project in case you don't make progress with CMSIS:

    #define REQUIRED_MS ((1000/TICK_RESOLUTION))                         // the TICK frequency we require in kHz
    #define TICK_DIVIDE (((CORE_CLOCK + REQUIRED_MS/2)/REQUIRED_MS) - 1) // the divide ratio required (for systick)

    SYSTICK_RELOAD = TICK_DIVIDE;                                        // set reload value to determine the period
    SYSTEM_HANDLER_12_15_PRIORITY_REGISTER |= (SYSTICK_PRIORITY << 24);  // enter the SYSTICK priority
    SYSTICK_CSR = (SYSTICK_CORE_CLOCK | SYSTICK_ENABLE | SYSTICK_TICKINT); // enable timer and its interrupt

Regards

Mark

Kinetis: µTasker Kinetis support

KL26: µTasker Kinetis FRDM-KL26Z support / µTasker Kinetis Teensy LC support

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

0 Kudos