Skip to content
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
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"editor.formatOnSave": true,
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.allTargets": false,
"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
"rust-analyzer.cargo.features": "all",
"rust-analyzer.check.command": "clippy",
"[toml]": {
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 8 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
[package]
name = "embedded-rust-template"
[workspace]
resolver = "2"
members = ["mcu-traits"]

[workspace.package]
version = "0.1.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/OpenDevicePartnership/embedded-rust-template"
rust-version = "1.85"

[dependencies]
# dependencies for all targets

[target.'cfg(target_os = "none")'.dependencies]
# dependencies for no-std targets
repository = "https://github.com/OpenDevicePartnership/embedded-mcu"

[lints.clippy]
suspicious = "forbid"
correctness = "forbid"
perf = "forbid"
style = "forbid"
[workspace.dependencies]
embedded-services = { git = "https://github.com/OpenDevicePartnership/embedded-services" }
64 changes: 3 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,5 @@
# embedded-rust-template
Template repository for Embedded Rust development
# embedded-mcu

## Customizing This Template
This houses a colletion of MCU agnostic traits + libraries to manipulate hardware peripherals. It is similar to embedded-hal except mapping to high level of abstraction like USB C PD and HID. Some of the traits housed here will be upstreamed to embedded-hal if the community aligns to the same vision.
Comment thread
jerrysxie marked this conversation as resolved.

### Changing the Target Architecture

This template is configured for `thumbv8m.main-none-eabihf`, by default, but you can modify it for other targets (i.e. `aarch64-unknown-none`):

1. **VSCode Settings**: Update the target in `.vscode/settings.json`:
```json
"rust-analyzer.cargo.target": "your-target-architecture"
```


This configuration ensures that:
- Only the specified target architecture is analyzed, not the host platform
- Code is checked against the no_std environment

To temporarily analyze code for the host platform instead, you can remove the `rust-analyzer.cargo.target` setting.

2. **GitHub Workflows**: Modify the target in two workflow files:
- `.github/workflows/nostd.yml`: Update the targets in the matrix:
```yaml
matrix:
target: [your-target-architecture]
```
- `.github/workflows/check.yml`: If there are any target-specific checks, update them accordingly.

3. **Cargo Configuration**: If needed, you can add target-specific configuration in a `.cargo/config.toml` file.

### Converting from Binary to Library

To convert this project from a binary to a library:

1. **Cargo.toml**: Update your project structure:
```toml
[lib]
name = "your_library_name"
```

2. **Directory Structure**:
- For a library, ensure you have a `src/lib.rs` file instead of `src/main.rs`
- Move your code from `main.rs` to `lib.rs` and adjust as needed

3. **No-std Configuration**: If you're creating a no-std library, ensure you have:
```rust
// In lib.rs
#![cfg_attr(target_os = "none", no_std)]
// Add other attributes as needed
```

### Project Dependencies

Update the dependencies in `Cargo.toml` based on your target platform:

```toml
[dependencies]
# Common dependencies for all targets

[target.'cfg(target_os = "none")'.dependencies]
# Dependencies for no-std targets
```
This repo is not intended to link to any MCU specific code.
8 changes: 8 additions & 0 deletions mcu-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "mcu-traits"
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
5 changes: 5 additions & 0 deletions mcu-traits/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![no_std]

pub fn add(left: u64, right: u64) -> u64 {
left + right
}
6 changes: 0 additions & 6 deletions src/baremetal/mod.rs

This file was deleted.

18 changes: 0 additions & 18 deletions src/main.rs

This file was deleted.