Skip to content
Permalink
Browse files

Nicer version, flashing functionality, editorconfig, nice things

  • Loading branch information...
nickray committed May 28, 2019
1 parent 0596f53 commit d63406d857eebc7b42de455aec7c53bc7ae437d3
Showing with 85 additions and 27 deletions.
  1. +13 −0 .editorconfig
  2. +1 −0 .gitignore
  3. +1 −0 Cargo.toml
  4. +38 −10 Makefile
  5. +1 −1 build.rs
  6. +7 −0 flash.gdb
  7. +6 −0 rustfmt.toml
  8. +14 −10 src/main.rs
  9. +4 −6 src/usb/ccid/mod.rs
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
tab_width = 4
trim_trailing_whitespace = true
insert_final_newline = true

[Makefile]
indent_style = tab
@@ -2,3 +2,4 @@
**/*.rs.bk
Cargo.lock
.gdb_history
openocd.log
@@ -43,3 +43,4 @@ path = "./stm32l43x-usbd"
codegen-units = 1
debug = true
lto = true
opt-level = "s"
@@ -1,15 +1,43 @@
build:
rustup component add llvm-tools-preview
rustup target add thumbv7em-none-eabihf
cargo build --release
GDB ?= arm-none-eabi-gdb
TARGET ?= thumbv7em-none-eabihf
ZISSOU ?= target/$(TARGET)/release/zissou


zissou $(ZISSOU): build

fmt:
rustup component add rustfmt
cargo fmt

clippy:
rustup component add clippy
cargo clippy
bloat: build
cargo bloat $(BLOAT_ARGS) -n 50 --target $(TARGET)

build:
rustup install stable
rustup component add --toolchain stable llvm-tools-preview
rustup target add --toolchain stable $(TARGET)
cargo +stable build --release

clean:
cargo clean

# clippy:
# rustup component add clippy
# cargo clippy

flash: $(ZISSOU)
$(GDB) -q -x flash.gdb $(ZISSOU)

fmt:
rustup install nightly
rustup component add --toolchain nightly rustfmt
cargo +nightly fmt

openocd:
openocd

# NB: needs separate OpenOCD running
run: build
cargo +stable run --release

size: build
cargo size --bin zissou --release


@@ -5,7 +5,7 @@ fn main() {
// Put the git version into the binary using
// and environment variable.
let git_desc = Command::new("git")
.args(&["describe", "--all", "--tags", "--dirty"])
.args(&["describe", "--tags", "--dirty"])
.output()
.unwrap();
println!(
@@ -0,0 +1,7 @@
set history save on
set confirm off
target extended-remote | openocd -c "gdb_port pipe; log_output openocd.log" -f openocd.cfg
monitor reset halt
load
monitor reset
quit
@@ -0,0 +1,6 @@
ignore = [
"stm32l4xx-hal",
"stm32l43x-usbd",
"stm32-rs",
"usb-device",
]
@@ -4,17 +4,17 @@
extern crate panic_halt;
use cortex_m_rt::entry;

use stm32l4xx_hal as hal;
use hal::prelude::*;
use stm32l4xx_hal as hal;

use usb_device::prelude::*;
use stm32l43x_usbd::UsbBus;
use usb_device::prelude::*;

mod usb;

/// This is the version number generated by git.
static GIT_DESCRIBE: &'static str = env!("GIT_DESCRIBE");
static CCID_PRODUCT: &'static str = concat!("Zissou ", env!("GIT_DESCRIBE"));
static CCID_PRODUCT: &'static str = concat!("Zissou v", env!("GIT_DESCRIBE"));

#[entry]
fn main() -> ! {
@@ -23,7 +23,8 @@ fn main() -> ! {
// let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();

let clocks = rcc.cfgr
let clocks = rcc
.cfgr
.sysclk(48.mhz())
.pclk1(24.mhz())
.hsi48(true)
@@ -37,17 +38,20 @@ fn main() -> ! {
let pwr = dp.PWR.constrain(&mut rcc.apb1r1); // turns it on
pwr.enable_usb();

let usb_bus = UsbBus::usb_with_reset(dp.USB,
&mut rcc.apb1r1, &clocks, &mut gpioa.moder, &mut gpioa.otyper, usb_dp);
let usb_bus = UsbBus::usb_with_reset(
dp.USB,
&mut rcc.apb1r1,
&clocks,
&mut gpioa.moder,
&mut gpioa.otyper,
usb_dp,
);

let mut smartcard = usb::ccid::SmartCard::new(&usb_bus);
// let mut serial = cdc_acm::SerialPort::new(&usb_bus);

// vid/pid: http://pid.codes/1209/CC1D/
let mut usb_dev = UsbDeviceBuilder::new(
&usb_bus,
UsbVidPid(0x1209, 0xcc1d),
)
let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x1209, 0xcc1d))
.manufacturer("HardcoreBits")
.product(CCID_PRODUCT)
.serial_number("N/a")
@@ -1,6 +1,5 @@
/// Minimal and incomplete CDC-ACM implementation for the examples - this will eventually be a real
/// crate!

use core::cmp::min;
use usb_device::class_prelude::*;
use usb_device::Result;
@@ -20,9 +19,8 @@ const CCID_PROTOCOL_ICCD_B: u8 = 0x02;

const CCID_FUNCTIONAL_INTERFACE: u8 = 0x21;


pub struct SmartCard<'a, B: UsbBus> {
intf: InterfaceNumber, // need this?
intf: InterfaceNumber, // need this?
read_ep: EndpointOut<'a, B>,
write_ep: EndpointIn<'a, B>,
intr_ep: EndpointIn<'a, B>,
@@ -90,9 +88,11 @@ impl<B: UsbBus> UsbClass<B> for SmartCard<'_, B> {
self.intf,
USB_CLASS_CCID,
USB_SUBCLASS_NONE,
CCID_PROTOCOL_CCID)?;
CCID_PROTOCOL_CCID,
)?;

// TODO: wrap this in something nicer, just stealing Yubikey values here
#[rustfmt::skip]
writer.write(
CCID_FUNCTIONAL_INTERFACE,
&[
@@ -130,7 +130,6 @@ impl<B: UsbBus> UsbClass<B> for SmartCard<'_, B> {
writer.endpoint(&self.read_ep)?;
writer.endpoint(&self.intr_ep)?;


Ok(())
}

@@ -140,5 +139,4 @@ impl<B: UsbBus> UsbClass<B> for SmartCard<'_, B> {
self.write_ep.write(&[]).ok();
}
}

}

0 comments on commit d63406d

Please sign in to comment.
You can’t perform that action at this time.