S32K3 UTEST program generates hardfault

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

S32K3 UTEST program generates hardfault

Jump to solution
68 Views
Hareesh_S
Contributor II

Hello,

I am trying to create a test application to restrict JTAG/debug access by setting a 16 byte password (without HSE) for an S32K312. Previously my approach was 2 staged - I had one program to set the password, and another to advance the lifecycle, and this seemingly worked fine.

I am now trying to combine both into a single sequence to integrate into my main application eventually, but I am facing issues where the MCU generates a hardfault when I try to program the password.

I can confirm that before trying to program the password, there is no password set (0xFF throughout) and even though a hardfault was generated, the password has actually been programmed - this must have been why my previous 2 staged approach worked, as even if the first stage hardfaulted, I would not have noticed and simply programmed the second stage.

Below is my code snippet. Do note that I have also set the lifecycle configuration word address in the startup script, to be included in the IVT. There are no other modifications to the startup script or linker.

#define MASTER_ID 						(0U)
#define CUST_DB_PSWD_A_ADDR 			(0x1B000080U)
#define CUST_DB_PSWD_A_SECTOR 			(C40_UTEST_ARRAY_0_S000)
#define CUST_DB_PSWD_A_LENGTH 			(16U)

#define LC_CONFIGURATION_WORD_ADDR 		(0x005A6000)
#define LC_CONFIGURATION_WORD_SECTOR 	(C40_CODE_ARRAY_0_BLOCK_1_S211)
#define LC_CONFIGURATION_WORD_LENGTH 	(8U)

uint8_t cust_db_pswd_a[CUST_DB_PSWD_A_LENGTH] __attribute__((aligned(4)))
= { 0x35, 0x2E, 0x04, 0x92, 0x65, 0x25, 0x09, 0x23, 0x35, 0x2E, 0x04, 0x92,
		0x65, 0x25, 0x09, 0x23 };

uint8_t lc_configuration_word[LC_CONFIGURATION_WORD_LENGTH] __attribute__((aligned(4)))
= { 0xBA, 0xBA, 0xBA, 0xBA, 0x0, 0x0, 0x0, 0x0 }; /* Minimum data length 8 bytes */

int main(void) {

	Clock_Ip_Init(&Clock_Ip_aClockConfig[0]);

	C40_Ip_Init(&C40_Ip_InitCfg);

	/* PROGRAMMING ADKP */
	if (C40_Ip_GetLock(CUST_DB_PSWD_A_SECTOR)
			== C40_IP_STATUS_SECTOR_PROTECTED) {
		C40_Ip_ClearLock(CUST_DB_PSWD_A_SECTOR, MASTER_ID);
	}

	C40_Ip_MainInterfaceWrite(CUST_DB_PSWD_A_ADDR, CUST_DB_PSWD_A_LENGTH,
			cust_db_pswd_a, MASTER_ID); /* Hardfaults here, but UTEST program is actually successful */
	while (C40_Ip_MainInterfaceWriteStatus() == C40_IP_STATUS_BUSY)
		;

	/* ADVANCING LC */
	if (C40_Ip_GetLock(LC_CONFIGURATION_WORD_SECTOR)
			== C40_IP_STATUS_SECTOR_PROTECTED) {
		C40_Ip_ClearLock(LC_CONFIGURATION_WORD_SECTOR, MASTER_ID);
	}

	C40_Ip_MainInterfaceSectorErase(LC_CONFIGURATION_WORD_SECTOR,
	MASTER_ID);
	while (C40_Ip_MainInterfaceSectorEraseStatus() == C40_IP_STATUS_BUSY)
		;

	C40_Ip_MainInterfaceWrite(LC_CONFIGURATION_WORD_ADDR,
	LC_CONFIGURATION_WORD_LENGTH, lc_configuration_word, MASTER_ID);
	while (C40_Ip_MainInterfaceWriteStatus() == C40_IP_STATUS_BUSY)
		;

	while (true)
		;

	return 0U;
}

 
my .mex configuration is as such - 

Hareesh_S_3-1792008676439.pngHareesh_S_4-1792008695732.png

 

Any inputs as to what I am doing wrong?

With regards,
Hareesh S

0 Kudos
Reply
1 Solution
40 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi

Please check the value of "21.7.1.3 Module Configuration Status (MCRS)" at address 0x402EC004.  If MCRS[RWE] = 1, it means that an RWW error occurred during a previous read.

Then please read the discussion in  "Hard Fault in C40_Ip_MainInterfaceHVJobStatus api when flash is erase in s32k312".

Best Regards,
Robin

View solution in original post

2 Replies
41 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi

Please check the value of "21.7.1.3 Module Configuration Status (MCRS)" at address 0x402EC004.  If MCRS[RWE] = 1, it means that an RWW error occurred during a previous read.

