MCPcopy Index your code
hub / github.com/SharpCoder/teensycore

github.com/SharpCoder/teensycore @v0.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.0 ↗ · + Follow
495 symbols 1,246 edges 42 files 153 documented · 31%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Teensycore

Teensycore is a kernel written in rust for the Teensy-4.0 microcontroller.

Installation

To properly build teensycore and any subsequent project, you'll need the following:

# Install build tools
sudo apt-get install build-essential gcc-arm-none-eabi jq

# Configure rust
rustup default nightly
rustup target add thumbv7em-none-eabihf

Usage

You must first configure your project as a library. Your Cargo.toml should look something like this:

[package]
name = "my_project"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["staticlib"]
path = "src/lib.rs"

[dependencies]
teensycore = "^0.1.0"

Teensycore exports a convenient macro that helps to configure the entrypoint of your application. It takes care of the default panic handler, initializing system clocks, setting up irq, enabling debug UART, and much more. In this way, you can just focus on what your project needs to get going. Replace your src/lib.rs with something like this:

#![feature(lang_items)]
#![crate_type = "staticlib"]
#![no_std]

use teensycore::prelude::*;

teensycore::main!({
    /* Application code here */
});

You are now ready to start writing some baremetal rust!

Building

In order for your project to build correctly, you'll need the following:

  • Configure your project as a library
  • Put your entrypoint code in src/lib.rs
  • Download the build template bash script
  • Execute build-template.sh in lieu of cargo build.

The build script will generate a .hex file and place it in a folder called out. This hex file is compatible with the teensy 4.0 and can be flashed with the teensy-loader utility.

CAUTION: Do not build this in release mode. It optimizes a lot of stuff away, and can cause problems.

Example

Here is a very basic blinky example. To see more examples, check out the /examples folder.

#![feature(lang_items)]
#![crate_type = "staticlib"]
#![no_std]

use teensycore::prelude::*;

main!({
    pin_mode(13, Mode::Output);

    loop {
        pin_out(13, Power::High);
        wait_ns(1 * S_TO_NANO);
        pin_out(13, Power::Low);
        wait_ns(1 * S_TO_NANO);
    }
});

Contributing

This project is a work-in-progress and will be undergoing significant development over the coming months and years as I make it suitable for my own needs. Contributions are welcome. Please open an issue if you'd like to discuss anything specific.

License

MIT

Extension points exported contracts — how you extend this code

Array (Interface)
(no doc) [3 implementers]
src/system/vector.rs
Task (Interface)
(no doc)
src/lib.rs
Stack (Interface)
(no doc) [2 implementers]
src/system/vector.rs
Queue (Interface)
(no doc) [2 implementers]
src/system/vector.rs
StringOps (Interface)
(no doc) [1 implementers]
src/system/str.rs
StringBuffer (Interface)
(no doc) [1 implementers]
src/system/strings.rs

Core symbols most depended-on inside this repo

assign
called by 139
src/phys.rs
read_word
called by 99
src/phys.rs
size
called by 31
src/system/map.rs
get_addr
called by 29
src/phys/uart.rs
len
called by 28
src/system/str.rs
push
called by 28
src/system/buffer.rs
set_bit_from_bool
called by 24
src/phys/uart.rs
append
called by 22
src/system/str.rs

Shape

Function 288
Method 132
Class 35
Enum 32
Interface 8

Languages

Rust99%
C1%

Modules by API surface

src/phys/uart.rs45 symbols
src/system/str.rs42 symbols
src/system/vector.rs36 symbols
src/phys/usb.rs26 symbols
src/serio.rs24 symbols
src/phys/dma.rs21 symbols
src/i2c.rs21 symbols
src/system/map.rs19 symbols
examples/mpu6050/lib.rs19 symbols
src/phys/irq.rs18 symbols
src/debug.rs16 symbols
src/phys/usb/models.rs15 symbols

For agents

$ claude mcp add teensycore \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact