Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] make all teensy devices variants #753

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sndsgd
Copy link
Contributor

@sndsgd sndsgd commented Aug 30, 2024

🚨 Work in progress, BUT LOOKING FOR FEEDBACK!

I recently created a custom imxrt1062 pcb with teensy bootloader + sdram, and in the process of trying to get it working I ended up making lots of changes to the teensy4 cores. While I was able to get everything that I needed working, it was a pretty painful process, and I lost a lot of momentum on the software side. I'm not looking forward to revisiting the pain when the next beta comes out, so I pre-emptively jumped down the rabbit hole of exploring how teensy cores could be updated to make it trivial to get a custom variant working.

The steps I'd like to see are:

  1. define some properties about your custom pcb in a yaml file (example)
  2. run a script to generate a single header file that creates #defines using data from the reference manual.
  3. save the header file in your project named teensy4_custom_variant.h
  4. profit

To get this working seamlessly, the existing teensy4 "variants" should also have all the same information defined in a single header file per variant. The files included in ./teensy4/variants/ were generated using a script, and require a few tweaks before they could be used:

  • the pins to adc channel map in master has what I assume are some hacks to make it simple for people to use analogRead() on A0 by providing pin0. my script didn't include this behavior as I believe it's confusing.
  • the serial interface to uart order for the micromod doesn't follow the implicit ordering that exists on the T40 and T41. This could be updated by hand, or the script could be updated to allow for explicitly defining the serial interface order.

The safety of such a change should certainly be in question, but diffing post-preprocessed sources from master and this branch makes it pretty easy to see what has changed.

Also, please note that I purposefully did not rejigger some things that probably should be tweaked so as to keep the post preprocessor diff clean.

#!/usr/bin/env bash

readonly dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
readonly repodir="$HOME/git/github.com/paulstoffregen-cores"
readonly main_branch=master
readonly feature_branch=sndsgd-variants
readonly branches=("$main_branch" "$feature_branch")
readonly variants=(ARDUINO_TEENSY40 ARDUINO_TEENSY41 ARDUINO_TEENSY_MICROMOD)

readonly arduino_path="$HOME/.arduino15"
readonly teensy_arduino_path="$arduino_path/packages/teensy"
readonly c_compiler="$(find "$teensy_arduino_path" -name aarm-none-eabi-gcc)"
readonly cpp_compiler="$(find "$teensy_arduino_path" -name arm-none-eabi-g++)"

cd "$repodir" || echo "weird directory" && exit
diff_files="$(git diff --name-only master sndsgd-variants)"

outfile() {
  readonly branch="$1"
  readonly variant="$2"
  readonly relpath="$3"
  readonly path="$dir/diff/$branch/$variant/$relpath.out"
  mkdir -p "$(dirname "$path")"
  echo "$path"
}

for branch in "${branches[@]}"; do
  git checkout "$branch"
  for variant in "${variants[@]}"; do
    for file in $diff_files; do
      if [[ $file != teensy4/variants/* && $file != *.h ]]; then
        echo "$branch / $variant / $file..."
        output_path="$(outfile "$branch" "$variant" "$file")"
        mkdir -p "$(dirname "$output_path")"
        "$cpp_compiler" -E -D__IMXRT1062__=1 "-D$variant=1" -Iteensy4 -E "$file" \
        | clang-format --style="file:$dir/clang.fmt" \
        | grep -v '^#' \
        | awk 'NF' > "$output_path"
      fi
    done
  done
done

for variant in "${variants[@]}"; do
  for file in $diff_files; do
    if [[ $file != teensy4/variants/* && $file != *.h ]]; then
      old="$(outfile "$main_branch" "$variant" "$file")"
      new="$(outfile "$feature_branch" "$variant" "$file")"
      diff "$old" "$new" > "$(outfile diff "$variant" "$file")"
    fi
  done
done

I'm going to halt this effort here until I can get some feedback, and/or confirmation that something like this has the possibility to be merged. There is still a reasonable amount of work to complete this, and while I'd be happy to push this across the line and get it merged, I would rather not spend time on this if it doesn't have a chance.

Additional Reading


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant