Kinetis MKL05Z dies after trying to implement STOP mode

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Kinetis MKL05Z dies after trying to implement STOP mode

2,430件の閲覧回数
rampsr
Contributor III

Trying to program a STOP mode on the MKL05Z microcontroller using codewarrior 10.3. When I try to send the processor into stop mode, my MKL05Z no longer functions and seems bricked. In other words, the board no longer programs or is detected by the Universal PE multilink. I use the 3V, GND, SWD_DIO, SWD_CLK, and SWD_RESET pins to program my board. Works great until I started to write code to go into stop mode.

I wrote the following command:

Cpu_SetOperationMode(DOM_STOP, NULL, NULL);

I have done this with two microcontrollers now and am about to solder on another one to start testing.

I'm not using the Freedom boards. I have my own circuit designed and am starting the prototype phase as well as firmware. I've eliminated all components except a 3V linear regulator, a couple caps, and the processor. Still becomes dead after setting into Stopmode.

I am using some processor expert commands, but where greater efficiency is needed have avoided using processor expert. Especially when pinouts and their functions are remapped depending on what voltage divider value I read from a pair of resistors which are read at startup.

I've switched from the HC08 family to the kinetis family on my designs and going through a new learning curve. Hopefully I am just doing something wrong and someone can tell me the correct way to put the processor into a stop mode. I should also note that I am not using an OS other than my own roundrobin.

ラベル(1)
タグ(2)
0 件の賞賛
14 返答(返信)

1,185件の閲覧回数
rampsr
Contributor III

I think I solved my issue and discovered a possible bug in Codewarrior 10.3 or Processor Expert.

I simply started a new project, set the STOP mode in processor expert to LLS (good enough for me). I set the LLWU to wake on LPTMR0. I set the LPTMR to 5000ms.

In my code I periodically check for a Low Voltage Warning. When detected, I enter my STOP mode by calling "Cpu_SetOperationMode(DOM_STOP, NULL, NULL);". I hold a good charge around 2V from a 22uF cap. After my LPTMR interrupts, I come out of STOP mode with no problems.

Now I went ahead and started to add components. When i added my DAC, I ran into problems. Here is what I ultimately discovered.

My DAC is enabled and initialized by processor expert by setting the "Enabled in init. code"  & "auto initialization" to YES.

Now before I enter STOP mode, I want to disable the DAC. However, when I use processor expert to disable the DAC by calling: DA1_Disable(NULL); the program crashes. Atleast that is what it appears because in the debug mode, it enters the following ISR:

PE_ISR(Cpu_Interrupt)

{

  /* This code can be changed using the CPU component property "Build Options / Unhandled int code" */

  PE_DEBUGHALT();

}

However, if I simply do the following command instead, everything works just fine:

DAC_PDD_EnableDevice(DAC0_BASE_PTR,PDD_DISABLE); /* Disable device */

DAC_PDD_EnableDevice(DAC0_BASE_PTR,PDD_ENABLE); /* Disable device */

