PaulStoffregen / OneWire

Library for Dallas/Maxim 1-Wire Chips
http://www.pjrc.com/teensy/td_libs_OneWire.html
579 stars 382 forks source link

ESP32 compile error with arduino-esp32 v2.0.3-rc1 (error: 'esp32_gpioMux' was not declared in this scope) #112

Closed bghavami closed 2 years ago

bghavami commented 2 years ago

Board Esp32S2 Dev Module and Esp32S3 Dev Module

Device Description NodeMcu-32S or Esp32-S3-DevKitC-1 v1.6 Testing with Dallas OneWire Temperature sensor

Hardware Configuration GPIO 2 connected to Dallas Temperature sensor

Version latest master

IDE Name Arduino IDE 1.8.20

Operating System Windows 10

Flash frequency 80 Mhz

PSRAM enabled no

Upload speed 921600

Description: I am getting an error while compiling sample/example code for Dallas Temperature sensor. Steps to generate the error: 1- Load the code: File -> Examples -> Dallas Temperature -> Simple 2- verify / Compile

Compiler generates the following error: OneWire_direct_gpio.h:191:38: error: 'esp32_gpioMux' was not declared in this scope ESP_REG(DR_REG_IO_MUX_BASE + esp32_gpioMux[pin].reg) = pinFunction;

It appears that "esp32_gpioMux" is no longer defined!!!

Sketch: // Include the libraries we need

include

include

// Data wire is plugged into port 2 on the Arduino

define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire);

