-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new transport can be used to bootstrap the CW340 and the Voyager board via the FTDI chip. Signed-off-by: Douglas Reis <[email protected]>
- Loading branch information
Showing
10 changed files
with
495 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"includes": ["/__builtin__/opentitan.json"], | ||
"interface": "ftdi", | ||
"pins": [ | ||
{ | ||
"name": "RESET", | ||
"mode": "PushPull", | ||
"invert": false, | ||
"alias_of": "adbus5", | ||
"pull_mode": "None" | ||
}, | ||
{ | ||
"name": "TRST", | ||
"mode": "PushPull", | ||
"level": false, | ||
"alias_of": "adbus4", | ||
"pull_mode": "None" | ||
}, | ||
{ | ||
"name": "IOC0", | ||
"alias_of": "bdbus4" | ||
}, | ||
{ | ||
"name": "IOC1", | ||
"alias_of": "bdbus5" | ||
}, | ||
{ | ||
"name": "IOC2", | ||
"alias_of": "bdbus6" | ||
}, | ||
{ | ||
"name": "MUX_FTDI", | ||
"alias_of": "bdbus7" | ||
}, | ||
{ | ||
"name": "IOC8", | ||
"alias_of": "adbus6" | ||
}, | ||
{ | ||
"name": "IOC5", | ||
"alias_of": "adbus7" | ||
} | ||
], | ||
"spi": [ | ||
{ | ||
"name": "BOOTSTRAP" | ||
} | ||
], | ||
"uarts": [ | ||
{ | ||
"name": "console", | ||
"alias_of": "0" | ||
}, | ||
{ | ||
"name": "dut", | ||
"alias_of": "3" | ||
} | ||
], | ||
"strappings": [ | ||
{ | ||
"name": "ROM_BOOTSTRAP", | ||
"pins": [ | ||
{ | ||
"name": "SW_STRAP0", | ||
"level": true | ||
}, | ||
{ | ||
"name": "SW_STRAP1", | ||
"level": true | ||
}, | ||
{ | ||
"name": "SW_STRAP2", | ||
"level": true | ||
}, | ||
{ | ||
"name": "MUX_FTDI", | ||
"level": true | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use anyhow::Result; | ||
|
||
use crate::backend::BackendOpts; | ||
use crate::transport::ftdi::chip::Chip; | ||
use crate::transport::ftdi::Ftdi; | ||
use crate::transport::Transport; | ||
|
||
pub fn create<C: Chip + 'static>(_args: &BackendOpts) -> Result<Box<dyn Transport>> { | ||
Ok(Box::new(Ftdi::<C>::new()?)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub trait Chip { | ||
const VENDOR_ID: u16 = 0x0403; | ||
const PRODUCT_ID: u16; | ||
|
||
const UART_BAUD: u32 = 115200; | ||
|
||
const INTERFACES: &'static [ftdi::Interface]; | ||
} | ||
|
||
pub struct Ft4232hq {} | ||
|
||
impl Chip for Ft4232hq { | ||
const PRODUCT_ID: u16 = 0x6011; | ||
const INTERFACES: &'static [ftdi::Interface] = &[ | ||
ftdi::Interface::A, | ||
ftdi::Interface::B, | ||
// ftdi::Interface::C, | ||
ftdi::Interface::D, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use anyhow::Result; | ||
use std::cell::RefCell; | ||
use std::collections::HashMap; | ||
use std::rc::Rc; | ||
|
||
use embedded_hal::digital::OutputPin; | ||
use ftdi_embedded_hal as ftdi_hal; | ||
|
||
use crate::io::gpio::{GpioError, GpioPin, PinMode, PullMode}; | ||
use crate::transport::ftdi::Chip; | ||
|
||
pub struct Pin { | ||
pin: Rc<RefCell<ftdi_hal::OutputPin<ftdi::Device>>>, | ||
pinname: String, | ||
} | ||
|
||
impl Pin { | ||
pub fn open<C: Chip>( | ||
ftdi_interfaces: &HashMap<ftdi::Interface, ftdi_hal::FtHal<ftdi::Device>>, | ||
pinname: String, | ||
) -> Result<Self> { | ||
let pinname = pinname.to_lowercase(); | ||
let (interface, pin) = pinname.split_at(1); | ||
let interface = match interface { | ||
"a" => ftdi::Interface::A, | ||
"b" => ftdi::Interface::B, | ||
"c" => ftdi::Interface::C, | ||
"d" => ftdi::Interface::D, | ||
&_ => panic!("{}", pinname.clone()), | ||
}; | ||
|
||
let hal = ftdi_interfaces | ||
.get(&interface) | ||
.ok_or_else(|| GpioError::InvalidPinName(pinname.clone()))?; | ||
let pin = match pin { | ||
"dbus0" => hal.ad0(), | ||
"dbus1" => hal.ad1(), | ||
"dbus2" => hal.ad2(), | ||
"dbus3" => hal.ad3(), | ||
"dbus4" => hal.ad4(), | ||
"dbus5" => hal.ad5(), | ||
"dbus6" => hal.ad6(), | ||
"dbus7" => hal.ad7(), | ||
_ => return Err(GpioError::InvalidPinName(pinname).into()), | ||
}?; | ||
|
||
Ok(Self { | ||
pin: Rc::new(RefCell::new(pin)), | ||
pinname, | ||
}) | ||
} | ||
} | ||
|
||
impl GpioPin for Pin { | ||
fn read(&self) -> Result<bool> { | ||
Ok(false) | ||
} | ||
|
||
fn write(&self, value: bool) -> Result<()> { | ||
if value { | ||
self.pin.borrow_mut().set_high()?; | ||
} else { | ||
self.pin.borrow_mut().set_low()?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn set_mode(&self, _mode: PinMode) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn set_pull_mode(&self, _mode: PullMode) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn get_internal_pin_name(&self) -> Option<&str> { | ||
Some(&self.pinname) | ||
} | ||
} |
Oops, something went wrong.