From 0831dca922b62b748be57f7087bfc4e9acf835ff Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 May 2024 18:40:06 +0700 Subject: [PATCH 01/11] adding get_deps.py to replace mcu driver submodules --- .github/workflows/build_arm.yml | 3 +- tools/get_deps.py | 139 ++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 tools/get_deps.py diff --git a/.github/workflows/build_arm.yml b/.github/workflows/build_arm.yml index 6e8f71d9e..8c3f67e7f 100644 --- a/.github/workflows/build_arm.yml +++ b/.github/workflows/build_arm.yml @@ -89,7 +89,8 @@ jobs: - name: Build run: | arm-none-eabi-gcc --version - make -C $ENV_PORT BOARD=${{ matrix.board }} get-deps + #make -C $ENV_PORT BOARD=${{ matrix.board }} get-deps + python tools/get_deps.py --board ${{ matrix.board }} make -C $ENV_PORT BOARD=${{ matrix.board }} all self-update copy-artifact for app in ${{ env.ENV_PORT }}/apps/*/; do if [ $app != 'apps/self_update/' ]; then make -C $app BOARD=${{ matrix.board }} all; fi done diff --git a/tools/get_deps.py b/tools/get_deps.py new file mode 100644 index 000000000..35ba80166 --- /dev/null +++ b/tools/get_deps.py @@ -0,0 +1,139 @@ +import argparse +import sys +import subprocess +from pathlib import Path +from multiprocessing import Pool + +# Mandatory Dependencies that is always fetched +# path, url, commit, family (Alphabet sorted by path) +deps_mandatory = {} + +# Optional Dependencies per MCU +# path, url, commit, family (Alphabet sorted by path) +deps_optional = { + 'lib/nxp/mcux-sdk': ['https://github.com/hathach/mcux-sdk.git', + '9990f264f98430f6d885041ab0f24224d68f4958', + 'kinetis_k kinetis_k32l2 kinetis_kl lpc51 lpc54 lpc55 mcx imxrt'], + 'lib/st/cmsis_device_f3': ['https://github.com/STMicroelectronics/cmsis_device_f3.git', + '5e4ee5ed7a7b6c85176bb70a9fd3c72d6eb99f1b', + 'stm32f3'], + 'lib/st/cmsis_device_f4': ['https://github.com/STMicroelectronics/cmsis_device_f4.git', + '2615e866fa48fe1ff1af9e31c348813f2b19e7ec', + 'stm32f4'], + 'lib/st/cmsis_device_h7': ['https://github.com/STMicroelectronics/cmsis_device_h7.git', + '60dc2c913203dc8629dc233d4384dcc41c91e77f', + 'stm32h7'], + 'lib/st/cmsis_device_l4': ['https://github.com/STMicroelectronics/cmsis_device_l4.git', + '6ca7312fa6a5a460b5a5a63d66da527fdd8359a6', + 'stm32l4'], + 'lib/st/stm32f3xx_hal_driver': ['https://github.com/STMicroelectronics/stm32f3xx_hal_driver.git', + '1761b6207318ede021706e75aae78f452d72b6fa', + 'stm32f3'], + 'lib/st/stm32f4xx_hal_driver': ['https://github.com/STMicroelectronics/stm32f4xx_hal_driver.git', + '04e99fbdabd00ab8f370f377c66b0a4570365b58', + 'stm32f4'], + 'lib/st/stm32h7xx_hal_driver': ['https://github.com/STMicroelectronics/stm32h7xx_hal_driver.git', + 'd8461b980b59b1625207d8c4f2ce0a9c2a7a3b04', + 'stm32h7'], + 'lib/st/stm32l4xx_hal_driver': ['https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git', + 'aee3d5bf283ae5df87532b781bdd01b7caf256fc', + 'stm32l4'], + # 'lib/wch/ch32v20x': ['https://github.com/openwch/ch32v20x.git', + # 'c4c38f507e258a4e69b059ccc2dc27dde33cea1b', + # 'ch32v20x'], + 'lib/sct_neopixel': ['https://github.com/gsteiert/sct_neopixel.git', + '497ca8974927e3b853fd80c8fc35f4e557af79b9', + 'lpc55'], +} + +# combined 2 deps +deps_all = {**deps_mandatory, **deps_optional} + +# TOP is tinyusb root dir +TOP = Path(__file__).parent.parent.resolve() + + +def run_cmd(cmd): + r = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + if r.returncode != 0: + print(f'Error: {cmd} failed with {r.returncode}') + print(r.stdout.decode("utf-8")) + return r + + +def get_a_dep(d): + if d not in deps_all.keys(): + print('{} is not found in dependency list') + return 1 + url = deps_all[d][0] + commit = deps_all[d][1] + families = deps_all[d][2] + + print(f'cloning {d} with {url}') + + p = Path(TOP / d) + git_cmd = f"git -C {p}" + + # Init git deps if not existed + if not p.exists(): + p.mkdir(parents=True) + run_cmd(f"{git_cmd} init") + run_cmd(f"{git_cmd} remote add origin {url}") + + # Check if commit is already fetched + result = run_cmd(f"{git_cmd} rev-parse HEAD") + head = result.stdout.decode("utf-8").splitlines()[0] + run_cmd(f"{git_cmd} reset --hard") + if commit != head: + run_cmd(f"{git_cmd} fetch --depth 1 origin {commit}") + run_cmd(f"{git_cmd} checkout FETCH_HEAD") + + return 0 + + +def find_family(board): + bsp_dir = Path(TOP / "ports") + for family_dir in bsp_dir.iterdir(): + if family_dir.is_dir(): + board_dir = family_dir / 'boards' / board + if board_dir.exists(): + return family_dir.name + return None + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('families', nargs='*', default=[], help='Families to fetch') + parser.add_argument('-b', '--board', action='append', default=[], help='Boards to fetch') + parser.add_argument('--print', action='store_true', help='Print commit hash only') + args = parser.parse_args() + + families = args.families + boards = args.board + print_only = args.print + + status = 0 + deps = list(deps_mandatory.keys()) + + if 'all' in families: + deps += deps_optional.keys() + else: + families = list(families) + if boards is not None: + for b in boards: + f = find_family(b) + if f is not None: + families.append(f) + + for f in families: + for d in deps_optional: + if d not in deps and f in deps_optional[d][2]: + deps.append(d) + + with Pool() as pool: + status = sum(pool.map(get_a_dep, deps)) + return status + + +if __name__ == "__main__": + sys.exit(main()) From f4fc96cb22abbd206a933144e23689be54823ba0 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 May 2024 18:47:10 +0700 Subject: [PATCH 02/11] remove f3 submodules --- .gitmodules | 6 ------ lib/st/cmsis_device_f3 | 1 - lib/st/stm32f3xx_hal_driver | 1 - 3 files changed, 8 deletions(-) delete mode 160000 lib/st/cmsis_device_f3 delete mode 160000 lib/st/stm32f3xx_hal_driver diff --git a/.gitmodules b/.gitmodules index be4b44d64..5bee8427b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,12 +19,6 @@ [submodule "lib/sct_neopixel"] path = lib/sct_neopixel url = https://github.com/gsteiert/sct_neopixel -[submodule "lib/st/stm32f3xx_hal_driver"] - path = lib/st/stm32f3xx_hal_driver - url = https://github.com/STMicroelectronics/stm32f3xx_hal_driver -[submodule "lib/st/cmsis_device_f3"] - path = lib/st/cmsis_device_f3 - url = https://github.com/STMicroelectronics/cmsis_device_f3.git [submodule "lib/nxp/mcux-sdk"] path = lib/nxp/mcux-sdk url = https://github.com/NXPmicro/mcux-sdk.git diff --git a/lib/st/cmsis_device_f3 b/lib/st/cmsis_device_f3 deleted file mode 160000 index 167eefd81..000000000 --- a/lib/st/cmsis_device_f3 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 167eefd811de90a58c41e0a32071cdfecede389a diff --git a/lib/st/stm32f3xx_hal_driver b/lib/st/stm32f3xx_hal_driver deleted file mode 160000 index 75cf4fce5..000000000 --- a/lib/st/stm32f3xx_hal_driver +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 75cf4fce556ec3b338e3a3798e4b7c1ce20ba83d From 336f3dedba49a564c68c6b92152ab595b5e9e088 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 May 2024 18:53:50 +0700 Subject: [PATCH 03/11] remove f4 submodule --- .gitmodules | 6 ------ lib/st/cmsis_device_f4 | 1 - lib/st/stm32f4xx_hal_driver | 1 - ports/stm32f3/Makefile | 2 +- ports/stm32f3/family.cmake | 1 - ports/stm32f4/Makefile | 2 +- ports/stm32f4/family.cmake | 1 - 7 files changed, 2 insertions(+), 12 deletions(-) delete mode 160000 lib/st/cmsis_device_f4 delete mode 160000 lib/st/stm32f4xx_hal_driver diff --git a/.gitmodules b/.gitmodules index 5bee8427b..ef8ce8e80 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,6 @@ -[submodule "lib/st/cmsis_device_f4"] - path = lib/st/cmsis_device_f4 - url = https://github.com/STMicroelectronics/cmsis_device_f4.git [submodule "lib/st/cmsis_device_l4"] path = lib/st/cmsis_device_l4 url = https://github.com/STMicroelectronics/cmsis_device_l4.git -[submodule "lib/st/stm32f4xx_hal_driver"] - path = lib/st/stm32f4xx_hal_driver - url = https://github.com/STMicroelectronics/stm32f4xx_hal_driver.git [submodule "lib/st/stm32l4xx_hal_driver"] path = lib/st/stm32l4xx_hal_driver url = https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git diff --git a/lib/st/cmsis_device_f4 b/lib/st/cmsis_device_f4 deleted file mode 160000 index 7ac69098b..000000000 --- a/lib/st/cmsis_device_f4 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7ac69098b3e5f9b2d929acd4f087e92a7e59e0e9 diff --git a/lib/st/stm32f4xx_hal_driver b/lib/st/stm32f4xx_hal_driver deleted file mode 160000 index 1d99564fe..000000000 --- a/lib/st/stm32f4xx_hal_driver +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1d99564fee7e2d766efc94d3811ca4ec6389036c diff --git a/ports/stm32f3/Makefile b/ports/stm32f3/Makefile index a618e4c52..b90cda823 100644 --- a/ports/stm32f3/Makefile +++ b/ports/stm32f3/Makefile @@ -1,5 +1,5 @@ # List of git submodules that is included as part of the UF2 version -GIT_SUBMODULES = st/cmsis_device_f3 st/stm32f3xx_hal_driver tinyusb +GIT_SUBMODULES = tinyusb include ../make.mk include port.mk diff --git a/ports/stm32f3/family.cmake b/ports/stm32f3/family.cmake index e523062ac..2a6105f83 100644 --- a/ports/stm32f3/family.cmake +++ b/ports/stm32f3/family.cmake @@ -8,7 +8,6 @@ set(UF2_FAMILY_ID 0x6b846188) set(ST_HAL_DRIVER ${TOP}/lib/st/stm32f3xx_hal_driver) set(ST_CMSIS ${TOP}/lib/st/cmsis_device_f3) set(CMSIS_5 ${TOP}/lib/CMSIS_5) -set(FAMILY_SUBMODULE_DEPS ${ST_CMSIS} ${ST_HAL_DRIVER}) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) diff --git a/ports/stm32f4/Makefile b/ports/stm32f4/Makefile index 1b44376e4..5c3736c7a 100644 --- a/ports/stm32f4/Makefile +++ b/ports/stm32f4/Makefile @@ -1,5 +1,5 @@ # List of git submodules that is included as part of the UF2 version -GIT_SUBMODULES = st/cmsis_device_f4 st/stm32f4xx_hal_driver tinyusb +GIT_SUBMODULES = tinyusb include ../make.mk include port.mk diff --git a/ports/stm32f4/family.cmake b/ports/stm32f4/family.cmake index 37e13db2c..74de107ba 100644 --- a/ports/stm32f4/family.cmake +++ b/ports/stm32f4/family.cmake @@ -8,7 +8,6 @@ set(UF2_FAMILY_ID 0x57755a57) set(ST_HAL_DRIVER ${TOP}/lib/st/stm32f4xx_hal_driver) set(ST_CMSIS ${TOP}/lib/st/cmsis_device_f4) set(CMSIS_5 ${TOP}/lib/CMSIS_5) -set(FAMILY_SUBMODULE_DEPS ${ST_CMSIS} ${ST_HAL_DRIVER}) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) From 515523eaf5219633597534254980b31cff16fe2e Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 May 2024 19:06:28 +0700 Subject: [PATCH 04/11] remove submodule for h7, l4 --- .gitmodules | 12 ------------ lib/st/cmsis_device_h7 | 1 - lib/st/cmsis_device_l4 | 1 - lib/st/stm32h7xx_hal_driver | 1 - lib/st/stm32l4xx_hal_driver | 1 - ports/stm32h7/Makefile | 2 +- ports/stm32l4/Makefile | 2 +- 7 files changed, 2 insertions(+), 18 deletions(-) delete mode 160000 lib/st/cmsis_device_h7 delete mode 160000 lib/st/cmsis_device_l4 delete mode 160000 lib/st/stm32h7xx_hal_driver delete mode 160000 lib/st/stm32l4xx_hal_driver diff --git a/.gitmodules b/.gitmodules index ef8ce8e80..e045ad359 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ -[submodule "lib/st/cmsis_device_l4"] - path = lib/st/cmsis_device_l4 - url = https://github.com/STMicroelectronics/cmsis_device_l4.git -[submodule "lib/st/stm32l4xx_hal_driver"] - path = lib/st/stm32l4xx_hal_driver - url = https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git [submodule "lib/tinyusb"] path = lib/tinyusb url = https://github.com/hathach/tinyusb.git @@ -16,9 +10,3 @@ [submodule "lib/nxp/mcux-sdk"] path = lib/nxp/mcux-sdk url = https://github.com/NXPmicro/mcux-sdk.git -[submodule "lib/st/cmsis_device_h7"] - path = lib/st/cmsis_device_h7 - url = https://github.com/STMicroelectronics/cmsis_device_h7.git -[submodule "lib/st/stm32h7xx_hal_driver"] - path = lib/st/stm32h7xx_hal_driver - url = https://github.com/STMicroelectronics/stm32h7xx_hal_driver.git diff --git a/lib/st/cmsis_device_h7 b/lib/st/cmsis_device_h7 deleted file mode 160000 index 834d18ff6..000000000 --- a/lib/st/cmsis_device_h7 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 834d18ff6b79e72e6ed93cc87a9f6b2d22e3340c diff --git a/lib/st/cmsis_device_l4 b/lib/st/cmsis_device_l4 deleted file mode 160000 index a546853e4..000000000 --- a/lib/st/cmsis_device_l4 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a546853e4834bcd2c56d52c1bfccb658237b72f3 diff --git a/lib/st/stm32h7xx_hal_driver b/lib/st/stm32h7xx_hal_driver deleted file mode 160000 index 3ba4eb3e1..000000000 --- a/lib/st/stm32h7xx_hal_driver +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3ba4eb3e14ec1d407c05f5af5665e0eae789bd0b diff --git a/lib/st/stm32l4xx_hal_driver b/lib/st/stm32l4xx_hal_driver deleted file mode 160000 index ccde09b7e..000000000 --- a/lib/st/stm32l4xx_hal_driver +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ccde09b7e4fc94958f22de49b45efee6c25e0837 diff --git a/ports/stm32h7/Makefile b/ports/stm32h7/Makefile index e3bd25b7a..16f41a035 100644 --- a/ports/stm32h7/Makefile +++ b/ports/stm32h7/Makefile @@ -1,5 +1,5 @@ # List of git submodules that is included as part of the UF2 version -GIT_SUBMODULES = st/cmsis_device_h7 st/stm32h7xx_hal_driver tinyusb uf2 +GIT_SUBMODULES = tinyusb uf2 include ../make.mk include port.mk diff --git a/ports/stm32l4/Makefile b/ports/stm32l4/Makefile index 11e2bd914..44e5f4f52 100644 --- a/ports/stm32l4/Makefile +++ b/ports/stm32l4/Makefile @@ -1,5 +1,5 @@ # List of git submodules that is included as part of the UF2 version -GIT_SUBMODULES = st/cmsis_device_l4 st/stm32l4xx_hal_driver tinyusb +GIT_SUBMODULES = tinyusb include ../make.mk include port.mk From e168b07c4347bcedff608061d623196803a4afc2 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 May 2024 19:12:18 +0700 Subject: [PATCH 05/11] remove nxp mcu-sdk as submodules --- .github/workflows/build_cmake.yml | 16 +++++----------- .gitmodules | 3 --- lib/nxp/mcux-sdk | 1 - ports/mimxrt10xx/Makefile | 2 +- ports/mimxrt10xx/family.cmake | 1 - 5 files changed, 6 insertions(+), 17 deletions(-) delete mode 160000 lib/nxp/mcux-sdk diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml index ba0a04f95..d3685d07a 100644 --- a/.github/workflows/build_cmake.yml +++ b/.github/workflows/build_cmake.yml @@ -41,9 +41,6 @@ jobs: - 'stm32f411ve_discovery' steps: - - name: Install Ninja - run: sudo apt install -y ninja-build - - name: Checkout code uses: actions/checkout@v4 with: @@ -57,15 +54,12 @@ jobs: with: release: '11.2-2022.02' + - name: Get Dependencies + run: | + sudo apt install -y ninja-build + python tools/get_deps.py --board ${{ matrix.board }} + - name: Build run: | cmake . -B _build -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DBOARD=${{ matrix.board }} cmake --build _build - -# - uses: actions/upload-artifact@v3 -# with: -# name: ${{ matrix.board }} -# path: | -# _build/ports/*/tinyusb.bin -# _build/ports/*/tinyusb.hex -# _build/ports/*/apps/*/*.uf2 diff --git a/.gitmodules b/.gitmodules index e045ad359..a79504cf9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,3 @@ [submodule "lib/sct_neopixel"] path = lib/sct_neopixel url = https://github.com/gsteiert/sct_neopixel -[submodule "lib/nxp/mcux-sdk"] - path = lib/nxp/mcux-sdk - url = https://github.com/NXPmicro/mcux-sdk.git diff --git a/lib/nxp/mcux-sdk b/lib/nxp/mcux-sdk deleted file mode 160000 index 9990f264f..000000000 --- a/lib/nxp/mcux-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9990f264f98430f6d885041ab0f24224d68f4958 diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile index f25a4d6d7..5b8edbcdb 100644 --- a/ports/mimxrt10xx/Makefile +++ b/ports/mimxrt10xx/Makefile @@ -1,5 +1,5 @@ # List of git submodules that is included as part of the UF2 version -GIT_SUBMODULES = nxp/mcux-sdk tinyusb +GIT_SUBMODULES = tinyusb # For flash-pyocd-bin target FLASH_BIN_ADDR = $(UF2_$(MCU)_WRITE_ADDR) diff --git a/ports/mimxrt10xx/family.cmake b/ports/mimxrt10xx/family.cmake index 411f4be21..7248e9ebe 100644 --- a/ports/mimxrt10xx/family.cmake +++ b/ports/mimxrt10xx/family.cmake @@ -6,7 +6,6 @@ include_guard() set(UF2_FAMILY_ID 0x4fb2d5bd) set(SDK_DIR ${TOP}/lib/nxp/mcux-sdk) set(CMSIS_DIR ${TOP}/lib/CMSIS_5) -set(FAMILY_SUBMODULE_DEPS ${SDK_DIR}) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) From 505caa0526c05d2cfda8a1b431fc73de58631f78 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 May 2024 20:43:44 +0700 Subject: [PATCH 06/11] also remove sct --- .gitmodules | 3 --- lib/sct_neopixel | 1 - 2 files changed, 4 deletions(-) delete mode 160000 lib/sct_neopixel diff --git a/.gitmodules b/.gitmodules index a79504cf9..2c8e665f3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "lib/uf2"] path = lib/uf2 url = https://github.com/microsoft/uf2.git -[submodule "lib/sct_neopixel"] - path = lib/sct_neopixel - url = https://github.com/gsteiert/sct_neopixel diff --git a/lib/sct_neopixel b/lib/sct_neopixel deleted file mode 160000 index 497ca8974..000000000 --- a/lib/sct_neopixel +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 497ca8974927e3b853fd80c8fc35f4e557af79b9 From 5f24acfb09e538927490c5ce631e3b804b73c0b0 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 May 2024 20:48:14 +0700 Subject: [PATCH 07/11] fix mimxrt10xx, rename k32l2 to kinetis_k32l2 --- ports/{k32l2 => kinetis_k32l2}/Makefile | 128 ++++----- ports/{k32l2 => kinetis_k32l2}/board_flash.c | 0 ports/{k32l2 => kinetis_k32l2}/boards.c | 0 ports/{k32l2 => kinetis_k32l2}/boards.h | 0 .../boards/frdm-k32l2b/board.h | 0 .../boards/frdm-k32l2b/board.mk | 36 +-- .../boards/kuiic/board.h | 0 .../boards/kuiic/board.mk | 56 ++-- .../boards/kuiic/kuiic_rgb.c | 258 +++++++++--------- .../boards/kuiic/kuiic_rgb.h | 136 ++++----- .../boards/kuiic/kuiic_rgb.md | 78 +++--- ports/{k32l2 => kinetis_k32l2}/clock_config.c | 0 ports/{k32l2 => kinetis_k32l2}/clock_config.h | 0 ports/{k32l2 => kinetis_k32l2}/tusb_config.h | 194 ++++++------- ports/lpc55/Makefile | 2 +- tools/get_deps.py | 2 +- 16 files changed, 445 insertions(+), 445 deletions(-) rename ports/{k32l2 => kinetis_k32l2}/Makefile (96%) rename ports/{k32l2 => kinetis_k32l2}/board_flash.c (100%) rename ports/{k32l2 => kinetis_k32l2}/boards.c (100%) rename ports/{k32l2 => kinetis_k32l2}/boards.h (100%) rename ports/{k32l2 => kinetis_k32l2}/boards/frdm-k32l2b/board.h (100%) rename ports/{k32l2 => kinetis_k32l2}/boards/frdm-k32l2b/board.mk (93%) rename ports/{k32l2 => kinetis_k32l2}/boards/kuiic/board.h (100%) rename ports/{k32l2 => kinetis_k32l2}/boards/kuiic/board.mk (94%) rename ports/{k32l2 => kinetis_k32l2}/boards/kuiic/kuiic_rgb.c (97%) rename ports/{k32l2 => kinetis_k32l2}/boards/kuiic/kuiic_rgb.h (97%) rename ports/{k32l2 => kinetis_k32l2}/boards/kuiic/kuiic_rgb.md (98%) rename ports/{k32l2 => kinetis_k32l2}/clock_config.c (100%) rename ports/{k32l2 => kinetis_k32l2}/clock_config.h (100%) rename ports/{k32l2 => kinetis_k32l2}/tusb_config.h (97%) diff --git a/ports/k32l2/Makefile b/ports/kinetis_k32l2/Makefile similarity index 96% rename from ports/k32l2/Makefile rename to ports/kinetis_k32l2/Makefile index 543948cfd..b886f5b6c 100644 --- a/ports/k32l2/Makefile +++ b/ports/kinetis_k32l2/Makefile @@ -1,64 +1,64 @@ -# List of git submodules that is included as part of the UF2 version -GIT_SUBMODULES = nxp/mcux-sdk tinyusb - -include ../make.mk - -# inline port details -UF2_FAMILY_ID = 0x7f83e793 -CROSS_COMPILE = arm-none-eabi- - -SDK_DIR = lib/nxp/mcux-sdk -MCU_DIR = $(SDK_DIR)/devices/$(MCU) - -# Port Compiler Flags -CFLAGS += \ - -flto \ - -mthumb \ - -mabi=aapcs \ - -mcpu=cortex-m0plus - -# suppress warning caused by vendor mcu driver -CFLAGS += -Wno-error=cast-align -Wno-error=unused-parameter - -# Port source -SRC_C += \ - $(MCU_DIR)/system_$(MCU).c \ - $(MCU_DIR)/drivers/fsl_clock.c \ - $(SDK_DIR)/drivers/gpio/fsl_gpio.c \ - $(SDK_DIR)/drivers/flash/fsl_ftfx_controller.c \ - $(SDK_DIR)/drivers/flash/fsl_ftfx_flash.c \ - $(SDK_DIR)/drivers/flash/fsl_ftfx_cache.c \ - $(SDK_DIR)/drivers/flash/fsl_ftfx_flexnvm.c \ - $(SDK_DIR)/drivers/lpuart/fsl_lpuart.c \ - $(PORT_DIR)/clock_config.c \ - $(PORT_DIR)/boards.c \ - $(PORT_DIR)/board_flash.c - -ifndef BUILD_NO_TINYUSB -SRC_C += lib/tinyusb/src/portable/nxp/khci/dcd_khci.c -endif - -SRC_S += $(MCU_DIR)/gcc/startup_$(MCU).S - -# Port include -INC += \ - $(TOP)/$(PORT_DIR) \ - $(TOP)/$(BOARD_DIR) \ - $(TOP)/$(SDK_DIR)/CMSIS/Include \ - $(TOP)/$(MCU_DIR) \ - $(TOP)/$(MCU_DIR)/drivers \ - $(TOP)/$(SDK_DIR)/drivers/smc \ - $(TOP)/$(SDK_DIR)/drivers/rtc \ - $(TOP)/$(SDK_DIR)/drivers/common \ - $(TOP)/$(SDK_DIR)/drivers/gpio \ - $(TOP)/$(SDK_DIR)/drivers/port \ - $(TOP)/$(SDK_DIR)/drivers/lpuart \ - $(TOP)/$(SDK_DIR)/drivers/flash - -LD_FILES ?= $(MCU_DIR)/gcc/$(LD_FNAME) - -include ../rules.mk - -#-------------- Self-update -------------- -self-update: - @echo "not implemented yet" +# List of git submodules that is included as part of the UF2 version +GIT_SUBMODULES = nxp/mcux-sdk tinyusb + +include ../make.mk + +# inline port details +UF2_FAMILY_ID = 0x7f83e793 +CROSS_COMPILE = arm-none-eabi- + +SDK_DIR = lib/nxp/mcux-sdk +MCU_DIR = $(SDK_DIR)/devices/$(MCU) + +# Port Compiler Flags +CFLAGS += \ + -flto \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m0plus + +# suppress warning caused by vendor mcu driver +CFLAGS += -Wno-error=cast-align -Wno-error=unused-parameter + +# Port source +SRC_C += \ + $(MCU_DIR)/system_$(MCU).c \ + $(MCU_DIR)/drivers/fsl_clock.c \ + $(SDK_DIR)/drivers/gpio/fsl_gpio.c \ + $(SDK_DIR)/drivers/flash/fsl_ftfx_controller.c \ + $(SDK_DIR)/drivers/flash/fsl_ftfx_flash.c \ + $(SDK_DIR)/drivers/flash/fsl_ftfx_cache.c \ + $(SDK_DIR)/drivers/flash/fsl_ftfx_flexnvm.c \ + $(SDK_DIR)/drivers/lpuart/fsl_lpuart.c \ + $(PORT_DIR)/clock_config.c \ + $(PORT_DIR)/boards.c \ + $(PORT_DIR)/board_flash.c + +ifndef BUILD_NO_TINYUSB +SRC_C += lib/tinyusb/src/portable/nxp/khci/dcd_khci.c +endif + +SRC_S += $(MCU_DIR)/gcc/startup_$(MCU).S + +# Port include +INC += \ + $(TOP)/$(PORT_DIR) \ + $(TOP)/$(BOARD_DIR) \ + $(TOP)/$(SDK_DIR)/CMSIS/Include \ + $(TOP)/$(MCU_DIR) \ + $(TOP)/$(MCU_DIR)/drivers \ + $(TOP)/$(SDK_DIR)/drivers/smc \ + $(TOP)/$(SDK_DIR)/drivers/rtc \ + $(TOP)/$(SDK_DIR)/drivers/common \ + $(TOP)/$(SDK_DIR)/drivers/gpio \ + $(TOP)/$(SDK_DIR)/drivers/port \ + $(TOP)/$(SDK_DIR)/drivers/lpuart \ + $(TOP)/$(SDK_DIR)/drivers/flash + +LD_FILES ?= $(MCU_DIR)/gcc/$(LD_FNAME) + +include ../rules.mk + +#-------------- Self-update -------------- +self-update: + @echo "not implemented yet" diff --git a/ports/k32l2/board_flash.c b/ports/kinetis_k32l2/board_flash.c similarity index 100% rename from ports/k32l2/board_flash.c rename to ports/kinetis_k32l2/board_flash.c diff --git a/ports/k32l2/boards.c b/ports/kinetis_k32l2/boards.c similarity index 100% rename from ports/k32l2/boards.c rename to ports/kinetis_k32l2/boards.c diff --git a/ports/k32l2/boards.h b/ports/kinetis_k32l2/boards.h similarity index 100% rename from ports/k32l2/boards.h rename to ports/kinetis_k32l2/boards.h diff --git a/ports/k32l2/boards/frdm-k32l2b/board.h b/ports/kinetis_k32l2/boards/frdm-k32l2b/board.h similarity index 100% rename from ports/k32l2/boards/frdm-k32l2b/board.h rename to ports/kinetis_k32l2/boards/frdm-k32l2b/board.h diff --git a/ports/k32l2/boards/frdm-k32l2b/board.mk b/ports/kinetis_k32l2/boards/frdm-k32l2b/board.mk similarity index 93% rename from ports/k32l2/boards/frdm-k32l2b/board.mk rename to ports/kinetis_k32l2/boards/frdm-k32l2b/board.mk index bd10dbd5a..88323bfe6 100644 --- a/ports/k32l2/boards/frdm-k32l2b/board.mk +++ b/ports/kinetis_k32l2/boards/frdm-k32l2b/board.mk @@ -1,18 +1,18 @@ -MCU = K32L2B31A - -CFLAGS += \ - -DCPU_K32L2B31VLH0A \ - -DCFG_TUSB_MCU=OPT_MCU_K32L2BXX - -SRC_S += - -LD_FNAME = K32L2B31xxxxA_flash.ld - -DBL_TAP_REG_ADDR = 0x4003D008 - -# For flash-pyocd target -PYOCD_TARGET = K32L2B3 - -# flash using pyocd -flash: flash-pyocd -erase: erase-jlink +MCU = K32L2B31A + +CFLAGS += \ + -DCPU_K32L2B31VLH0A \ + -DCFG_TUSB_MCU=OPT_MCU_K32L2BXX + +SRC_S += + +LD_FNAME = K32L2B31xxxxA_flash.ld + +DBL_TAP_REG_ADDR = 0x4003D008 + +# For flash-pyocd target +PYOCD_TARGET = K32L2B3 + +# flash using pyocd +flash: flash-pyocd +erase: erase-jlink diff --git a/ports/k32l2/boards/kuiic/board.h b/ports/kinetis_k32l2/boards/kuiic/board.h similarity index 100% rename from ports/k32l2/boards/kuiic/board.h rename to ports/kinetis_k32l2/boards/kuiic/board.h diff --git a/ports/k32l2/boards/kuiic/board.mk b/ports/kinetis_k32l2/boards/kuiic/board.mk similarity index 94% rename from ports/k32l2/boards/kuiic/board.mk rename to ports/kinetis_k32l2/boards/kuiic/board.mk index a81de10c4..6d5240162 100644 --- a/ports/k32l2/boards/kuiic/board.mk +++ b/ports/kinetis_k32l2/boards/kuiic/board.mk @@ -1,28 +1,28 @@ -MCU = K32L2B31A - -CFLAGS += \ - -DCPU_K32L2B31VLH0A \ - -DCFG_TUSB_MCU=OPT_MCU_K32L2BXX - -SRC_C += \ - $(SDK_DIR)/drivers/dma/fsl_dma.c \ - $(SDK_DIR)/drivers/dmamux/fsl_dmamux.c \ - $(SDK_DIR)/drivers/tpm/fsl_tpm.c \ - $(BOARD_DIR)/kuiic_rgb.c - -INC += \ - $(TOP)/$(SDK_DIR)/drivers/dma \ - $(TOP)/$(SDK_DIR)/drivers/dmamux \ - $(TOP)/$(SDK_DIR)/drivers/tpm - - -LD_FNAME = K32L2B31xxxxA_flash.ld - -DBL_TAP_REG_ADDR = 0x4003D008 - -# For flash-pyocd target -PYOCD_TARGET = K32L2B3 - -# flash using pyocd -flash: flash-pyocd -erase: erase-jlink +MCU = K32L2B31A + +CFLAGS += \ + -DCPU_K32L2B31VLH0A \ + -DCFG_TUSB_MCU=OPT_MCU_K32L2BXX + +SRC_C += \ + $(SDK_DIR)/drivers/dma/fsl_dma.c \ + $(SDK_DIR)/drivers/dmamux/fsl_dmamux.c \ + $(SDK_DIR)/drivers/tpm/fsl_tpm.c \ + $(BOARD_DIR)/kuiic_rgb.c + +INC += \ + $(TOP)/$(SDK_DIR)/drivers/dma \ + $(TOP)/$(SDK_DIR)/drivers/dmamux \ + $(TOP)/$(SDK_DIR)/drivers/tpm + + +LD_FNAME = K32L2B31xxxxA_flash.ld + +DBL_TAP_REG_ADDR = 0x4003D008 + +# For flash-pyocd target +PYOCD_TARGET = K32L2B3 + +# flash using pyocd +flash: flash-pyocd +erase: erase-jlink diff --git a/ports/k32l2/boards/kuiic/kuiic_rgb.c b/ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.c similarity index 97% rename from ports/k32l2/boards/kuiic/kuiic_rgb.c rename to ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.c index 581aaa1de..c3c655245 100644 --- a/ports/k32l2/boards/kuiic/kuiic_rgb.c +++ b/ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.c @@ -1,129 +1,129 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Greg Steiert for NXP - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "kuiic_rgb.h" -#include "fsl_common.h" -#include "fsl_port.h" -#include "fsl_tpm.h" -#include "fsl_dma.h" -#include "fsl_dmamux.h" - -//--------------------------------------------------------------------+ -// Variables -//--------------------------------------------------------------------+ -const uint32_t DISABLED_TIMER_REG_VALUE = KUIIC_RGB_TPM_SC_STOP; -volatile bool kuiic_rgb_on; - -//--------------------------------------------------------------------+ -// Code -//--------------------------------------------------------------------+ - -// KUIIC RGB initialization -void kuiic_rgb_init(void) { - tpm_config_t tpmConfig; - dma_handle_t dmaHandle; /* DMA handler. */ - dma_transfer_config_t transferConfig; - uint8_t rgb[3] = {0,0,0x80}; - - /* Select timer output for LED pins */ - CLOCK_EnableClock(KUIIC_RGB_CLK_PORT); - PORT_SetPinMux(KUIIC_RGB_BR_PORT, KUIIC_RGB_BR_PIN, KUIIC_RGB_BR_MUX); - PORT_SetPinMux(KUIIC_RGB_GB_PORT, KUIIC_RGB_GB_PIN, KUIIC_RGB_GB_MUX); - - /* Select the clock source for the TPM counter as kCLOCK_McgIrc48MClk */ - CLOCK_SetTpmClock(1U); - - /* - * tpmConfig.prescale = kTPM_Prescale_Divide_1; - * tpmConfig.useGlobalTimeBase = false; - * tpmConfig.enableDoze = false; - * tpmConfig.enableDebugMode = false; - * tpmConfig.enableReloadOnTrigger = false; - * tpmConfig.enableStopOnOverflow = false; - * tpmConfig.enableStartOnTrigger = false; - * tpmConfig.enablePauseOnTrigger = false; - * tpmConfig.triggerSelect = kTPM_Trigger_Select_0; - * tpmConfig.triggerSource = kTPM_TriggerSource_External; - */ - TPM_GetDefaultConfig(&tpmConfig); - tpmConfig.enableDebugMode = true; - tpmConfig.enableReloadOnTrigger = true; - tpmConfig.enableStopOnOverflow = true; - /* Initialize TPM module */ - TPM_Init(KUIIC_RGB_TPM, &tpmConfig); - // clear flag, edge mode - KUIIC_RGB_TPM->CONTROLS[KUIIC_RGB_BR_CH].CnSC = 0x28; - KUIIC_RGB_TPM->CONTROLS[KUIIC_RGB_GB_CH].CnSC = 0x28; - KUIIC_RGB_TPM->SC = KUIIC_RGB_TPM_SC_STOP; - - kuiic_rgb_write(rgb); - - /* Configure DMAMUX. */ - DMAMUX_Init(DMAMUX0); - DMAMUX_SetSource(DMAMUX0, KUIIC_RGB_DMA_CHANNEL, KUIIC_RGB_DMA_SOURCE); /* Map TPM2 TOF source to channel 0 */ - DMAMUX_EnableChannel(DMAMUX0, KUIIC_RGB_DMA_CHANNEL); - - DMA_Init(DMA0); - DMA_CreateHandle(&dmaHandle, DMA0, KUIIC_RGB_DMA_CHANNEL); - /* enable cycle steal and enable auto disable channel request */ - - DMA_PrepareTransferConfig(&transferConfig, (void *)(&DISABLED_TIMER_REG_VALUE), sizeof(uint32_t), - (void *)&KUIIC_RGB_TPM->SC, sizeof(uint32_t), sizeof(uint32_t), - kDMA_AddrNoIncrement, kDMA_AddrNoIncrement); - DMA_SubmitTransfer(&dmaHandle, &transferConfig, kDMA_NoOptions); - /* Enable transfer. */ - DMA0->DMA[KUIIC_RGB_DMA_CHANNEL].DCR &= ~DMA_DCR_D_REQ(true); - DMA0->DMA[KUIIC_RGB_DMA_CHANNEL].DCR |= DMA_DCR_ERQ(true) | DMA_DCR_CS(true); - -} - -// KUIIC RGB write function -void kuiic_rgb_write(uint8_t const rgb[]) { - if ((rgb[0]==0)&&(rgb[1]==0)&&(rgb[2]==0)) { - kuiic_rgb_on = false; - } else { - kuiic_rgb_on = true; - uint32_t r = rgb[0] << KUIIC_RGB_BRIGHT_SHIFT; - // avoid setting counts to zero by padding green pulse if 0 - uint32_t g = (rgb[1]>0) ? (rgb[1] << KUIIC_RGB_BRIGHT_SHIFT) : 1; - uint32_t b = rgb[2] << KUIIC_RGB_BRIGHT_SHIFT; - KUIIC_RGB_TPM->MOD = (r + g + b); - KUIIC_RGB_TPM->CONTROLS[KUIIC_RGB_BR_CH].CnV = (g + b); - KUIIC_RGB_TPM->CONTROLS[KUIIC_RGB_GB_CH].CnV = (g); - } -} - -// KUIIC RGB tick handler -// This should be called in the systick handler -// to initiate the next pulses -void kuiic_rgb_tick(void) { - if (kuiic_rgb_on) { - // clear DMA DONE bit - DMA0->DMA[KUIIC_RGB_DMA_CHANNEL].DSR_BCR = DMA_DSR_BCR_DONE(true); - // reset transfer count - DMA0->DMA[KUIIC_RGB_DMA_CHANNEL].DSR_BCR = 4; - // start timer - KUIIC_RGB_TPM->SC = KUIIC_RGB_TPM_SC_GO; - } -} +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Greg Steiert for NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "kuiic_rgb.h" +#include "fsl_common.h" +#include "fsl_port.h" +#include "fsl_tpm.h" +#include "fsl_dma.h" +#include "fsl_dmamux.h" + +//--------------------------------------------------------------------+ +// Variables +//--------------------------------------------------------------------+ +const uint32_t DISABLED_TIMER_REG_VALUE = KUIIC_RGB_TPM_SC_STOP; +volatile bool kuiic_rgb_on; + +//--------------------------------------------------------------------+ +// Code +//--------------------------------------------------------------------+ + +// KUIIC RGB initialization +void kuiic_rgb_init(void) { + tpm_config_t tpmConfig; + dma_handle_t dmaHandle; /* DMA handler. */ + dma_transfer_config_t transferConfig; + uint8_t rgb[3] = {0,0,0x80}; + + /* Select timer output for LED pins */ + CLOCK_EnableClock(KUIIC_RGB_CLK_PORT); + PORT_SetPinMux(KUIIC_RGB_BR_PORT, KUIIC_RGB_BR_PIN, KUIIC_RGB_BR_MUX); + PORT_SetPinMux(KUIIC_RGB_GB_PORT, KUIIC_RGB_GB_PIN, KUIIC_RGB_GB_MUX); + + /* Select the clock source for the TPM counter as kCLOCK_McgIrc48MClk */ + CLOCK_SetTpmClock(1U); + + /* + * tpmConfig.prescale = kTPM_Prescale_Divide_1; + * tpmConfig.useGlobalTimeBase = false; + * tpmConfig.enableDoze = false; + * tpmConfig.enableDebugMode = false; + * tpmConfig.enableReloadOnTrigger = false; + * tpmConfig.enableStopOnOverflow = false; + * tpmConfig.enableStartOnTrigger = false; + * tpmConfig.enablePauseOnTrigger = false; + * tpmConfig.triggerSelect = kTPM_Trigger_Select_0; + * tpmConfig.triggerSource = kTPM_TriggerSource_External; + */ + TPM_GetDefaultConfig(&tpmConfig); + tpmConfig.enableDebugMode = true; + tpmConfig.enableReloadOnTrigger = true; + tpmConfig.enableStopOnOverflow = true; + /* Initialize TPM module */ + TPM_Init(KUIIC_RGB_TPM, &tpmConfig); + // clear flag, edge mode + KUIIC_RGB_TPM->CONTROLS[KUIIC_RGB_BR_CH].CnSC = 0x28; + KUIIC_RGB_TPM->CONTROLS[KUIIC_RGB_GB_CH].CnSC = 0x28; + KUIIC_RGB_TPM->SC = KUIIC_RGB_TPM_SC_STOP; + + kuiic_rgb_write(rgb); + + /* Configure DMAMUX. */ + DMAMUX_Init(DMAMUX0); + DMAMUX_SetSource(DMAMUX0, KUIIC_RGB_DMA_CHANNEL, KUIIC_RGB_DMA_SOURCE); /* Map TPM2 TOF source to channel 0 */ + DMAMUX_EnableChannel(DMAMUX0, KUIIC_RGB_DMA_CHANNEL); + + DMA_Init(DMA0); + DMA_CreateHandle(&dmaHandle, DMA0, KUIIC_RGB_DMA_CHANNEL); + /* enable cycle steal and enable auto disable channel request */ + + DMA_PrepareTransferConfig(&transferConfig, (void *)(&DISABLED_TIMER_REG_VALUE), sizeof(uint32_t), + (void *)&KUIIC_RGB_TPM->SC, sizeof(uint32_t), sizeof(uint32_t), + kDMA_AddrNoIncrement, kDMA_AddrNoIncrement); + DMA_SubmitTransfer(&dmaHandle, &transferConfig, kDMA_NoOptions); + /* Enable transfer. */ + DMA0->DMA[KUIIC_RGB_DMA_CHANNEL].DCR &= ~DMA_DCR_D_REQ(true); + DMA0->DMA[KUIIC_RGB_DMA_CHANNEL].DCR |= DMA_DCR_ERQ(true) | DMA_DCR_CS(true); + +} + +// KUIIC RGB write function +void kuiic_rgb_write(uint8_t const rgb[]) { + if ((rgb[0]==0)&&(rgb[1]==0)&&(rgb[2]==0)) { + kuiic_rgb_on = false; + } else { + kuiic_rgb_on = true; + uint32_t r = rgb[0] << KUIIC_RGB_BRIGHT_SHIFT; + // avoid setting counts to zero by padding green pulse if 0 + uint32_t g = (rgb[1]>0) ? (rgb[1] << KUIIC_RGB_BRIGHT_SHIFT) : 1; + uint32_t b = rgb[2] << KUIIC_RGB_BRIGHT_SHIFT; + KUIIC_RGB_TPM->MOD = (r + g + b); + KUIIC_RGB_TPM->CONTROLS[KUIIC_RGB_BR_CH].CnV = (g + b); + KUIIC_RGB_TPM->CONTROLS[KUIIC_RGB_GB_CH].CnV = (g); + } +} + +// KUIIC RGB tick handler +// This should be called in the systick handler +// to initiate the next pulses +void kuiic_rgb_tick(void) { + if (kuiic_rgb_on) { + // clear DMA DONE bit + DMA0->DMA[KUIIC_RGB_DMA_CHANNEL].DSR_BCR = DMA_DSR_BCR_DONE(true); + // reset transfer count + DMA0->DMA[KUIIC_RGB_DMA_CHANNEL].DSR_BCR = 4; + // start timer + KUIIC_RGB_TPM->SC = KUIIC_RGB_TPM_SC_GO; + } +} diff --git a/ports/k32l2/boards/kuiic/kuiic_rgb.h b/ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.h similarity index 97% rename from ports/k32l2/boards/kuiic/kuiic_rgb.h rename to ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.h index fb6d9e9c2..d537cd578 100644 --- a/ports/k32l2/boards/kuiic/kuiic_rgb.h +++ b/ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.h @@ -1,68 +1,68 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Greg Steiert for NXP - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef KUIIC_RGB_H_ -#define KUIIC_RGB_H_ - -#include - -//--------------------------------------------------------------------+ -// Definitions -//--------------------------------------------------------------------+ -#define KUIIC_RGB_DMA_CHANNEL 0U -#define KUIIC_RGB_DMA_SOURCE 56U -#define KUIIC_RGB_TPM_SC_GO 0x10C -#define KUIIC_RGB_TPM_SC_STOP 0x084 -#define KUIIC_RGB_TPM TPM2 -#define KUIIC_RGB_BR_CH 0U -#define KUIIC_RGB_GB_CH 1U -#define KUIIC_RGB_BRIGHT_SHIFT 4 -#define KUIIC_RGB_CLK_PORT kCLOCK_PortA -#define KUIIC_RGB_BR_PORT PORTA -#define KUIIC_RGB_BR_PIN 1 -#define KUIIC_RGB_BR_MUX kPORT_MuxAlt3 -#define KUIIC_RGB_GB_PORT PORTA -#define KUIIC_RGB_GB_PIN 2 -#define KUIIC_RGB_GB_MUX kPORT_MuxAlt3 - -//--------------------------------------------------------------------+ -// Basic API -//--------------------------------------------------------------------+ - -/*! @brief KUIIC RGB initialization - */ -void kuiic_rgb_init(void); - -/*! @brief KUIIC RGB write function - * @param byte array for RGB values to be written - */ -void kuiic_rgb_write(uint8_t const rgb[]); - -/*! @brief KUIIC RGB tick handler - * @note This should be called in the systick handler to - * initiate the next pulses - */ -void kuiic_rgb_tick(void); - -#endif +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Greg Steiert for NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef KUIIC_RGB_H_ +#define KUIIC_RGB_H_ + +#include + +//--------------------------------------------------------------------+ +// Definitions +//--------------------------------------------------------------------+ +#define KUIIC_RGB_DMA_CHANNEL 0U +#define KUIIC_RGB_DMA_SOURCE 56U +#define KUIIC_RGB_TPM_SC_GO 0x10C +#define KUIIC_RGB_TPM_SC_STOP 0x084 +#define KUIIC_RGB_TPM TPM2 +#define KUIIC_RGB_BR_CH 0U +#define KUIIC_RGB_GB_CH 1U +#define KUIIC_RGB_BRIGHT_SHIFT 4 +#define KUIIC_RGB_CLK_PORT kCLOCK_PortA +#define KUIIC_RGB_BR_PORT PORTA +#define KUIIC_RGB_BR_PIN 1 +#define KUIIC_RGB_BR_MUX kPORT_MuxAlt3 +#define KUIIC_RGB_GB_PORT PORTA +#define KUIIC_RGB_GB_PIN 2 +#define KUIIC_RGB_GB_MUX kPORT_MuxAlt3 + +//--------------------------------------------------------------------+ +// Basic API +//--------------------------------------------------------------------+ + +/*! @brief KUIIC RGB initialization + */ +void kuiic_rgb_init(void); + +/*! @brief KUIIC RGB write function + * @param byte array for RGB values to be written + */ +void kuiic_rgb_write(uint8_t const rgb[]); + +/*! @brief KUIIC RGB tick handler + * @note This should be called in the systick handler to + * initiate the next pulses + */ +void kuiic_rgb_tick(void); + +#endif diff --git a/ports/k32l2/boards/kuiic/kuiic_rgb.md b/ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.md similarity index 98% rename from ports/k32l2/boards/kuiic/kuiic_rgb.md rename to ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.md index c79030bb4..bccc1b27b 100644 --- a/ports/k32l2/boards/kuiic/kuiic_rgb.md +++ b/ports/kinetis_k32l2/boards/kuiic/kuiic_rgb.md @@ -1,39 +1,39 @@ -# KUIIC RGB Multiplexing Driver - -The KUIIC board uses two timer capable pins to drive an RGB LED. This was done to provide a full color indicator without consuming the 6ch timer resource in the K32L2B. This driver enables full color on the LED with a two channel timer/PWM. - -## Theory of operation - -The three LEDS are connected in the following order: - -``` - red B/R# blue G/B# green -3V3 - 2k ->|- PTA1 - 1k ->|- PTA2 - 2k ->|- GND -``` - -The state of the LEDs is described in the following truth table: - - B/R# | G/B# | R | G | B | Color --------|-------|-----|-----|-----|------- - Z | Z | off | off | off | black - 0 | 0 | ON | off | off | red - 0 | 1 | ON | ON | off | yellow - 1 | 0 | off | off | ON | blue - 1 | 1 | off | ON | off | green - -As seen in the table, with simple GPIO control including tri-state, 5 combinations are possible including black, R, G, B, and yellow as a bonus color option. Implementing these 5 options is left as an exercise for the reader. This driver enables generating 24bit RGB color using two timer channels. - -## Timer operation - -At the beginning of a new period, the timer will drive both channels high generating green. After the green count expires, it will drive the second channel (CH 1, G/B#) low changing the color to blue. After the green + blue count expires, the first channel (CH 0, B/R#) is driven low to output red. The timer is disabled after green + blue + red counts expire. The process repeats at the next SysTick interrupt when the timer is enabled. - -To implement this with the timer: - * TPM Channel 1 (G/B#) Value is loaded with the green RGB value - * TPM Channel 0 (B/R#) Value is loaded with the green + blue values - * TPM Modulo is loaded with the green + blue + red values - * The timer is configured to trigger a DMA transfer when the modulo count exprires that will disable (tri-state) the outputs - * The timer is enabled at every SysTick interrupt - -## Clocking - -This library utilizes the 48MHz clock that is required for USB operation. It sets the prescaler to divide by 1 for the highest resolution. KUIIC_RGB_BRIGHT_SHIFT is provided to allow for maximum brightness addjustments. The three color counts need to be completed within the 1ms SysTick interval which is 48,000 clocks when running at 48MHz, therefore the maximum count needs to be less than 16,000 for each color and KUIIC_RGB_BRIGHT_SHIFT should not be set above 5 (255 * 2^5 = 8160). +# KUIIC RGB Multiplexing Driver + +The KUIIC board uses two timer capable pins to drive an RGB LED. This was done to provide a full color indicator without consuming the 6ch timer resource in the K32L2B. This driver enables full color on the LED with a two channel timer/PWM. + +## Theory of operation + +The three LEDS are connected in the following order: + +``` + red B/R# blue G/B# green +3V3 - 2k ->|- PTA1 - 1k ->|- PTA2 - 2k ->|- GND +``` + +The state of the LEDs is described in the following truth table: + + B/R# | G/B# | R | G | B | Color +-------|-------|-----|-----|-----|------- + Z | Z | off | off | off | black + 0 | 0 | ON | off | off | red + 0 | 1 | ON | ON | off | yellow + 1 | 0 | off | off | ON | blue + 1 | 1 | off | ON | off | green + +As seen in the table, with simple GPIO control including tri-state, 5 combinations are possible including black, R, G, B, and yellow as a bonus color option. Implementing these 5 options is left as an exercise for the reader. This driver enables generating 24bit RGB color using two timer channels. + +## Timer operation + +At the beginning of a new period, the timer will drive both channels high generating green. After the green count expires, it will drive the second channel (CH 1, G/B#) low changing the color to blue. After the green + blue count expires, the first channel (CH 0, B/R#) is driven low to output red. The timer is disabled after green + blue + red counts expire. The process repeats at the next SysTick interrupt when the timer is enabled. + +To implement this with the timer: + * TPM Channel 1 (G/B#) Value is loaded with the green RGB value + * TPM Channel 0 (B/R#) Value is loaded with the green + blue values + * TPM Modulo is loaded with the green + blue + red values + * The timer is configured to trigger a DMA transfer when the modulo count exprires that will disable (tri-state) the outputs + * The timer is enabled at every SysTick interrupt + +## Clocking + +This library utilizes the 48MHz clock that is required for USB operation. It sets the prescaler to divide by 1 for the highest resolution. KUIIC_RGB_BRIGHT_SHIFT is provided to allow for maximum brightness addjustments. The three color counts need to be completed within the 1ms SysTick interval which is 48,000 clocks when running at 48MHz, therefore the maximum count needs to be less than 16,000 for each color and KUIIC_RGB_BRIGHT_SHIFT should not be set above 5 (255 * 2^5 = 8160). diff --git a/ports/k32l2/clock_config.c b/ports/kinetis_k32l2/clock_config.c similarity index 100% rename from ports/k32l2/clock_config.c rename to ports/kinetis_k32l2/clock_config.c diff --git a/ports/k32l2/clock_config.h b/ports/kinetis_k32l2/clock_config.h similarity index 100% rename from ports/k32l2/clock_config.h rename to ports/kinetis_k32l2/clock_config.h diff --git a/ports/k32l2/tusb_config.h b/ports/kinetis_k32l2/tusb_config.h similarity index 97% rename from ports/k32l2/tusb_config.h rename to ports/kinetis_k32l2/tusb_config.h index b11b0f916..f3edc4551 100644 --- a/ports/k32l2/tusb_config.h +++ b/ports/kinetis_k32l2/tusb_config.h @@ -1,97 +1,97 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#ifndef _TUSB_CONFIG_H_ -#define _TUSB_CONFIG_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -//-------------------------------------------------------------------- -// COMMON CONFIGURATION -//-------------------------------------------------------------------- - -#ifndef CFG_TUSB_MCU -#error CFG_TUSB_MCU must be defined in board.mk -#endif - -#define BOARD_DEVICE_RHPORT_NUM 0 -#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED - -#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED) -#define CFG_TUSB_OS OPT_OS_NONE - -// can be defined by compiler in DEBUG build -#ifndef CFG_TUSB_DEBUG - #define CFG_TUSB_DEBUG 0 -#endif - -/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. - * Tinyusb use follows macros to declare transferring memory so that they can be put - * into those specific section. - * e.g - * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) - * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) - */ -#ifndef CFG_TUSB_MEM_SECTION -#define CFG_TUSB_MEM_SECTION -#endif - -#ifndef CFG_TUSB_MEM_ALIGN -#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) -#endif - -//-------------------------------------------------------------------- -// DEVICE CONFIGURATION -//-------------------------------------------------------------------- - -#ifndef CFG_TUD_ENDPOINT0_SIZE -#define CFG_TUD_ENDPOINT0_SIZE 64 -#endif - -//------------- CLASS -------------// -#define CFG_TUD_CDC 0 -#define CFG_TUD_MSC 1 -#define CFG_TUD_HID 0 -#define CFG_TUD_MIDI 0 -#define CFG_TUD_VENDOR 0 - -// MSC Buffer size of Device Mass storage -#define CFG_TUD_MSC_BUFSIZE 512 - -// HID buffer size Should be sufficient to hold ID (if any) + Data -#define CFG_TUD_HID_BUFSIZE 64 - -// Vendor FIFO size of TX and RX -// If not configured vendor endpoints will not be buffered -#define CFG_TUD_VENDOR_RX_BUFSIZE 64 -#define CFG_TUD_VENDOR_TX_BUFSIZE 64 - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_CONFIG_H_ */ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#ifndef _TUSB_CONFIG_H_ +#define _TUSB_CONFIG_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//-------------------------------------------------------------------- +// COMMON CONFIGURATION +//-------------------------------------------------------------------- + +#ifndef CFG_TUSB_MCU +#error CFG_TUSB_MCU must be defined in board.mk +#endif + +#define BOARD_DEVICE_RHPORT_NUM 0 +#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED + +#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED) +#define CFG_TUSB_OS OPT_OS_NONE + +// can be defined by compiler in DEBUG build +#ifndef CFG_TUSB_DEBUG + #define CFG_TUSB_DEBUG 0 +#endif + +/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. + * Tinyusb use follows macros to declare transferring memory so that they can be put + * into those specific section. + * e.g + * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) + * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) + */ +#ifndef CFG_TUSB_MEM_SECTION +#define CFG_TUSB_MEM_SECTION +#endif + +#ifndef CFG_TUSB_MEM_ALIGN +#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) +#endif + +//-------------------------------------------------------------------- +// DEVICE CONFIGURATION +//-------------------------------------------------------------------- + +#ifndef CFG_TUD_ENDPOINT0_SIZE +#define CFG_TUD_ENDPOINT0_SIZE 64 +#endif + +//------------- CLASS -------------// +#define CFG_TUD_CDC 0 +#define CFG_TUD_MSC 1 +#define CFG_TUD_HID 0 +#define CFG_TUD_MIDI 0 +#define CFG_TUD_VENDOR 0 + +// MSC Buffer size of Device Mass storage +#define CFG_TUD_MSC_BUFSIZE 512 + +// HID buffer size Should be sufficient to hold ID (if any) + Data +#define CFG_TUD_HID_BUFSIZE 64 + +// Vendor FIFO size of TX and RX +// If not configured vendor endpoints will not be buffered +#define CFG_TUD_VENDOR_RX_BUFSIZE 64 +#define CFG_TUD_VENDOR_TX_BUFSIZE 64 + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_CONFIG_H_ */ diff --git a/ports/lpc55/Makefile b/ports/lpc55/Makefile index 5fb3e9b69..63bdcf79d 100644 --- a/ports/lpc55/Makefile +++ b/ports/lpc55/Makefile @@ -1,5 +1,5 @@ # List of git submodules that is included as part of the UF2 version -GIT_SUBMODULES = nxp/mcux-sdk sct_neopixel tinyusb +GIT_SUBMODULES = tinyusb include ../make.mk include port.mk diff --git a/tools/get_deps.py b/tools/get_deps.py index 35ba80166..282f86feb 100644 --- a/tools/get_deps.py +++ b/tools/get_deps.py @@ -13,7 +13,7 @@ deps_optional = { 'lib/nxp/mcux-sdk': ['https://github.com/hathach/mcux-sdk.git', '9990f264f98430f6d885041ab0f24224d68f4958', - 'kinetis_k kinetis_k32l2 kinetis_kl lpc51 lpc54 lpc55 mcx imxrt'], + 'kinetis_k kinetis_k32l2 kinetis_kl lpc51 lpc54 lpc55 mcx mimxrt10xx'], 'lib/st/cmsis_device_f3': ['https://github.com/STMicroelectronics/cmsis_device_f3.git', '5e4ee5ed7a7b6c85176bb70a9fd3c72d6eb99f1b', 'stm32f3'], From fe3d5a0fd2676b080bdaa09336c1c887abf408b7 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 May 2024 22:18:30 +0700 Subject: [PATCH 08/11] temp fix cmake --- ports/family_support.cmake | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ports/family_support.cmake b/ports/family_support.cmake index e5ed9eba6..db9872f1b 100644 --- a/ports/family_support.cmake +++ b/ports/family_support.cmake @@ -174,21 +174,21 @@ endfunction() function(family_add_uf2version TARGET DEPS_REPO) execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION) string(STRIP ${GIT_VERSION} GIT_VERSION) - string(REPLACE ${TOP}/ "" DEPS_REPO "${DEPS_REPO}") - foreach (DEP ${DEPS_REPO}) - execute_process(COMMAND ${GIT_EXECUTABLE} -C ${TOP} submodule status ${DEP} - OUTPUT_VARIABLE DEP_VERSION - ) - string(STRIP ${DEP_VERSION} DEP_VERSION) - string(FIND "${DEP_VERSION}" " " SPACE_POS) - string(SUBSTRING "${DEP_VERSION}" ${SPACE_POS} -1 DEP_VERSION) - string(STRIP ${DEP_VERSION} DEP_VERSION) - - set(GIT_SUBMODULE_VERSIONS "${GIT_SUBMODULE_VERSIONS} ${DEP_VERSION}") - endforeach () - - string(STRIP ${GIT_SUBMODULE_VERSIONS} GIT_SUBMODULE_VERSIONS) - string(REPLACE lib/ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS}) +# string(REPLACE ${TOP}/ "" DEPS_REPO "${DEPS_REPO}") +# foreach (DEP ${DEPS_REPO}) +# execute_process(COMMAND ${GIT_EXECUTABLE} -C ${TOP} submodule status ${DEP} +# OUTPUT_VARIABLE DEP_VERSION +# ) +# string(STRIP ${DEP_VERSION} DEP_VERSION) +# string(FIND "${DEP_VERSION}" " " SPACE_POS) +# string(SUBSTRING "${DEP_VERSION}" ${SPACE_POS} -1 DEP_VERSION) +# string(STRIP ${DEP_VERSION} DEP_VERSION) +# +# set(GIT_SUBMODULE_VERSIONS "${GIT_SUBMODULE_VERSIONS} ${DEP_VERSION}") +# endforeach () +# +# string(STRIP ${GIT_SUBMODULE_VERSIONS} GIT_SUBMODULE_VERSIONS) +# string(REPLACE lib/ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS}) cmake_print_variables(GIT_VERSION) cmake_print_variables(GIT_SUBMODULE_VERSIONS) From 9f7590e1ef4f33c009e4476eede9693d55949738 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 30 May 2024 11:15:05 +0700 Subject: [PATCH 09/11] move mcu to lib/mcu --- .github/workflows/build_arm.yml | 14 ++--- .github/workflows/build_esp32.yml | 2 +- .github/workflows/build_selftest.yml | 2 +- .github/workflows/codeql.yml | 2 +- ports/kinetis_k32l2/Makefile | 2 +- ports/lpc55/port.mk | 2 +- ports/mimxrt10xx/family.cmake | 2 +- ports/mimxrt10xx/port.mk | 2 +- ports/stm32f3/family.cmake | 4 +- ports/stm32f3/port.mk | 4 +- ports/stm32f4/family.cmake | 4 +- ports/stm32f4/port.mk | 4 +- ports/stm32h7/port.mk | 4 +- ports/stm32l4/port.mk | 4 +- tools/get_deps.py | 77 ++++++++++++++++------------ 15 files changed, 69 insertions(+), 60 deletions(-) diff --git a/.github/workflows/build_arm.yml b/.github/workflows/build_arm.yml index 8c3f67e7f..1fbfe1ba5 100644 --- a/.github/workflows/build_arm.yml +++ b/.github/workflows/build_arm.yml @@ -70,14 +70,17 @@ jobs: with: fetch-depth: 0 - - name: Checkout common submodules in lib - run: git submodule update --init lib/tinyusb lib/uf2 - - name: Install ARM GCC uses: carlosperate/arm-none-eabi-gcc-action@v1 with: release: '11.2-2022.02' + - name: Get Dependencies + run: | + git submodule update --init lib/tinyusb lib/uf2 + #make -C $ENV_PORT BOARD=${{ matrix.board }} get-deps + python tools/get_deps.py --board ${{ matrix.board }} + - name: Find Port run: | ENV_PORT=`echo ports/*/boards/${{ matrix.board }}` @@ -88,13 +91,10 @@ jobs: - name: Build run: | - arm-none-eabi-gcc --version - #make -C $ENV_PORT BOARD=${{ matrix.board }} get-deps - python tools/get_deps.py --board ${{ matrix.board }} make -C $ENV_PORT BOARD=${{ matrix.board }} all self-update copy-artifact for app in ${{ env.ENV_PORT }}/apps/*/; do if [ $app != 'apps/self_update/' ]; then make -C $app BOARD=${{ matrix.board }} all; fi done - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: ${{ matrix.board }} path: ${{ env.BIN_PATH }} diff --git a/.github/workflows/build_esp32.yml b/.github/workflows/build_esp32.yml index 3a54a236d..5008f80f3 100644 --- a/.github/workflows/build_esp32.yml +++ b/.github/workflows/build_esp32.yml @@ -137,7 +137,7 @@ jobs: - name: Build run: docker run --rm -v $PWD:/project -w /project espressif/idf:v5.1.1 /bin/bash -c "git config --global --add safe.directory /project && make -C ports/espressif/ BOARD=${{ matrix.board }} all self-update copy-artifact" - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: ${{ matrix.board }} path: ${{ env.BIN_PATH }} diff --git a/.github/workflows/build_selftest.yml b/.github/workflows/build_selftest.yml index ca5e14d94..277283af8 100644 --- a/.github/workflows/build_selftest.yml +++ b/.github/workflows/build_selftest.yml @@ -73,7 +73,7 @@ jobs: - name: Save newly generated self-test images as CI artifacts if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ghostfat_selftest_images path: ./ports/test_ghostfat/_build/${{ matrix.board }}/ghostfat_${{ matrix.board }}.img.gz.gz diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 4c87125f8..35fb682d4 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -114,7 +114,7 @@ jobs: - name: Upload CodeQL results as an artifact if: success() || failure() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: codeql-results path: ${{ steps.step1.outputs.sarif-output }} diff --git a/ports/kinetis_k32l2/Makefile b/ports/kinetis_k32l2/Makefile index b886f5b6c..be0b2e96e 100644 --- a/ports/kinetis_k32l2/Makefile +++ b/ports/kinetis_k32l2/Makefile @@ -7,7 +7,7 @@ include ../make.mk UF2_FAMILY_ID = 0x7f83e793 CROSS_COMPILE = arm-none-eabi- -SDK_DIR = lib/nxp/mcux-sdk +SDK_DIR = lib/mcu/nxp/mcux-sdk MCU_DIR = $(SDK_DIR)/devices/$(MCU) # Port Compiler Flags diff --git a/ports/lpc55/port.mk b/ports/lpc55/port.mk index 37c1faabc..523136eee 100644 --- a/ports/lpc55/port.mk +++ b/ports/lpc55/port.mk @@ -1,7 +1,7 @@ UF2_FAMILY_ID = 0x2abc77ec CROSS_COMPILE = arm-none-eabi- -SDK_DIR = lib/nxp/mcux-sdk +SDK_DIR = lib/mcu/nxp/mcux-sdk MCU_DIR = $(SDK_DIR)/devices/$(MCU) CMSIS_5 = lib/CMSIS_5 diff --git a/ports/mimxrt10xx/family.cmake b/ports/mimxrt10xx/family.cmake index 7248e9ebe..1bbaf0eec 100644 --- a/ports/mimxrt10xx/family.cmake +++ b/ports/mimxrt10xx/family.cmake @@ -4,7 +4,7 @@ include_guard() # Config #------------------------------------ set(UF2_FAMILY_ID 0x4fb2d5bd) -set(SDK_DIR ${TOP}/lib/nxp/mcux-sdk) +set(SDK_DIR ${TOP}/lib/mcu/nxp/mcux-sdk) set(CMSIS_DIR ${TOP}/lib/CMSIS_5) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) diff --git a/ports/mimxrt10xx/port.mk b/ports/mimxrt10xx/port.mk index b50341879..b5aa05c02 100644 --- a/ports/mimxrt10xx/port.mk +++ b/ports/mimxrt10xx/port.mk @@ -1,7 +1,7 @@ UF2_FAMILY_ID = 0x4fb2d5bd CROSS_COMPILE = arm-none-eabi- -SDK_DIR = lib/nxp/mcux-sdk +SDK_DIR = lib/mcu/nxp/mcux-sdk MCU_DIR = $(SDK_DIR)/devices/$(MCU) CMSIS_5 = lib/CMSIS_5 diff --git a/ports/stm32f3/family.cmake b/ports/stm32f3/family.cmake index 2a6105f83..7a5820956 100644 --- a/ports/stm32f3/family.cmake +++ b/ports/stm32f3/family.cmake @@ -5,8 +5,8 @@ include_guard() #------------------------------------ set(UF2_FAMILY_ID 0x6b846188) -set(ST_HAL_DRIVER ${TOP}/lib/st/stm32f3xx_hal_driver) -set(ST_CMSIS ${TOP}/lib/st/cmsis_device_f3) +set(ST_HAL_DRIVER ${TOP}/lib/mcu/st/stm32f3xx_hal_driver) +set(ST_CMSIS ${TOP}/lib/mcu/st/cmsis_device_f3) set(CMSIS_5 ${TOP}/lib/CMSIS_5) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) diff --git a/ports/stm32f3/port.mk b/ports/stm32f3/port.mk index 35a88d1df..d8da67d94 100644 --- a/ports/stm32f3/port.mk +++ b/ports/stm32f3/port.mk @@ -1,8 +1,8 @@ UF2_FAMILY_ID = 0x6b846188 CROSS_COMPILE = arm-none-eabi- -ST_HAL_DRIVER = lib/st/stm32f3xx_hal_driver -ST_CMSIS = lib/st/cmsis_device_f3 +ST_HAL_DRIVER = lib/mcu/st/stm32f3xx_hal_driver +ST_CMSIS = lib/mcu/st/cmsis_device_f3 CMSIS_5 = lib/CMSIS_5 # Port Compiler Flags diff --git a/ports/stm32f4/family.cmake b/ports/stm32f4/family.cmake index 74de107ba..2caaedd10 100644 --- a/ports/stm32f4/family.cmake +++ b/ports/stm32f4/family.cmake @@ -5,8 +5,8 @@ include_guard() #------------------------------------ set(UF2_FAMILY_ID 0x57755a57) -set(ST_HAL_DRIVER ${TOP}/lib/st/stm32f4xx_hal_driver) -set(ST_CMSIS ${TOP}/lib/st/cmsis_device_f4) +set(ST_HAL_DRIVER ${TOP}/lib/mcu/st/stm32f4xx_hal_driver) +set(ST_CMSIS ${TOP}/lib/mcu/st/cmsis_device_f4) set(CMSIS_5 ${TOP}/lib/CMSIS_5) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) diff --git a/ports/stm32f4/port.mk b/ports/stm32f4/port.mk index 4710f2c90..32479417f 100644 --- a/ports/stm32f4/port.mk +++ b/ports/stm32f4/port.mk @@ -1,8 +1,8 @@ UF2_FAMILY_ID = 0x57755a57 CROSS_COMPILE = arm-none-eabi- -ST_HAL_DRIVER = lib/st/stm32f4xx_hal_driver -ST_CMSIS = lib/st/cmsis_device_f4 +ST_HAL_DRIVER = lib/mcu/st/stm32f4xx_hal_driver +ST_CMSIS = lib/mcu/st/cmsis_device_f4 CMSIS_5 = lib/CMSIS_5 # Port Compiler Flags diff --git a/ports/stm32h7/port.mk b/ports/stm32h7/port.mk index bd0f4fa22..6e1d1b843 100644 --- a/ports/stm32h7/port.mk +++ b/ports/stm32h7/port.mk @@ -3,8 +3,8 @@ include $(TOP)/$(PORT_DIR)/boards/$(BOARD)/board.mk UF2_FAMILY_ID = 0x6db66082 CROSS_COMPILE = arm-none-eabi- -ST_HAL_DRIVER = lib/st/stm32h7xx_hal_driver -ST_CMSIS = lib/st/cmsis_device_h7 +ST_HAL_DRIVER = lib/mcu/st/stm32h7xx_hal_driver +ST_CMSIS = lib/mcu/st/cmsis_device_h7 CMSIS_5 = lib/CMSIS_5 # Compiler flags diff --git a/ports/stm32l4/port.mk b/ports/stm32l4/port.mk index 464fbec29..b88655b33 100644 --- a/ports/stm32l4/port.mk +++ b/ports/stm32l4/port.mk @@ -1,8 +1,8 @@ UF2_FAMILY_ID = 0x00ff6919 CROSS_COMPILE = arm-none-eabi- -ST_HAL_DRIVER = lib/st/stm32l4xx_hal_driver -ST_CMSIS = lib/st/cmsis_device_l4 +ST_HAL_DRIVER = lib/mcu/st/stm32l4xx_hal_driver +ST_CMSIS = lib/mcu/st/cmsis_device_l4 CMSIS_5 = lib/CMSIS_5 # Port Compiler Flags diff --git a/tools/get_deps.py b/tools/get_deps.py index 282f86feb..61def2228 100644 --- a/tools/get_deps.py +++ b/tools/get_deps.py @@ -11,34 +11,34 @@ # Optional Dependencies per MCU # path, url, commit, family (Alphabet sorted by path) deps_optional = { - 'lib/nxp/mcux-sdk': ['https://github.com/hathach/mcux-sdk.git', - '9990f264f98430f6d885041ab0f24224d68f4958', - 'kinetis_k kinetis_k32l2 kinetis_kl lpc51 lpc54 lpc55 mcx mimxrt10xx'], - 'lib/st/cmsis_device_f3': ['https://github.com/STMicroelectronics/cmsis_device_f3.git', - '5e4ee5ed7a7b6c85176bb70a9fd3c72d6eb99f1b', - 'stm32f3'], - 'lib/st/cmsis_device_f4': ['https://github.com/STMicroelectronics/cmsis_device_f4.git', - '2615e866fa48fe1ff1af9e31c348813f2b19e7ec', - 'stm32f4'], - 'lib/st/cmsis_device_h7': ['https://github.com/STMicroelectronics/cmsis_device_h7.git', - '60dc2c913203dc8629dc233d4384dcc41c91e77f', - 'stm32h7'], - 'lib/st/cmsis_device_l4': ['https://github.com/STMicroelectronics/cmsis_device_l4.git', - '6ca7312fa6a5a460b5a5a63d66da527fdd8359a6', - 'stm32l4'], - 'lib/st/stm32f3xx_hal_driver': ['https://github.com/STMicroelectronics/stm32f3xx_hal_driver.git', - '1761b6207318ede021706e75aae78f452d72b6fa', - 'stm32f3'], - 'lib/st/stm32f4xx_hal_driver': ['https://github.com/STMicroelectronics/stm32f4xx_hal_driver.git', - '04e99fbdabd00ab8f370f377c66b0a4570365b58', - 'stm32f4'], - 'lib/st/stm32h7xx_hal_driver': ['https://github.com/STMicroelectronics/stm32h7xx_hal_driver.git', - 'd8461b980b59b1625207d8c4f2ce0a9c2a7a3b04', - 'stm32h7'], - 'lib/st/stm32l4xx_hal_driver': ['https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git', - 'aee3d5bf283ae5df87532b781bdd01b7caf256fc', - 'stm32l4'], - # 'lib/wch/ch32v20x': ['https://github.com/openwch/ch32v20x.git', + 'lib/mcu/nxp/mcux-sdk': ['https://github.com/nxp-mcuxpresso/mcux-sdk.git', + '0906a567e26a1b41fcdf1a217825e126872bda32', + 'kinetis_k kinetis_k32l2 kinetis_kl lpc51 lpc54 lpc55 mcx mimxrt10xx'], + 'lib/mcu/st/cmsis_device_f3': ['https://github.com/STMicroelectronics/cmsis_device_f3.git', + '5e4ee5ed7a7b6c85176bb70a9fd3c72d6eb99f1b', + 'stm32f3'], + 'lib/mcu/st/cmsis_device_f4': ['https://github.com/STMicroelectronics/cmsis_device_f4.git', + '2615e866fa48fe1ff1af9e31c348813f2b19e7ec', + 'stm32f4'], + 'lib/mcu/st/cmsis_device_h7': ['https://github.com/STMicroelectronics/cmsis_device_h7.git', + '60dc2c913203dc8629dc233d4384dcc41c91e77f', + 'stm32h7'], + 'lib/mcu/st/cmsis_device_l4': ['https://github.com/STMicroelectronics/cmsis_device_l4.git', + '6ca7312fa6a5a460b5a5a63d66da527fdd8359a6', + 'stm32l4'], + 'lib/mcu/st/stm32f3xx_hal_driver': ['https://github.com/STMicroelectronics/stm32f3xx_hal_driver.git', + '1761b6207318ede021706e75aae78f452d72b6fa', + 'stm32f3'], + 'lib/mcu/st/stm32f4xx_hal_driver': ['https://github.com/STMicroelectronics/stm32f4xx_hal_driver.git', + '04e99fbdabd00ab8f370f377c66b0a4570365b58', + 'stm32f4'], + 'lib/mcu/st/stm32h7xx_hal_driver': ['https://github.com/STMicroelectronics/stm32h7xx_hal_driver.git', + 'd8461b980b59b1625207d8c4f2ce0a9c2a7a3b04', + 'stm32h7'], + 'lib/mcu/st/stm32l4xx_hal_driver': ['https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git', + 'aee3d5bf283ae5df87532b781bdd01b7caf256fc', + 'stm32l4'], + # 'lib/mcu/wch/ch32v20x': ['https://github.com/openwch/ch32v20x.git', # 'c4c38f507e258a4e69b059ccc2dc27dde33cea1b', # 'ch32v20x'], 'lib/sct_neopixel': ['https://github.com/gsteiert/sct_neopixel.git', @@ -79,11 +79,13 @@ def get_a_dep(d): p.mkdir(parents=True) run_cmd(f"{git_cmd} init") run_cmd(f"{git_cmd} remote add origin {url}") + head = None + else: + # Check if commit is already fetched + result = run_cmd(f"{git_cmd} rev-parse HEAD") + head = result.stdout.decode("utf-8").splitlines()[0] + run_cmd(f"{git_cmd} reset --hard") - # Check if commit is already fetched - result = run_cmd(f"{git_cmd} rev-parse HEAD") - head = result.stdout.decode("utf-8").splitlines()[0] - run_cmd(f"{git_cmd} reset --hard") if commit != head: run_cmd(f"{git_cmd} fetch --depth 1 origin {commit}") run_cmd(f"{git_cmd} checkout FETCH_HEAD") @@ -130,8 +132,15 @@ def main(): if d not in deps and f in deps_optional[d][2]: deps.append(d) - with Pool() as pool: - status = sum(pool.map(get_a_dep, deps)) + if print_only: + pvalue = {} + for d in deps: + commit = deps_all[d][1] + pvalue[d] = commit + print(pvalue) + else: + with Pool() as pool: + status = sum(pool.map(get_a_dep, deps)) return status From c28baa78d4df4f6732a15b2c324b31d835f51f87 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 30 May 2024 11:32:22 +0700 Subject: [PATCH 10/11] selftest has issue with upload v4 revert mcux to previously good commit --- .github/workflows/build_selftest.yml | 2 +- tools/get_deps.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_selftest.yml b/.github/workflows/build_selftest.yml index 277283af8..ca5e14d94 100644 --- a/.github/workflows/build_selftest.yml +++ b/.github/workflows/build_selftest.yml @@ -73,7 +73,7 @@ jobs: - name: Save newly generated self-test images as CI artifacts if: always() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v3 with: name: ghostfat_selftest_images path: ./ports/test_ghostfat/_build/${{ matrix.board }}/ghostfat_${{ matrix.board }}.img.gz.gz diff --git a/tools/get_deps.py b/tools/get_deps.py index 61def2228..bbb14b986 100644 --- a/tools/get_deps.py +++ b/tools/get_deps.py @@ -12,7 +12,7 @@ # path, url, commit, family (Alphabet sorted by path) deps_optional = { 'lib/mcu/nxp/mcux-sdk': ['https://github.com/nxp-mcuxpresso/mcux-sdk.git', - '0906a567e26a1b41fcdf1a217825e126872bda32', + '9990f264f98430f6d885041ab0f24224d68f4958', 'kinetis_k kinetis_k32l2 kinetis_kl lpc51 lpc54 lpc55 mcx mimxrt10xx'], 'lib/mcu/st/cmsis_device_f3': ['https://github.com/STMicroelectronics/cmsis_device_f3.git', '5e4ee5ed7a7b6c85176bb70a9fd3c72d6eb99f1b', From bffea8097bf601c590fadceb063dd4317d87ab42 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 30 May 2024 11:45:25 +0700 Subject: [PATCH 11/11] update readme, also update get-deps target for backward-compatible --- README.md | 5 +++-- ports/rules.mk | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f4f919f34..b4d748754 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,11 @@ To build this for a specific board, we need to change current directory to its p $ cd ports/stm32f4 ``` -Firstly we need to get all of submodule dependency for our board e.g mcu driver with `get-deps` target. You only need to do this once for each mcu family +Firstly we need to get all submodule dependency for our board using `tools/get_deps.py` script with either family input or using --board option. You only need to do this once for each family ``` -make BOARD=feather_stm32f405_express get-deps +python tools/get_deps.py stm32f4 +python tools/get_deps.py --board feather_stm32f405_express ``` Then compile with `all` target: diff --git a/ports/rules.mk b/ports/rules.mk index df8fc32c2..b974e241a 100644 --- a/ports/rules.mk +++ b/ports/rules.mk @@ -64,13 +64,10 @@ clean: $(RM) -rf $(BUILD) $(RM) -rf $(BIN) -# get depenecies +# get dependencies .PHONY: get-deps get-deps: - ifdef GIT_SUBMODULES - git -C $(TOP) submodule update --init $(addprefix lib/,$(GIT_SUBMODULES)) - endif - + $(PYTHON3) $(TOP)/tools/get_deps.py --board $(BOARD) #-------------- Artifacts -------------- SELF_UF2 ?= apps/self_update/$(BUILD)/update-$(OUTNAME).uf2