Giter Site home page Giter Site logo

moonglow / pcan_pro_x Goto Github PK

View Code? Open in Web Editor NEW
226.0 24.0 135.0 15.83 MB

:alien: XCAN PRO/PRO FD/FD USB2CAN firmware implementation for cheap STM32F4 hardware

License: Do What The F*ck You Want To Public License

C 96.89% C++ 0.09% Assembly 3.01% Makefile 0.01%
pcan stm32f4 busmaster pcanview canutils socketcan usb2can

pcan_pro_x's Introduction

!ACHTUNG! READ FIRST COPYRIGHT ISSUE

XPCAN PRO/PRO FD firmware for STM32F4 based boards

Target hardware:

  • Any STM32F407/405/417/415 based boards with 8/25MHz oscillator

Pinout:

PIN/PINS DESCRIPTION
PC10 STATUS LED
PA2/PA3 TX/RX CAN1 LED
PC6/PC7 TX/RX CAN2 LED
PB8/PB9 CAN1 RX/TX
PB5/PB6 CAN2 RX/TX
PB14/PB15 USB HS DM/DP
PA11/PA12 USB FS DM/DP*

Features:

Limits:

  • PRO FD firmware does not support FD frames cause bxCAN not supports it, but it will works with classic CAN
  • Some protocol specific messages not implemented yet
  • Be sure to use PB14/PB15 pins for USB if you wants PRO/PRO FD

Toolchain:

  • GNU Arm Embedded Toolchain

Tips:

  • PRO FD firmware has better performance on windows ( due internal PEAK driver implementation )

Build:

  • XCAN PRO firmware make pro only for USB HS
  • XCAN PRO FD firmware make pro_fd only for USB HS
  • XCAN FD firmware make fd supports by USB FS/HS
  • XCAN FD firmware for HEX-V2 HW make fd TARGET_CRYSTAL=25 TARGET_USB_ID=FS TARGET_VARIANT=HEXV2_CLONE

License

WTFPL

pcan_pro_x's People

Contributors

moonglow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pcan_pro_x's Issues

bus load monitoring

I noticed that the Pro doesn't have bus load monitoring, and the FD does。
I'm not sure if their(PCAN PRO and PCAN PRO FD) usb protocol is similar?and whether we can fix this problem in a similar way?

support canfd

stm32g431 has canfd,does this project can port to it?what any other change need to do?

Sending data lost with huge data stream

Recently I did a stress test for data sending .
I find that sending data will be lost when huge data stream what comes without delay.

For pcan_cantact, I seen this code that will NACK to host when TXFIFO is full.
(This commit : moonglow/pcan_cantact@43533b5)
And pcan_cantact can pass this test perfectly with this commit.

I'm not sure if their(PCAN and PCAN PRO) usb protocol is similar?and whether we can fix this problem in a similar way?

lack of CODESYS Support

Tried to use your Firmware with Codesys 2.3
Cant Write to Target.
In IFM Flasher i get the Error 4000 (Invalid Block Size, Blockmode only)
And in Codesys i get the following, are you aware of this?
unnamed (1)
unnamed

And are you aware in this? PCAN with new firmware 8.6.1

Do you think its a Clone? XD

STM32f407 Standard

Standard usb pin on most devebox stm32f407 is

PA11 USB_DM
PA12 USB_DP

Can you please make CubeMX project to easy change pin configuration

Thanks

LIN implementation, lack of USB endpoints

STM32F4 ( HS in FS mode with internal phy ) has only 6 bidirectional endpoints ( includes EP0 ) . Thats mean what LIN channel 1 will works OK ( EP5 ) and LIN channel 2 will not works at all ( EP6 ) ( but it implemented and works on hardware what will support needed count of endpoints ). Cons what this cannot be fixed on current hardware, so now it will 2 CAN + 1 LIN.

Is it working good with TJA1042

Hi. In my circuit using TJA1042 but in recommendets code owner says using TJA1050 is it changes someting? I only have TJA1042 should I buy TJA1050 for it ?

can't open device

For some reason it does not work with mainline driver. After getting pcan driver it is detected correctly but works only sometime. After building pcan driver with #define DEBUG_TRACE and DBG=DEBUG works every single time. It also does not work on win32. Any clue?

[ 4224.616141] pcan: data [brp=0 tseg1=0 tseg2=0 sjw=0 sp=0]
[ 4224.616144] pcan: dumping sent message (12 bytes):
[ 4224.616146] pcan: 01 00 00 00 02 00 01 00 06 00 1c 00
[ 4224.616251] pcan: dumping sent message (8 bytes):
[ 4224.616253] pcan: 01 00 00 00 05 00 00 00
[ 4227.613400] pcan: pcan_usbpro_cmd_send_ex(pcan32): failed to send sync cmd (err -2)
[ 4227.613402] pcan: can't open device hardware itself (err -2)!
[ 4227.613530] pcan: PCAN-USB Pro CAN2: 500 items Tx FIFO allocated
[ 4227.613537] pcan: PCAN-USB Pro CAN2: 500 items Rx FIFO allocated
[ 4227.613537] pcan: pcan_usb_stop(CAN2), minor=33
[ 4227.613538] pcan: PCAN-USB Pro CAN2 rx=0 tx=0
[ 4227.613539] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(500): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4227.613540] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(100): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4227.613541] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(140): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4227.613541] pcan: opening PCAN-USB Pro CAN2 with nominal bittiming:
[ 4227.613541] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(562): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4227.613542] pcan: PCAN-USB Pro(CAN2): time=1624804228.464147s: opening with clk=56000000 bitrate=500000 dbitrate=2000000 (flags=00000000h)
[ 4227.613543] pcan: nominal [brp=7 tseg1=13 tseg2=2 sjw=1 sp=8750]
[ 4227.613543] pcan: data [brp=0 tseg1=0 tseg2=0 sjw=0 sp=0]
[ 4227.613544] pcan: dumping sent message (12 bytes):
[ 4227.613545] pcan: 01 00 00 00 02 01 00 00 06 00 1c 00
[ 4230.613466] pcan: pcan_usbpro_cmd_send_ex(pcan33): failed to send sync cmd (err -2)
[ 4230.613468] pcan: can't open device hardware itself (err -2)!
[ 4230.615491] pcan: PCAN-USB Pro CAN1: 500 items Tx FIFO allocated
[ 4230.615498] pcan: PCAN-USB Pro CAN1: 500 items Rx FIFO allocated
[ 4230.615499] pcan: pcan_usb_stop(CAN1), minor=32
[ 4230.615500] pcan: PCAN-USB Pro CAN1 rx=0 tx=0
[ 4230.615501] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(500): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4230.615502] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(100): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4230.615503] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(140): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4230.615503] pcan: opening PCAN-USB Pro CAN1 with nominal bittiming:
[ 4230.615503] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(562): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4230.615504] pcan: PCAN-USB Pro(CAN1): time=1624804231.466128s: opening with clk=56000000 bitrate=500000 dbitrate=2000000 (flags=00000000h)
[ 4230.615505] pcan: nominal [brp=7 tseg1=13 tseg2=2 sjw=1 sp=8750]
[ 4230.615505] pcan: data [brp=0 tseg1=0 tseg2=0 sjw=0 sp=0]
[ 4230.615507] pcan: dumping sent message (12 bytes):
[ 4230.615508] pcan: 01 00 00 00 02 00 00 00 06 00 1c 00
[ 4233.613402] pcan: pcan_usbpro_cmd_send_ex(pcan32): failed to send sync cmd (err -2)
[ 4233.613404] pcan: can't open device hardware itself (err -2)!
[ 4246.408709] pcan: PCAN-USB Pro CAN1: 500 items Tx FIFO allocated
[ 4246.408727] pcan: PCAN-USB Pro CAN1: 500 items Rx FIFO allocated
[ 4246.408730] pcan: pcan_usb_stop(CAN1), minor=32
[ 4246.408731] pcan: PCAN-USB Pro CAN1 rx=0 tx=0
[ 4246.408735] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(500): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4246.408737] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(100): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4246.408739] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(140): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4246.408740] pcan: opening PCAN-USB Pro CAN1 with nominal bittiming:
[ 4246.408742] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(562): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4246.408745] pcan: PCAN-USB Pro(CAN1): time=1624804247.259463s: opening with clk=56000000 bitrate=500000 dbitrate=2000000 (flags=00000000h)
[ 4246.408747] pcan: nominal [brp=7 tseg1=13 tseg2=2 sjw=1 sp=8750]
[ 4246.408748] pcan: data [brp=0 tseg1=0 tseg2=0 sjw=0 sp=0]
[ 4246.408751] pcan: dumping sent message (12 bytes):
[ 4246.408753] pcan: 01 00 00 00 02 00 00 00 06 00 1c 00
[ 4249.405424] pcan: pcan_usbpro_cmd_send_ex(pcan32): failed to send sync cmd (err -2)
[ 4249.405425] pcan: can't open device hardware itself (err -2)!
[ 4249.405509] pcan: PCAN-USB Pro CAN2: 500 items Tx FIFO allocated
[ 4249.405516] pcan: PCAN-USB Pro CAN2: 500 items Rx FIFO allocated
[ 4249.405517] pcan: pcan_usb_stop(CAN2), minor=33
[ 4249.405518] pcan: PCAN-USB Pro CAN2 rx=0 tx=0
[ 4249.405519] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(500): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4249.405520] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(100): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4249.405520] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(140): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4249.405521] pcan: opening PCAN-USB Pro CAN2 with nominal bittiming:
[ 4249.405521] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(562): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4249.405522] pcan: PCAN-USB Pro(CAN2): time=1624804250.256260s: opening with clk=56000000 bitrate=500000 dbitrate=2000000 (flags=00000000h)
[ 4249.405522] pcan: nominal [brp=7 tseg1=13 tseg2=2 sjw=1 sp=8750]
[ 4249.405523] pcan: data [brp=0 tseg1=0 tseg2=0 sjw=0 sp=0]
[ 4249.405524] pcan: dumping sent message (12 bytes):
[ 4249.405525] pcan: 01 00 00 00 02 01 00 00 06 00 1c 00
[ 4252.405329] pcan: pcan_usbpro_cmd_send_ex(pcan33): failed to send sync cmd (err -2)
[ 4252.405331] pcan: can't open device hardware itself (err -2)!
[ 4253.536224] pcan: PCAN-USB Pro CAN1: 500 items Tx FIFO allocated
[ 4253.536243] pcan: PCAN-USB Pro CAN1: 500 items Rx FIFO allocated
[ 4253.536245] pcan: pcan_usb_stop(CAN1), minor=32
[ 4253.536247] pcan: PCAN-USB Pro CAN1 rx=0 tx=0
[ 4253.536251] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(500): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4253.536253] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(100): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4253.536255] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(140): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4253.536256] pcan: opening PCAN-USB Pro CAN1 with nominal bittiming:
[ 4253.536258] pcan: /var/lib/dkms/peak-linux-driver/8.12.0/build/src/pcanfd_core.c(562): clk=56MHz btr=500kbps sp=8750 [BRP=7 TSEGx=13/2 SJW=1 TQ=125]
[ 4253.536261] pcan: PCAN-USB Pro(CAN1): time=1624804254.387022s: opening with clk=56000000 bitrate=500000 dbitrate=2000000 (flags=00000000h)
[ 4253.536263] pcan: nominal [brp=7 tseg1=13 tseg2=2 sjw=1 sp=8750]
[ 4253.536264] pcan: data [brp=0 tseg1=0 tseg2=0 sjw=0 sp=0]
[ 4253.536267] pcan: dumping sent message (12 bytes):
[ 4253.536269] pcan: 01 00 00 00 02 00 00 00 06 00 1c 00
[ 4256.533372] pcan: pcan_usbpro_cmd_send_ex(pcan32): failed to send sync cmd (err -2)
[ 4256.533373] pcan: can't open device hardware itself (err -2)!

Passthru support

Have you ever tried to use this with the J2534 Passthru API? I got a VCDS clone working with this, using PCAN-OBD-2, so the adapter itself works. However, at least ODIS says that communication with the interface does not work.

HSE frequency auto-detect?

Any chance for HSE frequency auto detect in light of https://rusefi.com/forum/viewtopic.php?f=13&t=2243?

rusEFI has that like this

static constexpr float rtcpreDivider = 31;

// This only works if you're using the PLL as the configured clock source!
static_assert(STM32_SW == RCC_CFGR_SW_PLL);

static void enableTimer() {
	RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;
}

static void disableTimer() {
	RCC->APB2ENR &= ~RCC_APB2ENR_TIM11EN;
}

static void reprogramPll(uint8_t roundedHseMhz) {
	// Switch back to HSI to configure PLL
	// clear SW to use HSI
	RCC->CFGR &= ~RCC_CFGR_SW;

	// Stop the PLL
	RCC->CR &= ~RCC_CR_PLLON;

	// Mask out the old PLLM and PLLSRC
	RCC->PLLCFGR &= ~(RCC_PLLCFGR_PLLM_Msk | RCC_PLLCFGR_PLLSRC_Msk);

	// Stick in the new PLLM value
	RCC->PLLCFGR |= (roundedHseMhz << RCC_PLLCFGR_PLLM_Pos) & RCC_PLLCFGR_PLLM_Msk;
	// Set PLLSRC to HSE
	RCC->PLLCFGR |= RCC_PLLCFGR_PLLSRC_HSE;

	// Reenable PLL, wait for lock
	RCC->CR |= RCC_CR_PLLON;
	while (!(RCC->CR & RCC_CR_PLLRDY));

	// Switch clock source back to PLL
	RCC->CFGR &= ~RCC_CFGR_SW;
	RCC->CFGR |= RCC_CFGR_SW_PLL;
	while ((RCC->CFGR & RCC_CFGR_SWS) != (STM32_SW << 2));
}

