[core] Organize GCC compilation flags

This commit is contained in:
Kuba Szczodrzyński
2023-03-04 17:19:24 +01:00
parent 3113b387c3
commit 6b92aac1da
20 changed files with 102 additions and 143 deletions

View File

@@ -44,32 +44,9 @@ queue.AppendPublic(
"-march=armv5te", "-march=armv5te",
"-mthumb", "-mthumb",
"-mthumb-interwork", "-mthumb-interwork",
"-g",
"-O2",
"-fdata-sections",
"-ffunction-sections",
"-fno-strict-aliasing",
"-fsigned-char",
"-Wno-comment",
"-Wno-write-strings", "-Wno-write-strings",
"-Wno-char-subscripts",
"-Wno-missing-braces",
"-Wno-attributes", "-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=[ CPPDEFINES=[
# SDK options # SDK options
("CFG_OS_FREERTOS", "1"), ("CFG_OS_FREERTOS", "1"),
@@ -92,9 +69,7 @@ queue.AppendPublic(
"-mcpu=arm968e-s", "-mcpu=arm968e-s",
"-marm", "-marm",
"-mthumb-interwork", "-mthumb-interwork",
"-g",
"--specs=nano.specs", "--specs=nano.specs",
"-Wl,--gc-sections",
"-Wl,-wrap,bk_flash_get_info", "-Wl,-wrap,bk_flash_get_info",
"-Wl,-wrap,bk_flash_erase", "-Wl,-wrap,bk_flash_erase",
"-Wl,-wrap,bk_flash_write", "-Wl,-wrap,bk_flash_write",
@@ -103,6 +78,17 @@ queue.AppendPublic(
"-Wl,-wrap,bk_printf", "-Wl,-wrap,bk_printf",
], ],
) )
queue.AppendPrivate(
CCFLAGS=[
"-Wno-comment",
"-Wno-char-subscripts",
"-Wno-missing-braces",
],
CFLAGS=[
"-Wno-format",
"-Wno-unknown-pragmas",
],
)
srcs_core = [] srcs_core = []
@@ -330,8 +316,8 @@ queue.AddLibrary(
CCFLAGS=[ CCFLAGS=[
"-Wno-unused-variable", "-Wno-unused-variable",
"-Wno-implicit-function-declaration", "-Wno-implicit-function-declaration",
"-w",
], ],
CFLAGS=["-<-Wall>"],
), ),
) )

View File

@@ -17,27 +17,7 @@ queue.AppendPublic(
"-mthumb", "-mthumb",
"-mfloat-abi=hard", "-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16", "-mfpu=fpv4-sp-d16",
"-g2",
"-w",
"-O2",
"-fdata-sections",
"-ffunction-sections",
"-fmessage-length=0",
"-fno-common",
"-fno-short-enums", "-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=[ CPPDEFINES=[
# other options # other options
@@ -52,17 +32,11 @@ queue.AppendPublic(
"-mthumb", "-mthumb",
"-mfloat-abi=hard", "-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16", "-mfpu=fpv4-sp-d16",
"-g",
"--specs=nano.specs", "--specs=nano.specs",
"-Os",
"-Wl,--gc-sections",
"-Wl,--cref",
# the entrypoint in ROM (?) # the entrypoint in ROM (?)
"-Wl,--entry=Reset_Handler", "-Wl,--entry=Reset_Handler",
# start function table in startup.c # start function table in startup.c
"-Wl,--undefined=gImage2EntryFun0", "-Wl,--undefined=gImage2EntryFun0",
"-Wl,--no-enum-size-warning",
"-Wl,--no-wchar-size-warning",
"-Wl,-wrap,rom_psk_CalcGTK", "-Wl,-wrap,rom_psk_CalcGTK",
"-Wl,-wrap,rom_psk_CalcPTK", "-Wl,-wrap,rom_psk_CalcPTK",
"-Wl,-wrap,CalcMIC", "-Wl,-wrap,CalcMIC",
@@ -88,6 +62,14 @@ queue.AppendPublic(
"-Wl,-wrap,__rtl_vfprintf_r_v1_00", "-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 # Sources - from SDK project/realtek_amebaz_va0_example/GCC-RELEASE/application.mk
# - "console" is disabled as it introduces build error, and is generally useless # - "console" is disabled as it introduces build error, and is generally useless
@@ -203,6 +185,9 @@ queue.AddLibrary(
"+<component/common/network/mdns>", "+<component/common/network/mdns>",
"+<component/common/network/libwsclient>", "+<component/common/network/libwsclient>",
], ],
options=dict(
CFLAGS=["-w"],
),
) )
# Sources - lwIP # Sources - lwIP

