From f91ca8c77c4895426215ae70e4e7a0305eb630f7 Mon Sep 17 00:00:00 2001 From: Licardo Date: Wed, 7 May 2025 16:53:38 +0800 Subject: [PATCH] add-new-hardware-licardo_ht --- .github/workflows/build-firmware.yml | 5 + firmware/src/CMakeLists.txt | 6 +- firmware/src/build_all.cmd | 3 + firmware/src/build_all.sh | 2 + firmware/src/headtracker.code-workspace | 35 ++++ firmware/src/src/boards/licardo_ht.h | 84 ++++++++++ firmware/src/src/include/defines.h | 4 + .../boards/arm/licardo_ht/CMakeLists.txt | 2 + .../boards/arm/licardo_ht/Kconfig.defconfig | 12 ++ .../boards/arm/licardo_ht/Kconfig.licardo_ht | 6 + .../zephyr/boards/arm/licardo_ht/board.cmake | 11 ++ .../zephyr/boards/arm/licardo_ht/board.yml | 6 + .../boards/arm/licardo_ht/doc/index.rst | 10 ++ .../boards/arm/licardo_ht/licardo_ht.dts | 149 ++++++++++++++++++ .../boards/arm/licardo_ht/licardo_ht.yaml | 20 +++ .../arm/licardo_ht/licardo_ht_defconfig | 18 +++ .../boards/arm/licardo_ht/pre_dt_board.cmake | 7 + 17 files changed, 378 insertions(+), 2 deletions(-) create mode 100644 firmware/src/src/boards/licardo_ht.h create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/CMakeLists.txt create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/Kconfig.defconfig create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/Kconfig.licardo_ht create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/board.cmake create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/board.yml create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/doc/index.rst create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht.dts create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht.yaml create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht_defconfig create mode 100644 firmware/src/zephyr/boards/arm/licardo_ht/pre_dt_board.cmake diff --git a/.github/workflows/build-firmware.yml b/.github/workflows/build-firmware.yml index 9168e657..5fe21b6c 100644 --- a/.github/workflows/build-firmware.yml +++ b/.github/workflows/build-firmware.yml @@ -85,6 +85,11 @@ jobs: cd /src/firmware/src west build -p -b dtqsys_ht cp ./build/zephyr/*.bin build_bins/ + - name: Build Firmware Licardo Ht + run: | + cd /src/firmware/src + west build -p -b licardo_ht + cp ./build/zephyr/*.bin build_bins/ # - name: Setup tmate session # uses: mxschmitt/action-tmate@v3 diff --git a/firmware/src/CMakeLists.txt b/firmware/src/CMakeLists.txt index 005aee43..a5c55039 100644 --- a/firmware/src/CMakeLists.txt +++ b/firmware/src/CMakeLists.txt @@ -35,7 +35,8 @@ set (BOARD_HW_REV "") if((${BOARD} STREQUAL "arduino_nano_33_ble") OR (${BOARD} STREQUAL "xiao_ble/nrf52840/sense") OR (${BOARD} STREQUAL "xiao_ble/nrf52840") OR - (${BOARD} STREQUAL "dtqsys_ht")) + (${BOARD} STREQUAL "dtqsys_ht") OR + (${BOARD} STREQUAL "licardo_ht")) message(STATUS " Board is a NRF52 based board") # Pick the correct project file for this architecture @@ -52,7 +53,8 @@ if((${BOARD} STREQUAL "arduino_nano_33_ble") OR endif() #DTQ Board, use local board file from /zephyr/boards - if((${BOARD} STREQUAL "dtqsys_ht")) + if((${BOARD} STREQUAL "dtqsys_ht") OR + (${BOARD} STREQUAL "licardo_ht")) set (BOARD_ROOT "${CMAKE_SOURCE_DIR}/zephyr") endif() diff --git a/firmware/src/build_all.cmd b/firmware/src/build_all.cmd index 97fd4224..67ef0b8b 100644 --- a/firmware/src/build_all.cmd +++ b/firmware/src/build_all.cmd @@ -22,4 +22,7 @@ west build -p -b rpi_pico/rp2040/w || exit /b copy .\build\zephyr\rpi*.uf2 build_bins\ west build -p -b dtqsys_ht || exit /b +copy .\build\zephyr\*.bin build_bins\ + +west build -p -b licardo_ht || exit /b copy .\build\zephyr\*.bin build_bins\ \ No newline at end of file diff --git a/firmware/src/build_all.sh b/firmware/src/build_all.sh index cbc9dab3..f8c58a61 100644 --- a/firmware/src/build_all.sh +++ b/firmware/src/build_all.sh @@ -15,4 +15,6 @@ cp ./build/zephyr/*.bin build_bins/ && west build -p -b rpi_pico/rp2040/w && cp ./build/zephyr/*.uf2 build_bins/ && west build -p -b dtqsys_ht && +cp ./build/zephyr/*.bin build_bins/ && +west build -p -b licardo_ht && cp ./build/zephyr/*.bin build_bins/ \ No newline at end of file diff --git a/firmware/src/headtracker.code-workspace b/firmware/src/headtracker.code-workspace index 441ef655..2ddc4a41 100644 --- a/firmware/src/headtracker.code-workspace +++ b/firmware/src/headtracker.code-workspace @@ -138,6 +138,23 @@ "preLaunchTask": "Build (DTQSYS HT) - Debug", "svdFile": "${workspaceRoot:src}/nrf52840.svd", }, + { + "name": "Jlink - Licardo HT", + "device": "nRF52840_XXAA", + "cwd": "${workspaceRoot:src}", + "executable": "build/zephyr/zephyr.elf", + "request": "launch", + "type": "cortex-debug", + "runToEntryPoint": "main", + "servertype": "jlink", + "rtos": "Zephyr", + //"showDevDebugOutput":"raw", + "serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL.exe", // Check path to Jlink installation + "armToolchainPath": "${workspaceRoot:src}/../zephyr-sdk/arm-zephyr-eabi/bin", // NOTE Check version & path of SDK here + "toolchainPrefix": "arm-zephyr-eabi", + "preLaunchTask": "Build (Licardo HT) - Debug", + "svdFile": "${workspaceRoot:src}/nrf52840.svd", + }, { "name": "OpenOCD - ESP32C3_DevKitM (RISC-V)", "type": "cppdbg", @@ -271,6 +288,24 @@ "reveal": "always" }, "group": "build" + }, + { + "label": "Build (LICARDO HT) - Debug", + "type": "shell", + "command": "west", + "args": [ + "build", + "-p", "auto", + "-b", "licardo_ht", + "--", "-DCMAKE_BUILD_TYPE=Debug" + ], + "problemMatcher": [ + "$tsc" + ], + "presentation": { + "reveal": "always" + }, + "group": "build" } ] } diff --git a/firmware/src/src/boards/licardo_ht.h b/firmware/src/src/boards/licardo_ht.h new file mode 100644 index 00000000..7a9aa07e --- /dev/null +++ b/firmware/src/src/boards/licardo_ht.h @@ -0,0 +1,84 @@ +#pragma once + +#include + +#include "boardsdefs.h" + +// Pull up pin mode +#define INPUT_PULLUP (GPIO_INPUT | GPIO_PULL_UP) + +// Board features +#define HAS_WS2812 +#define HAS_BUZZER +#define HAS_NOTIFYLED +#define HAS_MPU6500 +#define HAS_QMC5883 +#define HAS_AUXSERIAL +#define HAS_CENTERBTN +#define HAS_PPMOUT +#define HAS_PPMIN +#define HAS_3CH_ANALOG +#define HAS_VOLTMON + +#define AN0 5 // Pin 0.29 +#define AN1 0 // Pin 0.02 +#define AN2 4 // Pin 0.28 +#define ANVOLTMON 1 // Battery Voltage +#define ANVOLTMON_SCALE 2.0f +#define ANVOLTMON_OFFSET 0.0f + +/* Pins (name, number, description) + NOTE: These pins are an enum entry. e.g. IO_CENTER_BTN = 0 + - Use PIN_NAME_TO_NUM(IO_D2) to get actual the pin number + - The pin number can be converted back into the NRF port/pin + using functions PIN_TO_GPORT & PIN_TO_GPIN + - The string descrition for CENTER_BTN would be StrPinDescriptions[IO_CENTER_BTN] + - The string of the pin name would be StrPins[CENTER_BTN] + + Change the pins to whatever you wish here. Some pins might be defined in the + board's devicetree overlay file (e.g. UART). You will have to change them there + & should make sure they match here so the GUI can show the correct pinout. + + Leave descriptions empty for pins if you don't want it to + show up in the pinout on the GUI + */ + +#define PIN_X \ + PIN(CENTER_BTN, NRFPIN(1, 13), "") \ + PIN(VOLTMON, NRFPIN(0, 3), "") \ + PIN(AN0, NRFPIN(0, 29), "Analog 0 (AIN_5)") \ + PIN(AN1, NRFPIN(0, 2), "Analog 1 (AIN_0)") \ + PIN(AN2, NRFPIN(0, 28), "Analog 2 (AIN_4)") \ + PIN(LEDWS, NRFPIN(1, 10), "") \ + PIN(LED, NRFPIN(0, 13), "") \ + PIN(PPMOUT, NRFPIN(0, 31), "") \ + PIN(PPMIN, NRFPIN(0, 30), "") \ + PIN(BUZZ, NRFPIN(1, 11), "") \ + PIN(TX, NRFPIN(0, 9), "") \ + PIN(RX, NRFPIN(0, 10), "") \ + PIN(TXINV, NRFPIN(0, 4), "") \ + PIN(RXINVO, NRFPIN(0, 0), "") \ + PIN(RXINVI, NRFPIN(0, 1), "") \ + PIN(I2CSDA, NRFPIN(0, 5), "") \ + PIN(I2CSCL, NRFPIN(1, 9), "") + +typedef enum { +#define PIN(NAME, PINNO, DESC) IO_##NAME, + PIN_X +#undef PIN +} pins_e; + +const int8_t PinNumber[] = { +#define PIN(NAME, PINNO, DESC) PINNO, + PIN_X +#undef PIN +}; + +// Required pin setting functions +#define pinMode(pin, mode) gpio_pin_configure(gpios[PIN_TO_GPORT(PIN_NAME_TO_NUM(pin))], PIN_TO_GPIN(PIN_NAME_TO_NUM(pin)), mode) +#define digitalWrite(pin, value) gpio_pin_set(gpios[PIN_TO_GPORT(PIN_NAME_TO_NUM(pin))], PIN_TO_GPIN(PIN_NAME_TO_NUM(pin)), value) +#define digitalRead(pin) gpio_pin_get(gpios[PIN_TO_GPORT(PIN_NAME_TO_NUM(pin))], PIN_TO_GPIN(PIN_NAME_TO_NUM(pin))) + +// Values below were determined by plotting Gyro Output (See sense.cpp, gyroCalibration()) +#define GYRO_STABLE_DIFF 200.0f +#define ACC_STABLE_DIFF 3.5f diff --git a/firmware/src/src/include/defines.h b/firmware/src/src/include/defines.h index 4e1f487e..762333f2 100644 --- a/firmware/src/src/include/defines.h +++ b/firmware/src/src/include/defines.h @@ -24,6 +24,10 @@ #define FW_BOARD "DTQSYS" #include "boards/dtqsys_ht.h" #define ARDUINO_BOOTLOADER +#elif defined(CONFIG_BOARD_LICARDO_HT) +#define FW_BOARD "LICARDO" +#include "boards/licardo_ht.h" +#define ARDUINO_BOOTLOADER #elif defined(CONFIG_BOARD_XIAO_BLE) #include "boards/xiaoble.h" #define SEEED_BOOTLOADER diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/CMakeLists.txt b/firmware/src/zephyr/boards/arm/licardo_ht/CMakeLists.txt new file mode 100644 index 00000000..9b12bd38 --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/CMakeLists.txt @@ -0,0 +1,2 @@ + +zephyr_library() diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/Kconfig.defconfig b/firmware/src/zephyr/boards/arm/licardo_ht/Kconfig.defconfig new file mode 100644 index 00000000..412bc83f --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/Kconfig.defconfig @@ -0,0 +1,12 @@ +# Copyright (c) 2020 Jefferson Lee. +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_LICARDO_HT + +config BT_CTLR + default BT + +config I2C + default y + +endif #board diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/Kconfig.licardo_ht b/firmware/src/zephyr/boards/arm/licardo_ht/Kconfig.licardo_ht new file mode 100644 index 00000000..5f63ca1a --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/Kconfig.licardo_ht @@ -0,0 +1,6 @@ +# Copyright (c) 2020 Jefferson Lee. +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_LICARDO_HT + select SOC_NRF52840_QIAA + diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/board.cmake b/firmware/src/zephyr/boards/arm/licardo_ht/board.cmake new file mode 100644 index 00000000..84673ec4 --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/board.cmake @@ -0,0 +1,11 @@ + +board_runner_args(pyocd "--target=nrf52840" "--frequency=4000000") +board_runner_args(trace32 + "--startup-args" + "elfFile=${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME}" +) + +include(${ZEPHYR_BASE}/boards/common/bossac.board.cmake) +include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/blackmagicprobe.board.cmake) +include(${ZEPHYR_BASE}/boards/common/trace32.board.cmake) diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/board.yml b/firmware/src/zephyr/boards/arm/licardo_ht/board.yml new file mode 100644 index 00000000..e5545769 --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/board.yml @@ -0,0 +1,6 @@ +board: + name: licardo_ht + vendor: licardo + socs: + - name: nrf52840 + diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/doc/index.rst b/firmware/src/zephyr/boards/arm/licardo_ht/doc/index.rst new file mode 100644 index 00000000..1053bfb4 --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/doc/index.rst @@ -0,0 +1,10 @@ +DTQ Sys HT +################################# + +Overview +******** + +This is a custom board built for use as a Headtracker, based on the NRF52840 cpu + +Visit Headtracker.gitbook.io + diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht.dts b/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht.dts new file mode 100644 index 00000000..793a2c0d --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht.dts @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2020 Jefferson Lee + * Modified for LICARDO board by Licardo + * + * SPDX-License-Identifier: Apache-2.0 + */ +/dts-v1/; + +#include +#include + +/ { + model = "LICARDO Head Tracker"; + compatible = "licardo_ht"; + + chosen { + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,code-partition = &code_partition; + zephyr,ieee802154 = &ieee802154; + }; + + aliases { + adcctrl = &adc; + i2csensor = &i2c1; + guiuart = &cdc_acm_uart0; + }; +}; + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + code_partition: partition@10000 { + label = "code"; + reg = <0x10000 0xEC000>; + read-only; + }; + + storage_partition: partition@FB000 { + label = "storagept"; + reg = <0xFB000 0x3000>; + }; + + ht_data_partition: partition@FD000 { + label = "htdatapt"; + reg = <0xFE000 0x2000>; + }; + }; +}; + +&adc { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&gpio1 { + status = "okay"; +}; + +&gpiote { + status = "okay"; +}; + +&uart0 { + status = "disabled"; +}; + +&i2c0 { + status = "disabled"; +}; + +/* Disable Timer3, used by PPM output + */ +&timer3 { + status = "disabled"; +}; + +/* Disable Timer4, used by PPM input + */ +&timer4 { + status = "disabled"; +}; + +&pinctrl { + i2c1_dtq: i2c1_dtq { + group1 { + psels = , + ; + }; + }; + + spi2_dtq: spi2_dtq { + group1 { + psels = , + , + ; + }; + }; +}; + +// Sensor I2C +&i2c1 { + compatible = "nordic,nrf-twim"; + status = "okay"; + pinctrl-0 = <&i2c1_dtq>; + pinctrl-names = "default"; + clock-frequency = <400000>; +}; + +// RGB LED, SPI Interface +&spi2 { + compatible = "nordic,nrf-spim"; + status = "okay"; + pinctrl-0 = <&spi2_dtq>; + pinctrl-names = "default"; + led_strip: ws2812@0 { + compatible = "worldsemi,ws2812-spi"; + reg = <0>; + spi-max-frequency = <4000000>; + color-mapping = ; + chain-length = <1>; + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + }; +}; + +zephyr_udc0: &usbd { + compatible = "nordic,nrf-usbd"; + status = "okay"; + cdc_acm_uart0: cdc_acm_uart0 { + compatible = "zephyr,cdc-acm-uart"; + }; + + // Uncomment the below lines for kernel logging to a second USB CDC port + /* + cdc_acm_uart1: cdc_acm_uart1 { + compatible = "zephyr,cdc-acm-uart"; + }; */ +}; + +&ieee802154 { + status = "okay"; +}; diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht.yaml b/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht.yaml new file mode 100644 index 00000000..66b803fc --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht.yaml @@ -0,0 +1,20 @@ +identifier: licardo_ht +name: Licardo Head Tracker +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +supported: + - adc + - ble + - i2c + - pwm + - serial + - spi + - uart + - usb_cdc + - usb_device + - watchdog +vendor: licardo diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht_defconfig b/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht_defconfig new file mode 100644 index 00000000..0acfa794 --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/licardo_ht_defconfig @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Enable MPU +CONFIG_ARM_MPU=y +CONFIG_HW_STACK_PROTECTION=y + +# enable peripherals +CONFIG_GPIO=y +CONFIG_SERIAL=y + +CONFIG_BOOTLOADER_BOSSA=y +CONFIG_BOOTLOADER_BOSSA_LEGACY=y + +CONFIG_CLOCK_CONTROL_NRF=y +CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y + +CONFIG_LED_STRIP=y +CONFIG_SPI=y diff --git a/firmware/src/zephyr/boards/arm/licardo_ht/pre_dt_board.cmake b/firmware/src/zephyr/boards/arm/licardo_ht/pre_dt_board.cmake new file mode 100644 index 00000000..3369c21d --- /dev/null +++ b/firmware/src/zephyr/boards/arm/licardo_ht/pre_dt_board.cmake @@ -0,0 +1,7 @@ +# Copyright (c) 2022 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +# Suppress "unique_unit_address_if_enabled" to handle the following overlaps: +# - power@40000000 & clock@40000000 & bprot@40000000 +# - acl@4001e000 & flash-controller@4001e000 +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled")