From 6b92aac1daba94680dc92dfa51981dd9991abe66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 4 Mar 2023 17:19:24 +0100 Subject: [PATCH] [core] Organize GCC compilation flags --- builder/family/beken-72xx.py | 38 +++++--------- builder/family/realtek-ambz.py | 37 ++++---------- builder/family/realtek-ambz2.py | 31 ++---------- builder/frameworks/base.py | 45 +++++++++++++++-- builder/utils/cores.py | 16 +++++- builder/utils/libs-queue.py | 1 - cores/beken-72xx/arduino/libraries/LT/LT.cpp | 1 + .../arduino/libraries/WiFi/WiFi.cpp | 1 + .../common/IPv6Address/IPv6Address.cpp | 1 + .../arduino/libraries/common/Update/Update.h | 1 + .../common/WiFiServer/LwIPServer.cpp | 1 + cores/realtek-amb/arduino/libraries/LT/LT.cpp | 1 + .../arduino/libraries/WiFi/WiFiEvents.cpp | 2 +- .../arduino/libraries/WiFi/WiFiPrivate.h | 2 +- .../arduino/libraries/Wire/Wire.cpp | 2 + cores/realtek-amb/arduino/src/wiring_analog.c | 50 ------------------- .../realtek-amb/arduino/src/wiring_digital.c | 6 +-- cores/realtek-amb/arduino/src/wiring_irq.c | 2 +- cores/realtek-amb/base/sdk_private.h | 6 ++- cores/realtek-ambz/base/fixups/cmsis_ipsr.c | 1 + 20 files changed, 102 insertions(+), 143 deletions(-) diff --git a/builder/family/beken-72xx.py b/builder/family/beken-72xx.py index 5c4c500..b72d797 100644 --- a/builder/family/beken-72xx.py +++ b/builder/family/beken-72xx.py @@ -44,32 +44,9 @@ queue.AppendPublic( "-march=armv5te", "-mthumb", "-mthumb-interwork", - "-g", - "-O2", - "-fdata-sections", - "-ffunction-sections", - "-fno-strict-aliasing", - "-fsigned-char", - "-Wno-comment", "-Wno-write-strings", - "-Wno-char-subscripts", - "-Wno-missing-braces", "-Wno-attributes", ], - CFLAGS=[ - "-std=gnu99", - "-nostdlib", - "-Wall", - "-Wno-format", - "-Wno-unknown-pragmas", - ], - CXXFLAGS=[ - "-std=gnu++11", - "-MMD", - "-fno-exceptions", - "-fno-rtti", - "-Wno-literal-suffix", - ], CPPDEFINES=[ # SDK options ("CFG_OS_FREERTOS", "1"), @@ -92,9 +69,7 @@ queue.AppendPublic( "-mcpu=arm968e-s", "-marm", "-mthumb-interwork", - "-g", "--specs=nano.specs", - "-Wl,--gc-sections", "-Wl,-wrap,bk_flash_get_info", "-Wl,-wrap,bk_flash_erase", "-Wl,-wrap,bk_flash_write", @@ -103,6 +78,17 @@ queue.AppendPublic( "-Wl,-wrap,bk_printf", ], ) +queue.AppendPrivate( + CCFLAGS=[ + "-Wno-comment", + "-Wno-char-subscripts", + "-Wno-missing-braces", + ], + CFLAGS=[ + "-Wno-format", + "-Wno-unknown-pragmas", + ], +) srcs_core = [] @@ -330,8 +316,8 @@ queue.AddLibrary( CCFLAGS=[ "-Wno-unused-variable", "-Wno-implicit-function-declaration", + "-w", ], - CFLAGS=["-<-Wall>"], ), ) diff --git a/builder/family/realtek-ambz.py b/builder/family/realtek-ambz.py index d320863..e0bec86 100644 --- a/builder/family/realtek-ambz.py +++ b/builder/family/realtek-ambz.py @@ -17,27 +17,7 @@ queue.AppendPublic( "-mthumb", "-mfloat-abi=hard", "-mfpu=fpv4-sp-d16", - "-g2", - "-w", - "-O2", - "-fdata-sections", - "-ffunction-sections", - "-fmessage-length=0", - "-fno-common", "-fno-short-enums", - "-fomit-frame-pointer", - "-fsigned-char", - ], - CFLAGS=[ - "-std=gnu99", - "-Wno-pointer-sign", - ], - CXXFLAGS=[ - # borrowed from RtlDuino/development/rtl87xx/platform.txt - "-std=gnu++11", - "-MMD", - "-fno-exceptions", - "-fno-rtti", ], CPPDEFINES=[ # other options @@ -52,17 +32,11 @@ queue.AppendPublic( "-mthumb", "-mfloat-abi=hard", "-mfpu=fpv4-sp-d16", - "-g", "--specs=nano.specs", - "-Os", - "-Wl,--gc-sections", - "-Wl,--cref", # the entrypoint in ROM (?) "-Wl,--entry=Reset_Handler", # start function table in startup.c "-Wl,--undefined=gImage2EntryFun0", - "-Wl,--no-enum-size-warning", - "-Wl,--no-wchar-size-warning", "-Wl,-wrap,rom_psk_CalcGTK", "-Wl,-wrap,rom_psk_CalcPTK", "-Wl,-wrap,CalcMIC", @@ -88,6 +62,14 @@ queue.AppendPublic( "-Wl,-wrap,__rtl_vfprintf_r_v1_00", ], ) +queue.AppendPrivate( + CFLAGS=[ + "-Wno-implicit-function-declaration", + "-Wno-incompatible-pointer-types", + "-Wno-int-conversion", + "-Wno-pointer-sign", + ], +) # Sources - from SDK project/realtek_amebaz_va0_example/GCC-RELEASE/application.mk # - "console" is disabled as it introduces build error, and is generally useless @@ -203,6 +185,9 @@ queue.AddLibrary( "+", "+", ], + options=dict( + CFLAGS=["-w"], + ), ) # Sources - lwIP diff --git a/builder/family/realtek-ambz2.py b/builder/family/realtek-ambz2.py index 53a933b..2cab2fe 100644 --- a/builder/family/realtek-ambz2.py +++ b/builder/family/realtek-ambz2.py @@ -21,30 +21,14 @@ queue.AppendPublic( "-mthumb", "-mcmse", "-mfloat-abi=soft", - "-g", - "-gdwarf-3", - "-Os", - "-MMD", - "-fstack-usage", - "-fdata-sections", - "-ffunction-sections", - "-fmessage-length=0", - "-fno-common", "-fno-short-enums", - "-fomit-frame-pointer", - "-fsigned-char", ], CFLAGS=[ - "-std=gnu99", - "-Wall", "-Wpointer-arith", "-Wno-write-strings", "-Wno-maybe-uninitialized", ], CXXFLAGS=[ - "-std=c++11", - "-fno-exceptions", - "-fno-rtti", "-fno-use-cxa-atexit", ], CPPDEFINES=[ @@ -68,19 +52,9 @@ queue.AppendPublic( "-mthumb", "-mcmse", "-mfloat-abi=soft", - "-g", "--specs=nosys.specs", - "-nostartfiles", - "-nodefaultlibs", - "-nostdlib", - "-Os", - "-Wl,--gc-sections", - "-Wl,--warn-section-align", - "-Wl,--cref", - "-Wl,--build-id=none", "-Wl,--use-blx", "-Wl,--undefined=gRamStartFun", - "-Wl,-no-enum-size-warning", "-Wl,-wrap,aesccmp_construct_mic_iv", "-Wl,-wrap,aesccmp_construct_mic_header1", "-Wl,-wrap,aesccmp_construct_ctr_preload", @@ -362,6 +336,11 @@ queue.AddLibrary( "+", "+", ], + options=dict( + CFLAGS=[ + "-Wno-implicit-function-declaration", + ], + ), ) # Sources - mbedTLS diff --git a/builder/frameworks/base.py b/builder/frameworks/base.py index 4995979..cd13865 100644 --- a/builder/frameworks/base.py +++ b/builder/frameworks/base.py @@ -18,11 +18,33 @@ family: Family = env["FAMILY_OBJ"] # Move common core sources (env.AddCoreSources()) and Arduino libs # below per-family sources (to maintain child families taking precedence) -# Global flags (applying to the SDK) +# Global public flags +# Refer to https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html env.Append( CCFLAGS=[ - # Newer versions of GCC complain about undefined macros in #if - "-Wno-undef", + # C Language Options + "-fsigned-char", # Let the type char be signed + # Debugging Options + "-g2", # produce debugging information; the default level is 2 + # Optimization Options + "-Os", # optimize for size; enables all -O2 optimizations except those that often increase code size + "-fdata-sections", # place each function or data item into its own section + "-ffunction-sections", # place each function or data item into its own section + "-fno-strict-aliasing", # (don't) assume the strictest aliasing rules applicable + # Preprocessor Options + "-MMD", # output a rule suitable for make describing the dependencies of the main source file + # Code Generation Options + "-fno-common", # place uninitialized global variables in the BSS section of the object file + "-fno-exceptions", # disable exception handling + # Developer Options + "-fstack-usage", # output stack usage information for the program, on a per-function basis + ], + CFLAGS=[ + "-std=gnu99", + ], + CXXFLAGS=[ + "-std=gnu++11", + "-fno-rtti", # disable generation of information about every class with virtual functions ], ) @@ -62,11 +84,19 @@ queue.AddExternalLibrary("ltchiptool") # uf2ota source code queue.AddExternalLibrary("flashdb") queue.AddExternalLibrary("printf") -# Flags & linker options +# Non-SDK defines & linker options queue.AppendPublic( + CCFLAGS=[ + "-Wreturn-type", + "-Wno-undef", + ], CFLAGS=[ "-Werror=implicit-function-declaration", ], + CXXFLAGS=[ + "-Wno-literal-suffix", + "-Wno-write-strings", + ], CPPDEFINES=[ ("LIBRETUYA", 1), ("LT_VERSION", env.ReadLTVersion(platform.get_dir(), platform.version)), @@ -82,6 +112,13 @@ queue.AppendPublic( "$VARIANTS_DIR", ], LINKFLAGS=[ + "-g2", + "-Os", + "-Wl,--build-id=none", + "-Wl,--cref", + "-Wl,--gc-sections", + "-Wl,--no-enum-size-warning", + "-Wl,--no-wchar-size-warning", # malloc.c wrappers "-Wl,-wrap,malloc", "-Wl,-wrap,calloc", diff --git a/builder/utils/cores.py b/builder/utils/cores.py index 0c04d18..f4a8ad4 100644 --- a/builder/utils/cores.py +++ b/builder/utils/cores.py @@ -48,7 +48,6 @@ def env_add_core_sources(env: Environment, queue, name: str, path: str) -> bool: "+<*.c*>", "+", "+", - "+", "+", "+", "+", @@ -58,10 +57,23 @@ def env_add_core_sources(env: Environment, queue, name: str, path: str) -> bool: "!<.>", "!", "!", - "!", "!", ], ) + queue.AddLibrary( + name=f"core_{name}_fixups", + base_dir=path, + srcs=[ + "+", + ], + includes=[ + "!", + ], + options=dict( + # disable all warnings for fixups + CCFLAGS=["-w"], + ), + ) return True diff --git a/builder/utils/libs-queue.py b/builder/utils/libs-queue.py index 99cfda4..94b7078 100644 --- a/builder/utils/libs-queue.py +++ b/builder/utils/libs-queue.py @@ -166,7 +166,6 @@ class LibraryQueue: def BuildLibraries(self): if self.built: raise RuntimeError("Cannot build a library queue twice") - self.Print() # add public options to the environment apply_options(self.env, self.options_public) diff --git a/cores/beken-72xx/arduino/libraries/LT/LT.cpp b/cores/beken-72xx/arduino/libraries/LT/LT.cpp index 706d043..c95d5be 100644 --- a/cores/beken-72xx/arduino/libraries/LT/LT.cpp +++ b/cores/beken-72xx/arduino/libraries/LT/LT.cpp @@ -169,6 +169,7 @@ bool LibreTuya::otaSwitch(bool force) { bool LibreTuya::wdtEnable(uint32_t timeout) { wdt_ctrl(WCMD_SET_PERIOD, &timeout); wdt_ctrl(WCMD_POWER_UP, NULL); + return true; } void LibreTuya::wdtDisable() { diff --git a/cores/beken-72xx/arduino/libraries/WiFi/WiFi.cpp b/cores/beken-72xx/arduino/libraries/WiFi/WiFi.cpp index 1c198e8..b5e3545 100644 --- a/cores/beken-72xx/arduino/libraries/WiFi/WiFi.cpp +++ b/cores/beken-72xx/arduino/libraries/WiFi/WiFi.cpp @@ -36,6 +36,7 @@ WiFiStatus eventTypeToStatus(uint8_t type) { case RW_EVT_STA_DISCONNECTED: return WL_DISCONNECTED; } + return WL_IDLE_STATUS; } WiFiAuthMode securityTypeToAuthMode(uint8_t type) { diff --git a/cores/common/arduino/libraries/common/IPv6Address/IPv6Address.cpp b/cores/common/arduino/libraries/common/IPv6Address/IPv6Address.cpp index af94839..454dcb1 100644 --- a/cores/common/arduino/libraries/common/IPv6Address/IPv6Address.cpp +++ b/cores/common/arduino/libraries/common/IPv6Address/IPv6Address.cpp @@ -54,6 +54,7 @@ size_t IPv6Address::printTo(Print &p) const { } return n; */ + return 0; } String IPv6Address::toString() const { diff --git a/cores/common/arduino/libraries/common/Update/Update.h b/cores/common/arduino/libraries/common/Update/Update.h index 83b0805..dad3ebb 100644 --- a/cores/common/arduino/libraries/common/Update/Update.h +++ b/cores/common/arduino/libraries/common/Update/Update.h @@ -104,6 +104,7 @@ class UpdateClass { public: String md5String(void) { // return _md5.toString(); + return ""; } void md5(uint8_t *result) { diff --git a/cores/common/arduino/libraries/common/WiFiServer/LwIPServer.cpp b/cores/common/arduino/libraries/common/WiFiServer/LwIPServer.cpp index 710a96d..70dc7cc 100644 --- a/cores/common/arduino/libraries/common/WiFiServer/LwIPServer.cpp +++ b/cores/common/arduino/libraries/common/WiFiServer/LwIPServer.cpp @@ -61,6 +61,7 @@ bool LwIPServer::begin(uint16_t port, bool reuseAddr) { _active = true; _noDelay = false; _sockAccepted = -1; + return true; } void LwIPServer::end() { diff --git a/cores/realtek-amb/arduino/libraries/LT/LT.cpp b/cores/realtek-amb/arduino/libraries/LT/LT.cpp index 097849a..94b0771 100644 --- a/cores/realtek-amb/arduino/libraries/LT/LT.cpp +++ b/cores/realtek-amb/arduino/libraries/LT/LT.cpp @@ -183,6 +183,7 @@ bool LibreTuya::otaSwitch(bool force) { bool LibreTuya::wdtEnable(uint32_t timeout) { watchdog_init(timeout); watchdog_start(); + return true; } void LibreTuya::wdtDisable() { diff --git a/cores/realtek-amb/arduino/libraries/WiFi/WiFiEvents.cpp b/cores/realtek-amb/arduino/libraries/WiFi/WiFiEvents.cpp index 9f06c80..b889a9a 100644 --- a/cores/realtek-amb/arduino/libraries/WiFi/WiFiEvents.cpp +++ b/cores/realtek-amb/arduino/libraries/WiFi/WiFiEvents.cpp @@ -179,7 +179,7 @@ void handleRtwEvent(uint16_t event, char *data, int len, int flags) { if (len != 124) return; eventId = ARDUINO_EVENT_WIFI_AP_STACONNECTED; - memcpy(eventInfo.wifi_ap_staconnected.mac, (const char *)data[10], 6); + memcpy(eventInfo.wifi_ap_staconnected.mac, (const char *)data + 10, 6); break; case WIFI_EVENT_STA_DISASSOC: diff --git a/cores/realtek-amb/arduino/libraries/WiFi/WiFiPrivate.h b/cores/realtek-amb/arduino/libraries/WiFi/WiFiPrivate.h index 8800973..d6f5a83 100644 --- a/cores/realtek-amb/arduino/libraries/WiFi/WiFiPrivate.h +++ b/cores/realtek-amb/arduino/libraries/WiFi/WiFiPrivate.h @@ -35,7 +35,7 @@ extern rtw_wifi_setting_t wifi_setting; extern unsigned char sta_password[65]; extern unsigned char ap_password[65]; extern void reset_wifi_struct(void); -extern rtw_mode_t wifi_mode; +extern wifi_mode_t wifi_mode; extern WiFiAuthMode securityTypeToAuthMode(uint8_t type); // WiFiEvents.cpp extern void startWifiTask(); diff --git a/cores/realtek-amb/arduino/libraries/Wire/Wire.cpp b/cores/realtek-amb/arduino/libraries/Wire/Wire.cpp index 4756604..f850a7d 100644 --- a/cores/realtek-amb/arduino/libraries/Wire/Wire.cpp +++ b/cores/realtek-amb/arduino/libraries/Wire/Wire.cpp @@ -103,6 +103,7 @@ bool TwoWire::end() { i2c_reset(_i2c); delete _i2c; _i2c = NULL; + return true; } bool TwoWire::setClock(uint32_t freq) { @@ -110,6 +111,7 @@ bool TwoWire::setClock(uint32_t freq) { i2c_frequency(_i2c, freq); } _freq = freq; + return true; } void TwoWire::beginTransmission(uint8_t address) { diff --git a/cores/realtek-amb/arduino/src/wiring_analog.c b/cores/realtek-amb/arduino/src/wiring_analog.c index 1fde6e0..05d0796 100644 --- a/cores/realtek-amb/arduino/src/wiring_analog.c +++ b/cores/realtek-amb/arduino/src/wiring_analog.c @@ -106,53 +106,3 @@ void analogWrite(pin_size_t pinNumber, int value) { } } } - -typedef struct _tone_argument { - uint32_t ulPin; - uint32_t timer_id; -}; - -void _tone_timer_handler(const void *argument) { - struct _tone_argument *arg = (struct _tone_argument *)argument; - - uint32_t ulPin = (uint32_t)argument; - - noTone(arg->ulPin); - - os_timer_delete(arg->timer_id); - - free((struct _tone_argument *)arg); -} - -void _tone(uint32_t ulPin, unsigned int frequency, unsigned long duration) { - pwmout_t *obj; - - if ((pinTable[ulPin].supported & PIN_PWM) != PIN_PWM) { - return; - } - - if (pinTable[ulPin].enabled != PIN_PWM) { - if ((pinTable[ulPin].enabled == PIN_GPIO) || (pinTable[ulPin].enabled == PIN_IRQ)) { - pinRemoveMode(ulPin); - } - gpio_pin_struct[ulPin] = malloc(sizeof(pwmout_t)); - pwmout_t *obj = (pwmout_t *)gpio_pin_struct[ulPin]; - pwmout_init(obj, pinTable[ulPin].gpio); - pwmout_period(obj, 1.0 / frequency); - pwmout_pulsewidth(obj, 1.0 / (frequency * 2)); - pinTable[ulPin].enabled = PIN_PWM; - - } else { - // There is already a PWM configured - pwmout_t *obj = (pwmout_t *)gpio_pin_struct[ulPin]; - pwmout_period(obj, 1.0 / frequency); - pwmout_pulsewidth(obj, 1.0 / (frequency * 2)); - } - - if (duration > 0) { - struct _tone_argument *arg = (struct _tone_argument *)malloc(sizeof(struct _tone_argument)); - arg->ulPin = ulPin; - arg->timer_id = os_timer_create(_tone_timer_handler, 0, arg); - os_timer_start(arg->timer_id, duration); - } -} diff --git a/cores/realtek-amb/arduino/src/wiring_digital.c b/cores/realtek-amb/arduino/src/wiring_digital.c index 953ede4..0c8cb32 100644 --- a/cores/realtek-amb/arduino/src/wiring_digital.c +++ b/cores/realtek-amb/arduino/src/wiring_digital.c @@ -13,7 +13,7 @@ void pinRemoveMode(pin_size_t pinNumber) { } if (pinEnabled(pin, PIN_GPIO)) { gpio_t *obj = (gpio_t *)gpio_pin_struct[pinNumber]; - gpio_deinit(obj, pin->gpio); + gpio_deinit(obj); free(obj); } if (pinEnabled(pin, PIN_IRQ)) { @@ -107,9 +107,9 @@ void digitalWrite(pin_size_t pinNumber, PinStatus status) { PinStatus digitalRead(pin_size_t pinNumber) { PinInfo *pin = pinInfo(pinNumber); if (!pin) - return; + return LOW; if (pin->enabled != PIN_GPIO) - return; + return LOW; gpio_t *gpio = (gpio_t *)gpio_pin_struct[pinNumber]; return gpio_read(gpio); diff --git a/cores/realtek-amb/arduino/src/wiring_irq.c b/cores/realtek-amb/arduino/src/wiring_irq.c index 24d04b2..295b3d3 100644 --- a/cores/realtek-amb/arduino/src/wiring_irq.c +++ b/cores/realtek-amb/arduino/src/wiring_irq.c @@ -18,7 +18,7 @@ static void gpioIrqHandler(uint32_t id, gpio_irq_event event) { } void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode) { - attachInterruptParam(interruptNumber, callback, mode, NULL); + attachInterruptParam(interruptNumber, (voidFuncPtrParam)callback, mode, NULL); } void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void *param) { diff --git a/cores/realtek-amb/base/sdk_private.h b/cores/realtek-amb/base/sdk_private.h index 2164233..6ac590b 100644 --- a/cores/realtek-amb/base/sdk_private.h +++ b/cores/realtek-amb/base/sdk_private.h @@ -36,11 +36,13 @@ extern "C" { #include #endif +#include +#undef MBED_GPIO_API_H // ..no comment +#include + #include #include #include -#include -#include #include #include #include diff --git a/cores/realtek-ambz/base/fixups/cmsis_ipsr.c b/cores/realtek-ambz/base/fixups/cmsis_ipsr.c index ca47a89..d6307fd 100644 --- a/cores/realtek-ambz/base/fixups/cmsis_ipsr.c +++ b/cores/realtek-ambz/base/fixups/cmsis_ipsr.c @@ -8,4 +8,5 @@ __attribute__((weak)) uint32_t __get_IPSR() { uint32_t result; asm volatile ("MRS %0, ipsr" : "=r" (result) ); + return result; }