@@ -120,7 +120,6 @@ void hardfault_flash_write(
120120 const void * data_metadata ,
121121 size_t len_metadata
122122) {
123- __disable_irq ();
124123 HAL_FLASH_Unlock ();
125124
126125 // Erase sector
@@ -133,7 +132,8 @@ void hardfault_flash_write(
133132 erase .VoltageRange = FLASH_VOLTAGE_RANGE_3 ;
134133
135134 if (HAL_FLASHEx_Erase (& erase , & sector_error ) != HAL_OK ) {
136- __BKPT (0 );
135+ HAL_FLASH_Lock ();
136+ return ;
137137 }
138138
139139 size_t offset , copy_len ;
@@ -150,7 +150,8 @@ void hardfault_flash_write(
150150 addr_hard_fault + offset ,
151151 (uintptr_t )block
152152 ) != HAL_OK ) {
153- __BKPT (0 );
153+ HAL_FLASH_Lock ();
154+ return ;
154155 }
155156 offset += 32 ;
156157 }
@@ -166,7 +167,8 @@ void hardfault_flash_write(
166167 addr_metadata + offset ,
167168 (uintptr_t )block
168169 ) != HAL_OK ) {
169- __BKPT (0 );
170+ HAL_FLASH_Lock ();
171+ return ;
170172 }
171173 offset += 32 ;
172174 }
@@ -175,13 +177,12 @@ void hardfault_flash_write(
175177 SCB_InvalidateDCache ();
176178
177179 HAL_FLASH_Lock ();
178- __enable_irq ();
179180}
180181static uint8_t is_valid_pc (uint32_t pc ) {
181182 pc &= ~1U ; // Thumb
182183 return (pc >= (uint32_t )& _stext && pc < (uint32_t )& _etext );
183184}
184- __attribute__((noreturn , optimize ("O0" ))) static void
185+ __attribute__((optimize ("O0" ))) static void
185186scan_call_stack (sContextStateFrame * frame , HardFaultLog * log_hard_fault ) {
186187 uint32_t * stack_start = (uint32_t * )& _sstack ;
187188 uint32_t * stack_end = (uint32_t * )& _estack ;
@@ -314,37 +315,16 @@ void NMI_Handler(void) {
314315/**
315316 * @brief This function handles Memory management fault.
316317 */
317- void MemManage_Handler (void ) {
318- extern void my_fault_handler_c (sContextStateFrame * frame );
319-
320- __asm volatile ("mrs r0, msp\n" // obtener stack frame
321- "b my_fault_handler_c\n" );
322- }
323- /**
324- * @brief This function handles Pre-fetch fault, memory access fault.
318+ __attribute__((naked )) void MemManage_Handler (void ) { HARDFAULT_HANDLING_ASM (); }
319+ /**
320+ * @brief This function handles Pre-fetch fault, memory access fault.
325321 */
326- void BusFault_Handler (void ) {
327- /* USER CODE BEGIN BusFault_IRQn 0 */
322+ __attribute__((naked )) void BusFault_Handler (void ) { HARDFAULT_HANDLING_ASM (); }
328323
329- /* USER CODE END BusFault_IRQn 0 */
330- while (1 ) {
331- /* USER CODE BEGIN W1_BusFault_IRQn 0 */
332- /* USER CODE END W1_BusFault_IRQn 0 */
333- }
334- }
335-
336- /**
337- * @brief This function handles Undefined instruction or illegal state.
324+ /**
325+ * @brief This function handles Undefined instruction or illegal state.
338326 */
339- void UsageFault_Handler (void ) {
340- /* USER CODE BEGIN UsageFault_IRQn 0 */
341-
342- /* USER CODE END UsageFault_IRQn 0 */
343- while (1 ) {
344- /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
345- /* USER CODE END W1_UsageFault_IRQn 0 */
346- }
347- }
327+ __attribute__((naked )) void UsageFault_Handler (void ) { HARDFAULT_HANDLING_ASM (); }
348328
349329/**
350330 * @brief This function handles System service call via SWI instruction.
0 commit comments