S32K148 - Cannot program or erase flash

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

S32K148 - Cannot program or erase flash

5,886件の閲覧回数
tomasfrcek
Contributor III

Hello,

I am using Keil IDE and Keil ULINKPro probe to program S32K148. I added Watchdog function to my application as described in the reference manual:

int main(void)

{

      WDOG->CNT = 0xD928C520;                      //unlock watchdog
      WDOG->CS &= ~WDOG_CS_EN_MASK;  //disable watchdog

      // Modules initialization

      ...

      WDOG->CNT = 0xD928C520;                                                    //unlock watchdog
      while((WDOG->CS & WDOG_CS_ULK_MASK) == 0) { ; }        //wait until registers are unlocked
      WDOG->TOVAL = 256;                                                                //set timeout value
      WDOG->CS = WDOG_CS_EN(1) | WDOG_CS_CLK(1) | WDOG_CS_INT(1) | WDOG_CS_WIN(0) |       WDOG_CS_UPDATE(0);
      while((WDOG->CS & WDOG_CS_RCS_MASK) == 0);             //wait until new configuration takes effect

      while (1)

      {

            IRQ_Disable(); // disable global interrupt
            WDOG->CNT = 0xB480A602; // refresh watchdog
            IRQ_Enable(); // enable global interrupt

            // main loop

            ...

      }

}

However after programming I can no longer program or erase the MCU flash using the Keil IDE (I only get the SWD communication error message). I susspect my watchdog initialization or feeding mechanism is wrong and the MCU is stuck in some kind of a reset loop.

Is there something terribly wrong with the watchdog in my application? And is there a way to erase the MCU flash so that I can access it again?

Thanks!

タグ(3)
10 返答(返信)

4,224件の閲覧回数
adithyamanjunat
Contributor I

Hello Again,

Now I have answer to what happened in my case.

1. The port configuration in my case did not contain the JTAG configuration. It is a must that you add these Pin configuration either manually or automatically when Port module is added to your configuration in EB Tresos (See under Default Recommended Configurations -> select PortRecConfiguration_JtagPins and add Port module). This was the main reason for the JTAG/SWD debug connection failure and not the watchdog.

2. The NotUsedPortPin was configured as IN.

3. In absence of the above code snippet for disabling watchdog, the function Port_Port_Ci_Init_UnusedPins() (called from Port_Port_Ci_Init()) never successfully completed because of watchdog resetting the system within 8ms.

4. After disabling the watchdog the Port_Port_Ci_Init_UnusedPins() changed all JTAG pins to IN configuration and it lost the connection to the debugger. In my case I am using the SWD mode for debug using the Open SDA interface (S32K148EVB).

 

To recover

1. Download Kinetis recovery utility from https://www.pemicro.com/login.cfm?from_url=http%3A%2F%2Fwww%2Epemicro%2Ecom%2Fdownloads%2Fdownload_f... 

2. Make sure EVB is powered using 12V adapter and USB is connected to computer. All jumpers must be placed as per details in Quick start guide.

3. Launch the Kinetis utility, Select OpenSDAUSB under Test Hardware and SWD under communication. Click on Start.

4. Use should able to see the message "Continuously attempting to halt processor" and "Please try power cycling your board until this operation is sucessful" in the Kinetis utility console.

5. Remove the 12V adapter and reconnect. Now the message "Success. Process halted" is printed on the console. Close the Kinetis utility.

6. Reprogram the new software using NxpS32 Design Studio.

References:

1. Recovering Bricked Boards (FRDM, Reset, SWD and Low Power) 

2. Bricking and Recovering FRDM-KL25Z Boards: Reset, SWD Clock and Low Power | MCU on Eclipse 

Good luck,

Adithya M

0 件の賞賛
返信

4,224件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,

I’ve just noticed that by writing to the CS register like you did, without the first OR operator,

WDOG->CS = WDOG_CS_EN(1) | WDOG_CS_CLK(1) | WDOG_CS_INT(1) | WDOG_CS_WIN(0) |  WDOG_CS_UPDATE(0);

you disable the support for 32-bit refresh/unlock command (CS[CMD32EN] = 0).

 

So, any 32-bit write to the CNT register restarts the MCU instead of feeding the WDOG.

 

Regards,

Daniel

0 件の賞賛
返信

4,224件の閲覧回数
tomasfrcek
Contributor III

Hello, Daniel,

thank you for insight and sorry for late response. I will keep that in mind next time I try to modify the Watchdog function. Unfortunately, I still havent received the PE Multilink in order to try and erase/reprogramm the chip in the S32 Studio. I still can't make it work using the Keil ULink Pro.

Regards,

Tomas

0 件の賞賛
返信

4,224件の閲覧回数
adithyamanjunat
Contributor I

Hello Everybody,

I have unfortunately ended up in the same situation. I am using the on-board debugger in the evaluation board NxpS32148-q176 connected to my computer using USB. PE-MICRO debugger (gdb) software which is part of Design Studio is used.The Open SDA is not able to connect to target processor and I suspect watchdog has brought the MCU to a state which does not respond anymore to debugger chip. I am disabling the watchdog after start up code in main() as below. This code has worked in another set up but after programming this change it failed to connect in my current set up