Then please read the discussion in  "Hard Fault in C40_Ip_MainInterfaceHVJobStatus api when flash is erase in s32k312".

Best Regards,
Robin

23 Views
Hareesh_S
Contributor II

Hello @Robin_Shen,

Thanks for reverting back - It was indeed a RWW error as you had suggested.
I assumed the UTEST section was a different block and hence flash erase/program functions could run from flash but apparently not. Moving the functions to RAM solved my issues.

With regards,
Hareesh S

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2421177%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K3%20UTEST%20program%20generates%20hardfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2421177%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3CBR%20%2F%3E%3CBR%20%2F%3EI%20am%20trying%20to%20create%20a%20test%20application%20to%20restrict%20JTAG%2Fdebug%20access%20by%20setting%20a%2016%20byte%20password%20(without%20HSE)%20for%20an%20S32K312.%20Previously%20my%20approach%20was%202%20staged%20-%20I%20had%20one%20program%20to%20set%20the%20password%2C%20and%20another%20to%20advance%20the%20lifecycle%2C%20and%20this%20seemingly%20worked%20fine.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20am%20now%20trying%20to%20combine%20both%20into%20a%20single%20sequence%20to%20integrate%20into%20my%20main%20application%20eventually%2C%20but%20I%20am%20facing%20issues%20where%20the%20MCU%20generates%20a%20hardfault%20when%20I%20try%20to%20program%20the%20password.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20can%20confirm%20that%20before%20trying%20to%20program%20the%20password%2C%20there%20is%20no%20password%20set%20(0xFF%20throughout)%20and%20even%20though%20a%20hardfault%20was%20generated%2C%20the%20password%20has%20actually%20been%20programmed%20-%20this%20must%20have%20been%20why%20my%20previous%202%20staged%20approach%20worked%2C%20as%20even%20if%20the%20first%20stage%20hardfaulted%2C%20I%20would%20not%20have%20noticed%20and%20simply%20programmed%20the%20second%20stage.%3CBR%20%2F%3E%3CBR%20%2F%3EBelow%20is%20my%20code%20snippet.%20Do%20note%20that%20I%20have%20also%20set%20the%20lifecycle%20configuration%20word%20address%20in%20the%20startup%20script%2C%20to%20be%20included%20in%20the%20IVT.%20There%20are%20no%20other%20modifications%20to%20the%20startup%20script%20or%20linker.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E%23define%20MASTER_ID%20%09%09%09%09%09%09(0U)%0A%23define%20CUST_DB_PSWD_A_ADDR%20%09%09%09(0x1B000080U)%0A%23define%20CUST_DB_PSWD_A_SECTOR%20%09%09%09(C40_UTEST_ARRAY_0_S000)%0A%23define%20CUST_DB_PSWD_A_LENGTH%20%09%09%09(16U)%0A%0A%23define%20LC_CONFIGURATION_WORD_ADDR%20%09%09(0x005A6000)%0A%23define%20LC_CONFIGURATION_WORD_SECTOR%20%09(C40_CODE_ARRAY_0_BLOCK_1_S211)%0A%23define%20LC_CONFIGURATION_WORD_LENGTH%20%09(8U)%0A%0Auint8_t%20cust_db_pswd_a%5BCUST_DB_PSWD_A_LENGTH%5D%20__attribute__((aligned(4)))%0A%3D%20%7B%200x35%2C%200x2E%2C%200x04%2C%200x92%2C%200x65%2C%200x25%2C%200x09%2C%200x23%2C%200x35%2C%200x2E%2C%200x04%2C%200x92%2C%0A%09%090x65%2C%200x25%2C%200x09%2C%200x23%20%7D%3B%0A%0Auint8_t%20lc_configuration_word%5BLC_CONFIGURATION_WORD_LENGTH%5D%20__attribute__((aligned(4)))%0A%3D%20%7B%200xBA%2C%200xBA%2C%200xBA%2C%200xBA%2C%200x0%2C%200x0%2C%200x0%2C%200x0%20%7D%3B%20%2F*%20Minimum%20data%20length%208%20bytes%20*%2F%0A%0Aint%20main(void)%20%7B%0A%0A%09Clock_Ip_Init(%26amp%3BClock_Ip_aClockConfig%5B0%5D)%3B%0A%0A%09C40_Ip_Init(%26amp%3BC40_Ip_InitCfg)%3B%0A%0A%09%2F*%20PROGRAMMING%20ADKP%20*%2F%0A%09if%20(C40_Ip_GetLock(CUST_DB_PSWD_A_SECTOR)%0A%09%09%09%3D%3D%20C40_IP_STATUS_SECTOR_PROTECTED)%20%7B%0A%09%09C40_Ip_ClearLock(CUST_DB_PSWD_A_SECTOR%2C%20MASTER_ID)%3B%0A%09%7D%0A%0A%09C40_Ip_MainInterfaceWrite(CUST_DB_PSWD_A_ADDR%2C%20CUST_DB_PSWD_A_LENGTH%2C%0A%09%09%09cust_db_pswd_a%2C%20MASTER_ID)%3B%20%2F*%20Hardfaults%20here%2C%20but%20UTEST%20program%20is%20actually%20successful%20*%2F%0A%09while%20(C40_Ip_MainInterfaceWriteStatus()%20%3D%3D%20C40_IP_STATUS_BUSY)%0A%09%09%3B%0A%0A%09%2F*%20ADVANCING%20LC%20*%2F%0A%09if%20(C40_Ip_GetLock(LC_CONFIGURATION_WORD_SECTOR)%0A%09%09%09%3D%3D%20C40_IP_STATUS_SECTOR_PROTECTED)%20%7B%0A%09%09C40_Ip_ClearLock(LC_CONFIGURATION_WORD_SECTOR%2C%20MASTER_ID)%3B%0A%09%7D%0A%0A%09C40_Ip_MainInterfaceSectorErase(LC_CONFIGURATION_WORD_SECTOR%2C%0A%09MASTER_ID)%3B%0A%09while%20(C40_Ip_MainInterfaceSectorEraseStatus()%20%3D%3D%20C40_IP_STATUS_BUSY)%0A%09%09%3B%0A%0A%09C40_Ip_MainInterfaceWrite(LC_CONFIGURATION_WORD_ADDR%2C%0A%09LC_CONFIGURATION_WORD_LENGTH%2C%20lc_configuration_word%2C%20MASTER_ID)%3B%0A%09while%20(C40_Ip_MainInterfaceWriteStatus()%20%3D%3D%20C40_IP_STATUS_BUSY)%0A%09%09%3B%0A%0A%09while%20(true)%0A%09%09%3B%0A%0A%09return%200U%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3CBR%20%2F%3Emy%20.mex%20configuration%20is%20as%20such%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Hareesh_S_3-1792008676439.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_3-1792008676439.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_3-1792008676439.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F397991i92A8175A287898E1%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Hareesh_S_3-1792008676439.png%22%20alt%3D%22Hareesh_S_3-1792008676439.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Hareesh_S_4-1792008695732.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_4-1792008695732.png%22%20style%3D%22width%3A%20336px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_4-1792008695732.png%22%20style%3D%22width%3A%20336px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F397992i082051CCC79472FB%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Hareesh_S_4-1792008695732.png%22%20alt%3D%22Hareesh_S_4-1792008695732.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EAny%20inputs%20as%20to%20what%20I%20am%20doing%20wrong%3F%3CBR%20%2F%3E%3CBR%20%2F%3EWith%20regards%2C%3CBR%20%2F%3EHareesh%20S%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2421218%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K3%20UTEST%20program%20generates%20hardfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2421218%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%3C%2FP%3E%0A%3CP%3EPlease%20check%20the%20value%20of%20%22%3CSTRONG%3E21.7.1.3%20Module%20Configuration%20Status%20(MCRS)%3C%2FSTRONG%3E%22%26nbsp%3Bat%20address%200x402EC004.%26nbsp%3B%20If%20MCRS%5BRWE%5D%20%3D%201%2C%20it%20means%20that%20an%26nbsp%3BRWW%20error%20occurred%20during%20a%20previous%20read.%3C%2FP%3E%0A%3CP%3EThen%20please%20read%20the%20discussion%20in%26nbsp%3B%20%22%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K%2FHard-Fault-in-C40-Ip-MainInterfaceHVJobStatus-api-when-flash-is%2Fm-p%2F2002382%22%20target%3D%22_self%22%3EHard%20Fault%20in%20C40_Ip_MainInterfaceHVJobStatus%20api%20when%20flash%20is%20erase%20in%20s32k312%3C%2FA%3E%22.%3C%2FP%3E%0A%3CP%3EBest%20Regards%2C%3CBR%20%2F%3ERobin%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2421490%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K3%20UTEST%20program%20generates%20hardfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2421490%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F57959%22%20target%3D%22_blank%22%3E%40Robin_Shen%3C%2FA%3E%2C%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20for%20reverting%20back%20-%20It%20was%20indeed%20a%20RWW%20error%20as%20you%20had%20suggested.%3CBR%20%2F%3EI%20assumed%20the%20UTEST%20section%20was%20a%20different%20block%20and%20hence%20flash%20erase%2Fprogram%20functions%20could%20run%20from%20flash%20but%20apparently%20not.%20Moving%20the%20functions%20to%20RAM%20solved%20my%20issues.%3CBR%20%2F%3E%3CBR%20%2F%3EWith%20regards%2C%3CBR%20%2F%3EHareesh%20S%3C%2FP%3E%3C%2FLINGO-BODY%3E