Error "wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs" initializer is not constant

ammaree
Posts: 33
Joined: Tue Dec 27, 2016 2:10 am

Error "wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs" initializer is not constant

Postby ammaree » Tue Aug 22, 2017 9:37 pm

Anybody come across this error. Occurs using completely stock standard wifi initialization macro:

Code: Select all

wifi_init_config_t	wifi_cfg = WIFI_INIT_CONFIG_DEFAULT() ;
CC build/main/application.o
In file included from C:/Dropbox/devs/ws/z-appl/ewm01/main/application.c:9:0:
C:/Dropbox/devs/ws/z-sdk/esp-idf/components/esp32/include/esp_wifi.h:150:25: error: initializer element is not constant
.wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
^
C:/Dropbox/devs/ws/z-appl/ewm01/main/application.c:74:32: note: in expansion of macro 'WIFI_INIT_CONFIG_DEFAULT'
wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT() ;
^
C:/Dropbox/devs/ws/z-sdk/esp-idf/components/esp32/include/esp_wifi.h:150:25: note: (near initialization for 'wifi_cfg.wpa_crypto_funcs')
.wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
^
C:/Dropbox/devs/ws/z-appl/ewm01/main/application.c:74:32: note: in expansion of macro 'WIFI_INIT_CONFIG_DEFAULT'
wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT() ;
^
make[1]: *** [/c/Dropbox/devs/ws/z-sdk/esp-idf/make/component_wrapper.mk:229: application.o] Error 1
make: *** [/c/Dropbox/devs/ws/z-sdk/esp-idf/make/project.mk:391: component-main-build] Error 2
make: *** Waiting for unfinished jobs....
Have tried to replace the macro with is definitions directly in the source code, error remains exactly the same.

Any suggestions ?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Error "wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs" initializer is not constant

Postby kolban » Tue Aug 22, 2017 9:53 pm

Its not impossible that you have stumbled over some buggy code. Looking at the source files in Github, we see that those files were apparently committed only 3 weeks ago. You may want to test with a release build as opposed to "master" and see if the problem still manifests. Either way, this may be a good candidate for a Github issue. Also ensure that you aren't using a custom "toolchain build" and if you are or have otherwise changed the environment from the vanilla path, make note of those changes.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Error "wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs" initializer is not constant

Postby ESP_Angus » Tue Aug 22, 2017 11:47 pm

The way the WIFI_INIT_CONFIG_DEFAULT() macro is written, it can't be used to initialize a globally scoped variable.

What I mean is, if this line:

Code: Select all

wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT() ;
Is a local ("automatic") variable inside a function, it will be fine. But if the declaration is at the top level of the source file, outside any function, WIFI_INIT_CONFIG_DEFAULT() can't be used (and you get the errors that you posted above). This is a limitation of the C language.

If you want to have wifi_cfg as a global variable accessible from multiple places, then you can do something like this:

Code: Select all

wifi_init_config_t cfg; // Global config variable

void app_main() {
    const wifi_init_config_t cfg_init = WIFI_INIT_CONFIG_DEFAULT();
    cfg = cfg_init; // Initialise 'cfg'
}
"cfg" will be initialized to all zeroes when the app first starts at the very beginning, but then app_main() copies the correct default values (which will be stored in flash inside "cfg_init") into the "cfg" variable.

Note that keeping "cfg" around as a global variable uses more RAM than declaring it locally in the function. It doesn't need to be kept around after esp_wifi_init() has been called.


PS Fun fact, you can write "cfg = WIFI_INIT_CONFIG_DEFAULT()" as a global variable in a .cpp file and that will work, because C++ has more liberal rules around constant initializers. You can even "extern" that variable and then access it from your .c file.

Who is online

Users browsing this forum: No registered users and 140 guests