-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into reproducible-workspace
- Loading branch information
Showing
31 changed files
with
6,200 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
INCLUDE ./chip_layout.ld | ||
INCLUDE ../kernel_layout.ld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
Oops, something went wrong.