| | |
| | | /* Private includes ----------------------------------------------------------*/ |
| | | /* USER CODE BEGIN Includes */ |
| | | #include "bluetooth.h" |
| | | #include "DBG.h" |
| | | /* USER CODE END Includes */ |
| | | |
| | | /* Private typedef -----------------------------------------------------------*/ |
| | |
| | | void HardFault_Handler(void) |
| | | { |
| | | /* USER CODE BEGIN HardFault_IRQn 0 */ |
| | | |
| | | // 打印HardFault信息 |
| | | // 注意:这里假设printf已经重定向到UART,且在HardFault中还能工作 |
| | | // 如果不能工作,可能需要直接操作寄存器输出 |
| | | |
| | | // // 获取SCB->HFSR, CFSR等寄存器值 |
| | | // volatile uint32_t hfsr = SCB->HFSR; |
| | | // volatile uint32_t cfsr = SCB->CFSR; |
| | | // volatile uint32_t mmfar = SCB->MMFAR; |
| | | // volatile uint32_t bfar = SCB->BFAR; |
| | | // |
| | | // printf("\r\n=== HARD FAULT ===\r\n"); |
| | | // printf("HFSR: 0x%08X\r\n", hfsr); |
| | | // printf("CFSR: 0x%08X\r\n", cfsr); |
| | | // |
| | | // if (hfsr & (1 << 30)) { |
| | | // printf("Forced HardFault\r\n"); |
| | | // } |
| | | // |
| | | // if (cfsr & 0xFFFF0000) { |
| | | // printf("Usage Fault: 0x%04X\r\n", (cfsr >> 16)); |
| | | // if (cfsr & (1 << 24)) printf(" - UNALIGNED access\r\n"); |
| | | // if (cfsr & (1 << 25)) printf(" - DIVBYZERO\r\n"); |
| | | // } |
| | | // |
| | | // if (cfsr & 0x0000FF00) { |
| | | // printf("Bus Fault: 0x%02X\r\n", (cfsr >> 8)); |
| | | // if (cfsr & (1 << 15)) printf(" - BFAR valid: 0x%08X\r\n", bfar); |
| | | // if (cfsr & (1 << 10)) printf(" - IMPRECISERR (Imprecise data bus error)\r\n"); |
| | | // if (cfsr & (1 << 9)) printf(" - PRECISERR (Precise data bus error)\r\n"); |
| | | // if (cfsr & (1 << 8)) printf(" - IBUSERR (Instruction bus error)\r\n"); |
| | | // } |
| | | // |
| | | // if (cfsr & 0x000000FF) { |
| | | // printf("MemManage Fault: 0x%02X\r\n", cfsr & 0xFF); |
| | | // if (cfsr & (1 << 7)) printf(" - MMFAR valid: 0x%08X\r\n", mmfar); |
| | | // } |
| | | // |
| | | // // 尝试打印LR和PC(需要汇编辅助,这里简单打印寄存器) |
| | | // // __asm("MOV R0, LR"); |
| | | // // __asm("MRS R1, MSP"); |
| | | // // __asm("MRS R2, PSP"); |
| | | // |
| | | // printf("System Halted.\r\n"); |
| | | /* USER CODE END HardFault_IRQn 0 */ |
| | | while (1) |
| | | { |
| | |
| | | void USART6_IRQHandler(void) |
| | | { |
| | | /* USER CODE BEGIN USART6_IRQn 0 */ |
| | | // Circular DMA Mode: Just set a flag, do NOT stop DMA |
| | | uint32_t tmp_flag = 0; |
| | | uint32_t temp; |
| | | tmp_flag = __HAL_UART_GET_FLAG(&huart6, UART_FLAG_IDLE); |
| | | |
| | | if ((tmp_flag != RESET)) |
| | | { |
| | | |
| | | g_u32BtIdleIntCount++; // Debug Counter |
| | | __HAL_UART_CLEAR_IDLEFLAG(&huart6); |
| | | HAL_UART_DMAStop(&huart6); // |
| | | temp = __HAL_DMA_GET_COUNTER(&hdma_usart6_rx); |
| | | uart6_dma_recv_len = BT_UART_RX_BUF_SIZE - temp; |
| | | uart6_dma_recv_end_flag = 1; |
| | | // HAL_UART_Receive_DMA(&huart6, uart6_dma_rxbuf, UART6_DMA_RX_BUF_SIZE); // Moved to Poll to avoid race/overwrite |
| | | // For Circular DMA, we do NOT stop DMA. Just set a flag to notify Poll. |
| | | uart6_dma_recv_end_flag = 1; // Notify Poll that new data arrived |
| | | } |
| | | |
| | | /* USER CODE END USART6_IRQn 0 */ |