From b9de0dd52d4a3cc08a385f2fca5012862688d4d9 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 25 May 2021 21:29:08 +0700 Subject: [PATCH 1/4] fix various warnings --- cores/nRF5/HardwarePWM.cpp | 24 ++++++++++++----- cores/nRF5/Tone.cpp | 16 +++++------ cores/nRF5/WString.cpp | 23 +++++++++++----- .../Bluefruit52Lib/src/utility/bonding.cpp | 4 ++- libraries/SPI/SPI.cpp | 2 +- tools/build_all.py | 27 ++++--------------- 6 files changed, 51 insertions(+), 45 deletions(-) diff --git a/cores/nRF5/HardwarePWM.cpp b/cores/nRF5/HardwarePWM.cpp index 441c3fcb..d4d1d771 100644 --- a/cores/nRF5/HardwarePWM.cpp +++ b/cores/nRF5/HardwarePWM.cpp @@ -266,12 +266,16 @@ bool HardwarePWM::takeOwnership(uint32_t token) bool const thread_mode = !isInISR(); if (token == 0) { - if (thread_mode) LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in takeOwnership)"); + if (thread_mode) { + LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in takeOwnership)"); + } return false; } if (token == this->_owner_token) { - if (thread_mode) LOG_LV1("HwPWM", "failing to acquire ownership because already owned by requesting token (cannot take ownership twice)"); + if (thread_mode) { + LOG_LV1("HwPWM", "failing to acquire ownership because already owned by requesting token (cannot take ownership twice)"); + } return false; } @@ -290,22 +294,30 @@ bool HardwarePWM::releaseOwnership(uint32_t token) bool const thread_mode = !isInISR(); if (token == 0) { - if (thread_mode) LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in releaseOwnership)"); + if (thread_mode) { + LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in releaseOwnership)"); + } return false; } if (!this->isOwner(token)) { - if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when not the current owner"); + if (thread_mode) { + LOG_LV1("HwPWM", "attempt to release ownership when not the current owner"); + } return false; } if (this->usedChannelCount() != 0) { - if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when at least on channel is still connected"); + if (thread_mode) { + LOG_LV1("HwPWM", "attempt to release ownership when at least on channel is still connected"); + } return false; } if (this->enabled()) { - if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when PWM peripheral is still enabled"); + if (thread_mode) { + LOG_LV1("HwPWM", "attempt to release ownership when PWM peripheral is still enabled"); + } return false; // if it's enabled, do not allow ownership to be released, even with no pins in use } diff --git a/cores/nRF5/Tone.cpp b/cores/nRF5/Tone.cpp index 4f52d31f..68393d46 100644 --- a/cores/nRF5/Tone.cpp +++ b/cores/nRF5/Tone.cpp @@ -109,14 +109,14 @@ constexpr static uint64_t _calculate_pulse_count(uint32_t frequency, uint32_t du (((uint64_t)duration) * frequency / 1000ULL); }; -static int _bits_used(unsigned long x) { - if (0 == x) return 0; - unsigned int result = 0; - do { - result++; - } while (x >>= 1); - return result; -} +//static int _bits_used(unsigned long x) { +// if (0 == x) return 0; +// unsigned int result = 0; +// do { +// result++; +// } while (x >>= 1); +// return result; +//} static int _bits_used(unsigned long long x) { if (0 == x) return 0; diff --git a/cores/nRF5/WString.cpp b/cores/nRF5/WString.cpp index a6432f2a..683da203 100644 --- a/cores/nRF5/WString.cpp +++ b/cores/nRF5/WString.cpp @@ -693,13 +693,22 @@ void String::remove(unsigned int index){ } void String::remove(unsigned int index, unsigned int count){ - if (index >= len) { return; } - if (count <= 0) { return; } - if (count > len - index) { count = len - index; } - char *writeTo = buffer + index; - len = len - count; - strncpy(writeTo, buffer + index + count,len - index); - buffer[len] = 0; + // removes characters from the middle of a string. + if (count <= 0) { return; } // exit if nothing to remove + if (index >= len) { return; } // ensure start is within string length; thus, ensures (len-index >= 1) + if (count > len - index) { // ensure characters to remove is no larger than total length remaining + count = len - index; + } + char *writeTo = buffer + index; + char *copyFrom = buffer + index + count; + len = len - count; + + // strncpy() cannot be used with overlapping buffers, so copy one char at a time + unsigned int charactersToMove = len - index; // yes, uses post-adjusted length + for (unsigned int i = 0; i < charactersToMove; i++, writeTo++, copyFrom++) { + *writeTo = *copyFrom; + } + buffer[len] = 0; } void String::toLowerCase(void) diff --git a/libraries/Bluefruit52Lib/src/utility/bonding.cpp b/libraries/Bluefruit52Lib/src/utility/bonding.cpp index 3023ed97..0a4a40d3 100644 --- a/libraries/Bluefruit52Lib/src/utility/bonding.cpp +++ b/libraries/Bluefruit52Lib/src/utility/bonding.cpp @@ -288,7 +288,9 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, ble_gap_addr_t const* id_ad file.close(); - if ( !loaded ) LOG_LV1("BOND", "CCCD setting not found"); + if ( !loaded ) { + LOG_LV1("BOND", "CCCD setting not found"); + } return loaded; } diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index 96a34d79..acab625f 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -206,7 +206,7 @@ void SPIClass::transfer(const void *tx_buf, void *rx_buf, size_t count) while (count) { // each transfer can only up to 64KB (16-bit) bytes - const size_t xfer_len = min(count, UINT16_MAX); + const size_t xfer_len = min((uint16_t) count, UINT16_MAX); nrfx_spim_xfer_desc_t xfer_desc = { diff --git a/tools/build_all.py b/tools/build_all.py index aded32c9..2be79afd 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -7,10 +7,9 @@ import time SUCCEEDED = "\033[32msucceeded\033[0m" FAILED = "\033[31mfailed\033[0m" -SKIPPED = "\033[33mskipped\033[0m" -WARNING = "\033[31mwarnings\033[0m" +SKIPPED = "\033[36mskipped\033[0m" +WARNING = "\033[33mwarnings\033[0m " -all_warnings = False exit_status = 0 success_count = 0 fail_count = 0 @@ -31,15 +30,6 @@ else: all_examples = list(glob.iglob('libraries/**/*.ino', recursive=True)) all_examples.sort() -def errorOutputFilter(line): - if len(line) == 0: - return False - if line.isspace(): # Note: empty string does not match here! - return False - # TODO: additional items to remove? - return True - - def build_examples(variant): global exit_status, success_count, fail_count, skip_count, build_format, build_separator @@ -67,19 +57,12 @@ def build_examples(variant): elif glob.glob(sketchdir+"/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only'): success = SKIPPED else: - # TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR. - # preferably, would use Python logging handler to get both distinct outputs and one merged output - # for now, split STDERR when building with all warnings enabled, so can detect warning/error output. - if all_warnings: - build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE) - else: - build_result = subprocess.run("arduino-cli compile --warnings default --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE) + build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE) # get stderr into a form where len(warningLines) indicates a true warning was output to stderr warningLines = []; - if all_warnings and build_result.stderr: - tmpWarningLines = build_result.stderr.decode("utf-8").splitlines() - warningLines = list(filter(errorOutputFilter, (tmpWarningLines))) + if build_result.stderr: + warningLines = build_result.stderr.decode("utf-8").splitlines() if build_result.returncode != 0: exit_status = build_result.returncode From f655a052d3b24b118561e53a8d5561e3f352bf46 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 25 May 2021 22:52:07 +0700 Subject: [PATCH 2/4] fix more warnings --- .../BLEAdafruitService/src/services/BLEAdafruitSensor.h | 2 +- .../examples/Central/central_pairing/central_pairing.ino | 6 +++--- .../examples/Peripheral/ancs_oled/ancs_oled.ino | 2 +- .../arduino_science_journal/arduino_science_journal.ino | 2 +- .../Peripheral/image_eink_transfer/image_eink_transfer.ino | 4 ++++ libraries/SoftwareSerial/SoftwareSerial.h | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h index a934508b..7b2d0d65 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h @@ -44,8 +44,8 @@ class BLEAdafruitSensor : public BLEService void setNotifyCallback(notify_callback_t fp); protected: - BLECharacteristic _period; BLECharacteristic _measurement; + BLECharacteristic _period; Adafruit_Sensor* _sensor; diff --git a/libraries/Bluefruit52Lib/examples/Central/central_pairing/central_pairing.ino b/libraries/Bluefruit52Lib/examples/Central/central_pairing/central_pairing.ino index ab5043c4..3d77b923 100644 --- a/libraries/Bluefruit52Lib/examples/Central/central_pairing/central_pairing.ino +++ b/libraries/Bluefruit52Lib/examples/Central/central_pairing/central_pairing.ino @@ -310,6 +310,9 @@ void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status) }else { Serial.println("Failed"); + + // disconnect + conn->disconnect(); } #ifdef USE_ARCADA @@ -321,9 +324,6 @@ void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status) { tft->setTextColor(ARCADA_RED); tft->print("Failed "); - - // disconnect - conn->disconnect(); } tft->setTextColor(ARCADA_WHITE); diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino b/libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino index 141d8fdd..fb1ffb6b 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino @@ -241,7 +241,7 @@ void displayNotification(int index) }else { // Text size = 1, max char is 21. Text size = 2, max char is 10 - char tempbuf[22]; + char tempbuf[30]; sprintf(tempbuf, "%-15s %02d/%02d", myNtf->app_name, index+1, notifCount); oled.println(tempbuf); diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/arduino_science_journal/arduino_science_journal.ino b/libraries/Bluefruit52Lib/examples/Peripheral/arduino_science_journal/arduino_science_journal.ino index 3d1026db..7ce1de03 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/arduino_science_journal/arduino_science_journal.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/arduino_science_journal/arduino_science_journal.ino @@ -84,7 +84,7 @@ void onPDMdata() { uint16_t getSoundAverage() { uint32_t avg = 0; - for (int i = 0; i < sizeof(soundSampleBuffer)/sizeof(soundSampleBuffer[0]); i++) { + for (uint32_t i = 0; i < sizeof(soundSampleBuffer)/sizeof(soundSampleBuffer[0]); i++) { avg += soundSampleBuffer[i]*soundSampleBuffer[i]; } return sqrt(avg); diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/image_eink_transfer/image_eink_transfer.ino b/libraries/Bluefruit52Lib/examples/Peripheral/image_eink_transfer/image_eink_transfer.ino index ca6a408d..ce96be20 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/image_eink_transfer/image_eink_transfer.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/image_eink_transfer/image_eink_transfer.ino @@ -207,6 +207,10 @@ void bleuart_rx_callback(uint16_t conn_hdl) red = (c565 & 0xf800) >> 8; green = (c565 & 0x07e0) >> 3; blue = (c565 & 0x001f) << 3; + }else + { + Serial.println("Error: incorrect color bits "); + while(1) yield(); } // Convert RGB into Eink Color diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index ae1fc08f..e6ad9239 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -59,7 +59,7 @@ private: static SoftwareSerial *active_object; // private methods - void recv() __attribute__((__always_inline__)); + void recv(); uint32_t rx_pin_read(); void tx_pin_write(uint8_t pin_state) __attribute__((__always_inline__)); void setTX(uint8_t transmitPin); From 6e3ba93ac800a42dfa60332e7135c4ee032be063 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 25 May 2021 22:53:03 +0700 Subject: [PATCH 3/4] build with all warnings (not as error) --- tools/build_all.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/tools/build_all.py b/tools/build_all.py index 2be79afd..1158851c 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -7,7 +7,7 @@ import time SUCCEEDED = "\033[32msucceeded\033[0m" FAILED = "\033[31mfailed\033[0m" -SKIPPED = "\033[36mskipped\033[0m" +SKIPPED = "\033[35mskipped\033[0m" WARNING = "\033[33mwarnings\033[0m " exit_status = 0 @@ -54,42 +54,37 @@ def build_examples(variant): sketchdir = os.path.dirname(sketch) if os.path.exists(sketchdir + '/.all.test.skip') or os.path.exists(sketchdir + '/.' + variant + '.test.skip'): success = SKIPPED + skip_count += 1 elif glob.glob(sketchdir+"/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only'): success = SKIPPED + skip_count += 1 else: build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE) - # get stderr into a form where len(warningLines) indicates a true warning was output to stderr - warningLines = []; - if build_result.stderr: - warningLines = build_result.stderr.decode("utf-8").splitlines() - + # get stderr into a form where warning/error was output to stderr if build_result.returncode != 0: exit_status = build_result.returncode success = FAILED fail_count += 1 - elif len(warningLines) != 0: - exit_status = -1 - success = WARNING - fail_count += 1 else: - success = SUCCEEDED success_count += 1 + if build_result.stderr: + success = WARNING + else: + success = SUCCEEDED build_duration = time.monotonic() - start_time print(build_format.format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success, '{:5.2f}s'.format(build_duration))) if success != SKIPPED: + # Build failed if build_result.returncode != 0: print(build_result.stdout.decode("utf-8")) - if (build_result.stderr): - print(build_result.stderr.decode("utf-8")) - if len(warningLines) != 0: - for line in warningLines: - print(line) - else: - skip_count += 1 + + # Build with warnings + if build_result.stderr: + print(build_result.stderr.decode("utf-8")) build_time = time.monotonic() From 7f843dfb27fb450a7ef42527d41a82ff302b0a00 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 26 May 2021 10:02:09 +0700 Subject: [PATCH 4/4] bump builtin TinyUSB to 1.0.3 --- libraries/Adafruit_TinyUSB_Arduino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Adafruit_TinyUSB_Arduino b/libraries/Adafruit_TinyUSB_Arduino index 1b8b9c9b..8f4bc1f4 160000 --- a/libraries/Adafruit_TinyUSB_Arduino +++ b/libraries/Adafruit_TinyUSB_Arduino @@ -1 +1 @@ -Subproject commit 1b8b9c9b071065235341d0e503f2d6d05de19524 +Subproject commit 8f4bc1f438c9d89a9080438b2e36291c527b4e0e