WDOG->CNT=0xD928C520; /* Unlock watchdog */
WDOG->TOVAL=0x0000FFFF; /* Maximum timeout value */
WDOG->CS = 0x00002100; /* Disable watchdog */

Any updates on the solution is appreciated.

regards,

Adithya

4,224件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Tomas,
The WDOG is enabled out of reset and can be reconfigured only once unless SC[UPDATE] bit is set during the first reconfiguration, in that case it can be updated or reconfigured later.
I see in the code you posted that you reconfigure the WDOG twice and the first time the SC[UPDATE] bit is not set, also, you it doesn't wait for ULK = 1. 

I don't use Keil IDE and Keil ULINKPro probe. Have you tried to reprogram the MCU with OpenSDA and S32 Design Studio?

Regards,
Daniel

0 件の賞賛
返信

4,224件の閲覧回数
tomasfrcek
Contributor III

Hello, Daniel,

It's me again :smileyhappy: Unfortunatly I couldn't flash or erase the MCU in S32 studio, because I don't have any of the supported probes (I only have the ULINKPro from Keil). I am currently waiting for for the PEMicro USB Multilink FX. I'm hoping to be able to erase the programm Flash with this probe in the S32 studio as I can't currently do that with the ULINKPro in Keil.

When I was working with the LPC17xx, I was able to erase the flash with the Flash Magic tool and ULINK2 probe, unfortunatly Flash Magic does not support S32K MCUs and I couldn't find any other utility that would achieve this for the S32K MCUs.

Regards,

Tomas

0 件の賞賛
返信

4,224件の閲覧回数
robertboys
Contributor IV

Hello

The first problem I see is you need to get the SWD connection working.

The ULINKpro should work fine.

uVision supports P&E and also CMSIS-DAP.

In this document:  www.keil.com/appnotes/docs/apnt_305.asp

Page 7 describes how to get P&E working and Page 8 for CMSIS-DAP.

CMSIS-DAP file is attached.

I also had some problems - maybe with a 12 volt power supply it worked better ?

Also try these settings:

or Try Reset: Auto

  pastedImage_1.png

I have it working perfectly now with CMSIS-DAP.

Check these settings:

pastedImage_2.png

Thanks

Bob Boys

bob.boys@arm.com

0 件の賞賛
返信

4,224件の閲覧回数
tomasfrcek
Contributor III

Hello, Bob,

thank you for your reply. When I connect with the ULINKpro, I see under Debug->Settings the ULINKpro probe, but can't see the SW Device anymore. I tried to connect using the CMSIS-DAP and ULINK2 probe and I was able to detect both the Adapter and the SW Device. In the settings tab I set both settings you suggested (SYSRESETREQ and Autodetect). The settings in the startup file are the same as you posted. When trying to erase the chip, I am receiving RDDI-DAP error or the following error: Could not stop Cortex-M device, please check JTAG cable. I don't know what to do with the s19 file. We are using our custom PCB with S32K148 MCU, not the eval board.

Regards,

Tomas

0 件の賞賛
返信

4,224件の閲覧回数
robertboys
Contributor IV

Hello

If you are using a custom board and did not install a CMSIS-DAP processor - then you are unable to use CMSIS-DAP.s19 file.

I tried to connect to the 148 eval board and i had similar problems you experience.

I tried different RESET settings and slowed down the clock.  I had RDDI-DAP error (means CMSIS-DAP can't see target chip - usually because it is not powered or in a funny reset state) and can't stop target.  I cycled the target power  many times.  Using 12 volts appeared to help but I do not need this today.

pastedImage_2.png

I tried many things (using CMSIS-DAP OpenSDA) and it suddenly worked and now it works perfectly....even with a ULINKpro.  Twice uVision notified me the device was locked and I allowed it to unlock it.

With ULINKpro - try a new USB cable and being very careful not to disturb the battery - remove the case and un-connect and connect the 20 pin cable - I have seen a very few of these with perhaps bad connection ?

If you try something and fail - sometimes it might help to re-power the board and/or the debug adapter.

If you have a Segger J-Link - you might try this.

I just tried it all now and both CMSIS-DAP and ULINKpro work perfectly.  I have no idea why I had all the trouble yesterday.  I had never seen this before working with 144 or 148 board.  If you come to any conclusions, please let me know.

Thanks

Bob Boys

bob.boys@arm.com

San Mateo, California

0 件の賞賛
返信

4,224件の閲覧回数
tomasfrcek
Contributor III

Hello, Bob,

I tried to use the slowest clock possible (5 kHz) using the CMSIS-DAP and ULINK2 probe and still I'm getting the "Could not stop Cortex-M device" error. I don't think there is any problem with the ULINKpro debug probe as I'm still using it without any problems for different S32K148 and LPC1769 custom boards programming and debugging. As I said, this problem only started to occur after I downloaded the code with the watchdog configuration I posted in the original question. Now using the ULINKpro doesn't detect the SW Device at all in Keil IDE. I simply need to erase the program flash of the S32K148.

I am currently waiting for the PE Multilink debug probe so I can try to erase the flash in the S32 Design Studio.

Regards,

Tomas

0 件の賞賛
返信