Skip to content

Commit

Permalink
Merge branch 'master' into reproducible-workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
gendx committed Apr 7, 2020
2 parents 04cb360 + 0dc178c commit 6f6911c
Show file tree
Hide file tree
Showing 31 changed files with 6,200 additions and 66 deletions.
21 changes: 15 additions & 6 deletions boards/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,23 @@ RUSTFLAGS_FOR_CARGO ?= \
-C linker-flavor=ld.lld \
-C relocation-model=dynamic-no-pic \
-C link-arg=-zmax-page-size=512 \
-C link-arg=-icf=all \
--remap-path-prefix=$(TOCK_ROOT_DIRECTORY)= \

# RISC-V-specific flags.
ifneq ($(findstring riscv32i, $(TARGET)),)
# NOTE: This flag causes kernel panics on some ARM cores. Since the
# size benefit is almost exclusively for RISC-V, we only apply it for
# those targets.
RUSTFLAGS_FOR_CARGO += -C force-frame-pointers=no
endif

# Disallow warnings for continuous integration builds. Disallowing them here
# ensures that warnings during testing won't prevent compilation from succeeding.
ifeq ($(CI),true)
RUSTFLAGS_FOR_CARGO += -D warnings
endif

# The following flags should only be passed to the board's binary crate, but
# not to any of its dependencies (the kernel, capsules, chips, etc.). The
# dependencies wouldn't use it, but because the link path is different for each
Expand All @@ -51,12 +66,6 @@ RUSTFLAGS_FOR_CARGO ?= \
RUSTFLAGS_FOR_BIN ?= \
-C link-arg=-L$(abspath .) \

# Disallow warnings for continuous integration builds. Disallowing them here
# ensures that warnings during testing won't prevent compilation from succeeding.
ifeq ($(CI),true)
RUSTFLAGS_FOR_CARGO += -D warnings
endif

# http://stackoverflow.com/questions/10858261/abort-makefile-if-variable-not-set
# Check that given variables are set and all have non-empty values, print an
# error otherwise.
Expand Down
27 changes: 14 additions & 13 deletions boards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ Platforms Supported by Tock
The `/boards` directory contains the physical hardware platforms
that Tock supports.

| Board | Architecture | MCU | Interface | App deployment |
|---------------------------------------------------|-----------------|------------|------------|----------------|
| [Hail](hail/README.md) | ARM Cortex-M4 | SAM4LC8BA | Bootloader | tockloader |
| [Imix](imix/README.md) | ARM Cortex-M4 | SAM4LC8CA | Bootloader | tockloader |
| [Nordic nRF52-DK](nordic/nrf52dk/README.md) | ARM Cortex-M4 | nRF52832 | jLink | tockloader |
| [Nordic nRF52840-DK](nordic/nrf52840dk/README.md) | ARM Cortex-M4 | nRF52840 | jLink | tockloader |
| [ACD52832](acd52832/README.md) | ARM Cortex-M4 | nRF52832 | jLink | tockloader |
| [TI LAUNCHXL-CC26x2](launchxl/README.md) | ARM Cortex-M4 | CC2652R | openocd | tockloader |
| [ST Nucleo F446RE](nucleo_f446re/README.md) | ARM Cortex-M4 | STM32F446 | openocd | custom |
| [ST Nucleo F429ZI](nucleo_f429zi/README.md) | ARM Cortex-M4 | STM32F429 | openocd | custom |
| [SiFive HiFive1](hifive1/README.md) | RISC-V | FE310-G000 | openocd | tockloader |
| [Digilent Arty A-7 100T](arty-e21/README.md) | RISC-V RV32IMAC | SiFive E21 | openocd | tockloader |
| [Nexys Video OpenTitan](opentitan/README.md) | RISC-V RV32IMC | Ibex | custom | custom |
| Board | Architecture | MCU | Interface | App deployment |
|------------------------------------------------------|-----------------|----------------|------------|----------------|
| [Hail](hail/README.md) | ARM Cortex-M4 | SAM4LC8BA | Bootloader | tockloader |
| [Imix](imix/README.md) | ARM Cortex-M4 | SAM4LC8CA | Bootloader | tockloader |
| [Nordic nRF52-DK](nordic/nrf52dk/README.md) | ARM Cortex-M4 | nRF52832 | jLink | tockloader |
| [Nordic nRF52840-DK](nordic/nrf52840dk/README.md) | ARM Cortex-M4 | nRF52840 | jLink | tockloader |
| [ACD52832](acd52832/README.md) | ARM Cortex-M4 | nRF52832 | jLink | tockloader |
| [TI LAUNCHXL-CC26x2](launchxl/README.md) | ARM Cortex-M4 | CC2652R | openocd | tockloader |
| [ST Nucleo F446RE](nucleo_f446re/README.md) | ARM Cortex-M4 | STM32F446 | openocd | custom |
| [ST Nucleo F429ZI](nucleo_f429zi/README.md) | ARM Cortex-M4 | STM32F429 | openocd | custom |
| [STM32F3Discovery kit](stm32f3discovery/README.md) | ARM Cortex-M4 | STM32F303VCT6 | openocd | custom |
| [SiFive HiFive1](hifive1/README.md) | RISC-V | FE310-G000 | openocd | tockloader |
| [Digilent Arty A-7 100T](arty-e21/README.md) | RISC-V RV32IMAC | SiFive E21 | openocd | tockloader |
| [Nexys Video OpenTitan](opentitan/README.md) | RISC-V RV32IMC | Ibex | custom | custom |
25 changes: 25 additions & 0 deletions boards/stm32f3discovery/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "stm32f3discovery"
version = "0.1.0"
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
build = "build.rs"
edition = "2018"

