Description
Board
ESP32 Feather
Device Description
Adafruit ESP32 Feather dev board
Hardware Configuration
No
Version
v2.0.2
IDE Name
PlatformIO in Visual Studio Code
Operating System
Win10
Flash frequency
N/A
PSRAM enabled
no
Upload speed
115200
Description
Compiling Ticker give me a warning.
Calling this works fine, no warning:
Save_Ticker.once_ms(ms, EP_Save);
Calling this results in a worrisome warning message:
WiFiCtrl.SoftAP_Shutdown_Timer.once_ms(1000*timeout_secs, ShutdownSoftAP, u);
The difference is that the callback function "ShutdownSoftAP" has a parameter "u". It is this parameter that the compiler complains about. It seems to be an issue with the template in Ticker.h.
Background:
I am compiling under native IDF because I need access to functions that don't exist yet in Arduino. I have copied in arduinoespressif\cores and arduinoespressif\library\Ticker. I did fix many circular include dependencies. I am NOT compiling Arduino as IDF component. Tried that, finally gave up.
Targeting: platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2idf/platform-espressif32-2.0.2.zip
This uses IDF 4.4, Arduino 2.0.2
https://github.com/tasmota/platform-espressif32/releases/tag/v2.0.2idf
Sketch
void WiFiCtrlClass::ScheduleSoftAPShutdownTimeSecs(uint32_t timeout_secs, bool DisconnectClients) {
//Serial.printf("Scheduling SoftAP shutdown for %u secs\r\n", timeout_secs);
uint32_t u;
DisconnectClients == true ? u=1 : u=0;
if(timeout_secs == 0)
WiFiCtrl.SoftAP_Shutdown_Timer.detach();
else
WiFiCtrl.SoftAP_Shutdown_Timer.once_ms(1000*timeout_secs, ShutdownSoftAP, u);
}
void static ShutdownSoftAP(uint32_t disconnect_clients) {
if(disconnect_clients==0 && WiFi.softAPgetStationNum()>0) { //Client is still connected. Try again in 1 minute.
Serial.printf("ShutdownSoftAP() Clients=%u\r\n",WiFi.softAPgetStationNum());
WiFiCtrl.ScheduleSoftAPShutdownTimeSecs(10, false);
return;
}
//Serial.println("Shutting down SoftAP");
WiFi.enableAP(false);
}
---From Ticker.h---
template<typename TArg>
void once_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)
{
static_assert(sizeof(TArg) <= sizeof(uint32_t), "attach_ms() callback argument size must be <= 4 bytes");
uint32_t arg32 = (uint32_t)(arg);
_attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), arg32);
}
Debug Message
lib/Ticker/Ticker.h:92:37: warning: cast between incompatible function types from 'void (*)(unsigned int)' to 'Ticker::callback_with_arg_t' {aka 'void (*)(void*)'} [-Wcast-function-type]
_attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), arg32);
It appears to be unhappy with casting (unsigned int) to (void*).
Other Steps to Reproduce
Originally my callback function had a Boolean parameter, but I changed it to uint32_t because the template casts it to uint32_t. I get pretty much the same warning.
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Type
Projects
Status
Activity
mrengineer7777 commentedon Jan 19, 2022
Possibly related: #2849
The proposed change modifies once_ms so that it no longer casts the argument.
template<typename TArg> void once_ms(uint64_t milliseconds, void (*callback)(TArg), TArg arg) { static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)"); _attach_us(1000ULL * milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), (void*)arg); }
Edit: just tested with modified library in #2849. It still gives the same warning :(
VojtechBartoska commentedon Apr 11, 2022
Hello, can you please retest this on v2.0.3-rc1?
mrengineer7777 commentedon Apr 11, 2022
Retested, still fails. Not surprising since v2.0.3-rc1 didn't modify Ticker.h.
Setup: VSCode with Platformio.
platformio.ini config:
Note: since framework is IDF, my project includes a copy of Ticker.c/h. Yes I updated them.
Also note: I started a separate project with
framework=arduino
and was able to implement most needed functionality. The warning message about once_ms() does not occur for the Arduino framework, likely because the libraries are precompiled. The warning message is annoying but at the moment we aren't developing under IDF. I will understand if you want to close out this issue.VojtechBartoska commentedon Apr 11, 2022
Thanks for testing, I'm adding this to our Roadmap and we will take a look on it.
newHeiko commentedon Oct 8, 2022
JFTR: I updated my arduino-esp32 core to 2.0.5 today and this warning now shows up when compiling using the Arduino IDE as well.
Minimalist sketch to reproduce:
Warning message:
Compiling for ESP32-S2, compiler warnings: All.
Hope this helps,
Heiko
P.S: With my limited understanding of C++ templates, I guess the issue is the hard "void *" argument of callback_with_arg_t vs. the more flexible TArg.
11 remaining items