About the CAN controller.

Beck-Sisyphus
Posts: 14
Joined: Sun Jan 03, 2016 12:15 am

Re: About the CAN controller.

Postby Beck-Sisyphus » Fri May 12, 2017 7:35 am

Thank you Rudi for the explanation! I will test my board out and see the result.

Thanks iosixllc for the head up.


Beck

ThomasB
Posts: 38
Joined: Sun Dec 25, 2016 12:11 am

Re: About the CAN controller.

Postby ThomasB » Mon May 15, 2017 10:53 pm

Hi guys...

Sorry for the late reply but im drowning in work.
Ill try my best to implement the change requests in the next 2 weeks.

Regards
Thomas

ThomasB
Posts: 38
Joined: Sun Dec 25, 2016 12:11 am

Re: About the CAN controller.

Postby ThomasB » Wed May 17, 2017 12:16 pm

added extended frame format, check https://github.com/ThomasBarth/ESP32-CAN-Driver

ThomasB
Posts: 38
Joined: Sun Dec 25, 2016 12:11 am

Re: About the CAN controller.

Postby ThomasB » Wed May 17, 2017 1:36 pm

added RTR support: https://github.com/ThomasBarth/ESP32-CAN-Driver

The interface changed a little, the Frame Information record is now copied into the frame type.
This has the advantage that all the information like DLC or RTR can be copied in a single access, which boosts performance. Also this helps to keep the queues small.

Beck-Sisyphus
Posts: 14
Joined: Sun Jan 03, 2016 12:15 am

Re: About the CAN controller.

Postby Beck-Sisyphus » Thu May 18, 2017 6:11 am

Hi Rudi and Thomas,

Error report: 'CLEAR_PERI_REG_MASK' and 'SET_PERI_REG_MASK' error

OS: MacOS;
toolchain: ESP-IDF;
Commit: lastest from github.
component.mk: empty
Makefile:
PROJECT_NAME := CAN_demo
include $(IDF_PATH)/make/project.mk


I got new error in calling 'CLEAR_PERI_REG_MASK' and 'SET_PERI_REG_MASK', and here is a part of it:


/Users/Beck/Developer/esp/esp-idf/components/esp32/include/esp_assert.h:23:13: error: static assertion failed: "(Cannot use READ_PERI_REG for DPORT registers use DPORT_READ_PERI_REG)"
_Static_assert(__builtin_choose_expr(__builtin_constant_p(CONDITION), (CONDITION), 1), #MSG); \
^
/Users/Beck/Developer/esp/esp-idf/components/soc/esp32/include/soc/soc.h:218:76: note: in definition of macro 'WRITE_PERI_REG'
(*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \
^
/Users/Beck/Developer/esp/esp-idf/components/soc/esp32/include/soc/soc.h:138:38: note: in expansion of macro 'TRY_STATIC_ASSERT'
#define ASSERT_IF_DPORT_REG(_r, OP) TRY_STATIC_ASSERT(!IS_DPORT_REG(_r), (Cannot use OP for DPORT registers use DPORT_##OP));
^
/Users/Beck/Developer/esp/esp-idf/components/soc/esp32/include/soc/soc.h:211:13: note: in expansion of macro 'ASSERT_IF_DPORT_REG'
ASSERT_IF_DPORT_REG((addr), READ_PERI_REG); \
^
/Users/Beck/Developer/esp/esp-idf/components/soc/esp32/include/soc/soc.h:224:36: note: in expansion of macro 'READ_PERI_REG'
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \
^
/Users/Beck/Developer/esp/can_bus_components/components/can/./CAN.c:185:5: note: in expansion of macro 'CLEAR_PERI_REG_MASK'
CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);



May I got a hit how to resolve this?

miles0815
Posts: 3
Joined: Fri May 19, 2017 10:27 am

Re: About the CAN controller.

Postby miles0815 » Fri May 19, 2017 10:29 am

Hi all,

i have the same issue. Hope someone may help.

Thanks!

plexidj
Posts: 1
Joined: Sun May 07, 2017 9:47 am

Re: About the CAN controller.

Postby plexidj » Sat May 20, 2017 11:35 am

First of all thanks to everybody who contributed to the ESP32 CAN driver, especially to Thomas Barth. Thomas, I owe you a beer. (How about a Grohe Pilsener)
I am an hobby enthusiast to embedded systems and Android app programing. In embedded systems I started my "career" on Arduino AVR boards. My knowledge in C/Cpp and in electronics is limited and I have almost no knowlegde about compilers, makefiles, toolchains etc.
When the ESP8266 came out I learnd that the chip can also be programmed using the Arduino environment. With the ESP8266 I realized some nice projects in home automation.
I am also an motorcycle enthusiast and programmed a data recording (Android) app using a modified ELM327 Bluetooth adapter to tap the CAN bus of my motorcycle.
When I saw, that the ESP32 includes a CAN module I was thrilled, because now embedded system and motorcycle data recording meet.
But then I realized that even though there is support for the ESP32 in the Arduino environment there is no driver for the CAN module.
Lukily I found the CAN driver and the demo created by Thomas Barth. To use the driver in the Arduino environment I rearranged the folder structure a little bit, removed the "cfg" folder including CAN_config.c file and renamed CAN.c to CAN.cpp. It now looks like:

Code: Select all

[folder] library
     [folder] CAN_ESP32
          [file] CAN.cpp
          [file] CAN.h
          [folder] incude
               [file] CAN_config.h
               [file] can_regdef.h
For testing I set up a CAN bus with an Arduino Uno + CAN module (ID 0x120), an Arduino Nano + CAN module (ID 0x120) and an ESP32ST development board. The bus runs with 500 kbps. I use a 3,3 Volt SN65HVD230 CAN Bus Transceiver. The Arduinos fire each a CAN frames with eight data about every 10 milliseconds. The ESP32ST development board fire every second a CAN frame
The Arduino ino file looks like:

Code: Select all

#include "CAN.h"

CAN_device_t CAN_cfg = {
  .speed=CAN_SPEED_500KBPS,    // CAN Node baudrade
  .tx_pin_id = GPIO_NUM_5,    // CAN TX pin
  .rx_pin_id = GPIO_NUM_4,    // CAN RX pin
  .rx_queue=NULL,         // FreeRTOS queue for RX frames
};

CAN_frame_t frame;
CAN_frame_t __RX_frame;

long t_old;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(500000);

  //create CAN RX Queue
  CAN_cfg.rx_queue = xQueueCreate(10,sizeof(CAN_frame_t));

   //start CAN Module
  CAN_init();

}

