STM32 embedded operating system into the HardFault_Handler analysis

STM32 in use, because generally there is no other exception is thrown, it is usually thrown HardFault_Handler.

There are reasons for this phenomenon leads to the following points:

(1) Operation of array bounds;

(2) out of memory access violation;

(3) a stack overflow program running;

(4) interrupt handling errors;

First, array bounds

Needless to say, the program uses a static array, dynamic array assignment overflow during mass participation. Or dynamically allocated memory is too small, causing program exceptions.

Second, the memory overflow

Key areas to check RAM, RAM size of data compiled for the execution of the program whether the number of possible cross-border. Generally not set to the extreme circumstances, cause an exception when some dynamic array pass the program parameters.

image

Calculation RW-data + ZI-data is stored in the variable required RAM area and the like.

.MAP file after the inspection program is compiled.

Corresponding to the manual, or the compiler finds the corresponding storage area of ​​RAM. Find the regional analysis, and correspondence.

image

Examples of this chip into the RAM area of ​​48K 0X20000000 storage, checks these variables, in particular the distribution of global variables.

RAM memory allocation area is insufficient, to check whether certain variables present application is a code region.

This design can be seen, due to the application of several large static arrays, RAM area has been used to b790 C000 from the 48K memory is very close.

In this issue, in particular, need to pay attention:

Using the Printf, memory problems vsprintf, sprintf formatted data resulting from these functions use a larger memory space, due to speculation, in the form of an array of the copy function uses conversion, severe memory consumption.

If the operating system is used to set the hook function throws an exception, it will also have this problem. Configuring the operating system space, comprising an amount of a message, the message queue, a mailbox, and so the task stack.

Third, Stack Overflow

This problem is particularly acute in the use of operation, operating system, the variable is assigned the task of placing the stack space missions in the application, such as the FreeRTOS

xTaskCreate 

. Task H 

 

create a new task and add it to the task queue, ready to run 

 

the Parameters: 
. pvTaskCode pointing task entry function must be carried out and never returned (ie: infinite loop). 
name pcName description of the task. Mainly for debugging. ConfigMAX_TASK_NAME_LEN defined by the maximum length. 
The number of specified size usStackDepth the task stack, the stack can be protected variable - not the number of bytes for example, if the stack is 16 bits wide, usStackDepth defined as 100, 200 bytes, which will be allocated to stack. Nesting depth stack (stack width) can not exceed the maximum value of multi - type variable containing size_t 
pvParameters pointer is used as a parameter passed to the created task 
priority of tasks running uxPriority (0: lowest priority) 
pvCreatedTask for passing a process - a reference to create the task of 
return: 
pdPASS if the task is successfully created and added to the ready column, another error code projdefs H file definition.

Create a task requires you to specify the size of the stack, the stack lack of application, an exception occurs, the system can start hook function HOOK function for the problem, throw the exception.

Fourth, interrupt handling abnormal

Program opened some interruption, such as USART, TIMER, RTC and so on.

But in the execution of the program, interrupt condition is satisfied, but failed to find the interrupt service routine corresponding to the portion will be thrown.

Guess you like

Origin www.cnblogs.com/xiumusheng/p/10948927.html