(of course I added #include "DAC_PDD.h" to the list of includes as well)

What I thought was the STOP mode not working correctly all this time was actually the processor expert function: DA1_Disable(NULL) that was causing the program to crash before entering stop mode. So on my scope, it never held a charge on the cap.

Is this a bug in Processor Expert?


0 件の賞賛

1,185件の閲覧回数
chris_brown
NXP Employee
NXP Employee

Hi rampsr,

This does not look like a bug in Processor Expert.  You are passing this function a NULL pointer when it is expecting an LDD_TDeviceData pointer.  If you have auto enabled and initialized your DAC device, then you should be able to pass DA1_DeviceData to this function and everything should work fine.  By passing a NULL pointer to this function the part is trying to modify a random memory location somewhere but can't because the memory location is somewhere off in the weeds (so to speak).

Hope this helps,

Chris

0 件の賞賛

1,185件の閲覧回数
chris_brown
NXP Employee
NXP Employee

Hi rampsr,

Just wanted to let you know that I will be looking into this.

Thanks,

Chris

0 件の賞賛

1,185件の閲覧回数
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

If the chip wake up from VLLS mode, it need to clear Regulator statu and control register (PMC_REGSC) [ACKISO] bit.

More detailed info, please refer below code as an reference:

        // releases hold with ACKISO:  Only has an effect if recovering from VLLS1, VLLS2, or VLLS3

        // if ACKISO is set you must clear ackiso before calling pll_init

        //    or pll init hangs waiting for OSC to initialize

        // if osc enabled in low power modes - enable it first before ack

        // if I/O needs to be maintained without glitches enable outputs and modules first before ack.

        if (PMC_REGSC &  PMC_REGSC_ACKISO_MASK)

        PMC_REGSC |= PMC_REGSC_ACKISO_MASK;

And I also recommend you to refer KL05 example code [low_power_demo] with below link:

KL05-SC : FRDM-KL05Z Sample Code Package

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FRDM-KL05Z&fpsp=1&tab=Design_Tools_Ta...

Wish it helps.

0 件の賞賛

1,185件の閲覧回数
rampsr
Contributor III

Thanks for the response Hui.

I'm still not sure I grasp the way low power modes are suppose to be handled. Here's all I want it to do.

Low voltage warning detected

Enter Stop Mode

Every few milliseconds, wake up and check if low voltage is still detected.

If so, increment a counter. Enter Stop Mode.

Repeat until no more low voltage warnings detected.

This seemed very easy to do on the HC08 series microcontrollers. I could set the prescaler on a real-time interrupt, turn on the rti, enter stop mode, on exit check LVW flag, inc counter, enter stopmode. Was only like 8 lines of code.

I'm going to have to do a lot of reading tonight.

BTW, I still can't figure out how to revive the 2 microcontrollers that received the command: Cpu_SetOperationMode(DOM_STOP, NULL, NULL);

How can I reprogram those boards? Are they dead?

0 件の賞賛

1,185件の閲覧回数
philip_drake
NXP Employee
NXP Employee

Hello,

You might have changed the security locations (SEC bit) like in the S08 and the part might be secure. But maybe the part is just executing the code you have in the flash.  This might result in the part looking like it's ignoring the debug interface request to re-program.

So, a couple of things to try.

In CW there is a flash tool - look like a lightning bolt.  Try using that tool to erase the part.  You may need to hold down reset while this is going on.  In the factory we have a script used with the jlink tool that will erase and un-secure a part, but we have to hold down reset while the command script is executing.  This method also may work with the CW flasher tool. I'm sorry but I've not tried CW to recover a secure part or a busy part lately.

Also try increasing the VDD to 3.6 V, way above the high LVDW level to get the system out of the enter-stop function you created.

More about stop modes in the kinetis MCUs.  I've written an application note AN4503 about these low power modes. It's a good read, a bit long but very comprehensive.   Comparing them to the S08, the equivalent to STOP3 in Kinetis MCUs is 'Normal STOP'.  The LVD is still active in this mode.

The LVD is programmable for high or low voltage range.  If the voltage is below the LVDW trip level and interrupts are enabled, the MCU will never leave the LVDW  interrupt routine.  If in the interrupt routine you tried to go into STOP the pending LVDW interrupt would prevent this.  So you will have to disable the LVDW interrupt, clear the pending interrupt in the NVIC( the interrupt controller) and then you can go into STOP.  You can set a timer like the LPTMR to wake you up periodically to check the LVDW level.

The low power mode demo code that Hui pointed you too is a good example code to learn by.

Best Regards,

Philip

0 件の賞賛

1,185件の閲覧回数
DustyStew
Contributor V

Philip

I commend you for AN4503, which is pretty good as these things go.

I am using a K20, which would go into Stop mode, but not exit. Having spent 3 hours going through your AN as well as detailed analysis of MCG, PMC, SIM, SMC, PMS, and so on, said FUCK IT, and went back to good old reverse engineering ie trial and error. From this I learned that the MCU would not exit Stop mode if there were break points in the code (CW 10.4).

As well, I dug out the errata, which I had wisely reviewed when I started with the K20, but unfortunately had not noticed that Stop mode doesn't work!  That is, for mask set 1N86B.

Now I have to wonder if this design flaw is not also affecting other mask sets? Maybe EVERY mask set?

Also I wonder why you would not flag this in your document? Sure I understand the concept of separating errata from the functional docs, but in practice, you would better serve your customers by having a footnote referring to the errata. As a developer, I generally assume when something doesnt work, its probably one of the 10,000 configuration bits that is not in the right state.

The design of the register set is convoluted, you know for sure that the designers didn't "get" the idea of object-oriented design. That makes Kinetis difficult to learn. I wish the company would come up with a better system for providing documentation in a way that helps the developer get started.

0 件の賞賛

1,185件の閲覧回数
rampsr
Contributor III

Philip,

Either I'm an idiot (which could be the answer) or there is nothing that explains what stop(); is. I see in your application note stop(); being called but it doesn't exist. I feel like I am on an Easter Egg hunt.

So I have some settings done in Processor Expert and I want to send the processor into VLLS0 stop mode.

So I check the LVW flag to see if it is set (not using an interrupt for it). If it is set I enable my LPTMR and do enter_vlls0(1);

I have copied the code from the application note and codewarrior can't figure out what SMC_VLLSCTRL, SMC_VLLSCTRL_PORPO_SHIFT, or SMC_VLLSCTRL_VLLSM(3) are.

So I looked in the

file Hui recommended and looked under the low_power_demo.c and see that the smc.h file used there has code slightly different than your application note. So I used the code from that smc.h and smc.c file, but they too are calling a stop(); function.

I am unable to locate where or what the stop(); function is.

0 件の賞賛

1,185件の閲覧回数
chris_brown
NXP Employee
NXP Employee

Hi rampsr,

The stop function simply sets the Deep Sleep bit in the ARM core and then executes the WFI instruction.  So it is essentially this:

/* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */

  SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;

  asm("WFI");

Also, I had another thought.  Your project is written completely in Processor Expert correct?  So you are entering a VLLSx mode via the Processor Expert command?  Have you inserted code to service the ACKISO bit in the User Code Before PE Initialization box (CPU Component -> Build Options)?

Hope that helps,

Chris


0 件の賞賛

1,185件の閲覧回数
rampsr
Contributor III

Appsman,

Okay, I see that about the SLEEPDEEP.. Thanks.

I am using Processor Expert to set parameters up. I don't know how to use processor expert to enter VLLS mode though. Is there a method for it in PE?

Also, I have not inserted code to service the ACKISO bit in the user code.

0 件の賞賛

1,185件の閲覧回数
chris_brown
NXP Employee
NXP Employee

Ok.  So that could still be the problem.  If your start-up code was generated using PE then it won't be handling the ACKISO bit correctly.  To fix that, you can insert code in the location I previously described to service that bit.

As for entering VLLSx mode via PE, yes, there is a method for that.  The code for that is as follows:

// Move to VLL Stop Mode

Cpu_SetOperationMode(DOM_STOP, NULL, NULL);

If you want to see some more examples on how to use PE and low power modes, check out the PEx_low_power_demo in the KL25_SC sample code package located here:

FRDM-KL25Z Product Summary Page


0 件の賞賛

1,185件の閲覧回数
rampsr
Contributor III

Alright, I think I got it into NORMAL_STOP and any VLLSx STOP modes using processor expert, and I'm able to come out of it through a LPTMR. However, I am not able to truly get it into a low power setting.

Here's my scenario.

I have a 22 uF storage cap on my Vdd pin on the microcontroller. The 3V on the Vdd is isolated with a diode. So I have 3V on the Vdd and when power goes off, I expect the microcontroller to enter a low power mode, which should allow the 22uF cap to hold a charge long enough to keep the processor running (in low power mode) for several seconds. So when power is re applied, the microcontroller would return from low power mode and continue operating (with slight changes due to entering low power mode in the first place, but that is irrelevant to this discussion). The goal is to keep the processor on long enough so it does not actually power off.

However, when entering STOP_VLLS0,1, or 3 by setting "low power mode" under "STOP operating mode" in processor expert, and having Cpu_SetOperationMode(DOM_STOP, NULL, NULL); called after I check my LVW flag (no interrupt on the LVW). I get about 100ms of time between when the processor enters low power mode and the time the processor is no longer powered.

If I enter Normal_Stop by setting in Processor Expert the low power mode under the "SLEEP operation mode" to "STOP", and call Cpu_SetOperationMode(DOM_SLEEP, NULL, NULL);, I get about 45ms of time before the processor shuts off.

Something is draining the power and it's leaking through the microcontroller. if I remove the micro controller, I get minutes worth of storage time on the cap, so I know the 22uF is isolated properly.

plus, in my older design when using a HC08 QG8 or MP16 processor, I simply check the LVW flag, disable various PIT timers, disable PWM signals, and begin a RTI clock. Then I go into STOP3 mode. When the RTI interrupts, I come out of low power mode, check to see if I am still in LVW, increment counters, and re-enter STOP3 mode. Doing this would allow me about 10 seconds of time in which the processor remains powered.

Anyone have any ideas what I can do to get this Kinetis not to drain my cap in 100ms in Low Power Mode?

0 件の賞賛

1,185件の閲覧回数
rampsr
Contributor III

Philip,

Thanks for this response. I will try to reflash the microcontrollers that I deemed as dead later tonight or tomorrow morning. I will check out the application notes you recommended as well. I'm sure when I have this all figured out I'll look back at it all and wonder "what was a thinking!". I'm more of an electronics geek than a programming geek, even though I started programming on the commodore 64 in the early 80s (I still have about 100 5.25" disks that have probably been demagnetized by now). I should have kept up with the coding...

When I get things resolved, I'll come back on here and post my results and whether I resurrected my microcontrollers.

0 件の賞賛

1,185件の閲覧回数
JimDon
Senior Contributor III

>In the factory we have a script used with the jlink tool

Are you saying that Freescale uses a Segger jlink in your factory?

Just wondering....

0 件の賞賛