Skip to content

Commit

Permalink
cm4 port
Browse files Browse the repository at this point in the history
  • Loading branch information
dotcypress committed Nov 23, 2023
1 parent 9a66f00 commit be8d343
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ jobs:
./install.sh
./upico.service
./upico
outPath: upico_${{ github.ref_name }}.riscv64gc.tar.gz
- name: Copy CM4/A-04/A-06 binary
outPath: upico_${{ github.ref_name }}.r01.tar.gz
- name: Copy CM4 binary
run : cp -f ./target/armv7-unknown-linux-musleabihf/release/upico upico
- name: Compress CM4/A-04/A-06 Build
- name: Compress CM4 Build
uses: a7ul/tar-action@v1.1.0
with:
command: c
Expand All @@ -74,7 +74,7 @@ jobs:
./install.sh
./upico.service
./upico
outPath: upico_${{ github.ref_name }}.armv7.tar.gz
outPath: upico_${{ github.ref_name }}.cm4.tar.gz
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -86,5 +86,5 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
upico_${{ github.ref_name }}.riscv64gc.tar.gz
upico_${{ github.ref_name }}.armv7.tar.gz
upico_${{ github.ref_name }}.r01.tar.gz
upico_${{ github.ref_name }}.cm4.tar.gz
11 changes: 9 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Second project name is `atto`, cause 10<sup>−6</sup> * 10<sup>-12</sup> = 10<s

### Control app installation

⚠️ Only R-01 core is supported for now.
⚠️ Only R-01 and CM4 core are supported for now.

1. Download latest build from [Releases page](https://github.com/dotcypress/upico/releases)
2. Extract installer: `mkdir dist && tar -xzf upico_%version%.%arch%.tar.gz -C dist`
2. Extract installer: `mkdir dist && tar -xzf upico_%version%.%core%.tar.gz -C dist`
3. Install: `cd dist && sudo ./install.sh`
4. Cleanup: `cd .. && rm -rf dist`
5. Print help: `upico help`
Expand Down Expand Up @@ -81,6 +81,13 @@ See other examples: https://github.com/raspberrypi/pico-examples
╚══════╩══════╝
```

## Errata

### CM4 core & uPico PCB rev:0x02

* External 5V(AUX) switch isn't supported, 5V is always present on pin header.
* Overcurrent reporting feature isn't supported.

## License

Licensed under either of
Expand Down
28 changes: 14 additions & 14 deletions src/gpio.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
use crate::*;
use std::time::Duration;

#[cfg(not(target_arch = "arm"))]
mod pins {
pub const PICO_RUN: usize = 38;
pub const PICO_BOOT: usize = 37;
pub const AUX_EN: usize = 40;
pub const VDD_EN: usize = 36;
pub const USB_EN: usize = 31;
pub const AUX_OCP: usize = 39;
pub const VDD_OCP: usize = 35;
pub const USB_OCP: usize = 30;
}

#[cfg(target_arch = "arm")]
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
mod pins {
pub const PICO_BOOT: usize = 27;
pub const VDD_EN: usize = 26;
Expand All @@ -27,6 +15,18 @@ mod pins {
pub const USB_OCP: usize = 20;
}

#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
mod pins {
pub const PICO_RUN: usize = 38;
pub const PICO_BOOT: usize = 37;
pub const AUX_EN: usize = 40;
pub const VDD_EN: usize = 36;
pub const USB_EN: usize = 31;
pub const AUX_OCP: usize = 39;
pub const VDD_OCP: usize = 35;
pub const USB_OCP: usize = 30;
}

pub struct Gpio {}

impl Gpio {
Expand All @@ -46,7 +46,7 @@ impl Gpio {
Self::set_pin_state(pins::VDD_EN, true)?;
Self::set_pin_state(pins::PICO_RUN, false)?;
Self::set_pin_state(pins::PICO_BOOT, !boot)?;
thread::sleep(Duration::from_millis(100));
thread::sleep(Duration::from_millis(200));
Self::set_pin_state(pins::VDD_EN, false)?;
Self::set_pin_state(pins::PICO_RUN, true)?;
if boot {
Expand Down
27 changes: 19 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ fn main() {
fn cli() -> Command {
let mount_arg = arg!(mount: -m "Mount Pico disk");
let dev_arg = arg!(-d <PICO_DEV> "Path to Pico disk device").default_value("/dev/sda1");
let line_arg = arg!(<LINE> "Power line")
.value_parser([
let line_arg = arg!(<LINE> "Power line").required(true);
let line_arg = if cfg!(any(target_arch = "arm", target_arch = "aarch64")) {
line_arg.value_parser([PossibleValue::new("vdd"), PossibleValue::new("usb")])
} else {
line_arg.value_parser([
PossibleValue::new("aux"),
PossibleValue::new("vdd"),
PossibleValue::new("usb"),
])
.required(true);
};

Command::new("upico")
.about("uPico control app")
.version(env!("CARGO_PKG_VERSION"))
Expand All @@ -64,10 +68,13 @@ fn cli() -> Command {
.about("Install firmware to Pico")
.arg_required_else_help(true)
.arg(arg!(<FIRMWARE> "Path to UF2 firmware file").required(true))
.arg(
.arg(if cfg!(any(target_arch = "arm", target_arch = "aarch64")) {
arg!(-p <PICO_PATH> "Path to mounted Pico disk")
.default_value("/media/pi/RPI-RP2")
} else {
arg!(-p <PICO_PATH> "Path to mounted Pico disk")
.default_value("/media/cpi/RPI-RP2"),
)
.default_value("/media/cpi/RPI-RP2")
})
.arg(mount_arg)
.arg(dev_arg),
)
Expand All @@ -79,7 +86,11 @@ fn cli() -> Command {
.subcommand(Command::new("on").about("Power on").arg(line_arg.clone()))
.subcommand(Command::new("off").about("Power off").arg(line_arg.clone()))
.subcommand(Command::new("cycle").about("Power cycle").arg(line_arg))
.subcommand(Command::new("status").about("Power status")),
.subcommand(
Command::new("status")
.about("Power status")
.hide(cfg!(any(target_arch = "arm", target_arch = "aarch64"))),
),
)
.subcommand(Command::new("pinout").about("Print pinout diagram"))
}
Expand Down Expand Up @@ -179,7 +190,7 @@ fn run() -> AppResult {
let line = parse_power_line(cmd)?;
Service::send(Request::PowerCycle(line))?;
}
Some(("status", _)) => {
Some(("status", _)) if cfg!(not(any(target_arch = "arm", target_arch = "aarch64"))) => {
if let Response::PowerReport(report) = Service::send(Request::PowerStatus)? {
print_power_state("AUX", report.aux);
print_power_state("VDD", report.vdd);
Expand Down
2 changes: 1 addition & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Service {

let packet = to_vec(&req).unwrap();
stream.write(&packet).map_err(AppError::IoError)?;
thread::sleep(Duration::from_millis(250));
thread::sleep(Duration::from_millis(300));

let mut scratch = [0; 64];
let n = stream.read(&mut scratch).map_err(AppError::ServiceError)?;
Expand Down

0 comments on commit be8d343

Please sign in to comment.