Kinetis K10 does not run the code after power reset

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

Kinetis K10 does not run the code after power reset

Jump to solution
1,724 Views
salihbaydan
Contributor I

Dear All ;

I am trying to learn CortexM4 programming on MK10DX256VLL7 chip. I am able to run basic codes when i connected through jlink8 jtag. I download the code to the flash and i can run it easily .. But without changing anything when i cut the power off and repower it , device just does not do anything. And when i try to re download the code to it , keil uvision says again it is a secured kinetis device..

It seems like my code is not be written to the flash memory  .What can i do in order to fix this on keil uvision ?

Regards ,

Salih...

Labels (1)
Tags (4)
0 Kudos
1 Solution
905 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Salih,

Thanks for your information!! I found most part of your code is fine, except void SystemInit(void) , it should disable the watch dog out of reset, so that might be the cause for your issue.

and your rom settings also has some problem, seems it put the vector table starting from 0x10000000, but actually it should be placed at 0x00000000 just like below:

1.PNG

I have ported your code with above modification to TWR-K20D72M, it toggles PTC9 and PTC10 instead of PTB0 and PTB1, and it works well with or without the JTAG attached. Please kindly refer to the attachment for details.

Hope that helps,

Have a nice weekend!!

B.R

Kan

View solution in original post

0 Kudos
4 Replies
905 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Salih,

Would you please send the code for a review? Thanks for your patience!!

B.R

Kan

0 Kudos
905 Views
salihbaydan
Contributor I

#include "MK10D7.H"

#define red_led_loc  (1<<1)

#define red2_led_loc (1<<0)

#define red_led_on    PTB->PSOR =red_led_loc

#define red_led_off   PTB->PCOR =red_led_loc

#define red2_led_on   PTB->PSOR =red2_led_loc

#define red2_led_off  PTB->PCOR =red2_led_loc

void SystemInit(void){

}

       

void Delay(int Ticks){

   int i;  

   for(i=0;i<Ticks;i++)

   {

   }

}

int i ;   

int main (void)

{   

    SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;   

    SIM->SCGC6 |= SIM_SCGC6_PIT_MASK ;

   

///////////////////////////////////////////////////////////////////   

 

    PORTB->PCR[1] = PORT_PCR_MUX(1)   | PORT_PCR_DSE_MASK;

    PORTB->PCR[0] = PORT_PCR_MUX(1)   | PORT_PCR_DSE_MASK;

       

  PTB->PDDR  |= red_led_loc | red2_led_loc ;

   

    PIT->MCR = PIT_MCR_FRZ_MASK    ;

////////////////////

    red_led_off;

    red2_led_off;

   

    NVIC_EnableIRQ( PIT1_IRQn ); //enable interrupts timer1

    PIT -> CHANNEL[1].LDVAL = 0x0003E7FF; // Timer 1 =5 msn

    PIT -> CHANNEL[1].TCTRL =  PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK; //timer interrupt enable , timer enable

       

    while(1){

    }

   

}

void PIT1_IRQHandler(void){   

    i++;

   

    PIT ->CHANNEL[1].TFLG  |= PIT_TFLG_TIF_MASK;

    PIT ->CHANNEL[1].TCTRL  = PIT_TCTRL_TEN_SHIFT;

       

  PIT -> CHANNEL[1].LDVAL = 0x0003E7FF;

    PIT -> CHANNEL[1].TCTRL |=  PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK;

    if (!(i%100) ){

   red2_led_on;   

}

   

    if (!(i%200) ){

   red_led_on;   

}

 

    if (!(i%400)){

  red_led_off;           

    red2_led_off;

}   

}

This code is working on my prototype board right now after i download it to the chip with my Jlink8 . But when i cut the power and power it again , it does not start . Also you can see attached photos for my rom settings on keil...

Many thanks ,

Salih...



0 Kudos
906 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Salih,

Thanks for your information!! I found most part of your code is fine, except void SystemInit(void) , it should disable the watch dog out of reset, so that might be the cause for your issue.

and your rom settings also has some problem, seems it put the vector table starting from 0x10000000, but actually it should be placed at 0x00000000 just like below:

1.PNG

I have ported your code with above modification to TWR-K20D72M, it toggles PTC9 and PTC10 instead of PTB0 and PTB1, and it works well with or without the JTAG attached. Please kindly refer to the attachment for details.

Hope that helps,

Have a nice weekend!!

B.R

Kan

0 Kudos
905 Views
salihbaydan
Contributor I

Hi Kan ,

Thank you very much , magic is here at Watch Dog section of your code..

void SystemInit(void){ 

    /* Write 0xC520 to the unlock register */

    WDOG->UNLOCK = 0xC520;

    /* Followed by 0xD928 to complete the unlock */

    WDOG->UNLOCK = 0xD928;

    /* Clear the WDOGEN bit to disable the watchdog */

    WDOG->STCTRLH &= ~WDOG_STCTRLH_WDOGEN_MASK;

   

It is really painfull to get used to ARM cores after working on 8 bit MCUs . But we can move on eaiser on Freescale because you have better and simple documentation than others Smiley Happy . I will be back here soon with some other peripherals questions.

B.R.

Salih..

0 Kudos