[profile.dev]
panic = "abort"
lto = false
opt-level = "z"
debug = true

[profile.release]
panic = "abort"
lto = true
opt-level = "z"
debug = true

[dependencies]
components = { path = "../components" }
cortexm4 = { path = "../../arch/cortex-m4" }
capsules = { path = "../../capsules" }
kernel = { path = "../../kernel" }
stm32f3xx = { path = "../../chips/stm32f3xx", features = ["stm32f303vct6"] }
26 changes: 26 additions & 0 deletions boards/stm32f3discovery/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Makefile for building the tock kernel for the STM32F3DISCOVERY platform
#
TARGET=thumbv7em-none-eabi
PLATFORM=stm32f3discovery

include ../Makefile.common

OPENOCD=openocd
OPENOCD_OPTIONS=-f openocd.cfg

# OpenOCD requires fullpath
CWD=$(shell pwd)

# sudo is needed for libusb access to work properly

.PHONY: flash-debug
flash-debug: target/$(TARGET)/debug/$(PLATFORM).elf
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(CWD)/$<; verify_image $(CWD)/$<; reset; shutdown"

.PHONY: flash
flash: target/$(TARGET)/release/$(PLATFORM).elf
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(CWD)/$<; verify_image $(CWD)/$<; reset; shutdown"

.PHONY: program
program: target/$(TARGET)/debug/$(PLATFORM).elf
$(error See README.md and update this section accordingly)
58 changes: 58 additions & 0 deletions boards/stm32f3discovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
STM32 Discovery kit development board with STM32F303 MCU
========================================================

