fix log crashes, ITEMP calculation

print CS_FLT details
log errored AMS states as it happens
This commit is contained in:
Kilian Bracher 2025-04-26 18:55:19 +02:00
parent 765f1e5ee1
commit 2bbe11267a
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
4 changed files with 29 additions and 9 deletions

View File

@ -147,7 +147,7 @@ HAL_StatusTypeDef amsAuxAndStatusMeasurement(Cell_Module (*module)[N_BMS]) {
CHECK_RETURN(readCMD(RDSTATA, rxbuf, STATUS_GROUP_A_SIZE)); CHECK_RETURN(readCMD(RDSTATA, rxbuf, STATUS_GROUP_A_SIZE));
for (size_t i = 0; i < N_BMS; i++) { for (size_t i = 0; i < N_BMS; i++) {
size_t offset = BUFFER_BMS_OFFSET(i, STATUS_GROUP_A_SIZE); size_t offset = BUFFER_BMS_OFFSET(i, STATUS_GROUP_A_SIZE);
(*module)[i].internalDieTemp = (mV_from_ADBMS6830(rxbuf[offset + 2] | (rxbuf[offset + 3] << 8)) / 7.5) + 273; //datasheet page 72 (*module)[i].internalDieTemp = (mV_from_ADBMS6830(rxbuf[offset + 2] | (rxbuf[offset + 3] << 8)) / 7.5f) - 273; //datasheet page 72
} }
CHECK_RETURN(readCMD(RDSTATB, rxbuf, STATUS_GROUP_B_SIZE)); CHECK_RETURN(readCMD(RDSTATB, rxbuf, STATUS_GROUP_B_SIZE));

View File

@ -76,15 +76,27 @@ ADBMS_DetailedStatus AMS_Idle_Loop() {
if (deviceSleeps > MAX_DEVICE_SLEEP) { if (deviceSleeps > MAX_DEVICE_SLEEP) {
return (ADBMS_DetailedStatus){ADBMS_INTERNAL_BMS_TIMEOUT, match - 1}; return (ADBMS_DetailedStatus){ADBMS_INTERNAL_BMS_TIMEOUT, match - 1};
} else { } else {
debug_log(LOG_LEVEL_WARNING, "BMS %d unexpectedly in sleep mode, resetting...", match - 1);
amsReset(); amsReset();
} }
} }
if (any(module.status.CS_FLT || module.status.SPIFLT || module.status.CMED || module.status.SMED || if ((match = any(module.status.CS_FLT || module.status.SPIFLT || module.status.CMED || module.status.SMED ||
module.status.VDE || module.status.VDEL || module.status.OSCCHK || module.status.TMODCHK)) { module.status.VDE || module.status.VDEL || module.status.OSCCHK || module.status.TMODCHK))) {
// Fault bits are latched -- clear them so we can check again next // Fault bits are latched -- clear them so we can check again next
// iteration. // iteration.
amsClearFlag(); amsClearFlag();
// Log specific BMS fault details
debug_log(LOG_LEVEL_ERROR, "Fault on BMS %d: ", match - 1);
auto faultyModule = &modules[match - 1];
if (faultyModule->status.CS_FLT) debug_log_cont(LOG_LEVEL_ERROR, "CS_FLT ");
if (faultyModule->status.SPIFLT) debug_log_cont(LOG_LEVEL_ERROR, "SPIFLT ");
if (faultyModule->status.CMED) debug_log_cont(LOG_LEVEL_ERROR, "CMED ");
if (faultyModule->status.SMED) debug_log_cont(LOG_LEVEL_ERROR, "SMED ");
if (faultyModule->status.VDE) debug_log_cont(LOG_LEVEL_ERROR, "VDE ");
if (faultyModule->status.VDEL) debug_log_cont(LOG_LEVEL_ERROR, "VDEL ");
if (faultyModule->status.OSCCHK) debug_log_cont(LOG_LEVEL_ERROR, "OSCCHK ");
if (faultyModule->status.TMODCHK) debug_log_cont(LOG_LEVEL_ERROR, "TMODCHK ");
return (ADBMS_DetailedStatus){ADBMS_INTERNAL_BMS_FAULT, match - 1}; return (ADBMS_DetailedStatus){ADBMS_INTERNAL_BMS_FAULT, match - 1};
} }

View File

@ -81,7 +81,7 @@ HAL_StatusTypeDef battery_update() {
for (size_t cell = 0; cell < N_CELLS; cell++) { for (size_t cell = 0; cell < N_CELLS; cell++) {
if (voltage_flags & (1UL << cell)) { if (voltage_flags & (1UL << cell)) {
debug_log_cont(LOG_LEVEL_ERROR, "%zu (%d mV) ", cell, modules[ret.bms_id].cellVoltages[cell]); debug_log_cont(LOG_LEVEL_ERROR, "%u (%d mV) ", cell, modules[ret.bms_id].cellVoltages[cell]);
} }
} }
@ -159,7 +159,7 @@ HAL_StatusTypeDef battery_update() {
} }
if (cellTemps[i][j] > (MAX_TEMP * (uint16_t)(TEMP_CONV))) { if (cellTemps[i][j] > (MAX_TEMP * (uint16_t)(TEMP_CONV))) {
debug_log(LOG_LEVEL_ERROR, "Cell %zu on BMS %zu overtemp: %d0 mC", j, i, cellTemps[i][j]); debug_log(LOG_LEVEL_ERROR, "Cell %u on BMS %u overtemp: %d0 mC", j, i, cellTemps[i][j]);
can_send_error(TS_ERRORKIND_CELL_OVERTEMP, i); can_send_error(TS_ERRORKIND_CELL_OVERTEMP, i);
ts_sm_set_error_source(TS_ERROR_SOURCE_SLAVES, TS_ERRORKIND_CELL_OVERTEMP, true); ts_sm_set_error_source(TS_ERROR_SOURCE_SLAVES, TS_ERRORKIND_CELL_OVERTEMP, true);
} else { } else {

View File

@ -139,10 +139,18 @@ void print_battery_info() {
bufPos = stpcpy(bufPos, "VDEL "); bufPos = stpcpy(bufPos, "VDEL ");
hasFlags = true; hasFlags = true;
} }
swo_write(" Status flags: %s", swo_write(" Status flags: %s", hasFlags ? flagBuffer : "[none]");
hasFlags ? flagBuffer : "[none]");
if (modules[i].status.CS_FLT) { // Print out which ADCs are faulting
swo_write("Comparison fault on ADC/Cell(s): ");
for (ssize_t j = 0; j < 16; j++) {
if (modules[i].status.CS_FLT & (1u << j)) {
swo_write("%d ", j);
}
}
}
swo_write(" Conversion counter: %d", swo_write(" Conversion counter: %d",
modules[i].status.CCTS); modules[i].status.CCTS);
} }