pierremolinaro / acan-esp32

An ESP32 CAN 2.0B library
MIT License
40 stars 16 forks source link

Dependency on core_version.h in version 1.x #12

Open lphooge opened 4 months ago

lphooge commented 4 months ago

I had a bit of trouble compiling this library for an m5stack device, it complained about a missing core_version.h

After some investigation I found this is something thats included with specific boards that are installed via the arduino ide. However M5 does not include it for their boards, and thats why it fails.

However the definitions in that file are never used inside the library (only in places where it is commented out anyways), so maybe you can consider just removing it? That would allow hassle-free usage with the m5stack boards.

The offending line is in src/ACAN_ESP32.cpp, line 6 of version 1.1.1 and 1.1.2. Its not there in 1.1.0 and 2.0.0.

As a workaround I placed the following file under DUMMY_CORE_VERSION/core_version.h inside the arduino library folder:

define ARDUINO_ESP32_GIT_VER 0xae9dae4a

define ARDUINO_ESP32_GIT_DESC 2.0.11

define ARDUINO_ESP32_RELEASE_2_0_11

define ARDUINO_ESP32_RELEASE "2_0_11"

This way it compiles and everything works fine, but it might break things when later using an ESP board that DOES include that file for the board manager and maybe has different contents in it so thats not optimal.

pierremolinaro commented 4 months ago

What is the board manager version and what is the ACAN_ESP32 version ?

There are changes in ESP32 board manager version 3.

ESP32 version 2.0.11 —> use ACAN_ESP32 version 1.1.2 ESP32 version 3.0.0alpha3 —> use ACAN_ESP32 version 2.0.0

Le 24 févr. 2024 à 18:56, Lutz-Peter Hooge @.***> a écrit :

I had a bit of trouble compiling this library for an m5stack device, it complained about a missing core_version.h

After some investigation I found this is something thats included with specific boards that are installed via the arduino ide. However M5 does not include it for their boards, and thats why it fails.

However the definitions in that file are never used inside library (only in places where it is commented out anyways), so maybe you can consider just removing it? That would allow hassle-free usage with the m5stack boards.

As a workaround I placed the following file under DUMMY_CORE_VERSION/core_version.h inside the arduino library folder:

define ARDUINO_ESP32_GIT_VER 0xae9dae4a

define ARDUINO_ESP32_GIT_DESC 2.0.11

define ARDUINO_ESP32_RELEASE_2_0_11

define ARDUINO_ESP32_RELEASE "2_0_11"

This way it compiles and everything works fine, but it might break things when later using an ESP board that DOES include that file for the board manager and maybe has different contents in it so thats not optimal.

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan-esp32/issues/12, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVFM7ME3LWXUQRMZLH3YVISVBAVCNFSM6AAAAABDYFQCA6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE2TENBSGM2TCOI. You are receiving this because you are subscribed to this thread.

lphooge commented 4 months ago

ACAN_ESP32 is version 1.1.2 (so the latest 1.x version) Arduino IDE is version 2.

I am not entirely sure what exactly is meant with "board manager". There is the tool called "boards manager" inside the arduino IDE.

And there are helper tools/libraries for the esp32 platform that are installed via this boards manager.

For example in AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\cores\esp32 there is the file core_version.h and the directory seems to refer to a version 2.0.11 of these tools.

However for the m5stack board there is a different directory: AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.0\cores\esp32 This does NOT include this header file.

pierremolinaro commented 4 months ago

The board manager handles « board cores », see https://support.arduino.cc/hc/en-us/articles/360016119519-Add-boards-to-Arduino-IDE

I think you have installed the 2.0.11 release : 

What is your m5stack board ? There are several M5Stack boards.

What is the sketch your are compiling ?

Pierre

Le 25 févr. 2024 à 01:54, Lutz-Peter Hooge @.***> a écrit :

ACAN_ESP32 is version 1.1.2 (so the latest 1.x version) Arduino IDE is version 2.

I am not entirely sure what exactly is meant with "board manager". There is the tool called "boards manager" inside the arduino IDE.

And there are helper tools/libraties for the esp32 platform that are installed via this boards manager.

For example in AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\cores\esp32 there is the file core_version.h and the directory seems to refer to a version 2.0.11 of these tools.

However for the m5stack board there is a different directory: C:\Users\Lutz\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.1.0\cores\esp32 This does not include this header file.

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan-esp32/issues/12#issuecomment-1962773542, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVD7EOSTTUNXGXZHHHLYVKDTBAVCNFSM6AAAAABDYFQCA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRSG43TGNJUGI. You are receiving this because you commented.

lphooge commented 4 months ago

I use an M5stack tough, however I also have a M5 Core 2 and a M5 Stamp C3U here and tried that: It does not matter which of the M5 boards I select, everyone gives this compile error.

And on all of them it works when I just comment out the line "#include " in ACAN_ESP32.cpp but not when its in there. The problem does not show when I select an official ESP32 Board, like "ESP32 Dev Module" (I don't actually own one, but can test compiling it of course), then it compiles fine with that include in there.

Here is a full working sketch for the m5, basically a stripped down version of the loopback example with the m5unified library added for bord specific initialisation and the pins changed to match the Port A Grove Connector on the M5 Tough and Core 2 boards:

`

include

include // needed for proper function, remove for just testing if compiling works

static const uint32_t DESIRED_BIT_RATE = 250UL * 1000UL ; // 250 kb/s

void setup () {

/ needed for proper function, without this the result is always TXERR 128 - probably some pin initialization that is happening here. For just testing compilation, can be taken out. / M5.begin();

//--- Start serial Serial.begin (9600) ; delay (100) ; //--- Configure ESP32 CAN Serial.println ("Configure ESP32 CAN") ; ACAN_ESP32_Settings settings (DESIRED_BIT_RATE) ; settings.mRequestedCANMode = ACAN_ESP32_Settings::LoopBackMode ; settings.mRxPin = GPIO_NUM_33 ; // Optional, default Tx pin is GPIO_NUM_4 settings.mTxPin = GPIO_NUM_32 ; // Optional, default Rx pin is GPIO_NUM_5 const uint32_t errorCode = ACAN_ESP32::can.begin (settings) ; if (errorCode == 0) { Serial.println ("Configuration OK!"); }else { Serial.print ("Configuration error 0x") ; Serial.println (errorCode, HEX) ; } }

//----------------------------------------------------------------------------------------

static uint32_t gBlinkLedDate = 0 ; static uint32_t gReceivedFrameCount = 0 ; static uint32_t gSentFrameCount = 0 ;

//---------------------------------------------------------------------------------------- // LOOP //----------------------------------------------------------------------------------------

void loop () { CANMessage frame ; if (gBlinkLedDate < millis ()) { gBlinkLedDate += 500 ; // digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ; Serial.print ("Sent: ") ; Serial.print (gSentFrameCount) ; Serial.print (" ") ; Serial.print ("Receive: ") ; Serial.print (gReceivedFrameCount) ; Serial.print (" ") ; Serial.print (" STATUS 0x") ; Serial.print (TWAI_STATUS_REG, HEX) ; Serial.print (" RXERR ") ; Serial.print (TWAI_RX_ERR_CNT_REG) ; Serial.print (" TXERR ") ; Serial.println (TWAI_TX_ERR_CNT_REG) ; const bool ok = ACAN_ESP32::can.tryToSend (frame) ; if (ok) { gSentFrameCount += 1 ; } } while (ACAN_ESP32::can.receive (frame)) { gReceivedFrameCount += 1 ; } } `

lphooge commented 4 months ago

Here is the view of the arduino board manager board manager m5

pierremolinaro commented 4 months ago

Ah, you use the M5SStack board manager. My library is designed to be use with ESP32 boeard manager, that is why the compilation fails.

I have installed the M5SStack board manager. Compilation of the ACAN_ESP32 fails on line 7 of ACAN_ESP32.cpp :

include <esp_private/periph_ctrl.h>

After replacing this line with :

include <driver/periph_ctrl.h>

compilation succeeds.

However, as I have no such board, I can’t check if it runs. Can you try ?

Pierre

Le 25 févr. 2024 à 18:03, Lutz-Peter Hooge @.***> a écrit :

Here is the view of the arduino board manager board.manager.m5.png (view on web) https://github.com/pierremolinaro/acan-esp32/assets/1904057/238e23c1-aed0-45d4-9834-61ae93ae7017 — Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan-esp32/issues/12#issuecomment-1963000558, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVHTQGBXUXUOFGLTMULYVNVEVAVCNFSM6AAAAABDYFQCA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRTGAYDANJVHA. You are receiving this because you commented.

lphooge commented 4 months ago

I just tried, installed 2.0.0 and changed that line. It compiles and uploads to the board, but gives TXERR128 and doesn't receive anything.

With 1.1.2 (+core_version fix) it works.

lphooge commented 4 months ago

Ok now it works. I tried to find the problem and compiled a few times and suddently it worked. Maybe the build directory had old crap in it that messed up the first compilation with the new library.

Edit: I now tried the patched 2.0.0 library with my main project, where it connects via CAN to a electric motor controller. Works fine without any changes to my code.