diff --git a/.clang-format b/.clang-format index 0486d45..40f1a1f 100644 --- a/.clang-format +++ b/.clang-format @@ -71,7 +71,7 @@ IncludeCategories: - Regex: '^[<"]stm' Priority: 2 SortPriority: 0 - - Regex: "^ +#include + uint16_t cell_voltages[N_CELLS]; BQ_Status bq_status; @@ -36,11 +39,7 @@ void afe_init(UART_HandleTypeDef* uarthandle) { // Initialise underlying BQ Communication Functions init_BQCom(uarthandle); - // Turn the AFE on off on to cycle a full reset - afe_wakeup(); - HAL_Delay(10); - afe_shutdown(); - HAL_Delay(100); + // *Don't* power cycle the AFE to comply with 9.1.2 afe_wakeup(); HAL_Delay(10); @@ -51,6 +50,9 @@ void afe_init(UART_HandleTypeDef* uarthandle) { afe_config_gpios(); afe_activate_LED(); + // Clear FAULT_SYS[SYS_RESET] before writing REG_DISABLE + afe_clear_all_faults(); + afe_config_power(); afe_init_fault_thresholds(); @@ -60,7 +62,7 @@ void afe_init(UART_HandleTypeDef* uarthandle) { afe_clear_all_faults(); - HAL_Delay(10); + HAL_Delay(100); afe_check_faults(); } @@ -147,6 +149,7 @@ void afe_check_faults() { } void afe_clear_all_faults() { + memset(&bq_error, 0, sizeof(bq_error)); BQ_Write_Register(FAULT_SUM, FAULT_SUM_SIZE, 0xFFC0); // Clear all Faults bq_status = BQ_STDBY; HAL_Delay(1); @@ -191,6 +194,13 @@ void afe_config_communication() { void afe_config_gpios() { BQ_Write_Register(GPIO_DIR, GPIO_DIR_SIZE, 0x01); } +void afe_config_power() { + uint32_t devconfig; + BQ_Read_Register(DEVCONFIG, DEVCONFIG_SIZE, &devconfig); + devconfig |= DEVCONFIG_REG_DISABLE; + BQ_Write_Register(DEVCONFIG, DEVCONFIG_SIZE, devconfig); +} + void afe_activate_LED() { BQ_Write_Register(GPIO_OUT, GPIO_OUT_SIZE, 0x01); } void afe_config_balancing() {