View File

@@ -21,30 +21,14 @@ queue.AppendPublic(
"-mthumb", "-mthumb",
"-mcmse", "-mcmse",
"-mfloat-abi=soft", "-mfloat-abi=soft",
"-g",
"-gdwarf-3",
"-Os",
"-MMD",
"-fstack-usage",
"-fdata-sections",
"-ffunction-sections",
"-fmessage-length=0",
"-fno-common",
"-fno-short-enums", "-fno-short-enums",
"-fomit-frame-pointer",
"-fsigned-char",
], ],
CFLAGS=[ CFLAGS=[
"-std=gnu99",
"-Wall",
"-Wpointer-arith", "-Wpointer-arith",
"-Wno-write-strings", "-Wno-write-strings",
"-Wno-maybe-uninitialized", "-Wno-maybe-uninitialized",
], ],
CXXFLAGS=[ CXXFLAGS=[
"-std=c++11",
"-fno-exceptions",
"-fno-rtti",
"-fno-use-cxa-atexit", "-fno-use-cxa-atexit",
], ],
CPPDEFINES=[ CPPDEFINES=[
@@ -68,19 +52,9 @@ queue.AppendPublic(
"-mthumb", "-mthumb",
"-mcmse", "-mcmse",
"-mfloat-abi=soft", "-mfloat-abi=soft",
"-g",
"--specs=nosys.specs", "--specs=nosys.specs",
"-nostartfiles",
"-nodefaultlibs",
"-nostdlib",
"-Os",
"-Wl,--gc-sections",
"-Wl,--warn-section-align",
"-Wl,--cref",
"-Wl,--build-id=none",
"-Wl,--use-blx", "-Wl,--use-blx",
"-Wl,--undefined=gRamStartFun", "-Wl,--undefined=gRamStartFun",
"-Wl,-no-enum-size-warning",
"-Wl,-wrap,aesccmp_construct_mic_iv", "-Wl,-wrap,aesccmp_construct_mic_iv",
"-Wl,-wrap,aesccmp_construct_mic_header1", "-Wl,-wrap,aesccmp_construct_mic_header1",
"-Wl,-wrap,aesccmp_construct_ctr_preload", "-Wl,-wrap,aesccmp_construct_ctr_preload",
@@ -362,6 +336,11 @@ queue.AddLibrary(
"+<src/include>", "+<src/include>",
"+<src/include/netif>", "+<src/include/netif>",
], ],
options=dict(
CFLAGS=[
"-Wno-implicit-function-declaration",
],
),
) )
# Sources - mbedTLS # Sources - mbedTLS

View File

