Encountering hardfaults in FreeRTOS v10.3.0 on a Microchip PIC32 while using vsnprintf or sprin
Hi guys, I'm encountering hardfaults in FreeRTOS
v10.3.0
on a Microchip PIC32
while using vsnprintf
or sprintf
functions. I suspect stack corruption, as I'm using static memory allocation no malloc
with a pre-allocated buffer char _log_buffer[128]
. I've tried different printf implementations newlib
, newlib nano
, tinyprintf
without success.
I tried troubleshooting with these:
~Verified thread stack alignment.
~Ruled out dynamic allocation issues by mocking malloc/calloc/realloc/free
.
Are there any recommended techniques to confirm stack corruption specifically related to printf calls in FreeRTOS?
With static memory allocation, what are some effective ways to debug the stack pointer behavior during these hardfaults? @Middleware & OS4 Replies
Hi @Sterling you should start with basic format strings like "%d" instead of complex ones first of all to isolate formatting issues.
Add a canary value in the end of your stack and you check it before using
printf
to check for any potential stuffs overwritingSee here :
@Sterling Try out a debugger like MPLAB X to inspect the stack pointer and stack contents during the execution of your code.Then, you can now
set breakpoints and inspect variables to identify any issues with stack pointer behavior.You can try these techniques out.