CAN: show low-level error counters and flags

STM32 only
This commit is contained in:
Andrey Gusakov 2023-12-07 00:15:45 +03:00 committed by rusefillc
parent 49c502b53b
commit b87f1e8174
7 changed files with 46 additions and 0 deletions

View File

@ -90,9 +90,11 @@ static void canInfo() {
efiPrintf("CAN1 TX %s %s", hwPortname(engineConfiguration->canTxPin), getCan_baudrate_e(engineConfiguration->canBaudRate)); efiPrintf("CAN1 TX %s %s", hwPortname(engineConfiguration->canTxPin), getCan_baudrate_e(engineConfiguration->canBaudRate));
efiPrintf("CAN1 RX %s", hwPortname(engineConfiguration->canRxPin)); efiPrintf("CAN1 RX %s", hwPortname(engineConfiguration->canRxPin));
canHwInfo(detectCanDevice(engineConfiguration->canRxPin, engineConfiguration->canTxPin));
efiPrintf("CAN2 TX %s %s", hwPortname(engineConfiguration->can2TxPin), getCan_baudrate_e(engineConfiguration->can2BaudRate)); efiPrintf("CAN2 TX %s %s", hwPortname(engineConfiguration->can2TxPin), getCan_baudrate_e(engineConfiguration->can2BaudRate));
efiPrintf("CAN2 RX %s", hwPortname(engineConfiguration->can2RxPin)); efiPrintf("CAN2 RX %s", hwPortname(engineConfiguration->can2RxPin));
canHwInfo(detectCanDevice(engineConfiguration->can2RxPin, engineConfiguration->can2TxPin));
efiPrintf("type=%d canReadEnabled=%s canWriteEnabled=%s period=%d", engineConfiguration->canNbcType, efiPrintf("type=%d canReadEnabled=%s canWriteEnabled=%s period=%d", engineConfiguration->canNbcType,
boolToString(engineConfiguration->canReadEnabled), boolToString(engineConfiguration->canWriteEnabled), boolToString(engineConfiguration->canReadEnabled), boolToString(engineConfiguration->canWriteEnabled),

View File

@ -126,4 +126,10 @@ const CANConfig * findCanConfig(can_baudrate_e rate) {
} }
} }
void canHwInfo(CANDriver* cand)
{
/* TODO: */
(void)cand;
}
#endif /* EFI_CAN_SUPPORT */ #endif /* EFI_CAN_SUPPORT */

View File

@ -240,6 +240,12 @@ CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) {
return NULL; return NULL;
} }
void canHwInfo(CANDriver* cand)
{
/* TODO: */
(void)cand;
}
#endif /* EFI_CAN_SUPPORT */ #endif /* EFI_CAN_SUPPORT */
bool allowFlashWhileRunning() { bool allowFlashWhileRunning() {

View File

@ -233,6 +233,12 @@ CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) {
return NULL; return NULL;
} }
void canHwInfo(CANDriver* cand)
{
/* TODO: */
(void)cand;
}
#endif /* EFI_CAN_SUPPORT */ #endif /* EFI_CAN_SUPPORT */
bool allowFlashWhileRunning() { bool allowFlashWhileRunning() {

View File

@ -43,6 +43,7 @@ bool readSlowAnalogInputs(adcsample_t* convertedSamples);
bool isValidCanTxPin(brain_pin_e pin); bool isValidCanTxPin(brain_pin_e pin);
bool isValidCanRxPin(brain_pin_e pin); bool isValidCanRxPin(brain_pin_e pin);
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx); CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
void canHwInfo(CANDriver* cand);
#endif // HAL_USE_CAN #endif // HAL_USE_CAN
// Serial // Serial

View File

@ -231,4 +231,28 @@ const CANConfig * findCanConfig(can_baudrate_e rate) {
} }
} }
void canHwInfo(CANDriver* cand)
{
if (cand == NULL)
return;
if (cand->state != CAN_READY) {
efiPrintf("Interface is not ready");
return;
}
if (cand->can == NULL) {
efiPrintf("No device assigned!");
}
uint32_t esr = cand->can->ESR;
efiPrintf("Receive error counter %d", (esr >> 24) & 0xff);
efiPrintf("Transmit error counter %d", (esr >> 16) & 0xff);
efiPrintf("Last error %d", (esr >> 4) & 0x7);
efiPrintf("Flags: %s %s %s",
(esr & 0x4) ? "BOFF" : "",
(esr & 0x2) ? "EPVF" : "",
(esr & 0x1) ? "EWGF" : "");
}
#endif /* EFI_CAN_SUPPORT */ #endif /* EFI_CAN_SUPPORT */

View File

@ -4,6 +4,7 @@
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx); CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
static bool isValidCanTxPin(brain_pin_e) { return true; } static bool isValidCanTxPin(brain_pin_e) { return true; }
static bool isValidCanRxPin(brain_pin_e) { return true; } static bool isValidCanRxPin(brain_pin_e) { return true; }
static canHwInfo(CANDriver*) { return; }
#endif // HAL_USE_CAN #endif // HAL_USE_CAN
static bool allowFlashWhileRunning() { return true; } static bool allowFlashWhileRunning() { return true; }