@@ -18,11 +18,33 @@ family: Family = env["FAMILY_OBJ"]
# Move common core sources (env.AddCoreSources()) and Arduino libs # Move common core sources (env.AddCoreSources()) and Arduino libs
# below per-family sources (to maintain child families taking precedence) # 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( env.Append(
CCFLAGS=[ CCFLAGS=[
# Newer versions of GCC complain about undefined macros in #if # C Language Options
"-Wno-undef", "-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("flashdb")
queue.AddExternalLibrary("printf") queue.AddExternalLibrary("printf")
# Flags & linker options # Non-SDK defines & linker options
queue.AppendPublic( queue.AppendPublic(
CCFLAGS=[
"-Wreturn-type",
"-Wno-undef",
],
CFLAGS=[ CFLAGS=[
"-Werror=implicit-function-declaration", "-Werror=implicit-function-declaration",
], ],
CXXFLAGS=[
"-Wno-literal-suffix",
"-Wno-write-strings",
],
CPPDEFINES=[ CPPDEFINES=[
("LIBRETUYA", 1), ("LIBRETUYA", 1),
("LT_VERSION", env.ReadLTVersion(platform.get_dir(), platform.version)), ("LT_VERSION", env.ReadLTVersion(platform.get_dir(), platform.version)),
@@ -82,6 +112,13 @@ queue.AppendPublic(
"$VARIANTS_DIR", "$VARIANTS_DIR",
], ],
LINKFLAGS=[ 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 # malloc.c wrappers
"-Wl,-wrap,malloc", "-Wl,-wrap,malloc",
"-Wl,-wrap,calloc", "-Wl,-wrap,calloc",

View File

@@ -48,7 +48,6 @@ def env_add_core_sources(env: Environment, queue, name: str, path: str) -> bool:
"+<*.c*>", "+<*.c*>",
"+<common/*.c*>", "+<common/*.c*>",
"+<compat/*.c*>", "+<compat/*.c*>",
"+<fixups/*.c*>",
"+<port/*.c*>", "+<port/*.c*>",
"+<posix/*.c>", "+<posix/*.c>",
"+<wraps/*.c>", "+<wraps/*.c>",
@@ -58,10 +57,23 @@ def env_add_core_sources(env: Environment, queue, name: str, path: str) -> bool:
"!<.>", "!<.>",
"!<compat>", "!<compat>",
"!<config>", "!<config>",
"!<fixups>",
"!<port>", "!<port>",
], ],
) )
queue.AddLibrary(
name=f"core_{name}_fixups",
base_dir=path,
srcs=[
"+<fixups/*.c*>",
],
includes=[
"!<fixups>",
],
options=dict(
# disable all warnings for fixups
CCFLAGS=["-w"],
),
)
return True return True

View File

@@ -166,7 +166,6 @@ class LibraryQueue:
def BuildLibraries(self): def BuildLibraries(self):
if self.built: if self.built:
raise RuntimeError("Cannot build a library queue twice") raise RuntimeError("Cannot build a library queue twice")
self.Print()
# add public options to the environment # add public options to the environment
apply_options(self.env, self.options_public) apply_options(self.env, self.options_public)

View File

@@ -169,6 +169,7 @@ bool LibreTuya::otaSwitch(bool force) {
bool LibreTuya::wdtEnable(uint32_t timeout) { bool LibreTuya::wdtEnable(uint32_t timeout) {
wdt_ctrl(WCMD_SET_PERIOD, &timeout); wdt_ctrl(WCMD_SET_PERIOD, &timeout);
wdt_ctrl(WCMD_POWER_UP, NULL); wdt_ctrl(WCMD_POWER_UP, NULL);
return true;
} }
void LibreTuya::wdtDisable() { void LibreTuya::wdtDisable() {

View File

@@ -36,6 +36,7 @@ WiFiStatus eventTypeToStatus(uint8_t type) {
case RW_EVT_STA_DISCONNECTED: case RW_EVT_STA_DISCONNECTED:
return WL_DISCONNECTED; return WL_DISCONNECTED;
} }
return WL_IDLE_STATUS;
} }
WiFiAuthMode securityTypeToAuthMode(uint8_t type) { WiFiAuthMode securityTypeToAuthMode(uint8_t type) {

View File

@@ -54,6 +54,7 @@ size_t IPv6Address::printTo(Print &p) const {
} }
return n; */ return n; */
return 0;
} }
String IPv6Address::toString() const { String IPv6Address::toString() const {

View File

@@ -104,6 +104,7 @@ class UpdateClass {
public: public:
String md5String(void) { String md5String(void) {
// return _md5.toString(); // return _md5.toString();
return "";
} }
void md5(uint8_t *result) { void md5(uint8_t *result) {

View File

@@ -61,6 +61,7 @@ bool LwIPServer::begin(uint16_t port, bool reuseAddr) {
_active = true; _active = true;
_noDelay = false; _noDelay = false;
_sockAccepted = -1; _sockAccepted = -1;
return true;
} }
void LwIPServer::end() { void LwIPServer::end() {

View File

@@ -183,6 +183,7 @@ bool LibreTuya::otaSwitch(bool force) {
bool LibreTuya::wdtEnable(uint32_t timeout) { bool LibreTuya::wdtEnable(uint32_t timeout) {
watchdog_init(timeout); watchdog_init(timeout);
watchdog_start(); watchdog_start();
return true;
} }
void LibreTuya::wdtDisable() { void LibreTuya::wdtDisable() {

View File

@@ -179,7 +179,7 @@ void handleRtwEvent(uint16_t event, char *data, int len, int flags) {
if (len != 124) if (len != 124)
return; return;
eventId = ARDUINO_EVENT_WIFI_AP_STACONNECTED; 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; break;
case WIFI_EVENT_STA_DISASSOC: case WIFI_EVENT_STA_DISASSOC:

View File

@@ -35,7 +35,7 @@ extern rtw_wifi_setting_t wifi_setting;
extern unsigned char sta_password[65]; extern unsigned char sta_password[65];
extern unsigned char ap_password[65]; extern unsigned char ap_password[65];
extern void reset_wifi_struct(void); extern void reset_wifi_struct(void);
extern rtw_mode_t wifi_mode; extern wifi_mode_t wifi_mode;
extern WiFiAuthMode securityTypeToAuthMode(uint8_t type); extern WiFiAuthMode securityTypeToAuthMode(uint8_t type);
// WiFiEvents.cpp // WiFiEvents.cpp
extern void startWifiTask(); extern void startWifiTask();

View File

@@ -103,6 +103,7 @@ bool TwoWire::end() {
i2c_reset(_i2c); i2c_reset(_i2c);
delete _i2c; delete _i2c;
_i2c = NULL; _i2c = NULL;
return true;
} }
bool TwoWire::setClock(uint32_t freq) { bool TwoWire::setClock(uint32_t freq) {
@@ -110,6 +111,7 @@ bool TwoWire::setClock(uint32_t freq) {
i2c_frequency(_i2c, freq); i2c_frequency(_i2c, freq);
} }
_freq = freq; _freq = freq;
return true;
} }
void TwoWire::beginTransmission(uint8_t address) { void TwoWire::beginTransmission(uint8_t address) {

View File

@@ -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);
}
}

View File

@@ -13,7 +13,7 @@ void pinRemoveMode(pin_size_t pinNumber) {
} }
if (pinEnabled(pin, PIN_GPIO)) { if (pinEnabled(pin, PIN_GPIO)) {
gpio_t *obj = (gpio_t *)gpio_pin_struct[pinNumber]; gpio_t *obj = (gpio_t *)gpio_pin_struct[pinNumber];
gpio_deinit(obj, pin->gpio); gpio_deinit(obj);
free(obj); free(obj);
} }
if (pinEnabled(pin, PIN_IRQ)) { if (pinEnabled(pin, PIN_IRQ)) {
@@ -107,9 +107,9 @@ void digitalWrite(pin_size_t pinNumber, PinStatus status) {
PinStatus digitalRead(pin_size_t pinNumber) { PinStatus digitalRead(pin_size_t pinNumber) {
PinInfo *pin = pinInfo(pinNumber); PinInfo *pin = pinInfo(pinNumber);
if (!pin) if (!pin)
return; return LOW;
if (pin->enabled != PIN_GPIO) if (pin->enabled != PIN_GPIO)
return; return LOW;
gpio_t *gpio = (gpio_t *)gpio_pin_struct[pinNumber]; gpio_t *gpio = (gpio_t *)gpio_pin_struct[pinNumber];
return gpio_read(gpio); return gpio_read(gpio);

View File

@@ -18,7 +18,7 @@ static void gpioIrqHandler(uint32_t id, gpio_irq_event event) {
} }
void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode) { 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) { void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void *param) {

View File

@@ -36,11 +36,13 @@ extern "C" {
#include <rtl8710c.h> #include <rtl8710c.h>
#endif #endif
#include <gpio_api.h>
#undef MBED_GPIO_API_H // ..no comment
#include <gpio_ex_api.h>
#include <analogin_api.h> #include <analogin_api.h>
#include <analogout_api.h> #include <analogout_api.h>
#include <flash_api.h> #include <flash_api.h>
#include <gpio_api.h>
#include <gpio_ex_api.h>
#include <gpio_irq_api.h> #include <gpio_irq_api.h>
#include <gpio_irq_ex_api.h> #include <gpio_irq_ex_api.h>
#include <i2c_api.h> #include <i2c_api.h>

View File

@@ -8,4 +8,5 @@ __attribute__((weak)) uint32_t __get_IPSR()
{ {
uint32_t result; uint32_t result;
asm volatile ("MRS %0, ipsr" : "=r" (result) ); asm volatile ("MRS %0, ipsr" : "=r" (result) );
return result;
} }