Second CAN #3687
This commit is contained in:
parent
f350338642
commit
2205a57024
|
@ -120,7 +120,8 @@ static const CANConfig canConfig1000 = {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const CANConfig *canConfig = &canConfig500;
|
static const CANConfig *can1Config = &canConfig500;
|
||||||
|
static const CANConfig *can2Config = &canConfig500;
|
||||||
|
|
||||||
class CanRead final : public ThreadController<UTILITY_THREAD_STACK_SIZE> {
|
class CanRead final : public ThreadController<UTILITY_THREAD_STACK_SIZE> {
|
||||||
public:
|
public:
|
||||||
|
@ -168,8 +169,12 @@ static void canInfo() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
efiPrintf("CAN TX %s speed %d", hwPortname(engineConfiguration->canTxPin), engineConfiguration->canBaudRate);
|
efiPrintf("CAN1 TX %s speed %d", hwPortname(engineConfiguration->canTxPin), engineConfiguration->canBaudRate);
|
||||||
efiPrintf("CAN RX %s", hwPortname(engineConfiguration->canRxPin));
|
efiPrintf("CAN1 RX %s", hwPortname(engineConfiguration->canRxPin));
|
||||||
|
|
||||||
|
efiPrintf("CAN2 TX %s speed %d", hwPortname(engineConfiguration->can2TxPin), engineConfiguration->can2BaudRate);
|
||||||
|
efiPrintf("CAN2 RX %s", hwPortname(engineConfiguration->can2RxPin));
|
||||||
|
|
||||||
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),
|
||||||
engineConfiguration->canSleepPeriodMs);
|
engineConfiguration->canSleepPeriodMs);
|
||||||
|
@ -241,6 +246,22 @@ void startCanPins() {
|
||||||
efiSetPadModeIfConfigurationChanged("CAN2 RX", can2RxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
|
efiSetPadModeIfConfigurationChanged("CAN2 RX", can2RxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const CANConfig * findConfig(can_baudrate_e rate) {
|
||||||
|
switch (engineConfiguration->canBaudRate) {
|
||||||
|
case B100KBPS:
|
||||||
|
return &canConfig100;
|
||||||
|
break;
|
||||||
|
case B250KBPS:
|
||||||
|
return &canConfig250;
|
||||||
|
break;
|
||||||
|
case B1MBPS:
|
||||||
|
return &canConfig1000;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return &canConfig500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void initCan(void) {
|
void initCan(void) {
|
||||||
addConsoleAction("caninfo", canInfo);
|
addConsoleAction("caninfo", canInfo);
|
||||||
|
|
||||||
|
@ -256,30 +277,16 @@ void initCan(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (engineConfiguration->canBaudRate) {
|
can1Config = findConfig(engineConfiguration->canBaudRate);
|
||||||
case B100KBPS:
|
can2Config = findConfig(engineConfiguration->can2BaudRate);
|
||||||
canConfig = &canConfig100;
|
|
||||||
break;
|
|
||||||
case B250KBPS:
|
|
||||||
canConfig = &canConfig250;
|
|
||||||
break;
|
|
||||||
case B500KBPS:
|
|
||||||
canConfig = &canConfig500;
|
|
||||||
break;
|
|
||||||
case B1MBPS:
|
|
||||||
canConfig = &canConfig1000;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize hardware
|
// Initialize hardware
|
||||||
#if STM32_CAN_USE_CAN2
|
#if STM32_CAN_USE_CAN2
|
||||||
// CAN1 is required for CAN2
|
// CAN1 is required for CAN2
|
||||||
canStart(&CAND1, canConfig);
|
canStart(&CAND1, can1Config);
|
||||||
canStart(&CAND2, canConfig);
|
canStart(&CAND2, can2Config);
|
||||||
#else
|
#else
|
||||||
canStart(&CAND1, canConfig);
|
canStart(&CAND1, can1Config);
|
||||||
#endif /* STM32_CAN_USE_CAN2 */
|
#endif /* STM32_CAN_USE_CAN2 */
|
||||||
|
|
||||||
if (detectCanDevice(0) == detectCanDevice(1)) {
|
if (detectCanDevice(0) == detectCanDevice(1)) {
|
||||||
|
|
Loading…
Reference in New Issue