Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Minimal GPIO drivers #5

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

Merged
merged 24 commits into from
Feb 15, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/rust_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ jobs:
cargo make ci_debug
cargo make ci_release
cargo doc

- name: Minimal Drivers
working-directory: ${{github.workspace}}/minimal_drivers
run: |
cargo make ci_debug
cargo make ci_release
cargo doc
43 changes: 43 additions & 0 deletions minimal_drivers/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[target.thumbv7em-none-eabihf]
# uncomment this to make `cargo run` execute programs on QEMU
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# uncomment ONE of these three option to make `cargo run` start a GDB session
# which option to pick depends on your system
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
# runner = "gdb-multiarch -q -x openocd.gdb"
# runner = "gdb -q -x openocd.gdb"
rustflags = [
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
# "-C", "link-arg=--nmagic",

# LLD (shipped with the Rust toolchain) is used as the default linker
# "-C", "link-arg=-Tgcc_arm.ld",

# Generate a .map file
# "-C", "link-args=-Map=application.map",

# if you run into problems with LLD switch to the GNU linker by commenting out
# this line
"-C", "linker=arm-none-eabi-ld",

# if you need to link to pre-compiled C libraries provided by a C toolchain
# use GCC as the linker by commenting out both lines above and then
# uncommenting the three lines below
"-C", "linker=arm-none-eabi-gcc",
"-C", "link-arg=-Wl,-Tgcc_arm.ld",
"-C", "link-arg=-Wl,-Map,application.map",
"-C", "link-arg=-nostartfiles",
]

[build]
# Pick ONE of these compilation targets
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
# target = "thumbv7m-none-eabi" # Cortex-M3
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
# target = "thumbv8m.base-none-eabi" # Cortex-M23
# target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU)
# target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU)
6 changes: 6 additions & 0 deletions minimal_drivers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files
*.map
.vscode/.cortex-debug.*

# Folders
target
34 changes: 34 additions & 0 deletions minimal_drivers/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"configurations": [
{
"cwd": "${workspaceFolder}",
"executable": "target/thumbv7em-none-eabihf/debug/application",
"configFiles": [
"stm32l4discovery.cfg"
],
"postLaunchCommands": [
"load",
"monitor arm semihosting enable",
],
"name": "Rust Debug",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd"
},
{
"cwd": "${workspaceFolder}",
"executable": "target/thumbv7em-none-eabihf/release/application",
"configFiles": [
"stm32l4discovery.cfg"
],
"postLaunchCommands": [
"load",
"monitor arm semihosting enable",
],
"name": "Rust Release",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd"
}
]
}
7 changes: 7 additions & 0 deletions minimal_drivers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
members = [
"l0",
"l3",
"l4",
"l5"
]
87 changes: 87 additions & 0 deletions minimal_drivers/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[config]
default_to_workspace = false

# Duckscript is used here to convert \ to / for binary output path
[tasks.build_debug]
script_runner = "@duckscript"
script = '''
output = set ${CARGO_MAKE_CRATE_CUSTOM_TRIPLE_TARGET_DIRECTORY}/debug/application
echo OUTPUT: ${output}
output = replace ${output} \\ /
set_env OUTPUT ${output}
exec cargo build
'''

# Duckscript is used here to convert \ to / for binary output path
[tasks.build_release]
script_runner = "@duckscript"
script = '''
output = set ${CARGO_MAKE_CRATE_CUSTOM_TRIPLE_TARGET_DIRECTORY}/release/application
output = replace ${output} \\ /
set_env OUTPUT ${output}
exec cargo build --release
'''

[tasks.test]
command = "cargo"
args = ["test", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}"]

[tasks.flash_debug]
script_runner = "@shell"
script = '''
openocd -f board/stm32l4discovery.cfg -c "program ${OUTPUT} verify reset exit"
'''
dependencies = ["build_debug"]

[tasks.ci_debug]
dependencies = [
"build_debug",
"test",
"objcopy_to_binary",
"objcopy_to_hex",
"objdump",
"size",
]

