@@ -99,15 +99,34 @@ MEMFAULT_NO_OPT void memfault_fault_handling_assert(void *pc, void *lr) {
9999 #error "Unsupported Xtensa platform. Please visit https://mflt.io/contact-support"
100100 #endif // !defined(ESP_PLATFORM) && defined(__ZEPHYR__)
101101
102+ #if MEMFAULT_COREDUMP_CPU_COUNT > 1
103+ #if defined(__ZEPHYR__ )
104+ #error "Dual-core support not yet implemented for Zephyr Xtensa"
105+ #else
106+ #include "esp_cpu.h"
107+
108+ #endif
109+
110+ static int prv_get_current_cpu_id (void ) {
111+ return esp_cpu_get_core_id ();
112+ }
113+ #endif // MEMFAULT_COREDUMP_CPU_COUNT == 1
114+
102115void memfault_fault_handler (const sMfltRegState * regs , eMemfaultRebootReason reason ) {
116+ #if MEMFAULT_COREDUMP_CPU_COUNT == 1
117+ const sMfltRegState * current_cpu_regs = regs ;
118+ #else
119+ const int cpu_id = prv_get_current_cpu_id ();
120+ const sMfltRegState * current_cpu_regs = & regs [cpu_id ];
121+ #endif
103122 if (s_crash_reason == kMfltRebootReason_Unknown ) {
104123 // skip LR saving here.
105- prv_fault_handling_assert ((void * )regs -> pc , (void * )0 , reason );
124+ prv_fault_handling_assert ((void * )current_cpu_regs -> pc , (void * )0 , reason );
106125 }
107126
108127 sMemfaultCoredumpSaveInfo save_info = {
109128 .regs = regs ,
110- .regs_size = sizeof (* regs ),
129+ .regs_size = sizeof (* regs ) * MEMFAULT_COREDUMP_CPU_COUNT ,
111130 .trace_reason = s_crash_reason ,
112131 };
113132
@@ -122,7 +141,7 @@ void memfault_fault_handler(const sMfltRegState *regs, eMemfaultRebootReason rea
122141 // For the windowed ABI, a1 always holds the current "sp":
123142 // https://github.com/espressif/esp-idf/blob/v4.0/components/freertos/readme_xtensa.txt#L421-L428
124143 const uint32_t windowed_abi_spill_size = 64 ;
125- const uint32_t sp_prior_to_exception = regs -> a [1 ] - windowed_abi_spill_size ;
144+ const uint32_t sp_prior_to_exception = current_cpu_regs -> a [1 ] - windowed_abi_spill_size ;
126145
127146 sCoredumpCrashInfo info = {
128147 .stack_address = (void * )sp_prior_to_exception ,
@@ -139,7 +158,7 @@ void memfault_fault_handler(const sMfltRegState *regs, eMemfaultRebootReason rea
139158
140159size_t memfault_coredump_storage_compute_size_required (void ) {
141160 // actual values don't matter since we are just computing the size
142- sMfltRegState core_regs = { 0 };
161+ sMfltRegState core_regs [ MEMFAULT_COREDUMP_CPU_COUNT ] = { 0 };
143162 sMemfaultCoredumpSaveInfo save_info = {
144163 .regs = & core_regs ,
145164 .regs_size = sizeof (core_regs ),
0 commit comments