Skip to content
This repository was archived by the owner on Jan 23, 2021. It is now read-only.

Commit 5c3a62c

Browse files
committed
Initial port for STM32F4 Discovery
1 parent eaae21f commit 5c3a62c

29 files changed

+1631
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ Follow the official [getting started guide](https://github.com/helena-project/to
1414
## Supported Boards
1515

1616
* [Nucleo-F103RB](./boards/nucleo_f103)
17+
* [STM32F4DISCOVERY](./boards/stm32f4discovery)
1718

1819
Tock supports more than just STM32-based boards, take a look at [the boards](https://github.com/helena-project/tock/tree/master/boards) which are part of main repository too!

boards/stm32f4discovery/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.xargo/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "MCU",
6+
"type": "gdb",
7+
"request": "attach",
8+
"gdbpath": "arm-none-eabi-gdb",
9+
"executable": "./target/thumbv7em-none-eabi/debug/stm32f4discovery",
10+
"target": ":3333",
11+
"remote": true,
12+
"cwd": "${workspaceRoot}",
13+
"valuesFormatting": "prettyPrinters",
14+
"autorun": [
15+
"monitor reset halt",
16+
"monitor arm semihosting enable",
17+
],
18+
}
19+
]
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "shell",
6+
"label": "make debug",
7+
"command": "make",
8+
"args": [
9+
"debug"
10+
],
11+
"problemMatcher": [
12+
"$rustc"
13+
]
14+
},
15+
]
16+
}

boards/stm32f4discovery/Cargo.lock

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

boards/stm32f4discovery/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "stm32f4discovery"
3+
version = "0.1.0"
4+
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
5+
build = "build.rs"
6+
7+
[profile.dev]
8+
panic = "abort"
9+
lto = false
10+
opt-level = 0
11+
debug = true
12+
13+
[profile.release]
14+
panic = "abort"
15+
lto = true
16+
opt-level = "z"
17+
debug = true
18+
19+
[dependencies]
20+
cortexm4 = { path = "../../tock/arch/cortex-m4" }
21+
capsules = { path = "../../tock/capsules" }
22+
kernel = { path = "../../tock/kernel" }
23+
stm32f4 = { path = "../../chips/stm32f4" }

boards/stm32f4discovery/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Makefile for building the tock kernel for the Imix platform
2+
3+
TARGET = thumbv7em-none-eabi
4+
PLATFORM = stm32f4discovery
5+
6+
include ../../tock/boards/Makefile.common
7+
8+
export XARGO_HOME := $(PWD)/.xargo
9+
10+
OPENOCD = openocd -f connect.cfg
11+
12+
.PHONY: program
13+
program: target/$(TARGET)/release/$(PLATFORM).bin
14+
echo "Not implemented"
15+
16+
# upload kernel over JTAG
17+
.PHONY: flash
18+
flash: target/$(TARGET)/release/$(PLATFORM)
19+
$(OPENOCD) -c "program $< reset exit"
20+
21+
.PHONY: flash-debug
22+
flash-debug: target/$(TARGET)/debug/$(PLATFORM)
23+
$(OPENOCD) -c "program $< reset exit"
24+
25+
.PHONY: distclean
26+
distclean: clean
27+
$(Q)rm -rf .xargo
28+
29+
.PHONY: flash-debug-run
30+
flash-debug-run: flash-debug
31+
$(OPENOCD) -c "init; reset halt"
32+
33+
.PHONY: run
34+
run:
35+
$(OPENOCD) -c "init; reset halt"

boards/stm32f4discovery/Makefile-app

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$(call check_defined, BUILDDIR)
2+
$(call check_defined, PACKAGE_NAME)
3+
4+
APP_FLASH = $(TOCK_USERLAND_BASE_DIR)/tools/flash/stm32f4.sh
5+
6+
.PHONY: program
7+
program: $(BUILDDIR)/$(PACKAGE_NAME).tab
8+
echo "Not implemented"
9+
10+
# Upload programs over JTAG
11+
.PHONY: flash
12+
flash: $(BUILDDIR)/cortex-m4/cortex-m4.bin
13+
APP_BASE_ADDR=0x08080000 $(APP_FLASH) $<

boards/stm32f4discovery/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
stm32f4discovery: Platform-Specific Instructions
2+
=====================================
3+
4+
(http://www.st.com/en/evaluation-tools/stm32f4discovery.html)
5+
6+
7+
## Flashing the kernel
8+
9+
To program the Tock kernel onto the Discovery, `cd` into the `boards/stm32f4discovery` directory
10+
and run:
11+
12+
```bash
13+
make flash-debug
14+
```
15+
16+
This will build `boards/stm32f4discovery/target/thumbv7em-none-eabi/debug/stm32f4discovery` and use `openocd` to
17+
flash it to the board.
18+
19+
## Apps
20+
21+
All user-level code lives in the `userland` subdirectory. This includes a
22+
specially compiled version of newlib, a user-level library for talking to the
23+
kernel and specific drivers and a variety of example applications.
24+
25+
To compile an app, `cd` to the desired app and `make`. For example:
26+
27+
```bash
28+
cd tock/userland/examples/c_hello/
29+
make TOCK_BOARD=stm32f4discovery
30+
```
31+
32+
### Flashing one app
33+
34+
```bash
35+
cd tock/userland/examples/c_hello/
36+
make TOCK_BOARD=stm32f4discovery flash
37+
```
38+
39+
### Flashing multiple apps
40+
41+
```bash
42+
cd userland
43+
44+
APPS="buttons c_hello"
45+
BINS=()
46+
47+
for APP in $APPS; do
48+
pushd .
49+
cd "../../tock/userland/examples/${APP}/"
50+
make TOCK_BOARD=stm32f4discovery
51+
popd
52+
BINS+=("../../tock/userland/examples/${APP}/build/cortex-m4/cortex-m4.bin")
53+
done
54+
55+
APP_BASE_ADDR=0x08080000 ./tools/flash/stm32f4.sh "${BINS[@]}"
56+
```
57+
58+
## Debugging using Visual Studio Code
59+
60+
*TODO* (Status: working very well)
61+
62+
Edit `discovery.code-workspace` and point `rust.sysroot` to correct full path
63+
to `.xargo` in this directory.
64+
65+
## Console I/O
66+
67+
The the kernel debugging console and the stdout console is implemented using
68+
[semihosting](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471g/Bgbjjgij.html).
69+
70+
Huge benefit of semihosting console is that it in contrast to UART console requires no hardware
71+
initialization.
72+
73+
`std_out_init()` initializes the semihosting only if a debugger is connected
74+
so the kernel can run without debugger out-of-box without needing to replace
75+
or remove the semihosting console in code.
76+
77+
To enable semihosting with one needs to add `arm semihosting enable` to `openocd`
78+
initialization commnds e.g.:
79+
80+
```bash
81+
openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c "init; reset halt; arm semihosting enable"
82+
```
83+
84+
The command can also be passed from `gdb` using `monitor arm semihosting enable` command.

boards/stm32f4discovery/Xargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[dependencies.core]
2+
3+
[dependencies.compiler_builtins]
4+
features = ["mem"]
5+
git = "https://github.com/rust-lang-nursery/compiler-builtins"
6+
stage = 1
7+
rev = "67e0908d7f2fd86423ec32fc4d904952fe96e7a9"

0 commit comments

Comments
 (0)