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-08-07 13:36:00 +08:00
|
|
|
use stm32h7xx_hal::hal::digital::v2::{
|
|
|
|
InputPin,
|
|
|
|
OutputPin,
|
|
|
|
};
|
2020-09-10 17:44:33 +08:00
|
|
|
use stm32h7xx_hal::{gpio::Speed, pac, prelude::*, spi};
|
2020-08-07 13:36:00 +08:00
|
|
|
|
|
|
|
use cortex_m;
|
|
|
|
use cortex_m::asm::nop;
|
|
|
|
use cortex_m_rt::entry;
|
|
|
|
|
|
|
|
use core::ptr;
|
|
|
|
use nb::block;
|
|
|
|
|
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
|
|
|
|
|
|
|
let mut delay = cp.SYST.delay(ccdr.clocks);
|
|
|
|
|
|
|
|
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
|
|
|
|
let mut fpga_ss = gpioa.pa4.into_push_pull_output();
|
|
|
|
let mut fpga_creset = gpiof.pf3.into_open_drain_output();
|
|
|
|
|
|
|
|
// Setup CDONE
|
|
|
|
let fpga_cdone = gpiod.pd15.into_pull_up_input();
|
|
|
|
|
|
|
|
// Setup SPI interface
|
|
|
|
let mut fpga_cfg_spi = dp.SPI1.spi(
|
|
|
|
(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:21:24 +08:00
|
|
|
flash_ice40_fpga(fpga_cfg_spi, fpga_ss, fpga_creset, fpga_cdone, delay, config_data)?;
|
2020-08-07 13:36:00 +08:00
|
|
|
|
|
|
|
loop {
|
|
|
|
nop();
|
|
|
|
}
|
|
|
|
}
|