From 7027d2dfe8b071821e0dbf1e277cfa10b383f82b Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 8 Mar 2019 14:57:00 +0800 Subject: [PATCH] spi_master: compile as C11 due to use of stdatomic.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stdatomic.h is available both in newlib and GCC include directories. Normally (if you invoke the compiler without any flags) GCC include directories are first on the list, so GCC’s stdatomic.h is used. In IDF, we used to pass newlib include path as an extra include directory, so newlib’s stdint.h got included instead. Newlib 2.2.0 stdatomic implementation is compatible with -std=gnu99 but incompatible with -std=gnu11. And GCC doesn’t support atomic_load with -std=gnu99 (it’s a C11 feature). So when we used atomic_load with -std=gnu99, it worked due to newlib’s header. Since we are no longer going to be including newlib headers into IDF, GCC stdatomic will be used instead. Hence, add -std=gnu11 for source files which use atomic features. --- components/driver/CMakeLists.txt | 6 ++++++ components/driver/component.mk | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index e4e17b33e..488bf404f 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -25,3 +25,9 @@ set(COMPONENT_PRIV_INCLUDEDIRS "include/driver") set(COMPONENT_REQUIRES esp_ringbuf) register_component() + + +if(GCC_NOT_5_2_0) + # uses C11 atomic feature + set_source_files_properties(spi_master.c PROPERTIES COMPILE_FLAGS -std=gnu11) +endif() diff --git a/components/driver/component.mk b/components/driver/component.mk index a208f6ae2..bff34c912 100644 --- a/components/driver/component.mk +++ b/components/driver/component.mk @@ -6,3 +6,7 @@ COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_PRIV_INCLUDEDIRS := include/driver +ifeq ($(GCC_NOT_5_2_0), 1) +# uses C11 atomic feature +spi_master.o: CFLAGS += -std=gnu11 +endif