diff --git a/components/asio/port/include/esp_asio_config.h b/components/asio/port/include/esp_asio_config.h index f8e34d617a..cf42183a3e 100644 --- a/components/asio/port/include/esp_asio_config.h +++ b/components/asio/port/include/esp_asio_config.h @@ -30,6 +30,7 @@ # define ASIO_SEPARATE_COMPILATION # define ASIO_STANDALONE # define ASIO_HAS_PTHREADS +# define ASIO_DISABLE_CONCEPTS # ifdef CONFIG_ASIO_USE_ESP_OPENSSL # define ASIO_USE_ESP_OPENSSL diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 1997c6d757..4f2c65b4b7 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -127,6 +127,3 @@ else() REQUIRES esp_pm esp_ringbuf freertos soc hal esp_hw_support LDFRAGMENTS linker.lf) endif() - -# uses C11 atomic feature -set_source_files_properties(spi_master.c PROPERTIES COMPILE_FLAGS -std=gnu11) diff --git a/components/esp_common/include/esp_compiler.h b/components/esp_common/include/esp_compiler.h index 07019425d5..e1857956a7 100644 --- a/components/esp_common/include/esp_compiler.h +++ b/components/esp_common/include/esp_compiler.h @@ -40,7 +40,10 @@ * ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(arr, "Value") * }; */ -#ifdef __cplusplus +#if defined(__cplusplus) && __cplusplus >= 202002L +#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) .member = value, +#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { }, +#elif defined(__cplusplus) && __cplusplus < 202002L #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) { .member = value }, #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { }, #else diff --git a/components/esp_eth/CMakeLists.txt b/components/esp_eth/CMakeLists.txt index 56119ae9b6..5f2f506045 100644 --- a/components/esp_eth/CMakeLists.txt +++ b/components/esp_eth/CMakeLists.txt @@ -53,6 +53,3 @@ idf_component_register(SRCS "${srcs}" INCLUDE_DIRS ${include} REQUIRES "esp_event" # For using "ESP_EVENT_DECLARE_BASE" in header file PRIV_REQUIRES ${priv_requires}) - -# uses C11 atomic feature -set_source_files_properties(src/esp_eth.c PROPERTIES COMPILE_FLAGS -std=gnu11) diff --git a/components/esp_event/CMakeLists.txt b/components/esp_event/CMakeLists.txt index eb934b102f..4580a887d3 100644 --- a/components/esp_event/CMakeLists.txt +++ b/components/esp_event/CMakeLists.txt @@ -25,8 +25,3 @@ idf_component_register(SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires} LDFRAGMENTS linker.lf) - -if(CONFIG_ESP_EVENT_LOOP_PROFILING) - # uses C11 atomic feature - set_source_files_properties(esp_event.c PROPERTIES COMPILE_FLAGS -std=gnu11) -endif() diff --git a/components/soc/esp32/include/soc/soc.h b/components/soc/esp32/include/soc/soc.h index 92f4cb7a4e..e7cb5f33e9 100644 --- a/components/soc/esp32/include/soc/soc.h +++ b/components/soc/esp32/include/soc/soc.h @@ -37,10 +37,10 @@ #endif //write value to register -#define REG_WRITE(_r, _v) ({ \ +#define REG_WRITE(_r, _v) do { \ ASSERT_IF_DPORT_REG((_r), REG_WRITE); \ (*(volatile uint32_t *)(_r)) = (_v); \ - }) + } while(0) //read value from register #define REG_READ(_r) ({ \ @@ -55,22 +55,22 @@ }) //set bit or set bits to register -#define REG_SET_BIT(_r, _b) ({ \ +#define REG_SET_BIT(_r, _b) do { \ ASSERT_IF_DPORT_REG((_r), REG_SET_BIT); \ - (*(volatile uint32_t*)(_r) |= (_b)); \ - }) + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \ + } while(0) //clear bit or clear bits of register -#define REG_CLR_BIT(_r, _b) ({ \ +#define REG_CLR_BIT(_r, _b) do { \ ASSERT_IF_DPORT_REG((_r), REG_CLR_BIT); \ - (*(volatile uint32_t*)(_r) &= ~(_b)); \ - }) + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \ + } while(0) //set bits of register controlled by mask -#define REG_SET_BITS(_r, _b, _m) ({ \ +#define REG_SET_BITS(_r, _b, _m) do { \ ASSERT_IF_DPORT_REG((_r), REG_SET_BITS); \ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ - }) + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \ + } while(0) //get field from register, uses field _S & _V to determine mask #define REG_GET_FIELD(_r, _f) ({ \ @@ -79,10 +79,10 @@ }) //set field of a register from variable, uses field _S & _V to determine mask -#define REG_SET_FIELD(_r, _f, _v) ({ \ +#define REG_SET_FIELD(_r, _f, _v) do { \ ASSERT_IF_DPORT_REG((_r), REG_SET_FIELD); \ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ - }) + REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \ + } while(0) //get field value from a variable, used when _f is not left shifted by _f##_S #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) @@ -109,22 +109,22 @@ }) //write value to register -#define WRITE_PERI_REG(addr, val) ({ \ +#define WRITE_PERI_REG(addr, val) do { \ ASSERT_IF_DPORT_REG((addr), WRITE_PERI_REG); \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ - }) + } while(0) //clear bits of register controlled by mask -#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ +#define CLEAR_PERI_REG_MASK(reg, mask) do { \ ASSERT_IF_DPORT_REG((reg), CLEAR_PERI_REG_MASK); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ - }) + } while(0) //set bits of register controlled by mask -#define SET_PERI_REG_MASK(reg, mask) ({ \ +#define SET_PERI_REG_MASK(reg, mask) do { \ ASSERT_IF_DPORT_REG((reg), SET_PERI_REG_MASK); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ - }) + } while(0) //get bits of register controlled by mask #define GET_PERI_REG_MASK(reg, mask) ({ \ @@ -139,10 +139,10 @@ }) //set bits of register controlled by mask and shift -#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ +#define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \ ASSERT_IF_DPORT_REG((reg), SET_PERI_REG_BITS); \ - (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ - }) + WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \ + } while(0) //get field of register #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ diff --git a/components/soc/esp32c2/include/soc/soc.h b/components/soc/esp32c2/include/soc/soc.h index f2edefacac..1f5f9a098f 100644 --- a/components/soc/esp32c2/include/soc/soc.h +++ b/components/soc/esp32c2/include/soc/soc.h @@ -39,9 +39,9 @@ #ifndef __ASSEMBLER__ //write value to register -#define REG_WRITE(_r, _v) ({ \ +#define REG_WRITE(_r, _v) do { \ (*(volatile uint32_t *)(_r)) = (_v); \ - }) + } while(0) //read value from register #define REG_READ(_r) ({ \ @@ -54,19 +54,19 @@ }) //set bit or set bits to register -#define REG_SET_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) |= (_b)); \ - }) +#define REG_SET_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \ + } while(0) //clear bit or clear bits of register -#define REG_CLR_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) &= ~(_b)); \ - }) +#define REG_CLR_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \ + } while(0) //set bits of register controlled by mask -#define REG_SET_BITS(_r, _b, _m) ({ \ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ - }) +#define REG_SET_BITS(_r, _b, _m) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \ + } while(0) //get field from register, uses field _S & _V to determine mask #define REG_GET_FIELD(_r, _f) ({ \ @@ -74,9 +74,9 @@ }) //set field of a register from variable, uses field _S & _V to determine mask -#define REG_SET_FIELD(_r, _f, _v) ({ \ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ - }) +#define REG_SET_FIELD(_r, _f, _v) do { \ + REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \ + } while(0) //get field value from a variable, used when _f is not left shifted by _f##_S #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) @@ -102,19 +102,19 @@ }) //write value to register -#define WRITE_PERI_REG(addr, val) ({ \ +#define WRITE_PERI_REG(addr, val) do { \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ - }) + } while(0) //clear bits of register controlled by mask -#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ +#define CLEAR_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ - }) + } while(0) //set bits of register controlled by mask -#define SET_PERI_REG_MASK(reg, mask) ({ \ +#define SET_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ - }) + } while(0) //get bits of register controlled by mask #define GET_PERI_REG_MASK(reg, mask) ({ \ @@ -127,9 +127,9 @@ }) //set bits of register controlled by mask and shift -#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ - (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ - }) +#define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \ + WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \ + } while(0) //get field of register #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ diff --git a/components/soc/esp32c3/include/soc/soc.h b/components/soc/esp32c3/include/soc/soc.h index 365d6b7452..547b7fe815 100644 --- a/components/soc/esp32c3/include/soc/soc.h +++ b/components/soc/esp32c3/include/soc/soc.h @@ -32,9 +32,9 @@ #ifndef __ASSEMBLER__ //write value to register -#define REG_WRITE(_r, _v) ({ \ +#define REG_WRITE(_r, _v) do { \ (*(volatile uint32_t *)(_r)) = (_v); \ - }) + } while(0) //read value from register #define REG_READ(_r) ({ \ @@ -47,19 +47,19 @@ }) //set bit or set bits to register -#define REG_SET_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) |= (_b)); \ - }) +#define REG_SET_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \ + } while(0) //clear bit or clear bits of register -#define REG_CLR_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) &= ~(_b)); \ - }) +#define REG_CLR_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \ + } while(0) //set bits of register controlled by mask -#define REG_SET_BITS(_r, _b, _m) ({ \ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ - }) +#define REG_SET_BITS(_r, _b, _m) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \ + } while(0) //get field from register, uses field _S & _V to determine mask #define REG_GET_FIELD(_r, _f) ({ \ @@ -67,9 +67,9 @@ }) //set field of a register from variable, uses field _S & _V to determine mask -#define REG_SET_FIELD(_r, _f, _v) ({ \ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ - }) +#define REG_SET_FIELD(_r, _f, _v) do { \ + REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \ + } while(0) //get field value from a variable, used when _f is not left shifted by _f##_S #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) @@ -95,19 +95,19 @@ }) //write value to register -#define WRITE_PERI_REG(addr, val) ({ \ +#define WRITE_PERI_REG(addr, val) do { \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ - }) + } while(0) //clear bits of register controlled by mask -#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ +#define CLEAR_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ - }) + } while(0) //set bits of register controlled by mask -#define SET_PERI_REG_MASK(reg, mask) ({ \ +#define SET_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ - }) + } while(0) //get bits of register controlled by mask #define GET_PERI_REG_MASK(reg, mask) ({ \ @@ -120,9 +120,9 @@ }) //set bits of register controlled by mask and shift -#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ - (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ - }) +#define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \ + WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \ + } while(0) //get field of register #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ diff --git a/components/soc/esp32h2/include/soc/soc.h b/components/soc/esp32h2/include/soc/soc.h index 165e8c73b4..98c5f62c92 100644 --- a/components/soc/esp32h2/include/soc/soc.h +++ b/components/soc/esp32h2/include/soc/soc.h @@ -32,9 +32,9 @@ #ifndef __ASSEMBLER__ //write value to register -#define REG_WRITE(_r, _v) ({ \ +#define REG_WRITE(_r, _v) do { \ (*(volatile uint32_t *)(_r)) = (_v); \ - }) + } while(0) //read value from register #define REG_READ(_r) ({ \ @@ -47,19 +47,19 @@ }) //set bit or set bits to register -#define REG_SET_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) |= (_b)); \ - }) +#define REG_SET_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \ + } while(0) //clear bit or clear bits of register -#define REG_CLR_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) &= ~(_b)); \ - }) +#define REG_CLR_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \ + } while(0) //set bits of register controlled by mask -#define REG_SET_BITS(_r, _b, _m) ({ \ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ - }) +#define REG_SET_BITS(_r, _b, _m) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \ + } while(0) //get field from register, uses field _S & _V to determine mask #define REG_GET_FIELD(_r, _f) ({ \ @@ -67,9 +67,9 @@ }) //set field of a register from variable, uses field _S & _V to determine mask -#define REG_SET_FIELD(_r, _f, _v) ({ \ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ - }) +#define REG_SET_FIELD(_r, _f, _v) do { \ + REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \ + } while(0) //get field value from a variable, used when _f is not left shifted by _f##_S #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) @@ -95,19 +95,19 @@ }) //write value to register -#define WRITE_PERI_REG(addr, val) ({ \ +#define WRITE_PERI_REG(addr, val) do { \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ - }) + } while(0) //clear bits of register controlled by mask -#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ +#define CLEAR_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ - }) + } while(0) //set bits of register controlled by mask -#define SET_PERI_REG_MASK(reg, mask) ({ \ +#define SET_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ - }) + } while(0) //get bits of register controlled by mask #define GET_PERI_REG_MASK(reg, mask) ({ \ @@ -120,9 +120,9 @@ }) //set bits of register controlled by mask and shift -#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ - (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ - }) +#define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \ + WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \ + } while(0) //get field of register #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ diff --git a/components/soc/esp32s2/include/soc/soc.h b/components/soc/esp32s2/include/soc/soc.h index caa446355a..55112b84e9 100644 --- a/components/soc/esp32s2/include/soc/soc.h +++ b/components/soc/esp32s2/include/soc/soc.h @@ -38,9 +38,9 @@ #ifndef __ASSEMBLER__ //write value to register -#define REG_WRITE(_r, _v) ({ \ +#define REG_WRITE(_r, _v) do { \ (*(volatile uint32_t *)(_r)) = (_v); \ - }) + } while(0) //read value from register #define REG_READ(_r) ({ \ @@ -53,19 +53,19 @@ }) //set bit or set bits to register -#define REG_SET_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) |= (_b)); \ - }) +#define REG_SET_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \ + } while(0) //clear bit or clear bits of register -#define REG_CLR_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) &= ~(_b)); \ - }) +#define REG_CLR_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \ + } while(0) //set bits of register controlled by mask -#define REG_SET_BITS(_r, _b, _m) ({ \ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ - }) +#define REG_SET_BITS(_r, _b, _m) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \ + } while(0) //get field from register, uses field _S & _V to determine mask #define REG_GET_FIELD(_r, _f) ({ \ @@ -73,9 +73,9 @@ }) //set field of a register from variable, uses field _S & _V to determine mask -#define REG_SET_FIELD(_r, _f, _v) ({ \ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ - }) +#define REG_SET_FIELD(_r, _f, _v) do { \ + REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \ + } while(0) //get field value from a variable, used when _f is not left shifted by _f##_S #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) @@ -101,19 +101,19 @@ }) //write value to register -#define WRITE_PERI_REG(addr, val) ({ \ +#define WRITE_PERI_REG(addr, val) do { \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ - }) + } while(0) //clear bits of register controlled by mask -#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ +#define CLEAR_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ - }) + } while(0) //set bits of register controlled by mask -#define SET_PERI_REG_MASK(reg, mask) ({ \ +#define SET_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ - }) + } while(0) //get bits of register controlled by mask #define GET_PERI_REG_MASK(reg, mask) ({ \ @@ -126,9 +126,9 @@ }) //set bits of register controlled by mask and shift -#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ - (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ - }) +#define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \ + WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \ + } while(0) //get field of register #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ diff --git a/components/soc/esp32s3/include/soc/soc.h b/components/soc/esp32s3/include/soc/soc.h index bc94faf5f6..0b1a48d4e8 100644 --- a/components/soc/esp32s3/include/soc/soc.h +++ b/components/soc/esp32s3/include/soc/soc.h @@ -48,9 +48,9 @@ #ifndef __ASSEMBLER__ //write value to register -#define REG_WRITE(_r, _v) ({ \ +#define REG_WRITE(_r, _v) do { \ (*(volatile uint32_t *)(_r)) = (_v); \ - }) + } while(0) //read value from register #define REG_READ(_r) ({ \ @@ -63,19 +63,19 @@ }) //set bit or set bits to register -#define REG_SET_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) |= (_b)); \ - }) +#define REG_SET_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \ + } while(0) //clear bit or clear bits of register -#define REG_CLR_BIT(_r, _b) ({ \ - (*(volatile uint32_t*)(_r) &= ~(_b)); \ - }) +#define REG_CLR_BIT(_r, _b) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \ + } while(0) //set bits of register controlled by mask -#define REG_SET_BITS(_r, _b, _m) ({ \ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ - }) +#define REG_SET_BITS(_r, _b, _m) do { \ + *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \ + } while(0) //get field from register, uses field _S & _V to determine mask #define REG_GET_FIELD(_r, _f) ({ \ @@ -83,9 +83,9 @@ }) //set field of a register from variable, uses field _S & _V to determine mask -#define REG_SET_FIELD(_r, _f, _v) ({ \ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ - }) +#define REG_SET_FIELD(_r, _f, _v) do { \ + REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \ + } while(0) //get field value from a variable, used when _f is not left shifted by _f##_S #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) @@ -111,19 +111,19 @@ }) //write value to register -#define WRITE_PERI_REG(addr, val) ({ \ +#define WRITE_PERI_REG(addr, val) do { \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ - }) + } while(0) //clear bits of register controlled by mask -#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ +#define CLEAR_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ - }) + } while(0) //set bits of register controlled by mask -#define SET_PERI_REG_MASK(reg, mask) ({ \ +#define SET_PERI_REG_MASK(reg, mask) do { \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ - }) + } while(0) //get bits of register controlled by mask #define GET_PERI_REG_MASK(reg, mask) ({ \ @@ -136,9 +136,9 @@ }) //set bits of register controlled by mask and shift -#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ - (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ - }) +#define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \ + WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \ + } while(0) //get field of register #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ diff --git a/docs/en/migration-guides/peripherals.rst b/docs/en/migration-guides/peripherals.rst index 1d0fa4298c..8f7c49c0c8 100644 --- a/docs/en/migration-guides/peripherals.rst +++ b/docs/en/migration-guides/peripherals.rst @@ -319,3 +319,22 @@ LCD 7. Calling :cpp:func:`i2s_channel_disable` to stop the hardware of I2S channel. 8. Calling :cpp:func:`i2s_del_channel` to delete and release the resources of the channel if it is not needed any more, but the channel must be disabled before deleting it. + +Register access macros +---------------------- + +Previously, all register access macros could be used as expressions, so the following was allowed:: + + uint32_t val = REG_SET_BITS(reg, mask); + +In IDF v5.0, register access macros which write or read-modify-write the register can no longer be used as expressions, and can only be used as statements. This applies to the following macros: ``REG_WRITE``, ``REG_SET_BIT``, ``REG_CLR_BIT``, ``REG_SET_BITS``, ``REG_SET_FIELD``, ``WRITE_PERI_REG``, ``CLEAR_PERI_REG_MASK``, ``SET_PERI_REG_MASK``, ``SET_PERI_REG_BITS``. + +To store the value which would have been written into the register, split the operation as follows:: + + uint32_t new_val = REG_READ(reg) | mask; + REG_WRITE(reg, new_val); + +To get the value of the register after modification (which may be different from the value written), add an explicit read:: + + REG_SET_BITS(reg, mask); + uint32_t new_val = REG_READ(reg); diff --git a/examples/cxx/experimental/esp_mqtt_cxx/components/esp_mqtt_cxx/CMakeLists.txt b/examples/cxx/experimental/esp_mqtt_cxx/components/esp_mqtt_cxx/CMakeLists.txt index 5dd0329d08..15809a21ef 100644 --- a/examples/cxx/experimental/esp_mqtt_cxx/components/esp_mqtt_cxx/CMakeLists.txt +++ b/examples/cxx/experimental/esp_mqtt_cxx/components/esp_mqtt_cxx/CMakeLists.txt @@ -4,8 +4,6 @@ idf_component_register(SRCS "esp_mqtt_cxx.cpp" INCLUDE_DIRS "include" ) -target_compile_options(${COMPONENT_LIB} PRIVATE "-std=gnu++17") - if(TEST_BUILD) message(STATUS "Test build") idf_component_get_property(mqtt_dir mqtt COMPONENT_DIR) diff --git a/examples/cxx/experimental/esp_mqtt_cxx/ssl/main/CMakeLists.txt b/examples/cxx/experimental/esp_mqtt_cxx/ssl/main/CMakeLists.txt index 9871f4c78f..e06e5975be 100644 --- a/examples/cxx/experimental/esp_mqtt_cxx/ssl/main/CMakeLists.txt +++ b/examples/cxx/experimental/esp_mqtt_cxx/ssl/main/CMakeLists.txt @@ -1,4 +1,2 @@ idf_component_register(SRCS "mqtt_ssl_example.cpp" INCLUDE_DIRS ".") - -target_compile_options(${COMPONENT_LIB} PRIVATE "-std=gnu++17") diff --git a/examples/cxx/experimental/esp_mqtt_cxx/tcp/main/CMakeLists.txt b/examples/cxx/experimental/esp_mqtt_cxx/tcp/main/CMakeLists.txt index 07fa3e75c9..eeaa9534e5 100644 --- a/examples/cxx/experimental/esp_mqtt_cxx/tcp/main/CMakeLists.txt +++ b/examples/cxx/experimental/esp_mqtt_cxx/tcp/main/CMakeLists.txt @@ -1,3 +1,2 @@ idf_component_register(SRCS "mqtt_tcp_example.cpp" INCLUDE_DIRS ".") -target_compile_options(${COMPONENT_LIB} PRIVATE "-std=gnu++17") diff --git a/examples/protocols/asio/asio_chat/main/chat_message.hpp b/examples/protocols/asio/asio_chat/main/chat_message.hpp index 629105b05b..a6ffc83b8c 100644 --- a/examples/protocols/asio/asio_chat/main/chat_message.hpp +++ b/examples/protocols/asio/asio_chat/main/chat_message.hpp @@ -18,8 +18,8 @@ class chat_message { public: - enum { header_length = 4 }; - enum { max_body_length = 512 }; + static constexpr std::size_t header_length = 4; + static constexpr std::size_t max_body_length = 512; chat_message() : body_length_(0) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 35d4a4d68c..4f01018fff 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -117,16 +117,57 @@ function(__build_set_default_build_specifications) # go into the final binary so have no impact on size "-ggdb") - list(APPEND c_compile_options "-std=gnu99") - - list(APPEND cxx_compile_options "-std=gnu++11") - idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND) idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND) idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND) endfunction() +function(__build_set_lang_version) + if(NOT IDF_TARGET STREQUAL "linux") + # Building for chip targets: we use a known version of the toolchain. + # Use latest supported versions. + set(c_std gnu17) + set(cxx_std gnu++20) + else() + enable_language(C CXX) + # Building for Linux target, fall back to an older version of the standard + # if the preferred one is not supported by the compiler. + set(preferred_c_versions gnu17 gnu11 gnu99) + set(ver_found FALSE) + foreach(c_version ${preferred_c_versions}) + check_c_compiler_flag("-std=${c_version}" ver_${c_version}_supported) + if(ver_${c_version}_supported) + set(c_std ${c_version}) + set(ver_found TRUE) + break() + endif() + endforeach() + if(NOT ver_found) + message(FATAL_ERROR "Failed to set C language standard to one of the supported versions: " + "${preferred_c_versions}. Please upgrade the host compiler.") + endif() + + set(preferred_cxx_versions gnu++20 gnu++2a gnu++17 gnu++14) + set(ver_found FALSE) + foreach(cxx_version ${preferred_cxx_versions}) + check_cxx_compiler_flag("-std=${cxx_version}" ver_${cxx_version}_supported) + if(ver_${cxx_version}_supported) + set(cxx_std ${cxx_version}) + set(ver_found TRUE) + break() + endif() + endforeach() + if(NOT ver_found) + message(FATAL_ERROR "Failed to set C++ language standard to one of the supported versions: " + "${preferred_cxx_versions}. Please upgrade the host compiler.") + endif() + endif() + + idf_build_set_property(C_COMPILE_OPTIONS "-std=${c_std}" APPEND) + idf_build_set_property(CXX_COMPILE_OPTIONS "-std=${cxx_std}" APPEND) +endfunction() + # # Initialize the build. This gets called upon inclusion of idf.cmake to set internal # properties used for the processing phase of the build. @@ -151,6 +192,7 @@ function(__build_init idf_path) idf_build_set_property(IDF_COMPONENT_MANAGER 0) __build_set_default_build_specifications() + __build_set_lang_version() # Add internal components to the build idf_build_get_property(idf_path IDF_PATH) diff --git a/tools/cmake/idf.cmake b/tools/cmake/idf.cmake index 311346b5fe..aad4475af5 100644 --- a/tools/cmake/idf.cmake +++ b/tools/cmake/idf.cmake @@ -36,6 +36,8 @@ if(NOT __idf_env_set) set(IDF_PATH ${idf_path}) include(GetGitRevisionDescription) + include(CheckCCompilerFlag) + include(CheckCXXCompilerFlag) include(git_submodules) include(crosstool_version_check) include(kconfig) diff --git a/tools/test_apps/system/cxx_build_test/CMakeLists.txt b/tools/test_apps/system/cxx_build_test/CMakeLists.txt new file mode 100644 index 0000000000..6220fe0dff --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/CMakeLists.txt @@ -0,0 +1,9 @@ +# For more information about build system see +# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +set(COMPONENTS main) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(cxx_build_test) diff --git a/tools/test_apps/system/cxx_build_test/README.md b/tools/test_apps/system/cxx_build_test/README.md new file mode 100644 index 0000000000..85d7875f10 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/README.md @@ -0,0 +1,7 @@ +# C++ build test + +This build-only app can be used to check if certain headers, macros or features can be successfully compiled in a C++ source file. + +To add a new test, create a new file `main/test_.cpp` and add it to main/CMakeLists.txt. + +If you need to check specific compiler flags, use `set_source_files_properties` CMake function to adjust the compilation flags for the given source file. diff --git a/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt b/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt new file mode 100644 index 0000000000..ece9736565 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS cxx_build_test_main.cpp + test_soc_reg_macros.cpp + INCLUDE_DIRS "." + REQUIRES soc) diff --git a/tools/test_apps/system/cxx_build_test/main/cxx_build_test_main.cpp b/tools/test_apps/system/cxx_build_test/main/cxx_build_test_main.cpp new file mode 100644 index 0000000000..3196de6e05 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/main/cxx_build_test_main.cpp @@ -0,0 +1,10 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include + +extern "C" void app_main(void) +{ +} diff --git a/tools/test_apps/system/cxx_build_test/main/test_soc_reg_macros.cpp b/tools/test_apps/system/cxx_build_test/main/test_soc_reg_macros.cpp new file mode 100644 index 0000000000..fa2d60b509 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/main/test_soc_reg_macros.cpp @@ -0,0 +1,39 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +/* Compiling this file checks if SoC register access macros + * can be used from C++ successfully. This check is necessary + * because C++ 20 deprecates certain uses of 'volatile' qualified + * variables. + */ +#include "soc/soc.h" +#include "soc/uart_reg.h" + + +/* non-static, to prevent the value being optimized out */ +void sink(uint32_t arg) +{ +} + +void test_reg_macros(void) +{ + REG_WRITE(UART_DATE_REG(0), 1); + sink(REG_READ(UART_DATE_REG(0))); + sink(REG_GET_BIT(UART_DATE_REG(0), BIT(0))); + REG_SET_BIT(UART_DATE_REG(0), BIT(0)); + REG_CLR_BIT(UART_DATE_REG(0), BIT(0)); + REG_SET_BITS(UART_DATE_REG(0), BIT(0), BIT(0) | BIT(1)); + sink(REG_GET_FIELD(UART_DATE_REG(0), UART_DATE)); + REG_SET_FIELD(UART_DATE_REG(0), UART_DATE, 42); + + sink(READ_PERI_REG(UART_DATE_REG(0))); + WRITE_PERI_REG(UART_DATE_REG(0), 1); + CLEAR_PERI_REG_MASK(UART_DATE_REG(0), BIT(0)); + SET_PERI_REG_MASK(UART_DATE_REG(0), BIT(0)); + sink(GET_PERI_REG_MASK(UART_DATE_REG(0), BIT(0))); + sink(GET_PERI_REG_BITS(UART_DATE_REG(0), 2, 1)); + SET_PERI_REG_BITS(UART_DATE_REG(0), BIT(0) | BIT(1), 1, 2); + sink(GET_PERI_REG_BITS2(UART_DATE_REG(0), BIT(0) | BIT(1), 1)); +}