cancel
Showing results for 
Search instead for 
Did you mean: 

how to sort hardfault error in stm32f0.....?

NK.13
Associate II

can anyone suggest a method to sort hardfault error.I went on commenting few lines to sort the problem and found that when the uart is continuesly receiving and transmitting data this occurs.

1 ACCEPTED SOLUTION

Accepted Solutions
Ozone
Lead

> I went on commenting few lines to sort the problem ...

This is a superficial trial-and-error approach with unknown success prospects.

Use a document like this: http://www.keil.com/appnotes/files/apnt209.pdf , and try to identify the reason.

> ... and found that when the uart is continuesly receiving and transmitting data this occurs.

Sounds like an invalid pointer access in your interrupt handler.

Perhaps ignoring the the buffer size limit.

View solution in original post

3 REPLIES 3

Look at the frame stored in stack to find out the point in code (the stored program counter) where the problem occured (Clive has posted hardfault handlers here in past, outputting this to a connected terminal, search in forum, "hardfault handler" may be a good way to search). Observe vicinity of that point in disasm, observe the content of registers and the instruction preceding the fault. You can then trace back to the C code which corresponds to that offending point. If the source of problem is still not clear, place a breakpoint somewhere before that point and try to single-step; but if the problem is related to intensive communication and possibly buffer overflows or race conditions, breakpoints probably would do more harm than help.

JW

Ozone
Lead

> I went on commenting few lines to sort the problem ...

This is a superficial trial-and-error approach with unknown success prospects.

Use a document like this: http://www.keil.com/appnotes/files/apnt209.pdf , and try to identify the reason.

> ... and found that when the uart is continuesly receiving and transmitting data this occurs.

Sounds like an invalid pointer access in your interrupt handler.

Perhaps ignoring the the buffer size limit.

invalid pointer access in interrupt handler,thats the reason.

HAL_UART_Receive_IT( &huart1, Rx_data, 1); // i put this line in the main loop and to get data,i made the HAL_UART_RxCpltCallback(); function like following.

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

uint8_t i;

if (huart->Instance == USART1) //current UART

{

if (rx_intex==0) {for (i=0;i<8;i++) uart_test[i]=0;}  //clear Rx_Buffer before receiving new data

if (Rx_data[0]!='#') //if received data different from ascii # 

{

uart_test[rx_intex++]=Rx_data[0];  //add data to Rx_Buffer

}

else      //if received data = 13

{

rx_intex=0;

if((uart_test[0] == '$') && (uart_test[1] == 'R'))

{

 rpm_count = (((uart_test[3] - 48) * 1000) + ((uart_test[4] - 48) * 100) + ((uart_test[5] - 48) * 10) + ((uart_test[6] - 48) * 1));

//  memset(uart_test,0,8);

}

}

HAL_UART_Receive_IT(&huart1, Rx_data, 1);  //activate UART receive interrupt every time

}

}

i think this receiving logic should change...

can you help me to solve this....?