enable CAN on H7 (#2393)
* enable * guard correctly * h7 bit timing * allow longer frames * allow data smaller than maximum * mcu temperature * typo * tx message * testing * check for CAN or FDCAN * don't need that any more * h7 bitrate config * undo testing * h7-ify msg tx * comment * break out SID/EID macros * guard differently * update ChibiOS Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
3b6d5e9b24
commit
40c4238f13
|
@ -1 +1 @@
|
|||
Subproject commit 6b0f623d023ed984c586f8979c10bbf11807e121
|
||||
Subproject commit 948b015c9c491295d088d0db4b209b3a37b1a524
|
|
@ -11,9 +11,6 @@
|
|||
#undef EFI_MC33816
|
||||
#define EFI_MC33816 FALSE
|
||||
|
||||
#undef EFI_CAN_SUPPORT
|
||||
#define EFI_CAN_SUPPORT FALSE
|
||||
|
||||
#undef EFI_CJ125
|
||||
#define EFI_CJ125 FALSE
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ private:
|
|||
}
|
||||
|
||||
if (widebandUpdatePending) {
|
||||
#if EFI_WIDEBAND_FIRMWARE_UPDATE && HAL_USE_CAN
|
||||
#if EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT
|
||||
updateWidebandFirmware(logger);
|
||||
#endif
|
||||
widebandUpdatePending = false;
|
||||
|
|
|
@ -35,3 +35,12 @@ public:
|
|||
CanWrite();
|
||||
void PeriodicTask(efitime_t nowNt) override;
|
||||
};
|
||||
|
||||
// We need these helpers because the frame layout is different on STM32H7
|
||||
#ifdef STM32H7XX
|
||||
#define CAN_SID(f) ((f).std.SID)
|
||||
#define CAN_EID(f) ((f).ext.EID)
|
||||
#else
|
||||
#define CAN_SID(f) ((f).SID)
|
||||
#define CAN_EID(f) ((f).EID)
|
||||
#endif
|
||||
|
|
|
@ -64,7 +64,7 @@ bool acceptCanRx(int sid DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
* this build-in CAN sniffer is very basic but that's our CAN sniffer
|
||||
*/
|
||||
static void printPacket(const CANRxFrame &rx, Logging *logger) {
|
||||
bool accept = acceptCanRx(rx.SID);
|
||||
bool accept = acceptCanRx(CAN_SID(rx));
|
||||
if (!accept) {
|
||||
return;
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ static void printPacket(const CANRxFrame &rx, Logging *logger) {
|
|||
// only print info if we're in can debug mode
|
||||
|
||||
// internet people use both hex and decimal to discuss packed IDs, for usability it's better to print both right here
|
||||
scheduleMsg(logger, "CAN_rx %x %d %x, %x %x %x %x %x %x %x %x", rx.SID,
|
||||
rx.SID, rx.DLC, rx.data8[0], rx.data8[1], rx.data8[2], rx.data8[3],
|
||||
scheduleMsg(logger, "CAN_rx %x %d %x, %x %x %x %x %x %x %x %x", CAN_SID(rx),
|
||||
CAN_SID(rx), rx.DLC, rx.data8[0], rx.data8[1], rx.data8[2], rx.data8[3],
|
||||
rx.data8[4], rx.data8[5], rx.data8[6], rx.data8[7]);
|
||||
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ void processCanRxMessage(const CANRxFrame &frame, Logging *logger,
|
|||
processCanRxVss(frame, nowNt);
|
||||
|
||||
#if EFI_CANBUS_SLAVE
|
||||
if (frame.EID == CONFIG(verboseCanBaseAddress) + CAN_SENSOR_1_OFFSET) {
|
||||
if (CAN_EID(frame) == CONFIG(verboseCanBaseAddress) + CAN_SENSOR_1_OFFSET) {
|
||||
int16_t mapScaled = *reinterpret_cast<const int16_t*>(&frame.data8[0]);
|
||||
canMap = mapScaled / (1.0 * PACK_MULT_PRESSURE);
|
||||
} else
|
||||
|
@ -119,7 +119,7 @@ void processCanRxMessage(const CANRxFrame &frame, Logging *logger,
|
|||
|
||||
#if EFI_WIDEBAND_FIRMWARE_UPDATE
|
||||
// Bootloader acks with address 0x727573 aka ascii "rus"
|
||||
if (frame.EID == 0x727573) {
|
||||
if (CAN_EID(frame) == 0x727573) {
|
||||
handleWidebandBootloaderAck();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -82,7 +82,7 @@ void processCanRxVss(const CANRxFrame& frame, efitick_t nowNt) {
|
|||
}
|
||||
|
||||
//filter it we need to process the can message or not
|
||||
if ( frame.SID != filterCanID ) {
|
||||
if (CAN_SID(frame) != filterCanID ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "os_access.h"
|
||||
#include "engine.h"
|
||||
#include "obd2.h"
|
||||
#include "can.h"
|
||||
#include "can_msg_tx.h"
|
||||
#include "vehicle_speed.h"
|
||||
#include "map.h"
|
||||
|
@ -195,7 +196,7 @@ static void handleDtcRequest(int numCodes, int *dtcCode) {
|
|||
|
||||
#if HAL_USE_CAN
|
||||
void obdOnCanPacketRx(const CANRxFrame& rx) {
|
||||
if (rx.SID != OBD_TEST_REQUEST) {
|
||||
if (CAN_SID(rx) != OBD_TEST_REQUEST) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "global.h"
|
||||
|
||||
#if EFI_WIDEBAND_FIRMWARE_UPDATE && HAL_USE_CAN
|
||||
#if EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT
|
||||
|
||||
#include "ch.h"
|
||||
#include "can_msg_tx.h"
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
void showInfo(Logging* logger, const char* sensorName) const override;
|
||||
|
||||
CanSensorBase* processFrame(const CANRxFrame& frame, efitick_t nowNt) {
|
||||
if (frame.EID == m_eid) {
|
||||
if (CAN_EID(frame) == m_eid) {
|
||||
decodeFrame(frame, nowNt);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ static LoggingWithStorage logger("CAN driver");
|
|||
|
||||
// Values below calculated with http://www.bittiming.can-wiki.info/
|
||||
// Pick ST micro bxCAN
|
||||
// Clock rate of 42mhz for f4, 54mhz for f7
|
||||
// Clock rate of 42mhz for f4, 54mhz for f7, 80mhz for h7
|
||||
#ifdef STM32F4XX
|
||||
// These have an 85.7% sample point
|
||||
#define CAN_BTR_100 (CAN_BTR_SJW(0) | CAN_BTR_BRP(29) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
|
||||
|
@ -49,6 +49,21 @@ static LoggingWithStorage logger("CAN driver");
|
|||
#define CAN_BTR_250 (CAN_BTR_SJW(0) | CAN_BTR_BRP(11) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_500 (CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_1k0 (CAN_BTR_SJW(0) | CAN_BTR_BRP(2) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
|
||||
#elif defined(STM32H7XX)
|
||||
// These have an 87.5% sample point
|
||||
// FDCAN driver has different bit timing registers (yes, different format)
|
||||
// for the arbitration and data phases
|
||||
#define CAN_NBTP_100 0x00310C01
|
||||
#define CAN_DBTP_100 0x00310C13
|
||||
|
||||
#define CAN_NBTP_250 0x00130C01
|
||||
#define CAN_DBTP_250 0x00130C13
|
||||
|
||||
#define CAN_NBTP_500 0x00090C01
|
||||
#define CAN_DBTP_500 0x00090C13
|
||||
|
||||
#define CAN_NBTP_1k0 0x00040C01
|
||||
#define CAN_DBTP_1k0 0x00040C13
|
||||
#else
|
||||
#error Please define CAN BTR settings for your MCU!
|
||||
#endif
|
||||
|
@ -62,7 +77,7 @@ static LoggingWithStorage logger("CAN driver");
|
|||
* 29 bit would be CAN_TI0R_EXID (?) but we do not mention it here
|
||||
* CAN_TI0R_STID "Standard Identifier or Extended Identifier"? not mentioned as well
|
||||
*/
|
||||
|
||||
#if defined(STM32F4XX) || defined(STM32F7XX)
|
||||
static const CANConfig canConfig100 = {
|
||||
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
CAN_BTR_100 };
|
||||
|
@ -78,6 +93,39 @@ CAN_BTR_500 };
|
|||
static const CANConfig canConfig1000 = {
|
||||
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
CAN_BTR_1k0 };
|
||||
#elif defined(STM32H7XX)
|
||||
static const CANConfig canConfig100 = {
|
||||
CAN_NBTP_100,
|
||||
CAN_DBTP_100,
|
||||
0, // CCCR
|
||||
0, // TEST
|
||||
0,
|
||||
};
|
||||
|
||||
static const CANConfig canConfig250 = {
|
||||
CAN_NBTP_250,
|
||||
CAN_DBTP_250,
|
||||
0, // CCCR
|
||||
0, // TEST
|
||||
0,
|
||||
};
|
||||
|
||||
static const CANConfig canConfig500 = {
|
||||
CAN_NBTP_500,
|
||||
CAN_DBTP_500,
|
||||
0, // CCCR
|
||||
0, // TEST
|
||||
0,
|
||||
};
|
||||
|
||||
static const CANConfig canConfig1000 = {
|
||||
CAN_NBTP_1k0,
|
||||
CAN_DBTP_1k0,
|
||||
0, // CCCR
|
||||
0, // TEST
|
||||
0,
|
||||
};
|
||||
#endif
|
||||
|
||||
static const CANConfig *canConfig = &canConfig500;
|
||||
|
||||
|
@ -212,6 +260,8 @@ void initCan(void) {
|
|||
break;
|
||||
}
|
||||
|
||||
startCanPins();
|
||||
|
||||
// Initialize hardware
|
||||
#if STM32_CAN_USE_CAN2
|
||||
// CAN1 is required for CAN2
|
||||
|
@ -236,8 +286,6 @@ void initCan(void) {
|
|||
if (CONFIG(canReadEnabled)) {
|
||||
canRead.Start();
|
||||
}
|
||||
|
||||
startCanPins();
|
||||
}
|
||||
|
||||
#endif /* EFI_CAN_SUPPORT */
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "global.h"
|
||||
|
||||
#if EFI_CAN_SUPPORT
|
||||
#include "can.h"
|
||||
#include "can_msg_tx.h"
|
||||
#include "engine_configuration.h"
|
||||
|
||||
|
@ -27,10 +28,24 @@ extern int canWriteNotOk;
|
|||
}
|
||||
|
||||
CanTxMessage::CanTxMessage(uint32_t eid, uint8_t dlc, bool isExtended) {
|
||||
#ifndef STM32H7XX
|
||||
// ST bxCAN device
|
||||
m_frame.IDE = isExtended ? CAN_IDE_EXT : CAN_IDE_STD;
|
||||
m_frame.EID = eid;
|
||||
m_frame.RTR = CAN_RTR_DATA;
|
||||
#else /* if STM32H7XX */
|
||||
// Bosch M_CAN FDCAN device
|
||||
m_frame.common.XTD = isExtended;
|
||||
m_frame.common.RTR = 0;
|
||||
#endif
|
||||
|
||||
if (isExtended) {
|
||||
CAN_EID(m_frame) = eid;
|
||||
} else {
|
||||
CAN_SID(m_frame) = eid;
|
||||
}
|
||||
|
||||
m_frame.DLC = dlc;
|
||||
|
||||
memset(m_frame.data8, 0, sizeof(m_frame.data8));
|
||||
}
|
||||
|
||||
|
@ -43,7 +58,7 @@ CanTxMessage::~CanTxMessage() {
|
|||
}
|
||||
|
||||
if (CONFIG(debugMode) == DBG_CAN) {
|
||||
scheduleMsg(&sharedLogger, "Sending CAN message: SID %x/%x %x %x %x %x %x %x %x %x", m_frame.SID, m_frame.DLC,
|
||||
scheduleMsg(&sharedLogger, "Sending CAN message: SID %x/%x %x %x %x %x %x %x %x %x", CAN_SID(m_frame), m_frame.DLC,
|
||||
m_frame.data8[0], m_frame.data8[1],
|
||||
m_frame.data8[2], m_frame.data8[3],
|
||||
m_frame.data8[4], m_frame.data8[5],
|
||||
|
|
|
@ -74,11 +74,11 @@ template <typename TData>
|
|||
class CanTxTyped final : public CanTxMessage
|
||||
{
|
||||
#if EFI_CAN_SUPPORT
|
||||
static_assert(sizeof(TData) == sizeof(CANTxFrame::data8));
|
||||
static_assert(sizeof(TData) <= sizeof(CANTxFrame::data8));
|
||||
#endif // EFI_CAN_SUPPORT
|
||||
|
||||
public:
|
||||
explicit CanTxTyped(uint32_t eid) : CanTxMessage(eid) { }
|
||||
explicit CanTxTyped(uint32_t eid) : CanTxMessage(eid, sizeof(TData)) { }
|
||||
|
||||
#if EFI_CAN_SUPPORT
|
||||
/**
|
||||
|
|
|
@ -774,11 +774,11 @@ bool isValidCanRxPin(brain_pin_e pin) {
|
|||
}
|
||||
|
||||
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) {
|
||||
#if STM32_CAN_USE_CAN1
|
||||
#if STM32_CAN_USE_CAN1 || STM32_CAN_USE_FDCAN1
|
||||
if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx))
|
||||
return &CAND1;
|
||||
#endif
|
||||
#if STM32_CAN_USE_CAN2
|
||||
#if STM32_CAN_USE_CAN2 || STM32_CAN_USE_FDCAN2
|
||||
if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx))
|
||||
return &CAND2;
|
||||
#endif
|
||||
|
|
|
@ -239,7 +239,7 @@
|
|||
/*
|
||||
* CAN driver system settings.
|
||||
*/
|
||||
#define STM32_CAN_USE_FDCAN1 FALSE
|
||||
#define STM32_CAN_USE_FDCAN1 TRUE
|
||||
#define STM32_CAN_USE_FDCAN2 FALSE
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue