Close
0%
0%

USBCAN-2A Hack

USBCAN-2A is a Chinese CAN Bus Analyzer running with a stm32. My goal : flash the unit with my own program

Public Chat
Similar projects worth following
I was looking for a cheep, compact hardware with 2 CAN and arduino compatible in order to make a CAN gateway between 2 CAN networks.

Before to design a custom solution I bought a USBCAN-2A that is a Chinese CAN Bus Analyzer, to check how it was made.

By chance is running with a STM32F407VET6, two TJA1040 and easy to flash.

Portable Network Graphics (PNG) - 4.19 MB - 03/11/2021 at 15:44

Preview
Download

  • 1 × CAN Bus Analyzer USBCAN-2A USB to CAN Dual path
  • 1 × STLINK-V2 programmer

  • Enable USB

    F Caminade03/12/2021 at 13:04 0 comments

    The USB port is connected on PB15 and PB14 (OTG HS).

    To enable the Serial on this port, you have to configure the compiler options in the Arduino IDE :

    In "Tools" choose :

    • U(S)ART support : Disabled
    • USB support : CDC generic serial
    • USB speed : High speed in full speed mode

    Now the board should be reconized as an USB device

  • CAN1 & CAN2

    F Caminade03/12/2021 at 09:31 0 comments

    Now I want to check if the 2 CAN buses work.

    I am going to use the stm32f407.ino example from this repository : https://github.com/nopnop2002/Arduino-STM32-CAN

    1/In the stm32f407.ino I add these lines (in the

    "bool CANInit(BITRATE bitrate, int remap)" function) in order to match to the hardware :

      if (remap == 4) {
        // CAN1
        RCC->AHB1ENR |= 0x2;                 // Enable GPIOB clock 
        CANSetGpio(GPIOB, 8);                // Set PB8
        CANSetGpio(GPIOB, 9);                // Set PB9
        
        // CAN2
        RCC->AHB1ENR |= 0x2;                 // Enable GPIOB clock 
        CANSetGpio(GPIOB, 5);                // Set PB5
        CANSetGpio(GPIOB, 6);                // Set PB6
      }

    2/In the setup add :

        bool ret = CANInit(CAN_1000KBPS, 4);

    If you want to send to CAN2:

      //uint8_t send_ch = 1; //send to CAN1
      uint8_t send_ch = 2; ////send to CAN2

    Both CAN work : we have the bases !

  • 1st program upload

    F Caminade03/11/2021 at 17:38 0 comments

    After many tries I have succeded to flash the STM32. Details in "Build Instructions".

    First issue : impossible to connect  the STM32 and the STLINK. Solution : Put the NRST pin to the GND, click on connect in the cube programmer, then after 1s disconnect NRST.

    Second issue : The program doesn't start due to a wrong board selection in the ARDUINO IDE. Solution : In the list select the Blue F407VE mini.  Should correspond to this board (??) : https://stm32-base.org/boards/STM32F407VET6-VCC-GND-Small


    Next step : CAN test

  • Pinout

    F Caminade03/11/2021 at 16:34 0 comments

View all 4 project logs

  • 1
    Software requirements

    Arduino IDE

    Arduino for stm32  : https://github.com/stm32duino/Arduino_Core_STM32

    stm32cubeprogrammer

    More details about upload : https://github.com/stm32duino/wiki/wiki/Upload-methods#stm32cubeprogrammer

  • 2
    STLINK-V2 connection

    1/Connect the STLINK-V2 to the board :

    SWCLK->SWCLK

    SWDIO->SWDIO

    GND->GND


    2/If the USB is already plugged don't connect the 3.3V

    Open  STM32cubeProgrammer

    Setup :

    You should be able to connect to the stm32.

    If necessary connect the NRST to the GND to force the upload reset.

  • 3
    Arduino IDE setup

    Important choices :

    - Blue F407VE mini (others boards like generic or black... doesn't work, config issue ?)

    - STM32CubeProgrammer (SWD)

View all 4 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates