mirror of https://github.com/FOME-Tech/fome-fw.git
add 50/83.3/125kbit CAN (#5072)
* fix CAN * add 83/125 too * bump config version
This commit is contained in:
parent
8e37975a21
commit
cfe0aeef29
|
@ -567,10 +567,13 @@ typedef enum __attribute__ ((__packed__)) {
|
|||
} gppwm_channel_e;
|
||||
|
||||
typedef enum __attribute__ ((__packed__)) {
|
||||
B100KBPS = 0, // 100kbps
|
||||
B250KBPS = 1, // 250kbps
|
||||
B500KBPS = 2, // 500kbps
|
||||
B1MBPS = 3, // 1Mbps
|
||||
B50KBPS = 0, // 50kbps
|
||||
B83KBPS = 1, // 83.33kbps
|
||||
B100KBPS = 2, // 100kbps
|
||||
B125KBPS = 3, // 125kbps
|
||||
B250KBPS = 4, // 250kbps
|
||||
B500KBPS = 5, // 500kbps
|
||||
B1MBPS = 6, // 1Mbps
|
||||
} can_baudrate_e;
|
||||
|
||||
typedef enum __attribute__ ((__packed__)) {
|
||||
|
|
|
@ -31,30 +31,50 @@ static bool isCanEnabled = false;
|
|||
// Clock rate of 42mhz for f4, 54mhz for f7, 80mhz for h7
|
||||
#ifdef STM32F4XX
|
||||
// These have an 85.7% sample point
|
||||
#define CAN_BTR_50 (CAN_BTR_SJW(0) | CAN_BTR_BRP(59) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_83 (CAN_BTR_SJW(0) | CAN_BTR_BRP(35) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_100 (CAN_BTR_SJW(0) | CAN_BTR_BRP(29) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_125 (CAN_BTR_SJW(0) | CAN_BTR_BRP(23) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_250 (CAN_BTR_SJW(0) | CAN_BTR_BRP(11) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_500 (CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_1k0 (CAN_BTR_SJW(0) | CAN_BTR_BRP(2) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
|
||||
#elif defined(STM32F7XX)
|
||||
// These have an 88.9% sample point
|
||||
#define CAN_BTR_100 (CAN_BTR_SJW(0) | CAN_BTR_BRP(30) | CAN_BTR_TS1(15) | CAN_BTR_TS2(2))
|
||||
#define CAN_BTR_50 (CAN_BTR_SJW(0) | CAN_BTR_BRP(59) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_83 (CAN_BTR_SJW(0) | CAN_BTR_BRP(35) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_100 (CAN_BTR_SJW(0) | CAN_BTR_BRP(29) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
|
||||
#define CAN_BTR_125 (CAN_BTR_SJW(0) | CAN_BTR_BRP(23) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
|
||||
#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
|
||||
// 66% sample point, not ideal but best we can do without changing CAN clock
|
||||
#define CAN_NBTP_50 0x061F1F10
|
||||
#define CAN_DBTP_50 0x001F2003
|
||||
|
||||
// 86.7% sample point
|
||||
#define CAN_NBTP_83 0x061F1803
|
||||
#define CAN_DBTP_83 0x001F1833
|
||||
|
||||
// 88.0% sample point
|
||||
#define CAN_NBTP_100 0x061F1402
|
||||
#define CAN_DBTP_100 0x001F1423
|
||||
|
||||
// 85.0% sample point
|
||||
#define CAN_NBTP_125 0x061F0F02
|
||||
#define CAN_DBTP_125 0x001F0F23
|
||||
|
||||
// These have an 87.5% sample point
|
||||
#define CAN_NBTP_250 0x06130C01
|
||||
#define CAN_DBTP_250 0x00130C13
|
||||
|
||||
#define CAN_NBTP_500 0x00090C01
|
||||
#define CAN_NBTP_500 0x06090C01
|
||||
#define CAN_DBTP_500 0x00090C13
|
||||
|
||||
#define CAN_NBTP_1k0 0x00040C01
|
||||
#define CAN_NBTP_1k0 0x06040C01
|
||||
#define CAN_DBTP_1k0 0x00040C13
|
||||
#else
|
||||
#error Please define CAN BTR settings for your MCU!
|
||||
|
@ -70,11 +90,26 @@ static bool isCanEnabled = false;
|
|||
* CAN_TI0R_STID "Standard Identifier or Extended Identifier"? not mentioned as well
|
||||
*/
|
||||
#if defined(STM32F4XX) || defined(STM32F7XX)
|
||||
static const CANConfig canConfig50 = {
|
||||
.mcr = CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
.btr = CAN_BTR_50
|
||||
};
|
||||
|
||||
static const CANConfig canConfig83 = {
|
||||
.mcr = CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
.btr = CAN_BTR_83
|
||||
};
|
||||
|
||||
static const CANConfig canConfig100 = {
|
||||
.mcr = CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
.btr = CAN_BTR_100
|
||||
};
|
||||
|
||||
static const CANConfig canConfig125 = {
|
||||
.mcr = CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
.btr = CAN_BTR_125
|
||||
};
|
||||
|
||||
static const CANConfig canConfig250 = {
|
||||
.mcr = CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
.btr = CAN_BTR_250
|
||||
|
@ -89,6 +124,22 @@ static const CANConfig canConfig1000 = {
|
|||
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
CAN_BTR_1k0 };
|
||||
#elif defined(STM32H7XX)
|
||||
static const CANConfig canConfig50 = {
|
||||
.NBTP = CAN_NBTP_50,
|
||||
.DBTP = CAN_DBTP_50,
|
||||
.CCCR = 0,
|
||||
.TEST = 0,
|
||||
.RXGFC = 0,
|
||||
};
|
||||
|
||||
static const CANConfig canConfig83 = {
|
||||
.NBTP = CAN_NBTP_83,
|
||||
.DBTP = CAN_DBTP_83,
|
||||
.CCCR = 0,
|
||||
.TEST = 0,
|
||||
.RXGFC = 0,
|
||||
};
|
||||
|
||||
static const CANConfig canConfig100 = {
|
||||
.NBTP = CAN_NBTP_100,
|
||||
.DBTP = CAN_DBTP_100,
|
||||
|
@ -97,6 +148,14 @@ static const CANConfig canConfig100 = {
|
|||
.RXGFC = 0,
|
||||
};
|
||||
|
||||
static const CANConfig canConfig125 = {
|
||||
.NBTP = CAN_NBTP_125,
|
||||
.DBTP = CAN_DBTP_125,
|
||||
.CCCR = 0,
|
||||
.TEST = 0,
|
||||
.RXGFC = 0,
|
||||
};
|
||||
|
||||
static const CANConfig canConfig250 = {
|
||||
.NBTP = CAN_NBTP_250,
|
||||
.DBTP = CAN_DBTP_250,
|
||||
|
@ -125,7 +184,10 @@ static const CANConfig canConfig1000 = {
|
|||
#else // not EFI_PROD_CODE
|
||||
// Nothing to actually set for the simulator's CAN config.
|
||||
// It's impossible to set CAN bitrate from userspace, so we can't set it.
|
||||
static const CANConfig canConfig50;
|
||||
static const CANConfig canConfig83;
|
||||
static const CANConfig canConfig100;
|
||||
static const CANConfig canConfig125;
|
||||
static const CANConfig canConfig250;
|
||||
static const CANConfig canConfig500;
|
||||
static const CANConfig canConfig1000;
|
||||
|
@ -260,15 +322,18 @@ void startCanPins() {
|
|||
|
||||
static const CANConfig * findConfig(can_baudrate_e rate) {
|
||||
switch (rate) {
|
||||
case B50KBPS:
|
||||
return &canConfig50;
|
||||
case B83KBPS:
|
||||
return &canConfig83;
|
||||
case B100KBPS:
|
||||
return &canConfig100;
|
||||
break;
|
||||
case B125KBPS:
|
||||
return &canConfig125;
|
||||
case B250KBPS:
|
||||
return &canConfig250;
|
||||
break;
|
||||
case B1MBPS:
|
||||
return &canConfig1000;
|
||||
break;
|
||||
case B500KBPS:
|
||||
default:
|
||||
return &canConfig500;
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
! Any time an incompatible change is made to the configuration format stored in flash,
|
||||
! update this string to the current date! It is required to also update TS_SIGNATURE above
|
||||
! when this happens.
|
||||
#define FLASH_DATA_VERSION 10019
|
||||
#define FLASH_DATA_VERSION 10020
|
||||
|
||||
! this offset is part of console compatibility mechanism, please DO NOT change this offset
|
||||
#define TS_FILE_VERSION_OFFSET 124
|
||||
|
@ -1192,8 +1192,8 @@ int16_t tps2Max;Full throttle#2. tpsMax value as 10 bit ADC value. Not Voltage!\
|
|||
float throttlePedalSecondaryUpVoltage;;"voltage", 1, 0, -6, 6, 2
|
||||
float throttlePedalSecondaryWOTVoltage;Pedal in the floor;"voltage", 1, 0, -6, 6, 2
|
||||
|
||||
#define can_baudrate_e_enum "100kbps", "250kbps", "500kbps", "1Mbps"
|
||||
custom can_baudrate_e 1 bits, U08, @OFFSET@, [0:1], @@can_baudrate_e_enum@@
|
||||
#define can_baudrate_e_enum "50kbps", "83.33kbps", "100kbps", "125kbps", "250kbps", "500kbps", "1Mbps"
|
||||
custom can_baudrate_e 1 bits, U08, @OFFSET@, [0:2], @@can_baudrate_e_enum@@
|
||||
can_baudrate_e canBaudRate; set can_baudrate
|
||||
|
||||
#define ve_override_e_enum "None", "MAP", "TPS"
|
||||
|
|
Loading…
Reference in New Issue