void loop() {
  // put your main code here, to run repeatedly:  

  if ((millis()-t_old)>1000){
    t_old=millis();

    frame.MsgID=0x3ff;
    frame.DLC=8;
    frame.data.u8[0]='C';
    frame.data.u8[1]='A';
    frame.data.u8[2]='N';
    frame.data.u8[3]='E';
    frame.data.u8[4]='S';
    frame.data.u8[5]='P';
    frame.data.u8[6]='3';
    frame.data.u8[7]='2';
    
    CAN_write_frame(&frame);
  }

  if(xQueueReceive(CAN_cfg.rx_queue,&__RX_frame, 3*portTICK_PERIOD_MS)==pdTRUE){
    Serial.print(millis());
    Serial.print("/");
    Serial.print(String(__RX_frame.MsgID,HEX));
    Serial.print((char)__RX_frame.data.u8[0]);
    Serial.print((char)__RX_frame.data.u8[1]);
    Serial.print((char)__RX_frame.data.u8[2]);
    Serial.print((char)__RX_frame.data.u8[3]);
    Serial.print((char)__RX_frame.data.u8[4]);
    Serial.print((char)__RX_frame.data.u8[5]);
    Serial.print((char)__RX_frame.data.u8[6]);
    Serial.println((char)__RX_frame.data.u8[7]);
  }    
  delay(0);
}
The whole setup runs smooth over days. On the serial port of ESP32 the frames send by the Arduinos with a timestamp (in milliseconds) can be monitored.

Code: Select all

...
2073687/110CAN-NANO
2073690/120CAN-UNO
2073697/110CAN-NANO
2073700/120CAN-UNO 
2073708/110CAN-NANO
2073711/120CAN-UNO 
2073720/110CAN-NANO
2073723/120CAN-UNO 
2073731/110CAN-NANO
2073734/120CAN-UNO
2073741/110CAN-NANO
2073744/120CAN-UNO
2073752/110CAN-NANO
2073755/120CAN-UNO 
2073764/110CAN-NANO
2073767/120CAN-UNO
2073775/110CAN-NANO
2073778/120CAN-UNO 
2073785/110CAN-NANO
...
Next step for me is to connect the ESP32ST development board to my motorcycle. The motorcycle fires about 800 frames/seconds with 8 bytes payload each. I plan to perform the test in "Silent mode" to not interfere with the motorcycle CAN traffic.
If someone is interested I will report about the result.

fri.sch
Posts: 3
Joined: Tue Apr 11, 2017 7:16 pm

Re: About the CAN controller.

Postby fri.sch » Sat May 20, 2017 10:16 pm

The build issue with the CAN driver seems to have been introduced by: https://github.com/espressif/esp-idf/co ... 620f42173c

I posted a fix as a pull request to Thomas' git repo: https://github.com/ThomasBarth/ESP32-CAN-Driver/pull/7

Regards
Frieder

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: About the CAN controller.

Postby rudi ;-) » Sun May 21, 2017 1:14 pm

Beck-Sisyphus wrote:Hi Rudi and Thomas,

Error report: 'CLEAR_PERI_REG_MASK' and 'SET_PERI_REG_MASK' error

hi
you can try to use this branch in the meantime
i think thomas is update very soon the repo too. it was a change ( named changed ) on espressif ESP-IDF.

btw, thomas add support for extended frames and other things, this is in the top named repo included, also the DPORT access change.

have a try and let me know

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

ThomasB
Posts: 38
Joined: Sun Dec 25, 2016 12:11 am

Re: About the CAN controller.

Postby ThomasB » Sun May 21, 2017 4:07 pm

Merged

Who is online

Users browsing this forum: No registered users and 51 guests