[tasks.ci_release]
dependencies = [
"build_release",
"test",
"objcopy_to_binary",
"objcopy_to_hex",
"objdump",
"size",
]

# Private Tasks

# Requires
# arm-none-eabi-size executable (ARM GCC toolchain)
# OUTPUT env variable (Set by build_*)
[tasks.size]
private = true
command = "arm-none-eabi-size"
args = ["${OUTPUT}"]

# arm-none-eabi-objcopy executable (ARM GCC toolchain)
# OUTPUT env variable (Set by build_*)
[tasks.objcopy_to_binary]
private = true
command = "arm-none-eabi-objcopy"
args = ["-O", "binary", "${OUTPUT}", "${OUTPUT}.bin"]

# arm-none-eabi-objcopy executable (ARM GCC toolchain)
# OUTPUT env variable (Set by build_*)
[tasks.objcopy_to_hex]
private = true
command = "arm-none-eabi-objcopy"
args = ["-O", "ihex", "${OUTPUT}", "${OUTPUT}.hex"]

# arm-none-eabi-objdump executable (ARM GCC toolchain)
# OUTPUT env variable (Set by build_*)
[tasks.objdump]
private = true
script_runner = "@shell"
script = '''
arm-none-eabi-objdump --source --all-headers --demangle --line-numbers --wide ${OUTPUT} > ${OUTPUT}.lst
'''
111 changes: 111 additions & 0 deletions minimal_drivers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
- [Minimal Drivers](#minimal-drivers)
- [Links](#links)
- [Microcontrollers layers](#microcontrollers-layers)
- [Pre-requisites](#pre-requisites)
- [GPIO](#gpio)
- [Changelog](#changelog)
- [L2 Layer - Utilities](#l2-layer---utilities)
- [Own implementation](#own-implementation)
- [Crates.io](#cratesio)
- [L3 Layer - Interfaces](#l3-layer---interfaces)
- [L3 Layer - Drivers](#l3-layer---drivers)
- [L3 Layer - Miscellaneous](#l3-layer---miscellaneous)
- [L4](#l4)

# Minimal Drivers

This code has been tested on

- B-L475-IOT01A board (STM32L475VGT6 ARM Cortex M4 CPU with FPU)

## Links

- [Cargo binutils](https://github.com/rust-embedded/cargo-binutils)
- [Embedded Rust book](https://doc.rust-lang.org/stable/embedded-book/)
- [Lowlevel Embedded Rust book](https://docs.rust-embedded.org/embedonomicon/)

## Microcontrollers layers

- L0 Lowlevel
- CMSIS
- Controller registers
- Startup
- Linker script
- L1 RTOS
- L2 Utility
- Bitflags
- L3 Driver
- GPIO
- UART
- L4 Sensor
- L5 Application

## Pre-requisites

- Pre-requisites from `minimal_controller_peripheral`

## GPIO

- Module
- Functionality
- Port
- Registers
- Pin

---

- [GPIO Traits](https://github.com/mbr/gpio-rs)

```mermaid
graph BT;
subgraph Port
GPIOA-H
subgraph Periphal
GPIO
subgraph Register
MODER
IDR
ODR
subgraph Pin
0-15
end
end
end
end
```

# Changelog

## L2 Layer - Utilities

### Own implementation

### Crates.io

- [Bitflags](https://github.com/bitflags/bitflags)

## L3 Layer - Interfaces

- GpioIn
- GpioOut
- UsartIn
- UsartOut
- UsartInOut
- Port
- Generic interface that creates a port using base address and peripheral register layout
- In C it would be the equivalent of `GPIO_TypeDef * gpio = (GPIO_TypeDef *)BASE_ADDRESS`

## L3 Layer - Drivers

- RCC
- GPIO

## L3 Layer - Miscellaneous

- Singleton
- Safe access to global ports

## L4

- Led
- Button
Loading