[STM32F407ZG] Hard Fault with precise data access violation (PRECISERR)
Hi,
I am encountering a hard fault on my STM32F407ZG when using snprintf(). We are using FreeRTOS for the development.
The system resets due to a precise data access violation (PRECISERR).
Below is the fault status:
HFSR: 0x40000000
BFAR: 0x38383600
BF: 0x82
PC: 0x0806D62E at "_Balloc"
This error occurs randomly after multiple calls to snprintf(). Below is a simplified version of my actual code:
#define BUF_SIZE 10
char temp_str[9][BUF_SIZE];
float temp[9];
for (int n = 0; n < 9; n++) {
snprintf(temp_str[n], BUF_SIZE, "%.3g", temp[n]);
}
Fault Trace:
task1() → snprintf() → _svfprintf_r() → _dtoa_r() → _Balloc() → <signal handler called>() → HardFault_Handler() at STM32f4xx_it.c
Memory Layout (Snippet from Linker Script):
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20020000; /* end of RAM */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x08040000, LENGTH = 1024K
}
Questions:
- What could cause BFAR (Bus Fault Address Register) to hold an address outside the defined RAM region?
- Why does snprintf() randomly cause a hard fault, even though it has been called multiple times before?
- Could this be related to stack/heap corruption or unaligned memory access in _Balloc()?
- Are there any known issues with snprintf() in newlib when using floating-point formatting on STM32F4?
Any insights or debugging tips would be greatly appreciated!
