From 98136d36de40230c3166e647078955e68a8216b3 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 23 Mar 2023 18:53:46 +0700 Subject: [PATCH 1/6] try to fix ci --- .github/workflows/githubci.yml | 10 +++++++--- ...nrf52840.test.only => .none-cluenrf52840.test.only} | 0 ...nse.test.only => .none-feather52840sense.test.only} | 0 3 files changed, 7 insertions(+), 3 deletions(-) rename libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/{.cluenrf52840.test.only => .none-cluenrf52840.test.only} (100%) rename libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/{.feather52840sense.test.only => .none-feather52840sense.test.only} (100%) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 753cd5c8..3d94a3cf 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -21,12 +21,12 @@ jobs: steps: - name: Setup Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: python-version: '3.x' - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: submodules: 'true' @@ -58,7 +58,11 @@ jobs: # Install library dependency arduino-cli lib install "Adafruit AHRS" "Adafruit APDS9960 Library" "Adafruit Arcada Library" "Adafruit BMP280 Library" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit LIS3MDL" "Adafruit LSM6DS" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit Sensor Calibration" "Adafruit SHT31 Library" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" "SdFat - Adafruit Fork" - arduino-cli lib install "Arduino_TensorFlowLite" "MIDI Library" + arduino-cli lib install "MIDI Library" + + # Arduino_TensorFlowLite is removed per maintainer request https://github.com/arduino/library-registry/pull/1748 + # Find a way to compile later, skip TFL example for now + # arduino-cli lib install "Arduino_TensorFlowLite" # TODO use firmata master to prevent build error with gcc v9 (should be remove after 2.5.9 is released) # https://github.com/firmata/arduino/pull/438 diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.cluenrf52840.test.only b/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.none-cluenrf52840.test.only similarity index 100% rename from libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.cluenrf52840.test.only rename to libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.none-cluenrf52840.test.only diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.feather52840sense.test.only b/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.none-feather52840sense.test.only similarity index 100% rename from libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.feather52840sense.test.only rename to libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.none-feather52840sense.test.only From ac286837814d1014fed92822a8f594f1b38cb81e Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 23 Mar 2023 21:59:25 +0700 Subject: [PATCH 2/6] improve ci, run examples with pool to speed up compile time skip TinyUSB lib examples --- .github/workflows/githubci.yml | 16 ++-- tools/build_all.py | 150 +++++++++++++++++++-------------- 2 files changed, 92 insertions(+), 74 deletions(-) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 3d94a3cf..83e24041 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -2,8 +2,13 @@ name: Build on: [pull_request, push] +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: build: + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -16,8 +21,6 @@ jobs: - 'feather52840sense' - 'itsybitsy52840' - 'ledglasses_nrf52840' - - runs-on: ubuntu-latest steps: - name: Setup Python @@ -58,18 +61,11 @@ jobs: # Install library dependency arduino-cli lib install "Adafruit AHRS" "Adafruit APDS9960 Library" "Adafruit Arcada Library" "Adafruit BMP280 Library" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit LIS3MDL" "Adafruit LSM6DS" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit Sensor Calibration" "Adafruit SHT31 Library" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" "SdFat - Adafruit Fork" - arduino-cli lib install "MIDI Library" + arduino-cli lib install "MIDI Library" "Firmata" # Arduino_TensorFlowLite is removed per maintainer request https://github.com/arduino/library-registry/pull/1748 # Find a way to compile later, skip TFL example for now # arduino-cli lib install "Arduino_TensorFlowLite" - - # TODO use firmata master to prevent build error with gcc v9 (should be remove after 2.5.9 is released) - # https://github.com/firmata/arduino/pull/438 - git clone --depth 1 https://github.com/firmata/arduino.git $HOME/Arduino/libraries/firmata - - # TODO temporarily remove TinyUSB pre-1.0.0 version install by arduino-cli - rm -r $HOME/Arduino/libraries/Adafruit_TinyUSB_Library # Library summary arduino-cli lib list diff --git a/tools/build_all.py b/tools/build_all.py index 1566507d..0a44a565 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -2,98 +2,120 @@ import os import glob import sys import subprocess -from subprocess import Popen, PIPE import time +from multiprocessing import Pool SUCCEEDED = "\033[32msucceeded\033[0m" FAILED = "\033[31mfailed\033[0m" SKIPPED = "\033[35mskipped\033[0m" WARNING = "\033[33mwarnings\033[0m " -exit_status = 0 -success_count = 0 -fail_count = 0 -skip_count = 0 - build_format = '| {:25} | {:35} | {:18} | {:6} |' build_separator = '-' * 88 -default_boards = [ 'cluenrf52840', 'cplaynrf52840', 'feather52832', 'feather52840', 'feather52840sense', 'itsybitsy52840' ] +default_boards = [ + 'cluenrf52840', + 'cplaynrf52840', + 'feather52832', + 'feather52840', + 'feather52840sense', + 'itsybitsy52840' +] build_boards = [] -# build all variants if input not existed -if len(sys.argv) > 1: - build_boards.append(sys.argv[1]) -else: - build_boards = default_boards -all_examples = list(glob.iglob('libraries/**/*.ino', recursive=True)) -all_examples.sort() +def build_a_example(arg): + variant = arg[0] + sketch = arg[1] -def build_examples(variant): - global exit_status, success_count, fail_count, skip_count, build_format, build_separator + fqbn = "adafruit:nrf52:{}:softdevice={},debug=l0".format(variant, + 's140v6' if variant != 'feather52832' else 's132v6') + # succeeded, failed, skipped + ret = [0, 0, 0] + start_time = time.monotonic() + + # Skip if contains: ".board.test.skip" or ".all.test.skip" + # Skip if not contains: ".board.test.only" for a specific board + sketchdir = os.path.dirname(sketch) + if os.path.exists(sketchdir + '/.all.test.skip') or os.path.exists(sketchdir + '/.' + variant + '.test.skip'): + success = SKIPPED + ret[2] = 1 + elif glob.glob(sketchdir + "/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only'): + success = SKIPPED + ret[2] = 1 + else: + build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + # get stderr into a form where warning/error was output to stderr + if build_result.returncode != 0: + ret[1] = 1 + success = FAILED + else: + ret[0] = 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")) + + # Build with warnings + if build_result.stderr: + print(build_result.stderr.decode("utf-8")) + + return ret + + +def build_all_examples(variant): print('\n') print(build_separator) print('| {:^84} |'.format('Board ' + variant)) print(build_separator) print(build_format.format('Library', 'Example', '\033[39mResult\033[0m', 'Time')) print(build_separator) - - fqbn = "adafruit:nrf52:{}:softdevice={},debug=l0".format(variant, 's140v6' if variant != 'feather52832' else 's132v6') - for sketch in all_examples: - # skip TinyUSB library examples for nRF52832 - if variant == 'feather52832' and "libraries/Adafruit_TinyUSB_Arduino" in sketch: - continue + args = [[variant, s] for s in all_examples] + with Pool() as pool: + result = pool.map(build_a_example, args) + # sum all element of same index (column sum) + return list(map(sum, list(zip(*result)))) - start_time = time.monotonic() - # Skip if contains: ".board.test.skip" or ".all.test.skip" - # Skip if not contains: ".board.test.only" for a specific board - 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) +if __name__ == "__main__": + # build all variants if input not existed + if len(sys.argv) > 1: + build_boards.append(sys.argv[1]) + else: + build_boards = default_boards - # 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 - else: - success_count += 1 - if build_result.stderr: - success = WARNING - else: - success = SUCCEEDED + # All examples in libraries except TinyUSB which has its own ci to build + all_examples = list(glob.iglob('libraries/**/*.ino', recursive=True)) + all_examples = [i for i in all_examples if "Adafruit_TinyUSB_Arduino" not in i] + all_examples.sort() - build_duration = time.monotonic() - start_time + build_time = time.monotonic() - print(build_format.format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success, '{:5.2f}s'.format(build_duration))) + # succeeded, failed, skipped + total_result = [0, 0, 0] - if success != SKIPPED: - # Build failed - if build_result.returncode != 0: - print(build_result.stdout.decode("utf-8")) - - # Build with warnings - if build_result.stderr: - print(build_result.stderr.decode("utf-8")) + for board in build_boards: + fret = build_all_examples(board) + if len(fret) == len(total_result): + total_result = [total_result[i] + fret[i] for i in range(len(fret))] -build_time = time.monotonic() + build_time = time.monotonic() - build_time -for board in build_boards: - build_examples(board) + print(build_separator) + print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(total_result[0], SUCCEEDED, total_result[1], FAILED, total_result[2], SKIPPED, build_time)) + print(build_separator) -print(build_separator) -build_time = time.monotonic() - build_time -print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, build_time)) -print(build_separator) - -sys.exit(exit_status) + sys.exit(total_result[1]) From 4414359068d3081b085ab92b88718c31665f9379 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 23 Mar 2023 22:03:24 +0700 Subject: [PATCH 3/6] bump up tinyusb and nrfcrypto --- libraries/Adafruit_TinyUSB_Arduino | 2 +- libraries/Adafruit_nRFCrypto | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Adafruit_TinyUSB_Arduino b/libraries/Adafruit_TinyUSB_Arduino index e58ed11d..f43338a0 160000 --- a/libraries/Adafruit_TinyUSB_Arduino +++ b/libraries/Adafruit_TinyUSB_Arduino @@ -1 +1 @@ -Subproject commit e58ed11de15e2cfbd71f1a79cf84a2372ba27e08 +Subproject commit f43338a086764f829afd682dbc5f3abba3f3c881 diff --git a/libraries/Adafruit_nRFCrypto b/libraries/Adafruit_nRFCrypto index 7444c2e9..802d0a69 160000 --- a/libraries/Adafruit_nRFCrypto +++ b/libraries/Adafruit_nRFCrypto @@ -1 +1 @@ -Subproject commit 7444c2e9472b8731cbcb76be5216df04680c5529 +Subproject commit 802d0a6961eae5d1e9bc94a2a570214804e68638 From 5cd4c237eb15cc50da22981cddc7960420f28d3f Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 23 Mar 2023 22:05:08 +0700 Subject: [PATCH 4/6] fix reset to bootloader issue with busy SoftDevice --- cores/nRF5/common_func.h | 8 ++++---- cores/nRF5/wiring.c | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/cores/nRF5/common_func.h b/cores/nRF5/common_func.h index 7e42e956..7432423b 100644 --- a/cores/nRF5/common_func.h +++ b/cores/nRF5/common_func.h @@ -179,13 +179,13 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place #define PRINT_LOCATION() PRINTF("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__) #define PRINT_MESS(x) PRINTF("%s: %d: %s \r\n" , __FUNCTION__, __LINE__, (char*)(x)) #define PRINT_HEAP() if (CFG_DEBUG >= 3) PRINTF("\n%s: %d: Heap free: %d\r\n", __FUNCTION__, __LINE__, util_heap_get_free_size()) -#define PRINT_STR(x) PRINTF("%s: %d: " #x " = %s\r\n" , __FUNCTION__, __LINE__, (char*)(x) ) -#define PRINT_INT(x) PRINTF("%s: %d: " #x " = %ld\r\n" , __FUNCTION__, __LINE__, (uint32_t) (x) ) -#define PRINT_FLOAT(x) PRINTF("%s: %d: " #x " = %f\r\n" , __FUNCTION__, __LINE__, (float) (x) ) +#define PRINT_STR(x) PRINTF(#x " = %s\r\n" , (char*)(x) ) +#define PRINT_INT(x) PRINTF(#x " = %ld\r\n", (uint32_t) (x) ) +#define PRINT_FLOAT(x) PRINTF(#x " = %f\r\n" , (float) (x) ) #define PRINT_HEX(x) \ do {\ - PRINTF("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\ + PRINTF(#x " = 0x");\ char fmt[] = "%00X\r\n";\ fmt[2] += 2*sizeof(x); /* Hex with correct size */\ PRINTF(fmt, (x) );\ diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index a18e7fc5..bf695a5e 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -74,22 +74,41 @@ uint32_t readResetReason(void) return _reset_reason; } +static void reset_mcu(uint32_t gpregret) +{ + // disable SD + sd_softdevice_disable(); + + // Disable all interrupts + NVIC->ICER[0]=0xFFFFFFFF; + NVIC->ICPR[0]=0xFFFFFFFF; +#if defined(__NRF_NVIC_ISER_COUNT) && __NRF_NVIC_ISER_COUNT == 2 + NVIC->ICER[1]=0xFFFFFFFF; + NVIC->ICPR[1]=0xFFFFFFFF; +#endif + + NRF_POWER->GPREGRET = gpregret; + + NVIC_SystemReset(); + + // maybe yield ? + while(1) {} +} + void enterUf2Dfu(void) { - NRF_POWER->GPREGRET = DFU_MAGIC_UF2_RESET; - NVIC_SystemReset(); + reset_mcu(DFU_MAGIC_UF2_RESET); } void enterSerialDfu(void) { - NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL_ONLY_RESET; - NVIC_SystemReset(); + // shut down everything + reset_mcu(DFU_MAGIC_SERIAL_ONLY_RESET); } void enterOTADfu(void) { - NRF_POWER->GPREGRET = DFU_MAGIC_OTA_RESET; - NVIC_SystemReset(); + reset_mcu(DFU_MAGIC_OTA_RESET); } void waitForEvent(void) From cb37867074627e4df6f40506c23829e30d836c6f Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 23 Mar 2023 22:18:06 +0700 Subject: [PATCH 5/6] group warnings to make it easier to view --- tools/build_all.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/build_all.py b/tools/build_all.py index 0a44a565..bfe08e70 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -70,7 +70,9 @@ def build_a_example(arg): # Build with warnings if build_result.stderr: + print(f"::group::warning-message") print(build_result.stderr.decode("utf-8")) + print(f"::endgroup::") return ret From 211566bc25a0ea0f7d6b1847e615ac242597ae2b Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Thu, 23 Mar 2023 23:53:50 +0700 Subject: [PATCH 6/6] bump version for release --- platform.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.txt b/platform.txt index 77411e28..30313930 100644 --- a/platform.txt +++ b/platform.txt @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA name=Adafruit nRF52 Boards -version=1.3.0 +version=1.4.0 # Compile variables # -----------------