Skip to content

Commit

Permalink
Merge pull request #165 from dlktdr/esp_support
Browse files Browse the repository at this point in the history
Re-works the build system to use Zephyr's West tool
  • Loading branch information
dlktdr authored Apr 7, 2024
2 parents 57ca7a1 + 76ae22e commit 8301e60
Show file tree
Hide file tree
Showing 142 changed files with 50,181 additions and 21,523 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,5 @@ Release/
!/gui/bin/bossac*
/gui/build*

#Zephyr
/firmware/src/build*
# Ignore Zephyr workspace
/firmware/zephyr*
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@
[submodule "firmware/src/src/LSM6DS3"]
path = firmware/src/src/LSM6DS3
url = https://github.com/STMicroelectronics/LSM6DS3TR-C-PID
[submodule "firmware/src/src/third-party/ArduinoJson"]
path = firmware/src/src/third-party/ArduinoJson
url = https://github.com/bblanchon/ArduinoJson.git
[submodule "firmware/src/third-party/ArduinoJson"]
path = firmware/src/third-party/ArduinoJson
url = https://github.com/bblanchon/ArduinoJson.git
[submodule "firmware/src/third-party/BMI270_SensorAPI"]
path = firmware/src/third-party/BMI270_SensorAPI
url = https://github.com/boschsensortec/BMI270_SensorAPI
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# syntax=docker/dockerfile:1
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND noninteractive

SHELL [ "/bin/bash", "-c" ]
ENV SHELL=/bin/bash

#Update repositories
RUN apt-get update

#Install build dependencies
RUN apt-get install -y git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1

#Install zephyr-sdk. Don't include all tools
RUN cd ~ && \
wget --progress=bar:force:noscroll https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.5-1/zephyr-sdk-0.16.5-1_linux-x86_64_minimal.tar.xz && \
tar xvf zephyr-sdk-0.16.5-1_linux-x86_64_minimal.tar.xz && \
rm zephyr-sdk-0.16.5-1_linux-x86_64_minimal.tar.xz && \
cd zephyr-sdk-0.16.5-1 && \
./setup.sh -t arm-zephyr-eabi -t xtensa-espressif_esp32_zephyr-elf -t riscv64-zephyr-elf -h && \
ln -s ~/zephyr-sdk-0.16.5-1/ ~/zephyr-sdk

#Install west
RUN pip3 install west

#Install zephyr
RUN west init ~/zephyr && \
cd ~/zephyr && \
west update && \
west -z ~/zephyr zephyr-export && \
pip3 install -r ~/zephyr/zephyr/scripts/requirements.txt && \
west blobs fetch hal_espressif

# Always use bash as the shell
RUN echo "dash dash/sh boolean false" | debconf-set-selections
RUN DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash
RUN ln -sf /bin/bash /bin/sh

# Set zephyr's Environment Variables
RUN echo source /root/zephyr/zephyr/zephyr-env.sh >> ~/.bashrc
12 changes: 12 additions & 0 deletions firmware/src/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "zephyr-dev",
"image": "docker.io/dlktdr/zephyr:latest",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"trond-snekvik.devicetree"
]
}
}
}
9 changes: 7 additions & 2 deletions firmware/src/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.pio
.vscode

