Compare commits

..

No commits in common. "8d1ce39155e18ae962db24a2e64a78b0a5740081" and "eed80b80340a8e43470a10861f4dcefb331f47c0" have entirely different histories.

6 changed files with 29 additions and 61 deletions

View File

@ -16,7 +16,6 @@
#define MAX_MESSAGE_LENGTH 256
#define USE_MULTIPLE_CHANNELS false // if true, each log level has its own channel (FATAL : 0, ERROR : 1, etc.)
#define USE_ANSI_ESCAPE_CODES true // if true, log messages will be colored according to their log level, and the console can be cleared
#define PRINT_TIMESTAMP false // if true, timestamp (from HAL_GetTick) is printed before each log message
#if !USE_MULTIPLE_CHANNELS
#define DEBUG_CHANNEL 0 // channel to output messages on
@ -49,12 +48,12 @@ enum log_level_t {
static inline bool __ITM_channel_enabled(uint32_t channel) {
#if !USE_MULTIPLE_CHANNELS
#if USE_CHANNEL_MASK_VARIABLE
#if USE_CHANNEL_MASK_VARIABLE
return ((ITM->TER & (1UL << DEBUG_CHANNEL)) != 0UL) &&
((MASK_VARIABLE & (1UL << channel)) != 0UL);
#else
#else
channel = DEBUG_CHANNEL;
#endif
#endif
#endif
return ((ITM->TER & (1UL << channel)) != 0UL);
}
@ -111,18 +110,6 @@ static void debug_clear_console() {
size_t len = \
snprintf(__swo_buffer, sizeof(__swo_buffer), msg, ##__VA_ARGS__); \
__swo_putc('\n', level); \
/* Print timestamp if enabled */ \
if (PRINT_TIMESTAMP) { \
char __time_buffer[16]; \
if (USE_ANSI_ESCAPE_CODES) { \
snprintf(__time_buffer, sizeof(__time_buffer), \
"\033[90m[%lu]\033[0m ", HAL_GetTick()); \
} else { \
snprintf(__time_buffer, sizeof(__time_buffer), "[%lu] ", \
HAL_GetTick()); \
} \
__swo_print(level, __time_buffer); \
} \
__swo_print(level, log_level_names[level]); \
__swo_print(level, __swo_buffer); \
if (len >= sizeof(__swo_buffer)) { \

View File

@ -23,23 +23,6 @@ typedef enum : uint16_t {
NUM_ERROR_KINDS
} ADBMS_Status;
static const char* ADBMS_Status_Names[NUM_ERROR_KINDS] = {
"ADBMS_NO_ERROR",
"ADBMS_OVERTEMP",
"ADBMS_UNDERTEMP",
"ADBMS_OVERVOLT",
"ADBMS_UNDERVOLT",
"ADBMS_OPENWIRE",
"ADBMS_INTERNAL_BMS_TIMEOUT",
"ADBMS_INTERNAL_BMS_CHECKSUM_FAIL",
"ADBMS_INTERNAL_BMS_OVERTEMP",
"ADBMS_INTERNAL_BMS_FAULT"
};
static inline const char* ADBMS_Status_ToString(ADBMS_Status status) {
return (status < NUM_ERROR_KINDS) ? ADBMS_Status_Names[status] : "UNKNOWN";
}
typedef struct {
ADBMS_Status status : 16;
int16_t bms_id : 16; // the BMS that caused the error, zero if no error, -1 if unknown BMS

View File

@ -209,6 +209,7 @@ HAL_StatusTypeDef amsConfigBalancing(const uint32_t channels[static N_BMS], uint
for (size_t j = 0; j < 2; j++) {
debug_log_cont(LOG_LEVEL_DEBUG, "%x %x ", rxbufB[offsetB + j] & 0x0F, rxbufB[offsetB + j] >> 4);
}
debug_log_cont(LOG_LEVEL_DEBUG, "\n");
}
}

View File

@ -163,6 +163,7 @@ static void print_spi_details() {
debug_log_cont(LOG_LEVEL_ERROR, "%s ", errors[i].label);
}
}
debug_log_cont(LOG_LEVEL_ERROR, "\n");
}
HAL_StatusTypeDef ___writeCMD(uint16_t command, uint8_t * args, size_t arglen) {
@ -205,8 +206,7 @@ HAL_StatusTypeDef ___writeCMD(uint16_t command, uint8_t * args, size_t arglen) {
}
if (ret != HAL_OK) {
debug_log(LOG_LEVEL_ERROR, "STM32 SPI HAL returned error %s", HAL_Statuses[ret]);
debug_log(LOG_LEVEL_ERROR, "SPI error bits: ");
debug_log(LOG_LEVEL_ERROR, "STM32 SPI HAL returned error %s\n SPI error bits: ", HAL_Statuses[ret]);
print_spi_details();
}
@ -223,8 +223,7 @@ HAL_StatusTypeDef ___readCMD(uint16_t command, uint8_t * buffer, size_t arglen)
mcuAdbmsCSHigh();
if (status != HAL_OK) {
debug_log(LOG_LEVEL_ERROR, "STM32 SPI HAL returned error %s", HAL_Statuses[status]);
debug_log(LOG_LEVEL_ERROR, "SPI error bits: ");
debug_log(LOG_LEVEL_ERROR, "STM32 SPI HAL returned error %s\n SPI error bits: ", HAL_Statuses[status]);
print_spi_details();
return status;
}
@ -269,8 +268,7 @@ HAL_StatusTypeDef __pollCMD(uint16_t command, uint8_t waitTime) {
mcuAdbmsCSHigh();
if (status != HAL_OK) {
debug_log(LOG_LEVEL_ERROR, "STM32 SPI HAL returned error %s", HAL_Statuses[status]);
debug_log(LOG_LEVEL_ERROR, "SPI error bits: ");
debug_log(LOG_LEVEL_ERROR, "STM32 SPI HAL returned error %s\n SPI error bits: ", HAL_Statuses[status]);
print_spi_details();
return status;
}

View File

@ -101,11 +101,11 @@ int main(void)
debug_clear_console();
debug_log(LOG_LEVEL_INFO, "AMS_Master on %s (%s), compiled at %s", COMMIT_BRANCH, COMMIT_HASH, COMPILE_DATE);
debug_log(LOG_LEVEL_INFO, "Starting BMS...");
ADBMS_DetailedStatus status = {};
while (status.status != ADBMS_NO_ERROR) {
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);
int status = -1;
while (status != ADBMS_NO_ERROR) {
status = AMS_Init(&hspi1).status;
if (status != ADBMS_NO_ERROR) {
debug_log(LOG_LEVEL_ERROR, "Failed to initialize BMS, AMS_Init returned %d", status);
HAL_Delay(2000);
}
}
@ -116,12 +116,11 @@ int main(void)
int count = 0;
while (1)
{
status = AMS_Idle_Loop();
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);
status = AMS_Idle_Loop().status;
if (status != ADBMS_NO_ERROR) {
debug_log(LOG_LEVEL_ERROR, "AMS_Idle_Loop returned %d", status);
HAL_Delay(2000);
AMS_Init(&hspi1);
continue;
}
if (count % 4 == 0) {
for (size_t i = 0; i < N_BMS; i++) {

View File

@ -24,9 +24,9 @@ cDefinitions:
- STM32H7
- USE_HAL_DRIVER
- FTCAN_NUM_FILTERS=32
- COMMIT_HASH='"$(shell git describe --always --dirty --abbrev=8 2>/dev/null || echo unknown)"'
- COMMIT_BRANCH='"$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)"'
- COMPILE_DATE='"$(shell date "+%Y-%m-%d %H:%M:%S")"'
- COMMIT_HASH='"$(shell git describe --always --dirty --abbrev=8)"'
- COMMIT_BRANCH='"$(shell git rev-parse --abbrev-ref HEAD)"'
- COMPILE_DATE='"$(shell date +'%Y-%m-%d %H:%M:%S')"'
cxxDefinitions: []
asDefinitions: []