Marvee Amasi
Marvee Amasi
DIIDevHeads IoT Integration Server
Created by Sterling on 6/12/2024 in #middleware-and-os
Encountering hardfaults in FreeRTOS v10.3.0 on a Microchip PIC32 while using vsnprintf or sprin
See here :
#define STACK_CANARY_VALUE 0xDEADBEEF

char _log_buffer[128];
uint32_t _log_buffer_canary = STACK_CANARY_VALUE;

void my_function(void) {
// your code bla bla bla

// This is where you should check the canary before using printf
if (_log_buffer_canary != STACK_CANARY_VALUE) {
// Stack corruption detected!
// Handle the error prolly stop execution or trigger a watchdog
}

// Now it is safe hopefully to use printf
vsnprintf(_log_buffer, sizeof(_log_buffer), "%d", some_variable);
}
#define STACK_CANARY_VALUE 0xDEADBEEF

char _log_buffer[128];
uint32_t _log_buffer_canary = STACK_CANARY_VALUE;

void my_function(void) {
// your code bla bla bla

// This is where you should check the canary before using printf
if (_log_buffer_canary != STACK_CANARY_VALUE) {
// Stack corruption detected!
// Handle the error prolly stop execution or trigger a watchdog
}

// Now it is safe hopefully to use printf
vsnprintf(_log_buffer, sizeof(_log_buffer), "%d", some_variable);
}
5 replies