// __late_init runs after bss/zero initialziation, but before static constructors and main
extern "C" void __late_init() {
	// Set RTCPRE to /31 - just set all the bits
	RCC->CFGR |= RCC_CFGR_RTCPRE_Msk;

	// Turn on timer
	enableTimer();

	// Remap to connect HSERTC to CH1
#ifdef STM32H7XX
	// TI1SEL = 2, HSE_1MHz
	TIMER->TISEL = TIM_TISEL_TI1SEL_1;
#elif defined(STM32F4XX)
	TIMER->OR = TIM_OR_TI1_RMP_1;
#else
	// the definition has a different name on F7 for whatever reason
	TIMER->OR = TIM11_OR_TI1_RMP_1;
#endif

	// Enable capture on channel 1
	TIMER->CCMR1 = TIM_CCMR1_CC1S_0;
	TIMER->CCER = TIM_CCER_CC1E;

	// Start timer
	TIMER->CR1 |= TIM_CR1_CEN;

	// Measure HSE against SYSCLK
	auto hseCounts = getTimerCounts(10);

	// Turn off timer now that we're done with it
	disableTimer();

	float hseFrequencyHz = 10 * rtcpreDivider * STM32_TIMCLK2 / hseCounts;

	hseFrequencyMhz = hseFrequencyHz / 1e6;
	autoDetectedRoundedMhz = efiRound(hseFrequencyMhz, 1);

	reprogramPll(autoDetectedRoundedMhz);
}

Reference hardware

MCU board

  • DevEBox STM32F407VGT6 or STM32F407VET6

CAN transceiver

  • TJA1050 module

LIN transceiver

  • TJA1021

You can buy it on TaoBao or AliExpress

USB pins

Is it possible to use other pins for USB than PB14/PB15? I would like to use it with STM32F4DISCOVERY which have different pinout.

!ACHTUNG! PEAK company copyrighted data

Due PEAK company request to remove copyrighted data from USB descriptor, i removed such data from my repo. Sorry but we must respect other companies.

Q: Firmware will works ?
A: By default firmware not works anymore with PEAK drivers. USB VID set to another value. Vendor/Product strings was changed too.

Not an issue

Has anybody ported this awesome software to the STM32H750?

If I'm not mistaken it has 9-endpoints+0 and two canfd channels. This could solve the second LIN channel problem and add the canfd channels. Dev boards are easily got from Ebay and Aliexpress.

BTW, works great on STM32F429!

IMG_20210711_175540

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.