.vscode/*.json
!.vscode/c_cpp_properties.json
.cortex-debug.*
*.log
build*
!build_all*
_deps*
26 changes: 26 additions & 0 deletions firmware/src/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"configurations": [
{
"name": "Zephyr",
"includePath": [
"src/**",
"src/include/**",
"third-party/BMI270_SensorAPI/**",
"../zephyr/**"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"path": [
"src/**",
"src/include/**",
"third-party/BMI270_SensorAPI/**",
"../zephyr/**"
]
},
"cStandard": "c99",
"cppStandard": "c++11",
"compilerPath": "../zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe"
}
],
"version": 4
}
125 changes: 125 additions & 0 deletions firmware/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
cmake_minimum_required(VERSION 3.20.0)

# Get the Git Revision and Most recent version tag
execute_process(
COMMAND git rev-parse --short HEAD
OUTPUT_VARIABLE GIT_REV
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(ret EQUAL "1")
no_git()
endif()
execute_process(
COMMAND git describe --tags --abbrev=0
OUTPUT_VARIABLE GIT_TAG_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(ret EQUAL "1")
no_git()
endif()
string(REPLACE "v" "" GIT_TAG "${GIT_TAG_RAW}")
function(no_git)
message( FATAL_ERROR "Unable to fetch the project GIT status, be sure GIT is installed and in your path")
endfunction()
message(STATUS "Git Revision ${GIT_REV}")
message(STATUS "Git Tag ${GIT_TAG}")

# Rebuild all the the settings for the project
message(STATUS "Building the settings files (buildsettings.py) from ../settings.csv")
execute_process(
COMMAND ../settings/python buildsettings.py
)

message(STATUS "Board=${BOARD}")

# NRF52 Boards
if((${BOARD} STREQUAL "arduino_nano_33_ble") OR
(${BOARD} STREQUAL "xiao_ble/nrf52840/sense") OR
(${BOARD} STREQUAL "dtqsys_ht"))
message(STATUS " Board is a NRF52 based board")

# Pick the correct project file for this architecture
set (CONF_FILE zephyr/nrf_prj.conf)

# The sense revision 2 uses the same board file as the original
# but a few different defines in the code.
if(DEFINED BOARD_REV_SR2)
message(STATUS " Board is a Revision 2 Nano 33 BLE Sense")
set (BOARD "arduino_nano_33_ble")
# SEE BELOW for defined passed to compiler
endif()

#DTQ Board, use local board file from /zephyr/boards
if((${BOARD} STREQUAL "dtqsys_ht"))
set (BOARD_ROOT "${CMAKE_SOURCE_DIR}/zephyr")
endif()

#ESP32C3 Boards
elseif(${BOARD} STREQUAL "esp32c3_devkitm")
message(STATUS " Board is a ESP32C3 based board")
set (CONF_FILE zephyr/esp32c3_prj.conf)

# M5Stick CPLUS1
elseif((${BOARD} STREQUAL "m5stickc_plus/esp32/procpu") OR
(${BOARD} STREQUAL "m5stickc_plus"))
message(STATUS " Board is a ESP32 PICO based board")
set(CONF_FILE zephyr/m5stickc_plus_prj.conf)

# Raspberry Pi Pico
elseif((${BOARD} STREQUAL "rpi_pico/rp2040/w") OR
(${BOARD} STREQUAL "rpi_pico"))
message(STATUS " Board is a Raspberry Pi 2040 Pico")
set(CONF_FILE zephyr/rpi_pico.conf)

else()
message(FATAL_ERROR "ERROR: Board is not supported")
endif()

# Set the output filename in release mode
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
if(NOT build_type STREQUAL "debug")
message(STATUS "Building in Release mode")
string(REPLACE "." "_" output_name "${BOARD}_${GIT_TAG}_${GIT_REV}")
string(REPLACE "/" "_" output_name "${output_name}")
if(DEFINED BOARD_REV_SR2)
set(output_name "${output_name}_SR2")
endif()
set(CONFIG_KERNEL_BIN_NAME "\"${output_name}\"" CACHE INTERNAL "")
message(STATUS "Output File Name=${output_name}")
# Set KConfig Option to disable some optimizations in debug mode
# do this here so it's easy in VScode with a task to set the build type
else()
message(STATUS "Building in Debug mode")
set(CONFIG_DEBUG_OPTIMIZATIONS "y" CACHE INTERNAL "")
set(NO_BUILD_TYPE_WARNING "y")
endif()



find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(HeadTracker DESCRIPTION "HeadTracker")

# Set optimization level to -O1 for debug builds -o0 casuses stack issues
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O1")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1")

# -DOPENOCD=/openocd-esp32/bin -DOPENOCD_DEFAULT_PATH=/openocd-esp32/share/openocd/scripts
if(${BOARD} MATCHES "esp32c3")
target_compile_definitions(app PUBLIC "OPENOCD=\"c:\\openocd-esp32\\bin\"")
target_compile_definitions(app PUBLIC "OPENOCD_DEFAULT_PATH=\"c:\\openocd-esp32\\share\\openocd\\scripts\"")
endif()

# Arduino Nano Sense Rev 2
if(DEFINED BOARD_REV_SR2)
target_compile_definitions(app PUBLIC BOARD_REV_SR2=1)
endif()

target_compile_definitions(app PUBLIC FW_GIT_REV=${GIT_REV})
target_compile_definitions(app PUBLIC FW_VER_TAG=${GIT_TAG})
target_include_directories(app PRIVATE src/include)
target_include_directories(app PRIVATE src)
target_include_directories(app PRIVATE third-party/ArduinoJson/src)
target_include_directories(app PRIVATE third-party/BMI270_SensorAPI)

FILE(GLOB_RECURSE app_sources src/*.c*)
set(app_sources ${app_sources} third-party/BMI270_SensorAPI/bmi2.c)
set(app_sources ${app_sources} third-party/BMI270_SensorAPI/bmi270.c)
target_sources(app PRIVATE ${app_sources})
Binary file removed firmware/src/Release Checklist.docx
Binary file not shown.
98 changes: 98 additions & 0 deletions firmware/src/arduino_nano_33_ble.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/ {
model = "Arduino Nano 33 BLE (Sense)";
compatible = "arduino,arduino_nano_33_ble";

chosen {
/delete-property/ zephyr,console;
/delete-property/ zephyr,shell-uart;
/delete-property/ zephyr,uart-mcumgr;
/delete-property/ zephyr,bt-mon-uart;
/delete-property/ zephyr,bt-c2h-uart;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,code-partition = &code_partition;

// Uncomment the below line for kernel logging to a second USB CDC port
// Also uncomment the extra cdc at the bottom of the file
// zephyr,console = &cdc_acm_uart1;
};

aliases {
adcctrl = &adc;
i2csensor = &i2c1;
guiuart = &cdc_acm_uart0;
};
};

/* Flash Layout
* Bootloader 0x00000 - 0x10000 (Size 0x10000 65536 Bytes)
* Code 0x10000 - 0xFC000 (Size 0xEC000 966656 Bytes)
* NVM Data 0xFC000 - 0x100000 (Size 0x4000 16384 Bytes)
*/

/delete-node/ &storage_partition;

&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@FC000 {
label = "storagept";
reg = <0xFC000 0x4000>;
};
};
};

&adc {
status = "okay";
};

&uart0 {
status = "disabled";
};

&i2c0 {
status = "disabled";
};

&i2c1 {
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
zephyr,flash-buf-max-size = <128>;
zephyr,concat-buf-size = <128>;
};

/* Disable Timer3, used by PPM output
*/
&timer3 {
status = "disabled";
};

/* Disable Timer4, used by PPM input
*/
&timer4 {
status = "disabled";
};

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";
}; */
};

53 changes: 0 additions & 53 deletions firmware/src/boards/arduino_nano_33_ble.json

This file was deleted.

Loading

0 comments on commit 8301e60

Please sign in to comment.