/*

/*

Errors or Incorrect Output

Debug Message In file included from C:\Users\eghav\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\cores\esp32/Arduino.h:36, from C:\Users\eghav\Documents\Arduino\libraries\OneWire\OneWire.cpp:142: C:\Users\eghav\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h: In function 'void directModeInput(uint32_t)': C:\Users\eghav\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h:191:38: error: 'esp32_gpioMux' was not declared in this scope ESP_REG(DR_REG_IO_MUX_BASE + esp32_gpioMux[pin].reg) = pinFunction; ^~~~~ C:\Users\eghav\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\cores\esp32/esp32-hal.h:73:47: note: in definition of macro 'ESP_REG'

define ESP_REG(addr) ((volatile uint32_t )(addr))

                                           ^~~~

C:\Users\eghav\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h: In function 'void directModeOutput(uint32_t)': C:\Users\eghav\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h:232:38: error: 'esp32_gpioMux' was not declared in this scope ESP_REG(DR_REG_IO_MUX_BASE + esp32_gpioMux[pin].reg) = pinFunction; ^~~~~ C:\Users\eghav\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\cores\esp32/esp32-hal.h:73:47: note: in definition of macro 'ESP_REG'

define ESP_REG(addr) ((volatile uint32_t )(addr))

                                           ^~~~

exit status 1 Error compiling for board ESP32S3 Dev Module.

vangalvin commented 2 years ago

I seem to be having the same issue. I tried to move to OneWireNG but DSTherm is pretty limited in what it can do and i could not get the DallasTemperature lib to work with it.

uzi18 commented 2 years ago

OneWireNG and DallasTemperature works perfectly, what was your problem? If you got problem open issue in OneWireNG project @pstolarz

vangalvin commented 2 years ago

OneWireNG and DallasTemperature works perfectly, what was your problem? If you got problem open issue in OneWireNG project @pstolarz

Its working, perfectly now. The issue was being caused by another version of onewire that was lurking in my libraries. As soon as I huned it out and deleted it the error went away.

uzi18 commented 2 years ago

We tested it on esp32 and it works with perfect timings on logic analyzer. For esp32 it is perfect from 0.11.0 Glad you found solution.

goetmat commented 2 years ago

same issue on my side: .pio/libdeps/xxx/OneWire/util/OneWire_direct_gpio.h:191:38: error: 'esp32_gpioMux' was not declared in this scope

bghavami commented 2 years ago

We tested it on esp32 and it works with perfect timings on logic analyzer. For esp32 it is perfect from 0.11.0 Glad you found solution.

If possible, Please, verify that it works with Esp32s3 Dev Module using Version 2.0.3-RC1. I am unable to get it to function. Thanks.

uzi18 commented 2 years ago

If you got problem report it on OneWireNg project. Thanks

Jason2866 commented 2 years ago

@uzi18 OneWire is not working. No one here is interested if OneWireNG is working. As it is now OneWire does NOT work with actual Espressif32 Arduino Core 2.0.3. We changed it to work with actual version. It can be seen here. Will do no PR since it will not get merged (as any fix for espressif devices).

juergen-weber commented 2 years ago

I got a similar error on Platformio indicating that OneWire 2.3.6 is broken when being used with esp32-203: [env:m5stack-core2] platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32/releases/download/2.0.3/esp32-2.0.3.zip platform = espressif32 board = m5stack-core2

In function 'void directModeInput(uint32_t)': .pio/libdeps/m5stack-core2/OneWire/util/OneWire_direct_gpio.h:191:38: error: 'esp32_gpioMux' was not declared in this scope

Jason2866 commented 2 years ago

To be clear it is not a Arduino Core 2.0.3 issue. The problem is the external OneWire library. The library is not from espressif. So espressif is not responsible for. A example for a working modified version is mentioned in https://github.com/PaulStoffregen/OneWire/issues/112#issuecomment-1122689534

drquark commented 2 years ago

I am having the same problem today. I have one copy of OneWire, version 2.3.6 and it conflicts when I have the ESP32 TTGO LoRa32-OLED Board selected. The #include code verifies OK if there is an ESP8266 selected.

If I delete the #include statement, the code verifies OK with the ESP32.

drquark commented 2 years ago

For the previous comment: This was suggested on the Arduino Forum-- My only 2 suggestions would be to go to the github site of the onewire and report your issue there as you've done here. See if an older version of onewire will work.

ESPRESSIF has recently released a new version of the ESP32 core for the ESP-IDF. That core is not compatible, yet, with the ESP32 Arduino Core. From the errors OneWire is using the ESP32 API directly. OneWire may need to be updated.

uzi18 commented 2 years ago

But OneWireNG is compatible and works perfectly.

MrYsLab commented 2 years ago

+1 I, too, am having the compile issue. Downgrading to version 2.0.2 of the ESP32 Arduino core works as a temporary fix.

drquark commented 2 years ago

uzi18, I have read the docs on OneWireNG at github and I can't see how to do the following very simple read/write on a designated pin: --------- for function "dallas()" -------------------------- int dallas(int x) { OneWire ds(x) ; int data0 ; int data1 ; int result ;

ds.reset() ;
ds.write(0xCC) ;  // skip command
ds.write(0xBE) ;  // Read 1st 2 bytes of Scratchpad
data0 = ds.read() ;
data1 = ds.read() ;
result = (data1 << 8) | data0 ;
result = (((result * 90)+0x04) >> 3 ) + 3200 ;  // F x 100
ds.reset() ;
ds.write(0xCC) ;   // skip command
ds.write(0x44,1) ; // start conversion
return result ;

}

drquark commented 2 years ago

For the previous comment, that's one DS18B20 per pin and direct power. Real simple.

What I don't see in the OneWireNG examples is how it is compatible with OneWire. If it is directly compatible, then the code in the previous comment should work without change. Is that true?

The reason I wrote my own code to read the DS18B20 is that I have 20 remote units, but the Dallas library can take a second or so to do a read. I don't have the time to sit in the Dallas function 20 times reading the remotes, so my code (the first time through in each remote) gets garbage, but it starts the conversion. The second and subsequent passes, it reads good data and restarts the conversion process. This works really well with a Nano or Pro Mini.

drquark commented 2 years ago

OK, I used the library manager to add OneWireNg. The #include statement seems to work, but using the statement "OneWire" doesn't create the expected read/write functions, so I don't know what "compatible" means.

Jason2866 commented 2 years ago

@drquark Use this OneWire version. It is a modified version of OneWire and does work with actual Arduino Esp32 core 2.0.3

drquark commented 2 years ago

OK, Jason2866, I'll give it a try. Thanks.

I just downgraded to ESP32 core version 2.0.2 and that eliminated the #include error.

uzi18 commented 2 years ago

uzi18, I have read the docs on OneWireNG at github and I can't see how to do the following very simple read/write on a designated pin: --------- for function "dallas()" -------------------------- int dallas(int x) { OneWire ds(x) ; int data0 ; int data1 ; int result ;

ds.reset() ;
ds.write(0xCC) ;  // skip command
ds.write(0xBE) ;  // Read 1st 2 bytes of Scratchpad
data0 = ds.read() ;
data1 = ds.read() ;
result = (data1 << 8) | data0 ;
result = (((result * 90)+0x04) >> 3 ) + 3200 ;  // F x 100
ds.reset() ;
ds.write(0xCC) ;   // skip command
ds.write(0x44,1) ; // start conversion
return result ;

}

include is the same, but try to uninstall OneWire lib - they can collide in Arduino IDE

check also DSTemp example for code like above

PaulStoffregen commented 2 years ago

Please understand I am depending on the open source community to submit pull requests to maintain ESP32 defines.
I do not personally use or test ESP boards. The old defines, which worked with prior versions of the ESP software, were contributed by the open source community. My hope is someone in the ESP open source community will take the time to verify a new set of defines and send a pull request.

drquark commented 2 years ago

Using the ESP32 core version 2.0.2 and the current 2.3.6 version of OneWire, I'm uploading fine and reading the DS18B20s no sweat.

uzi18 commented 2 years ago

But now you are fixed with old core

Jason2866 commented 2 years ago

Have done a version which is PR ready and should work. Since i have no possibility to test (for the next 4 weeks) give it a try and if ok please give me a feedback here and i will do the PR.

MrYsLab commented 2 years ago

@Jason2866 Thanks for this fix. I just tried with a DS18B20 and am seeing some strange behavior. If I test with ESP32 core version 2.0.2, your version works. However, if I upgrade to 2.0.3, my sketch compiles, but I cannot upload it to my board. There is a serial communication problem. I am using a DoIt DevKit1. Here is the failure output from the Arduino IDE with Show verbose output during compilation turned on:

Sketch uses 705725 bytes (53%) of program storage space. Maximum is 1310720 bytes.
Global variables use 42228 bytes (12%) of dynamic memory, leaving 285452 bytes for local variables. Maximum is 327680 bytes.
esptool.py v3.3-dev
Serial port /dev/ttyUSB0
Connecting......................................

A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0x13)! The chip needs to be in download mode.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
the selected serial port For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
 does not exist or your board is not connected

I will research about the boot mode, and if I make any progress will report back.

juergen-weber commented 2 years ago

Sorted. By simply replacing .pio\libdeps\m5stack-core2\OneWire\utilOneWire_direct_gpio.h with your new file from https://github.com/Jason2866/OneWire/tree/esp32_arduino_core2/util/utilOneWire_direct_gpio.h solved the problem. Thanks Jason

PLATFORM: Espressif 32 (4.2.0) > M5Stack Core2 HARDWARE: ESP32 240MHz, 4.31MB RAM, 16MB Flash PACKAGES:

DallasTemperature @ 3.9.1 OneWire @ 2.3.6

ogiewon commented 2 years ago

@Jason2866 - Thank you very much! I still need to perform some final testing, but so far my code now compiles and loads on to my ESP32-WROOM DevKit.

Jason2866 commented 2 years ago

@Jason2866 Thanks for this fix. I just tried with a DS18B20 and am seeing some strange behavior. If I test with ESP32 core version 2.0.2, your version works. However, if I upgrade to 2.0.3, my sketch compiles, but I cannot upload it to my board. There is a serial communication problem. I am using a DoIt DevKit1. Here is the failure output from the Arduino IDE with Show verbose output during compilation turned on:

Sketch uses 705725 bytes (53%) of program storage space. Maximum is 1310720 bytes.
Global variables use 42228 bytes (12%) of dynamic memory, leaving 285452 bytes for local variables. Maximum is 327680 bytes.
esptool.py v3.3-dev
Serial port /dev/ttyUSB0
Connecting......................................

A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0x13)! The chip needs to be in download mode.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
the selected serial port For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
 does not exist or your board is not connected

I will research about the boot mode, and if I make any progress will report back.

This is issue is not related to the OneWire problem. You have a other problem here.

Jason2866 commented 2 years ago

PR #114

PaulStoffregen commented 2 years ago

I've merged #114. For everyone following this issue and still using ESP32, please download the latest OneWire and reply here to confirm (or deny) this fully solves the problem.

I am waiting for your feedback before publishing a new OneWire version which will make this fix available to everyone using the Arduino Library Manager. Please take a moment to test this latest code and let me know if it should be published as a release to the wider Arduino community?

MrYsLab commented 2 years ago

It works for me connecting to a DS18B20. Thanks.

ogiewon commented 2 years ago

I just tested the latest version on an ESP8266 with 4 DS18B20 sensors attached to a single pin and it still works fine. (I know this change is for the ESP32, but always good to make sure other platforms are not impacted as well.)

roboticboyer commented 2 years ago

I've merged #114. For everyone following this issue and still using ESP32, please download the latest OneWire and reply here to confirm (or deny) this fully solves the problem.

I am waiting for your feedback before publishing a new OneWire version which will make this fix available to everyone using the Arduino Library Manager. Please take a moment to test this latest code and let me know if it should be published as a release to the wider Arduino community?

It's working on ESP32!

MrYsLab commented 2 years ago

Is there an ETA on when a new release containing this PR might be? I want to publish my repository that depends on the fix or if I need to add some documentation to describe a workaround. Tnx.

PaulStoffregen commented 2 years ago

2.3.7 released

MrYsLab commented 2 years ago

@PaulStoffregen @Jason2866 Thank you.