Compare commits

..

2 Commits

Author SHA1 Message Date
a88f663afc give bms time to settle before erroring immediately 2025-03-23 15:44:19 +01:00
2ca3f72de8 get serial ID working? 2025-03-23 15:43:59 +01:00
2 changed files with 15 additions and 5 deletions

View File

@ -31,7 +31,9 @@ HAL_StatusTypeDef amsReset() {
amsWakeUp(); amsWakeUp();
readCMD(SRST, CMD_EMPTY_BUFFER, 0); readCMD(SRST, CMD_EMPTY_BUFFER, 0);
/* uint8_t sidbuffer[CMD_BUFFER_SIZE(SID_GROUP_SIZE)] = {}; amsWakeUp();
uint8_t sidbuffer[CMD_BUFFER_SIZE(SID_GROUP_SIZE)] = {};
if (readCMD(RDSID, sidbuffer, SID_GROUP_SIZE) != HAL_OK) { if (readCMD(RDSID, sidbuffer, SID_GROUP_SIZE) != HAL_OK) {
bool nonzero = false; bool nonzero = false;
for (size_t i = 0; i < N_BMS; i++) { for (size_t i = 0; i < N_BMS; i++) {
@ -61,7 +63,7 @@ HAL_StatusTypeDef amsReset() {
} }
debug_log_cont(LOG_LEVEL_INFO, "0x%lx%lx ", (uint32_t)(id >> 32), (uint32_t)(id & 0xFFFFFFFF)); //newlib does not support %llu debug_log_cont(LOG_LEVEL_INFO, "0x%lx%lx ", (uint32_t)(id >> 32), (uint32_t)(id & 0xFFFFFFFF)); //newlib does not support %llu
} }
} */ }
mcuDelay(10); mcuDelay(10);
amsWakeUp(); amsWakeUp();

View File

@ -114,14 +114,22 @@ int main(void)
/* Infinite loop */ /* Infinite loop */
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
int count = 0; int count = 0;
int error_count = 0;
while (1) while (1)
{ {
if (error_count > 10) {
debug_log(LOG_LEVEL_ERROR, "Too many errors, restarting BMS...");
status = AMS_Init(&hspi1);
if (status.status != ADBMS_NO_ERROR) {
debug_log(LOG_LEVEL_ERROR, "Failed to initialize BMS, AMS_Init returned %u (%s) on BMS %d", status.status, ADBMS_Status_ToString(status.status), status.bms_id);
HAL_Delay(2000);
continue;
}
}
status = AMS_Idle_Loop(); status = AMS_Idle_Loop();
if (status.status != ADBMS_NO_ERROR) { if (status.status != ADBMS_NO_ERROR) {
debug_log(LOG_LEVEL_ERROR, "AMS_Idle_Loop returned %u (%s) on BMS %d", status.status, ADBMS_Status_ToString(status.status), status.bms_id); debug_log(LOG_LEVEL_ERROR, "AMS_Idle_Loop returned %u (%s) on BMS %d", status.status, ADBMS_Status_ToString(status.status), status.bms_id);
HAL_Delay(2000); error_count++;
AMS_Init(&hspi1);
continue;
} }
if (count % 4 == 0) { if (count % 4 == 0) {
for (size_t i = 0; i < N_BMS; i++) { for (size_t i = 0; i < N_BMS; i++) {