Skip to content

Commit

Permalink
Spring 2024 Dev Launchpad (#220)
Browse files Browse the repository at this point in the history
* initial platformio devenv

* oops
  • Loading branch information
jr1221 authored Jan 4, 2025
1 parent a799851 commit f1fb165
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 147 deletions.
39 changes: 14 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
# Embedded-Base
Embedded-Base is a collection of drivers & middleware designed for use across various systems.
Embedded-Base is a collection of drivers, middlewares, and communication definitions designed for use across various systems.

This repository houses custom drivers and middleware that can be utilized in multiple projects.
Most firmware projects define Embedded-Base as a submodule.

To use this repository in any project, it should be set up as a submodule.
## Getting Started With NER Firmware

## Getting Started
All you need is on confluence [here](https://nerdocs.atlassian.net/wiki/spaces/NER/pages/1343533/Firmware+Onboarding+Embedded+Software#Development-Environment-Setup).

#### 1. Clone Embbeded-Base:
~~~
git clone https://github.com/Northeastern-Electric-Racing/Embedded-Base.git
~~~
### Notable items in this repository

#### 2. Initialize submodule
Within the application directory, run the following command to initialize the submodule:
~~~
git submodule update --init
~~~

## Development Guidelines

When developing in the parent directory, it's recommended to frequently run the following command to update all submodules in case changes have been made:
~~~
git submodule update --remote
~~~


**When making changes to a driver located within Embedded-Base, always make those changes directly within the Embedded-Base repository. Avoid making changes to a submodule from the parent directory.** Although it's technically possible, doing so can lead to disorganization, which we want to avoid.

This approach ensures that changes to Embedded-Base are tracked properly and can be easily integrated into your projects using it as a submodule.
- `cangen`: All JSON definitions of in-car CAN data as well as documentation and parsing utilities.
- `dev`: The manual version of the NER build system, compatible up circuit boards in competition 22A
- `ner_environment`: The NER developer environment compatible with all boards from 22A onwards and cross platform support.
- `general`: Cross-platform C source files for all peripheral drivers used by NER.
- `middleware`: Cross-platform C source files common utilities used across various platforms.
- `platforms`: C source files specific to STM HAL versions.
- `clang-format`: The organization wide clang-format definition.
- `ftdi_flash.cfg`: An openocd script to assist in FTDI flashing.
- `openocd.cfg`: A openocd stub to load GDB onto a target.


115 changes: 0 additions & 115 deletions launchpad.py

This file was deleted.

77 changes: 74 additions & 3 deletions ner_environment/build_system/build_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#
# To see a list of available commands and additional configuration options, run `ner --help`
# ==============================================================================
import shutil
import typer
from rich import print
import platform
Expand All @@ -31,9 +32,12 @@
# ==============================================================================

app = typer.Typer(help="Northeastern Electric Racing Firmware Build System",
epilog="For more information, visit https://nerdocs.atlassian.net/wiki/spaces/NER/pages/611516420/NER+Build+System",
epilog="For more information, visit https://nerdocs.atlassian.net/wiki/spaces/NER/pages/524451844/2024+Firmware+Onboarding+Master",
add_completion=False)

lp_app = typer.Typer(help="Install configure, and run launchpad environment items")
app.add_typer(lp_app, name="lp")

def unsupported_option_cb(value:bool):
if value:
print("[bold red] WARNING: the selected option is not currently implemented. This is either because is is an planned or deprecated feature")
Expand All @@ -59,7 +63,7 @@ def build(profile: str = typer.Option(None, "--profile", "-p", callback=unsuppor

@app.command(help="Configure autoformatter settings")
def clang(disable: bool = typer.Option(False, "--disable","-d", help="Disable clang-format"),
enablrune: bool = typer.Option(False, "--enable", "-e", help="Enable clang-format"),
enable: bool = typer.Option(False, "--enable", "-e", help="Enable clang-format"),
run: bool = typer.Option(False, "--run", "-r", help="Run clang-format")):

if disable:
Expand Down Expand Up @@ -239,7 +243,74 @@ def usbip(connect: bool = typer.Option(False, "--connect", help="Connect to a US

elif disconnect:
disconnect_usbip()


# ==============================================================================
# ---- Launchpad Section
# ==============================================================================


# ==============================================================================
# init
# ==============================================================================
@lp_app.command(help="Initialize launchpad, run before any commands")
def install():
"""Install PlatformIO package."""
try:
# Install the platformio package
subprocess.check_call(['pip', 'install', 'platformio'])

except subprocess.CalledProcessError as e:
print(f"Failed to install PlatformIO: {e}", file=sys.stderr)
sys.exit(1)

# ==============================================================================
# uninstall
# ==============================================================================
@lp_app.command(help="Remove launchpad")
def uninstall():
"""Uninstall PlatformIO package."""
try:
# Install the platformio package
subprocess.check_call(['pip', 'uninstall', '-y', 'platformio'])

platformio_dir = os.path.expanduser('~/.platformio')
if os.path.isdir(platformio_dir):
shutil.rmtree(platformio_dir)
print("PlatformIO directory removed.")
else:
print("PlatformIO directory does not exist.")

except subprocess.CalledProcessError as e:
print(f"Failed to uninstall PlatformIO: {e}", file=sys.stderr)
sys.exit(1)

# ==============================================================================
# build
# ==============================================================================
@lp_app.command(help="Build your launchpad project")
def build():
subprocess.run(['platformio', 'run'])

# ==============================================================================
# flash
# ==============================================================================
@lp_app.command(help="Flash your launchpad project to a board")
def flash():
subprocess.run(['platformio', 'run', '--target', 'upload'])

# ==============================================================================
# serial
# ==============================================================================
@lp_app.command(help="View serial output from the device")
def serial():
subprocess.run(['platformio', 'device', 'monitor'])


# ==============================================================================
# ---- End Launchpad Section
# ==============================================================================


# ==============================================================================
# Helper functions - not direct commands
# ==============================================================================
Expand Down
21 changes: 17 additions & 4 deletions ner_environment/ner_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ def install_precommit(venv_python):
print(f"Failed to install pre-commit: {e}", file=sys.stderr)
sys.exit(1)

def install_launchpad(venv_python):
print("Installing launchpad (platformio)...")
try:
run_command([venv_python, '-m', 'pip', 'install', 'platformio'])
except Exception as e:
print(f"Failed to install platformio: {e}", file=sys.stderr)
sys.exit(1)

def install_openocd():
os_type = platform.system()
try:
Expand Down Expand Up @@ -142,21 +150,26 @@ def main():

answer = input("Would you like to install all python packages in the venv? (yes/no)")
if 'y' in answer:
# Use the venv's Python
# Use the venv's Python
venv_python = os.path.join(venv_path, 'bin', 'python')

# Step 4: run setup.py (installs requirements and entry points)
run_setup(venv_python)

# Step 5: Run pre-commit install
install_precommit(venv_python)
# disabled bc buggy as all hell
#install_precommit(venv_python)
answer = input("Would you like to install launchpad? (yes/no)")
if 'y' in answer:
# Step 5: Install launchpad
install_launchpad(venv_python)

answer = input("Would you like to install openOCD? (do this manually if on a weird linux distro!) (yes/no)")
if 'y' in answer:
# Step 5: Install probe-rs
# Step 6: Install openocd
install_openocd()

# Step 6: Install usbip if on Linux
# Step 7: Install usbip if on Linux
if os_type == "Linux" and is_wsl() == 0:
answer = input("Would you like to install usbip? (yes/no)")
if 'y' in answer:
Expand Down

0 comments on commit f1fb165

Please sign in to comment.