For more details [visit the Discovery kit
website](https://www.st.com/en/evaluation-tools/stm32f3discovery.html).

## Flashing the kernel

The kernel can be programmed using OpenOCD. `cd` into `boards/stm32f3discovery`
directory and run:

```bash
$ make flash

(or)

$ make flash-debug
```

> **Note:** Unlike other Tock platforms, the default kernel image for this
> board will clear flashed apps when the kernel is loaded. This is to support
> the non-tockloader based app flash procedure below. To preserve loaded apps,
> comment out the `APP_HACK` variable in `src/main.rs`.
## Flashing app

Apps are built out-of-tree. Once an app is built, you can use
`arm-none-eabi-objcopy` with `--update-section` to create an ELF image with the
apps included.

```bash
$ arm-none-eabi-objcopy \
--update-section .apps=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf \
target/thumbv7em-none-eabi/debug/stm32f3discovery.elf \
target/thumbv7em-none-eabi/debug/stm32f3discovery-app.elf
```

For example, you can update `Makefile` as follows.

```
APP=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf
KERNEL=$(CWD)/target/$(TARGET)/debug/$(PLATFORM).elf
KERNEL_WITH_APP=$(CWD)/target/$(TARGET)/debug/$(PLATFORM)-app.elf
.PHONY: program
program: target/$(TARGET)/debug/$(PLATFORM).elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"
```

After setting `APP`, `KERNEL`, `KERNEL_WITH_APP`, and `program` target
dependency, you can do

```bash
$ make program
```

to flash the image.
5 changes: 5 additions & 0 deletions boards/stm32f3discovery/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
println!("cargo:rerun-if-changed=layout.ld");
println!("cargo:rerun-if-changed=chip_layout.ld");
println!("cargo:rerun-if-changed=../kernel_layout.ld");
}
14 changes: 14 additions & 0 deletions boards/stm32f3discovery/chip_layout.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Memory layout for the STM32F303VCT6
* rom = 256KB (LENGTH = 0x00040000)
* kernel = 128KB
* user = 128KB
* ram = 48KB */

MEMORY
{
rom (rx) : ORIGIN = 0x08000000, LENGTH = 0x00020000
prog (rx) : ORIGIN = 0x08020000, LENGTH = 0x00020000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
}

MPU_MIN_ALIGN = 8K;
2 changes: 2 additions & 0 deletions boards/stm32f3discovery/layout.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INCLUDE ./chip_layout.ld
INCLUDE ../kernel_layout.ld
18 changes: 18 additions & 0 deletions boards/stm32f3discovery/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#interface
interface hla
hla_layout stlink
hla_device_desc "ST-LINK/V2-1"
hla_vid_pid 0x0483 0x374b

# The chip has 48KB sram
set WORKAREASIZE 0xC000

# Revision C (newer revision)
# source [find interface/stlink-v2-1.cfg]

# Revision A and B (older revisions)
# source [find interface/stlink-v2.cfg]

source [find target/stm32f3x.cfg]


77 changes: 77 additions & 0 deletions boards/stm32f3discovery/src/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use core::fmt::Write;
use core::panic::PanicInfo;

use kernel::debug;
use kernel::debug::IoWrite;
use kernel::hil::led;
use kernel::hil::uart;
use kernel::hil::uart::Configure;

use stm32f3xx;
use stm32f3xx::gpio::PinId;

use crate::CHIP;
use crate::PROCESSES;

/// Writer is used by kernel::debug to panic message to the serial port.
pub struct Writer {
initialized: bool,
}

/// Global static for debug writer
pub static mut WRITER: Writer = Writer { initialized: false };

impl Writer {
/// Indicate that USART has already been initialized. Trying to double
/// initialize USART2 causes STM32F446RE to go into in in-deterministic state.
pub fn set_initialized(&mut self) {
self.initialized = true;
}
}

impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) {
let uart = unsafe { &mut stm32f3xx::usart::USART2 };

if !self.initialized {
self.initialized = true;

uart.configure(uart::Parameters {
baud_rate: 11500,
stop_bits: uart::StopBits::One,
parity: uart::Parity::None,
hw_flow_control: false,
width: uart::Width::Eight,
});
}

for &c in buf {
uart.send_byte(c);
}
}
}

/// Panic handler.
#[no_mangle]
#[panic_handler]
pub unsafe extern "C" fn panic_fmt(info: &PanicInfo) -> ! {
// User LD3 is connected to PE09
let led = &mut led::LedHigh::new(PinId::PE09.get_pin_mut().as_mut().unwrap());
let writer = &mut WRITER;

debug::panic(
&mut [led],
writer,
info,
&cortexm4::support::nop,
&PROCESSES,
&CHIP,
)
}

0 comments on commit 6f6911c

Please sign in to comment.