S32K116 when the SEC bit is set the MCU does not work

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

S32K116 when the SEC bit is set the MCU does not work

1,160 Views
Javier_Barriga
Contributor I

Hi,

            I am working in one S32K116 (32 pins encapsulate) project for mass production where it is needed to disable the debugging SWD port. This is achieved changing the FSEC[SEC] bit. We can disable/enable the debugging without problems.  The problem arises when debugging is disabled, then we get an scenario where we do not have CAN signals, No SPI signals, neither RESETS (Reset_b signal is always high). 

How could we debug this situation (no debugging available)? What is the difference of changing SEC bit with respect to normal running of the code? 

Thanks in advance,

Javier

0 Kudos
Reply
4 Replies

1,136 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Javier,

In addition to modifying the FSEC of Flash Configuration in startup_S32K116.S, are there any other changes?
If you just modify FSEC, I don't think it will cause this problem.
Maybe you can check if START_FROM_FLASH is defined.

Flash Configuration FlashConfig FSEC S32K11x START_FROM_FLASH.png


Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

1,128 Views
Javier_Barriga
Contributor I
I was doing it in a different way. I have posted a chunk of code where I set the SEC=1.
How can I debug how it is happening?
With this code set to SEC=0xCE, there aren't problems. 
if I put SEC 0xCF then nothing works.
 
 
void MTEST_FlashSecurized(void)
{

    UInt8 ccif_Securized=0;
    UInt8 SecurizedIsAlreadyDone = 0;
    UInt32 SectorArrayBackup={0xFFFFFFFF};
   
    UInt32 *Addr=(UInt32*)P_FLASH_BASE_ADDR;
    UInt32 *Addr_flex=(UInt32*)FLEXRAM_BASEADDR;
    UInt8 Address_flex_table[8]={0x00,0x01,0x02,0x03,0x04, 0x05, 0x06, 0x07};

    UInt16 i;
    UInt16 j;
    UInt16 m;



    SecurizedIsAlreadyDone=(REG_READ8(FLASH_FSEC_ADDR32) & 0x03);

        if(SecurizedIsAlreadyDone == 0x02)
        {


        /*Format FlexRam*/
            REG_WRITE8(FLASH_FCCOB0_ADDR32,0x80);
            REG_WRITE8(FLASH_FCCOB1_ADDR32,0x00);
            REG_WRITE8(FLASH_FCCOB2_ADDR32,0x00);
            REG_WRITE8(FLASH_FCCOB3_ADDR32,0x00);
            REG_WRITE8(FLASH_FCCOB4_ADDR32,0x0F);
            REG_WRITE8(FLASH_FCCOB5_ADDR32,0x00);
           
            REG_WRITE8(FLASH_FSTAT_ADDR32,0x80);

            ccif_Securized = 0;
            do{
                ccif_Securized=(REG_READ8(FLASH_FSTAT_ADDR32)&0x80)>>7;
            }while (ccif_Securized != 1);


        /*Erase FlexRam*/
          for (j=0;j<8;j++)
         {
              for(i=0;i<64;i++)
              {
                  *(UInt32*)(Addr_flex + j*64 + i) = 0xFFFFFFFF;
              }
          }


             REG_WRITE8(FLASH_FSTAT_ADDR32,0x30);

        /*SetFlexRam FlexRam*/
            REG_WRITE8(FLASH_FCCOB0_ADDR32,0x81);
            REG_WRITE8(FLASH_FCCOB1_ADDR32,0xFF);
            REG_WRITE8(FLASH_FCCOB4_ADDR32,0x00);
            REG_WRITE8(FLASH_FCCOB5_ADDR32,0x00);
           
            REG_WRITE8(FLASH_FSTAT_ADDR32,0x80);

            ccif_Securized = 0;
            do{
                ccif_Securized=(REG_READ8(FLASH_FSTAT_ADDR32)&0x80)>>7;
            }while (ccif_Securized != 1);


        /*Copy Sector 0 to FlexRam*/
         for (j=0;j<8;j++)
         {
             for(i=0;i<64;i++)
             {
                 *(UInt32*)(Addr_flex + j*64 + i) = 0xFFFFFFFF;
                 SectorArrayBackup = *(UInt32*)(Addr + i+j*64);
                 *(UInt32*)(Addr_flex + i + j*64)=SectorArrayBackup;

             }
         }

        /* Set non-debug condition on FlexRam*/
            *(UInt32*)(0x14000400) = 0x55555556;
            *(UInt32*)(0x14000404) = 0xAAAAAAAA;
            *(UInt32*)(0x14000408) = 0xFFFFFFFF;
            *(UInt32*)(0x1400040C) = 0xFFFFFFCE;
           
         
           REG_WRITE8(FLASH_FSTAT_ADDR32,0x30);

        /* Erase Sector 0*/
             REG_WRITE8(FLASH_FCCOB0_ADDR32,0x09);
             REG_WRITE8(FLASH_FCCOB1_ADDR32,0x00);
             REG_WRITE8(FLASH_FCCOB2_ADDR32,0x00);
             REG_WRITE8(FLASH_FCCOB3_ADDR32,0x00);

             REG_WRITE8(FLASH_FSTAT_ADDR32,0x80);

             ccif_Securized = 0;
             do{
                ccif_Securized=(REG_READ8(FLASH_FSTAT_ADDR32)&0x80)>>7;
             }while (ccif_Securized != 1);

         /*Copy Sector 0 to FlexRam*/ /* Program buffer*/
       
         
         for (j=0;j<8;j++)
         {

            for(m=0;m<64;m+=2)
            {
            /*Write backup copy + disable Jtag to Sector 0*/
                REG_WRITE8(FLASH_FCCOB0_ADDR32,0x07);
                REG_WRITE8(FLASH_FCCOB1_ADDR32,0x00);
                REG_WRITE8(FLASH_FCCOB2_ADDR32,Address_flex_table[j]);
                REG_WRITE8(FLASH_FCCOB3_ADDR32,(m*4));

                SectorArrayBackup = *(UInt32*)(Addr_flex + (m + (j*64)));
                REG_WRITE8(FLASH_FCCOB4_ADDR32, (UInt8)((SectorArrayBackup & 0xFF000000)>>24));
                REG_WRITE8(FLASH_FCCOB5_ADDR32, (UInt8)((SectorArrayBackup & 0x00FF0000)>>16));
                REG_WRITE8(FLASH_FCCOB6_ADDR32, (UInt8)((SectorArrayBackup & 0x0000FF00)>>8));
                REG_WRITE8(FLASH_FCCOB7_ADDR32, (UInt8)((SectorArrayBackup & 0x000000FF)));
                SectorArrayBackup = *(UInt32*)(Addr_flex + 1 + (m + (j*64)));
                REG_WRITE8(FLASH_FCCOB8_ADDR32, (UInt8)((SectorArrayBackup & 0xFF000000)>>24));
                REG_WRITE8(FLASH_FCCOB9_ADDR32, (UInt8)((SectorArrayBackup & 0x00FF0000)>>16));
                REG_WRITE8(FLASH_FCCOBA_ADDR32, (UInt8)((SectorArrayBackup & 0x0000FF00)>>8));
                REG_WRITE8(FLASH_FCCOBB_ADDR32, (UInt8)((SectorArrayBackup & 0x000000FF)));
               
                REG_WRITE8(FLASH_FSTAT_ADDR32,0x80);
               
                ccif_Securized = 0;

                do{
                    ccif_Securized=(REG_READ8(FLASH_FSTAT_ADDR32)&0x80)>>7;
                }while ((ccif_Securized != 1) );
            }


        }
0 Kudos
Reply

1,075 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Sorry I didn't debug your code.
What is the result if SecurizedIsAlreadyDone is ignored, that is, if this program is executed regardless of secure or unsecure? I wonder if these codes functions properly and erases the first flash sector correctly and reprograms it correctly.

AN12123 mentions: Note that changes to the flash configuration field will take effect at the next reset. Have you try to read back through the JTAG port before reset MCU?

4.1 Flash configuration field.png

In addition, when reprogramming, how about enable backdoor key feature so that temporary unlocking MCU then read and verified through the JTAG port?

0 Kudos
Reply

1,069 Views
Javier_Barriga
Contributor I

Hi, thank you for the reply.

Before performing a reset I have checked all, It seems to be ok.  I can continue debugging without problems until next reset. 

I have checked this code with unsecure configuration. Everything works fine.

But if I configure with secure configuration and I do a reset, the MCU does not send any signal or action.

Now, I am instrumentalizing the code for debugging with a GPIO when I am securized. 

0 Kudos
Reply