@@ -99,15 +99,34 @@ MEMFAULT_NO_OPT void memfault_fault_handling_assert(void *pc, void *lr) {
99
99
#error "Unsupported Xtensa platform. Please visit https://mflt.io/contact-support"
100
100
#endif // !defined(ESP_PLATFORM) && defined(__ZEPHYR__)
101
101
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
+
102
115
void 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
103
122
if (s_crash_reason == kMfltRebootReason_Unknown ) {
104
123
// 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 );
106
125
}
107
126
108
127
sMemfaultCoredumpSaveInfo save_info = {
109
128
.regs = regs ,
110
- .regs_size = sizeof (* regs ),
129
+ .regs_size = sizeof (* regs ) * MEMFAULT_COREDUMP_CPU_COUNT ,
111
130
.trace_reason = s_crash_reason ,
112
131
};
113
132
@@ -122,7 +141,7 @@ void memfault_fault_handler(const sMfltRegState *regs, eMemfaultRebootReason rea
122
141
// For the windowed ABI, a1 always holds the current "sp":
123
142
// https://github.com/espressif/esp-idf/blob/v4.0/components/freertos/readme_xtensa.txt#L421-L428
124
143
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 ;
126
145
127
146
sCoredumpCrashInfo info = {
128
147
.stack_address = (void * )sp_prior_to_exception ,
@@ -139,7 +158,7 @@ void memfault_fault_handler(const sMfltRegState *regs, eMemfaultRebootReason rea
139
158
140
159
size_t memfault_coredump_storage_compute_size_required (void ) {
141
160
// 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 };
143
162
sMemfaultCoredumpSaveInfo save_info = {
144
163
.regs = & core_regs ,
145
164
.regs_size = sizeof (core_regs ),
0 commit comments