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

Add Teensy 4 board #2200

Merged
merged 17 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ members = [
"boards/redboard_artemis_nano",
"boards/stm32f3discovery",
"boards/stm32f412gdiscovery",
"boards/teensy40",
"boards/nano33ble",
"capsules",
"chips/apollo3",
"chips/arty_e21_chip",
"chips/e310x",
"chips/imxrt1050",
"chips/earlgrey",
"chips/imxrt1050",
"chips/imxrt10xx",
"chips/lowrisc",
"chips/msp432",
"chips/nrf52",
Expand Down
1 change: 1 addition & 0 deletions arch/cortex-m7/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub use cortexm::svc_handler;
pub use cortexm::syscall;
pub use cortexm::systick;
pub use cortexm::systick_handler;
pub use cortexm::unhandled_interrupt;

/// Provide a `switch_to_user` function with exactly that name for syscall.rs.
#[cfg(all(target_arch = "arm", target_os = "none"))]
Expand Down
1 change: 1 addition & 0 deletions boards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ that Tock supports.
| [STM32F412G Discovery kit](stm32f412gdiscovery/README.md) | ARM Cortex-M4 | STM32F412G | openocd | custom | #1827 |
| [SparkFun RedBoard Artemis Nano](redboard_artemis_nano/README.md) | ARM Cortex-M4 | Apollo3 | custom | custom | No |
| [i.MX RT 1052 Evaluation Kit](imxrt1050-evkb/README.md) | ARM Cortex-M7 | i.MX RT 1052 | custom | custom | No |
| [Teensy 4.0](teensy40/README.md) | ARM Cortex-M7 | i.MX RT 1062 | custom | custom | No |
| [SiFive HiFive1](hifive1/README.md) | RISC-V | FE310-G000 | openocd | tockloader | [Yes (5.1)][qemu] |
| [Digilent Arty A-7 100T](arty_e21/README.md) | RISC-V RV32IMAC | SiFive E21 | openocd | tockloader | No |
| [Earlgrey on Nexys Video](earlgrey_nexysvideo/README.md) | RISC-V RV32IMC | EarlGrey | custom | custom | [Yes (5.1)][qemu] |
Expand Down
2 changes: 1 addition & 1 deletion boards/imxrt1050-evkb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ components = { path = "../components" }
cortexm7 = { path = "../../arch/cortex-m7" }
capsules = { path = "../../capsules" }
kernel = { path = "../../kernel" }
imxrt1050 = { path = "../../chips/imxrt1050" }
imxrt10xx = { path = "../../chips/imxrt10xx" }
2 changes: 1 addition & 1 deletion boards/imxrt1050-evkb/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kernel::hil::led;
use kernel::hil::uart;
use kernel::hil::uart::Configure;

use imxrt1050;
use crate::imxrt1050;
use imxrt1050::gpio::PinId;

use crate::CHIP;
Expand Down
21 changes: 11 additions & 10 deletions boards/imxrt1050-evkb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use kernel::{create_capability, static_init};

// use components::fxos8700::Fxos8700Component;
// use components::ninedof::NineDofComponent;

use imxrt1050::iomuxc::DriveStrength;
use imxrt1050::iomuxc::MuxMode;
use imxrt1050::iomuxc::OpenDrainEn;
Expand All @@ -28,6 +27,7 @@ use imxrt1050::iomuxc::PullKeepEn;
use imxrt1050::iomuxc::PullUpDown;
use imxrt1050::iomuxc::Sion;
use imxrt1050::iomuxc::Speed;
use imxrt10xx as imxrt1050;

// Unit Tests for drivers.
// #[allow(dead_code)]
Expand All @@ -45,7 +45,7 @@ const NUM_PROCS: usize = 1;
// Actual memory for holding the active process structures.
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = [None];

static mut CHIP: Option<&'static imxrt1050::chip::Imxrt1050> = None;
static mut CHIP: Option<&'static imxrt1050::chip::Imxrt10xx> = None;

// How should the kernel respond when a process faults.
const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultResponse::Panic;
Expand All @@ -67,7 +67,7 @@ pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
struct Imxrt1050EVKB {
alarm: &'static capsules::alarm::AlarmDriver<
'static,
VirtualMuxAlarm<'static, imxrt1050::gpt1::Gpt1<'static>>,
VirtualMuxAlarm<'static, imxrt1050::gpt::Gpt1<'static>>,
>,
button: &'static capsules::button::Button<'static, imxrt1050::gpio::Pin<'static>>,
console: &'static capsules::console::Console<'static>,
Expand Down Expand Up @@ -163,14 +163,15 @@ unsafe fn set_pin_primary_functions() {

/// Helper function for miscellaneous peripheral functions
unsafe fn setup_peripherals() {
use imxrt1050::gpt1::GPT1;
use imxrt1050::ccm::CCM;
use imxrt1050::gpt::GPT1;

// LPUART1 IRQn is 20
cortexm7::nvic::Nvic::new(imxrt1050::nvic::LPUART1).enable();

// TIM2 IRQn is 28
GPT1.enable_clock();
GPT1.start();
GPT1.start(CCM.perclk_sel(), CCM.perclk_divider());
cortexm7::nvic::Nvic::new(imxrt1050::nvic::GPT1).enable();
}

Expand Down Expand Up @@ -201,8 +202,8 @@ pub unsafe fn reset_handler() {
DynamicDeferredCall::set_global_instance(dynamic_deferred_caller);

let chip = static_init!(
imxrt1050::chip::Imxrt1050,
imxrt1050::chip::Imxrt1050::new()
imxrt1050::chip::Imxrt10xx,
imxrt1050::chip::Imxrt10xx::new()
);
CHIP = Some(chip);

Expand Down Expand Up @@ -298,13 +299,13 @@ pub unsafe fn reset_handler() {
.finalize(components::button_component_buf!(imxrt1050::gpio::Pin));

// ALARM
let gpt1 = &imxrt1050::gpt1::GPT1;
let gpt1 = &imxrt1050::gpt::GPT1;
let mux_alarm = components::alarm::AlarmMuxComponent::new(gpt1).finalize(
components::alarm_mux_component_helper!(imxrt1050::gpt1::Gpt1),
components::alarm_mux_component_helper!(imxrt1050::gpt::Gpt1),
);

let alarm = components::alarm::AlarmDriverComponent::new(board_kernel, mux_alarm)
.finalize(components::alarm_component_helper!(imxrt1050::gpt1::Gpt1));
.finalize(components::alarm_component_helper!(imxrt1050::gpt::Gpt1));

// GPIO
// For now we expose only two pins
Expand Down
13 changes: 13 additions & 0 deletions boards/teensy40/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "teensy40"
version = "0.1.0"
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
build = "build.rs"
edition = "2018"

[dependencies]
components = { path = "../components" }
cortexm7 = { path = "../../arch/cortex-m7" }
capsules = { path = "../../capsules" }
kernel = { path = "../../kernel" }
imxrt10xx = { path = "../../chips/imxrt10xx" }
31 changes: 31 additions & 0 deletions boards/teensy40/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Makefile for building the tock kernel for the Teensy 4

TARGET=thumbv7em-none-eabi
PLATFORM=teensy40

include ../Makefile.common

%.hex: %.elf
$(Q)$(OBJCOPY) -O ihex $< $@

kernel: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf

.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).hex
$(Q)teensy_loader_cli --mcu=TEENSY40 -w -v $<

# Unsupported; there's no easily-accessible JTAG interface
.PHONY: flash
flash:
echo "Use 'make program' to program the Teensy 4"
exit 1

# For testing with a blinky LED
BLINK=../../../libtock-c/examples/blink/build/cortex-m7/cortex-m7.tbf
app.elf: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
$(Q)arm-none-eabi-objcopy --update-section .apps=$(BLINK) $< $@

app: app.elf
$(Q)$(OBJCOPY) -O ihex $< $@
teensy_loader_cli --mcu=TEENSY40 -w -v $@
$(Q)rm $@ $<
80 changes: 80 additions & 0 deletions boards/teensy40/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Teensy 4.0 Development Board
============================

The `teensy40` board supports the Teensy **4.0** development board.
For more information, visit the
[Teensy 4.0 Development Board](https://www.pjrc.com/store/teensy40.html)
product page.

The board may suffice for the [Teensy **4.1** development board](t41), which
shares common pins and a larger amount of flash memory. However, the board
will not contain features that are only available on the Teensy 4.1 development
board, such as extended flash memory and RAM, an on-board SD card, or ethernet.

[t41]: https://www.pjrc.com/store/teensy41.html

Programming Dependencies
------------------------

Before attempting to program your Teensy 4.0 with Tock and Tock apps, make sure
that you have either

- a build of [`teensy_loader_cli`](https://github.com/PaulStoffregen/teensy_loader_cli), or
- the [Teensy Loader Application](https://www.pjrc.com/teensy/loader.html)

If you're already familiar with programming the Teensy with Arduino tools,
the Teensy Loader Application is already bundled with the Teensyduino add-ons
that you may already be using.

Programming
-----------

From this directory, build the Tock kernel for the Teensy 4:

```bash
$ make
```

Build Tock apps out of tree. Once you've built an app, use
`arm-none-eabi-objcopy` with `--update-section` to create an ELF image that
includes your app(s). The example below combines a prebuilt `blink` example
with the Teensy 4 Tock kernel.

```bash
$ arm-none-eabi-objcopy \
--update-section .apps=../../../libtock-c/examples/blink/build/cortex-m7/cortex-m7.tbf \
../../target/thumbv7em-none-eabi/release/teensy40.elf \
../../target/thumbv7em-none-eabi/release/teensy40-app.elf
```

Once you've created a single ELF image, use `arm-none-eabi-objcopy` to turn
that into HEX:

```bash
$ arm-none-eabi-objcopy -O ihex \
../../target/thumbv7em-none-eabi/release/teensy40-app.elf \
../../target/thumbv7em-none-eabi/release/teensy40-app.hex
```

Finally, use a Teensy programmer to flash `teensy40-app.hex` to your board!

```bash
$ teensy_loader_cli -w -v --mcu=TEENSY40 target/thumbv7em-none-eabi/release/teensy40-app.hex
```

Use the example `Makefile` below to create a build and flash workflow:

```Makefile
APP=../../../libtock-c/examples/blink/build/cortex-m7/cortex-m7.tbf
KERNEL=$(TOCK_ROOT_DIRECTORY)/target/teensy40/release/teensy40.elf
KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/teensy40/release/teensy40-app.elf
KERNEL_WITH_APP_HEX=$(TOCK_ROOT_DIRECTORY)/target/teensy40/release/teensy40-app.hex

.PHONY: program
program: target/thumbv7em-none-eabi/release/teensy40.elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
arm-none-eabi-objcopy -O ihex $(KENERL_WITH_APP) $(KERNEL_WITH_APP_HEX)
teensy_loader_cli -w -v --mcu=TEENSY40 $(KERNEL_WITH_APP_HEX)
```

For another example, see [`Makefile`](./Makefile).
4 changes: 4 additions & 0 deletions boards/teensy40/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
println!("cargo:rerun-if-changed=layout.ld");
println!("cargo:rerun-if-changed=../kernel_layout.ld");
}
72 changes: 72 additions & 0 deletions boards/teensy40/layout.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Teensy 4 Linker Script
*
* We do not utilize any of the tightly-coupled memory (TCM)
* regions. There's another 512KB region that could be
* used for RAM, or for instruction execution (ITCM), or for
* quickly-accessible data (DTCM).
*
* NXP's iMXRT processors require a special boot section, which
* we call '.boot' below. It contains the FlexSPI Configuration
* Block (FCB) for serial NOR flash, and the image vector table
* (IVT). The FCB is available in src/fcb.rs.
*/

MEMORY
{
rom (rx) : ORIGIN = 0x60000000, LENGTH = 512K
prog (rx) : ORIGIN = 0x60080000, LENGTH = 512K
ram (rwx) : ORIGIN = 0x20200000, LENGTH = 512K
}

MPU_MIN_ALIGN = 8K;

SECTIONS
{
.boot :
{
/* FlexSPI Configuration Block (defined in source) */
KEEP(*(.fcb));
KEEP(*(.fcb_buffer));
/* ------------------
* Image Vector Table
* ------------------
*
* See section 9.7.1.1 "Image vector table structure"
* of the IMXRT1060 reference manual.
*/
_ivt = .;
LONG(0x402000D1); /* Header, magic number */
/* Address to the vector table
*
* Relies on the fact that the vector table is the
* first thing in ROM.
*/
LONG(_stext);
LONG(0x00000000); /* RESERVED */
LONG(0x00000000); /* Device Configuration Data (unused) */
LONG(_boot_data); /* Address of boot data */
LONG(_ivt); /* Address to the IVT (self) */
LONG(0x00000000); /* Command Sequence File (unused) */
LONG(0x00000000); /* RESERVED */
/* ---------
* Boot Data
* ---------
*
* See section 9.7.1.2 "Boot data structure" of the
* IMXRT1060 reference manual.
*/
_boot_data = .;
LONG(ORIGIN(rom)); /* Start of image */
/* Size of the program image (assuming that we also need the boot section) */
LONG((_etext-_stext) + (_erelocate-_srelocate) + SIZEOF(.boot));
LONG(0x00000000); /* Plugin flag (unused) */
/* End of iMXRT10xx magic
*
* Need to align vector table on a 1024-byte boundary given the size of the table
*/
. = ALIGN(1024);
} > rom
}

INCLUDE ../kernel_layout.ld