Skip to content

Commit d1db5b5

Browse files
authored
Minimal GPIO drivers (#5)
1 parent e392c2b commit d1db5b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+82151
-0
lines changed

.github/workflows/rust_all.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ jobs:
6161
cargo make ci_debug
6262
cargo make ci_release
6363
cargo doc
64+
65+
- name: Minimal Drivers
66+
working-directory: ${{github.workspace}}/minimal_drivers
67+
run: |
68+
cargo make ci_debug
69+
cargo make ci_release
70+
cargo doc

minimal_drivers/.cargo/config.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[target.thumbv7em-none-eabihf]
2+
# uncomment this to make `cargo run` execute programs on QEMU
3+
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
4+
5+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
6+
# uncomment ONE of these three option to make `cargo run` start a GDB session
7+
# which option to pick depends on your system
8+
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
9+
# runner = "gdb-multiarch -q -x openocd.gdb"
10+
# runner = "gdb -q -x openocd.gdb"
11+
rustflags = [
12+
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
13+
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
14+
# "-C", "link-arg=--nmagic",
15+
16+
# LLD (shipped with the Rust toolchain) is used as the default linker
17+
# "-C", "link-arg=-Tgcc_arm.ld",
18+
19+
# Generate a .map file
20+
# "-C", "link-args=-Map=application.map",
21+
22+
# if you run into problems with LLD switch to the GNU linker by commenting out
23+
# this line
24+
"-C", "linker=arm-none-eabi-ld",
25+
26+
# if you need to link to pre-compiled C libraries provided by a C toolchain
27+
# use GCC as the linker by commenting out both lines above and then
28+
# uncommenting the three lines below
29+
"-C", "linker=arm-none-eabi-gcc",
30+
"-C", "link-arg=-Wl,-Tgcc_arm.ld",
31+
"-C", "link-arg=-Wl,-Map,application.map",
32+
"-C", "link-arg=-nostartfiles",
33+
]
34+
35+
[build]
36+
# Pick ONE of these compilation targets
37+
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
38+
# target = "thumbv7m-none-eabi" # Cortex-M3
39+
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
40+
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
41+
# target = "thumbv8m.base-none-eabi" # Cortex-M23
42+
# target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU)
43+
# target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU)

minimal_drivers/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Files
2+
*.map
3+
.vscode/.cortex-debug.*
4+
5+
# Folders
6+
target

minimal_drivers/.vscode/launch.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"configurations": [
3+
{
4+
"cwd": "${workspaceFolder}",
5+
"executable": "target/thumbv7em-none-eabihf/debug/application",
6+
"configFiles": [
7+
"stm32l4discovery.cfg"
8+
],
9+
"postLaunchCommands": [
10+
"load",
11+
"monitor arm semihosting enable",
12+
],
13+
"name": "Rust Debug",
14+
"request": "launch",
15+
"type": "cortex-debug",
16+
"servertype": "openocd"
17+
},
18+
{
19+
"cwd": "${workspaceFolder}",
20+
"executable": "target/thumbv7em-none-eabihf/release/application",
21+
"configFiles": [
22+
"stm32l4discovery.cfg"
23+
],
24+
"postLaunchCommands": [
25+
"load",
26+
"monitor arm semihosting enable",
27+
],
28+
"name": "Rust Release",
29+
"request": "launch",
30+
"type": "cortex-debug",
31+
"servertype": "openocd"
32+
}
33+
]
34+
}

minimal_drivers/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
members = [
3+
"l0",
4+
"l3",
5+
"l4",
6+
"l5"
7+
]

minimal_drivers/Makefile.toml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
[config]
2+
default_to_workspace = false
3+
4+
# Duckscript is used here to convert \ to / for binary output path
5+
[tasks.build_debug]
6+
script_runner = "@duckscript"
7+
script = '''
8+
output = set ${CARGO_MAKE_CRATE_CUSTOM_TRIPLE_TARGET_DIRECTORY}/debug/application
9+
echo OUTPUT: ${output}
10+
output = replace ${output} \\ /
11+
set_env OUTPUT ${output}
12+
exec cargo build
13+
'''
14+
15+
# Duckscript is used here to convert \ to / for binary output path
16+
[tasks.build_release]
17+
script_runner = "@duckscript"
18+
script = '''
19+
output = set ${CARGO_MAKE_CRATE_CUSTOM_TRIPLE_TARGET_DIRECTORY}/release/application
20+
output = replace ${output} \\ /
21+
set_env OUTPUT ${output}
22+
exec cargo build --release
23+
'''
24+
25+
[tasks.test]
26+
command = "cargo"
27+
args = ["test", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}"]
28+
29+
[tasks.flash_debug]
30+
script_runner = "@shell"
31+
script = '''
32+
openocd -f board/stm32l4discovery.cfg -c "program ${OUTPUT} verify reset exit"
33+
'''
34+
dependencies = ["build_debug"]
35+
36+
[tasks.ci_debug]
37+
dependencies = [
38+
"build_debug",
39+
"test",
40+
"objcopy_to_binary",
41+
"objcopy_to_hex",
42+
"objdump",
43+
"size",
44+
]
45+
46+
[tasks.ci_release]
47+
dependencies = [
48+
"build_release",
49+
"test",
50+
"objcopy_to_binary",
51+
"objcopy_to_hex",
52+
"objdump",
53+
"size",
54+
]
55+
56+
# Private Tasks
57+
58+
# Requires
59+
# arm-none-eabi-size executable (ARM GCC toolchain)
60+
# OUTPUT env variable (Set by build_*)
61+
[tasks.size]
62+
private = true
63+
command = "arm-none-eabi-size"
64+
args = ["${OUTPUT}"]
65+
66+
# arm-none-eabi-objcopy executable (ARM GCC toolchain)
67+
# OUTPUT env variable (Set by build_*)
68+
[tasks.objcopy_to_binary]
69+
private = true
70+
command = "arm-none-eabi-objcopy"
71+
args = ["-O", "binary", "${OUTPUT}", "${OUTPUT}.bin"]
72+
73+
# arm-none-eabi-objcopy executable (ARM GCC toolchain)
74+
# OUTPUT env variable (Set by build_*)
75+
[tasks.objcopy_to_hex]
76+
private = true
77+
command = "arm-none-eabi-objcopy"
78+
args = ["-O", "ihex", "${OUTPUT}", "${OUTPUT}.hex"]
79+
80+
# arm-none-eabi-objdump executable (ARM GCC toolchain)
81+
# OUTPUT env variable (Set by build_*)
82+
[tasks.objdump]
83+
private = true
84+
script_runner = "@shell"
85+
script = '''
86+
arm-none-eabi-objdump --source --all-headers --demangle --line-numbers --wide ${OUTPUT} > ${OUTPUT}.lst
87+
'''

minimal_drivers/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
- [Minimal Drivers](#minimal-drivers)
2+
- [Links](#links)
3+
- [Microcontrollers layers](#microcontrollers-layers)
4+
- [Pre-requisites](#pre-requisites)
5+
- [GPIO](#gpio)
6+
- [Changelog](#changelog)
7+
- [L2 Layer - Utilities](#l2-layer---utilities)
8+
- [Own implementation](#own-implementation)
9+
- [Crates.io](#cratesio)
10+
- [L3 Layer - Interfaces](#l3-layer---interfaces)
11+
- [L3 Layer - Drivers](#l3-layer---drivers)
12+
- [L3 Layer - Miscellaneous](#l3-layer---miscellaneous)
13+
- [L4](#l4)
14+
15+
# Minimal Drivers
16+
17+
This code has been tested on
18+
19+
- B-L475-IOT01A board (STM32L475VGT6 ARM Cortex M4 CPU with FPU)
20+
21+
## Links
22+
23+
- [Cargo binutils](https://github.com/rust-embedded/cargo-binutils)
24+
- [Embedded Rust book](https://doc.rust-lang.org/stable/embedded-book/)
25+
- [Lowlevel Embedded Rust book](https://docs.rust-embedded.org/embedonomicon/)
26+
27+
## Microcontrollers layers
28+
29+
- L0 Lowlevel
30+
- CMSIS
31+
- Controller registers
32+
- Startup
33+
- Linker script
34+
- L1 RTOS
35+
- L2 Utility
36+
- Bitflags
37+
- L3 Driver
38+
- GPIO
39+
- UART
40+
- L4 Sensor
41+
- L5 Application
42+
43+
## Pre-requisites
44+
45+
- Pre-requisites from `minimal_controller_peripheral`
46+
47+
## GPIO
48+
49+
- Module
50+
- Functionality
51+
- Port
52+
- Registers
53+
- Pin
54+
55+
---
56+
57+
- [GPIO Traits](https://github.com/mbr/gpio-rs)
58+
59+
```mermaid
60+
graph BT;
61+
subgraph Port
62+
GPIOA-H
63+
subgraph Periphal
64+
GPIO
65+
subgraph Register
66+
MODER
67+
IDR
68+
ODR
69+
subgraph Pin
70+
0-15
71+
end
72+
end
73+
end
74+
end
75+
```
76+
77+
# Changelog
78+
79+
## L2 Layer - Utilities
80+
81+
### Own implementation
82+
83+
### Crates.io
84+
85+
- [Bitflags](https://github.com/bitflags/bitflags)
86+
87+
## L3 Layer - Interfaces
88+
89+
- GpioIn
90+
- GpioOut
91+
- UsartIn
92+
- UsartOut
93+
- UsartInOut
94+
- Port
95+
- Generic interface that creates a port using base address and peripheral register layout
96+
- In C it would be the equivalent of `GPIO_TypeDef * gpio = (GPIO_TypeDef *)BASE_ADDRESS`
97+
98+
## L3 Layer - Drivers
99+
100+
- RCC
101+
- GPIO
102+
103+
## L3 Layer - Miscellaneous
104+
105+
- Singleton
106+
- Safe access to global ports
107+
108+
## L4
109+
110+
- Led
111+
- Button

0 commit comments

Comments
 (0)