cancel
Showing results for 
Search instead for 
Did you mean: 

stm32l4p5: HardFault_Handler() at stm32l4xx_it.c:90 0x800b2d2

BRobe.3
Associate III

Dear all,

I am using stm32cubeide with stm32l4p5 micro.

Everything is working fine but for the first time, I try to write and read my USB key.

For that, i use the USB_OTG_FS set up

I am able to write and read only one time and the recorded file is OK

But the issue is, if I try to record several time in the while(1) loop, I get a HardFault_Handler() at stm32l4xx_it.c:90 0x800b2d2 and the program stop.

I saw some equivalent issues in the past, but I don't understand how to solve this issue.

Thanks for your help

Robert

4 REPLIES 4

Rather that have a while(1) loop in the Hard Fault Handler, unpack the fault state and look at what's actually faulting.

Invalid addresses/pointers, corrupt structures/instances, resource leaks on the heap

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
BRobe.3
Associate III

Dear Member,

Thanks for your answer.

Sorry, I was not clear. The while (1) is the loop of the main task.

Below is the detail of 2 version of this while (1)

PPROGRAM1 with N_Write_USB limiting use of MX_USB_HOST_Process() only ONE TIME, Recording is successfull;

PPROGRAM2 without N_Write_USB use of MX_USB_HOST_Process() MANY TIMES, Recording fail; I don't understand why ?

Best Regards

Robert

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

PPROGRAM1 with N_Write_USB

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

#ifdef WRITE_USB

if(N_Write_USB == 0)

{

uint8_t i , j;

for ( i = 0 ; i < strlen(wrchar_text_USB) ; i ++) {wrchar_text_USB[i] = '\0'; }

for ( i = 0 ; i < strlen(char_file_USB) ; i ++) {char_file_USB[i] = '\0';}

//Programmation du Fichier

char_file_USB[0] = 'L';

char_file_USB[1] = 'I';

char_file_USB[2] = 'S';

char_file_USB[3] = 'T';

char_file_USB[4] = 'M';

char_file_USB[5] = 'O';

char_file_USB[6] = 'D';

char_file_USB[7] = '.';

char_file_USB[8] = 'T';

char_file_USB[9] = 'X';

char_file_USB[10] = 'T';

char_file_USB[11] = '\0';

//Programmation du Parametre

char result_2ascii[2];

// Autres Modeles

wrchar_text_USB[0] = '_';

_ByteTo_Result_2ascii(Model_Num[0], result_2ascii);

strcat(wrchar_text_USB, result_2ascii);

strcat(wrchar_text_USB, "_");

strcat(wrchar_text_USB, "x");

strcat(wrchar_text_USB, Model_Name[0]);

strcat(wrchar_text_USB, "x");

strcat(wrchar_text_USB, "_");

_ByteTo_Result_2ascii(Model_Num[1], result_2ascii);

strcat(wrchar_text_USB, result_2ascii);

strcat(wrchar_text_USB, "_");

strcat(wrchar_text_USB, "x");

strcat(wrchar_text_USB, Model_Name[1]);

strcat(wrchar_text_USB, "x");

Flag_Write_USB = TRUE;

HAL_Delay(100);

}

N_Write_USB++;

//

#endif //WRITE_USB

if((Flag_Write_USB==TRUE)||(Flag_Read_USB==TRUE)||(Flag_WriteRead_USB))

{

/* USER CODE END WHILE */

MX_USB_HOST_Process();

/* USER CODE BEGIN 3 */

} //End if((Flag_Write_USB==TRUE)||(Flag_Read_USB==TRUE)||(Flag_WriteRead_USB))

} //End while (1)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

PPROGRAM2 without N_Write_USB

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

#ifdef WRITE_USB

//// if(N_Write_USB == 0)

//// {

uint8_t i , j;

for ( i = 0 ; i < strlen(wrchar_text_USB) ; i ++) {wrchar_text_USB[i] = '\0'; }

for ( i = 0 ; i < strlen(char_file_USB) ; i ++) {char_file_USB[i] = '\0';}

//Programmation du Fichier

char_file_USB[0] = 'L';

char_file_USB[1] = 'I';

char_file_USB[2] = 'S';

char_file_USB[3] = 'T';

char_file_USB[4] = 'M';

char_file_USB[5] = 'O';

char_file_USB[6] = 'D';

char_file_USB[7] = '.';

char_file_USB[8] = 'T';

char_file_USB[9] = 'X';

char_file_USB[10] = 'T';

char_file_USB[11] = '\0';

//Programmation du Parametre

char result_2ascii[2];

// Autres Modeles

wrchar_text_USB[0] = '_';

_ByteTo_Result_2ascii(Model_Num[0], result_2ascii);

strcat(wrchar_text_USB, result_2ascii);

strcat(wrchar_text_USB, "_");

strcat(wrchar_text_USB, "x");

strcat(wrchar_text_USB, Model_Name[0]);

strcat(wrchar_text_USB, "x");

strcat(wrchar_text_USB, "_");

_ByteTo_Result_2ascii(Model_Num[1], result_2ascii);

strcat(wrchar_text_USB, result_2ascii);

strcat(wrchar_text_USB, "_");

strcat(wrchar_text_USB, "x");

strcat(wrchar_text_USB, Model_Name[1]);

strcat(wrchar_text_USB, "x");

Flag_Write_USB = TRUE;

HAL_Delay(100);

////// }

////N_Write_USB++;

#endif //WRITE_USB

if((Flag_Write_USB==TRUE)||(Flag_Read_USB==TRUE)||(Flag_WriteRead_USB))

{

/* USER CODE END WHILE */

MX_USB_HOST_Process();

/* USER CODE BEGIN 3 */

} //End if((Flag_Write_USB==TRUE)||(Flag_Read_USB==TRUE)||(Flag_WriteRead_USB))

} //End while (1)

As Clive said, observe in the fault handler, where the fault happened, and in mixed source/debug view find, which instruction caused the problem (you may need to go backwards a couple of instructions). Observe content of registers and match them to the variables in source. That will help you find the source of problem.

In other words, only in rare cases (when there's a widely used code with a known straightforward bug) the problem can be deciphered by looking at a fragment of source code which uses a bunch of deep and complex function calls and unknown data and structures. It's up to you to drill down. That you used some clicky configurator and a prechewed "library", that's your problem.

JW

BRobe.3
Associate III

Thanks Jan for your reply,

I will try to understand this.

I was expecting a more obvious mistake in my software for the USB key. (Above)

Best Regards

Robert