humpback-dds/examples/fpga_config.rs

80 lines
1.8 KiB
Rust
Raw Normal View History

2020-08-07 13:36:00 +08:00
#![no_main]
#![no_std]
2020-09-10 17:44:33 +08:00
extern crate log;
2020-09-17 10:21:50 +08:00
use log::debug;
2020-09-17 12:59:22 +08:00
use stm32h7xx_hal::{pac, prelude::*, spi};
2020-08-07 13:36:00 +08:00
use cortex_m;
use cortex_m::asm::nop;
use cortex_m_rt::entry;
2020-09-17 11:21:24 +08:00
use firmware::flash::flash_ice40_fpga;
2020-09-10 17:44:33 +08:00
#[path = "util/logger.rs"]
mod logger;
2020-08-07 13:36:00 +08:00
#[entry]
fn main() -> ! {
2020-09-10 17:44:33 +08:00
let mut cp = cortex_m::Peripherals::take().unwrap();
2020-08-07 13:36:00 +08:00
let dp = pac::Peripherals::take().unwrap();
let pwr = dp.PWR.constrain();
let vos = pwr.freeze();
let rcc = dp.RCC.constrain();
let ccdr = rcc
.sys_ck(400.mhz())
.pll1_q_ck(48.mhz())
2020-09-10 17:44:33 +08:00
.pll1_r_ck(400.mhz()) // for TRACECK
2020-08-07 13:36:00 +08:00
.freeze(vos, &dp.SYSCFG);
2020-09-10 17:44:33 +08:00
unsafe {
logger::enable_itm(&dp.DBGMCU, &mut cp.DCB, &mut cp.ITM);
}
2020-08-07 13:36:00 +08:00
2020-09-17 12:59:22 +08:00
let delay = cp.SYST.delay(ccdr.clocks);
2020-08-07 13:36:00 +08:00
let gpioa = dp.GPIOA.split(ccdr.peripheral.GPIOA);
let gpiob = dp.GPIOB.split(ccdr.peripheral.GPIOB);
let gpiod = dp.GPIOD.split(ccdr.peripheral.GPIOD);
let gpiof = dp.GPIOF.split(ccdr.peripheral.GPIOF);
2020-09-10 17:44:33 +08:00
// gpiob.pb3.into_alternate_af0().set_speed(Speed::VeryHigh);
logger::init();
debug!("Flashing configuration bitstream to iCE40 HX8K on Humpback.");
2020-08-07 13:36:00 +08:00
// Using SPI_1 alternate functions (af5)
let fpga_sck = gpiob.pb3.into_alternate_af5();
let fpga_sdo = gpiob.pb4.into_alternate_af5();
let fpga_sdi = gpiob.pb5.into_alternate_af5();
// Setup SPI_SS_B and CRESET_B
2020-09-17 12:59:22 +08:00
let fpga_ss = gpioa.pa4.into_push_pull_output();
let fpga_creset = gpiof.pf3.into_open_drain_output();
2020-08-07 13:36:00 +08:00
// Setup CDONE
let fpga_cdone = gpiod.pd15.into_pull_up_input();
// Setup SPI interface
2020-09-17 12:59:22 +08:00
let fpga_cfg_spi = dp.SPI1.spi(
2020-08-07 13:36:00 +08:00
(fpga_sck, fpga_sdo, fpga_sdi),
spi::MODE_3,
12.mhz(),
ccdr.peripheral.SPI1,
&ccdr.clocks,
);
2020-09-17 11:21:24 +08:00
// Pre-load the configuration bytes
2020-09-16 17:46:58 +08:00
let config_data = include_bytes!("../build/top.bin");
2020-09-17 11:48:32 +08:00
flash_ice40_fpga(fpga_cfg_spi, fpga_ss, fpga_creset, fpga_cdone, delay, config_data).unwrap();
2020-08-07 13:36:00 +08:00
loop {
nop();
}
}