From a75568bd4235572837e8521bfe8ffcd6416fc87f Mon Sep 17 00:00:00 2001 From: newell Date: Tue, 13 Aug 2024 13:52:21 -0700 Subject: [PATCH 01/10] EBAZ4205 Initial commit --- experiments/Cargo.toml | 1 + experiments/src/main.rs | 3 +- libboard_zynq/Cargo.toml | 1 + libboard_zynq/src/clocks/source.rs | 2 + libboard_zynq/src/ddr/mod.rs | 121 ++++++++++++++++++----------- libboard_zynq/src/eth/phy/mod.rs | 12 ++- libboard_zynq/src/sdio/mod.rs | 18 ++++- libboard_zynq/src/stdio.rs | 6 +- libboard_zynq/src/uart/mod.rs | 33 ++++++++ libconfig/Cargo.toml | 1 + libconfig/src/net_settings.rs | 4 + libsupport_zynq/Cargo.toml | 1 + openocd/ebaz4205.cfg | 33 ++++++++ szl/Cargo.toml | 1 + 14 files changed, 187 insertions(+), 50 deletions(-) create mode 100644 openocd/ebaz4205.cfg diff --git a/experiments/Cargo.toml b/experiments/Cargo.toml index b8456c8..aa06754 100644 --- a/experiments/Cargo.toml +++ b/experiments/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [features] target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706"] target_coraz7 = ["libboard_zynq/target_coraz7", "libsupport_zynq/target_coraz7"] +target_ebaz4205 = ["libboard_zynq/target_ebaz4205", "libsupport_zynq/target_ebaz4205"] target_redpitaya = ["libboard_zynq/target_redpitaya", "libsupport_zynq/target_redpitaya"] target_kasli_soc = ["libboard_zynq/target_kasli_soc", "libsupport_zynq/target_kasli_soc"] default = ["target_zc706"] diff --git a/experiments/src/main.rs b/experiments/src/main.rs index cf86587..14b0379 100644 --- a/experiments/src/main.rs +++ b/experiments/src/main.rs @@ -116,6 +116,7 @@ pub fn main_core0() { #[cfg(any( feature = "target_zc706", + feature = "target_ebaz4205", feature = "target_redpitaya", feature = "target_kasli_soc", ))] @@ -203,7 +204,7 @@ pub fn main_core0() { let mut err_cdwn = timer.countdown(); let mut err_state = true; let mut led = zynq::error_led::ErrorLED::error_led(); - task::spawn( async move { + task::spawn( async move { loop { led.toggle(err_state); err_state = !err_state; diff --git a/libboard_zynq/Cargo.toml b/libboard_zynq/Cargo.toml index d3b4ae2..bae2d5d 100644 --- a/libboard_zynq/Cargo.toml +++ b/libboard_zynq/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [features] target_zc706 = [] target_coraz7 = [] +target_ebaz4205 = [] target_redpitaya = [] target_kasli_soc = [] ipv6 = [ "smoltcp/proto-ipv6" ] diff --git a/libboard_zynq/src/clocks/source.rs b/libboard_zynq/src/clocks/source.rs index 4bbacbf..6c547d1 100644 --- a/libboard_zynq/src/clocks/source.rs +++ b/libboard_zynq/src/clocks/source.rs @@ -6,6 +6,8 @@ use super::slcr; pub const PS_CLK: u32 = 33_333_333; #[cfg(feature = "target_coraz7")] pub const PS_CLK: u32 = 50_000_000; +#[cfg(feature = "target_ebaz4205")] +pub const PS_CLK: u32 = 33_333_333; #[cfg(feature = "target_redpitaya")] pub const PS_CLK: u32 = 33_333_333; #[cfg(feature = "target_kasli_soc")] diff --git a/libboard_zynq/src/ddr/mod.rs b/libboard_zynq/src/ddr/mod.rs index d1be20a..3ae588e 100644 --- a/libboard_zynq/src/ddr/mod.rs +++ b/libboard_zynq/src/ddr/mod.rs @@ -16,6 +16,10 @@ const DDR_FREQ: u32 = 666_666_666; /// Micron MT41K256M16HA-125: 800 MHz DDR3L, max supported 533 MHz const DDR_FREQ: u32 = 525_000_000; +#[cfg(feature = "target_ebaz4205")] +/// EtronTech Memory EM6GD16EWKG-12H: 800 MHz DDR3 at 533 MHz +const DDR_FREQ: u32 = 533_333_333; + #[cfg(feature = "target_redpitaya")] /// Alliance Memory AS4C256M16D3B: 800 MHz DDR3 at 533 MHz const DDR_FREQ: u32 = 533_333_333; @@ -147,22 +151,23 @@ impl DdrRam { .output_en(slcr::DdriobOutputEn::Obuf); #[cfg(feature = "target_zc706")] let data1_config = data0_config.clone(); - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_redpitaya", + feature = "target_kasli_soc", + ))] let data0_config = slcr::DdriobConfig::zeroed() .inp_type(slcr::DdriobInputType::VrefDifferential) .term_en(true) .dci_type(slcr::DdriobDciType::Termination) .output_en(slcr::DdriobOutputEn::Obuf); - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] - let data1_config = slcr::DdriobConfig::zeroed() - .pullup_en(true); - #[cfg(feature = "target_redpitaya")] - let data0_config = slcr::DdriobConfig::zeroed() - .inp_type(slcr::DdriobInputType::VrefDifferential) - .term_en(true) - .dci_type(slcr::DdriobDciType::Termination) - .output_en(slcr::DdriobOutputEn::Obuf); - #[cfg(feature = "target_redpitaya")] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_redpitaya", + feature = "target_kasli_soc", + ))] let data1_config = slcr::DdriobConfig::zeroed() .pullup_en(true); slcr.ddriob_data0.write(data0_config); @@ -176,22 +181,23 @@ impl DdrRam { .output_en(slcr::DdriobOutputEn::Obuf); #[cfg(feature = "target_zc706")] let diff1_config = diff0_config.clone(); - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_redpitaya", + feature = "target_kasli_soc", + ))] let diff0_config = slcr::DdriobConfig::zeroed() .inp_type(slcr::DdriobInputType::Differential) .term_en(true) .dci_type(slcr::DdriobDciType::Termination) .output_en(slcr::DdriobOutputEn::Obuf); - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] - let diff1_config = slcr::DdriobConfig::zeroed() - .pullup_en(true); - #[cfg(feature = "target_redpitaya")] - let diff0_config = slcr::DdriobConfig::zeroed() - .inp_type(slcr::DdriobInputType::Differential) - .term_en(true) - .dci_type(slcr::DdriobDciType::Termination) - .output_en(slcr::DdriobOutputEn::Obuf); - #[cfg(feature = "target_redpitaya")] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_redpitaya", + feature = "target_kasli_soc", + ))] let diff1_config = slcr::DdriobConfig::zeroed() .pullup_en(true); slcr.ddriob_diff0.write(diff0_config); @@ -210,7 +216,12 @@ impl DdrRam { slcr.ddriob_drive_slew_clock.write(0x00F9861C); } - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_redpitaya", + feature = "target_kasli_soc", + ))] slcr.ddriob_ddr_ctrl.modify(|_, w| w .vref_int_en(false) .vref_ext_en_lower(true) @@ -224,13 +235,6 @@ impl DdrRam { .vref_ext_en_lower(false) .vref_ext_en_upper(false) ); - #[cfg(feature = "target_redpitaya")] - slcr.ddriob_ddr_ctrl.modify(|_, w| w - .vref_int_en(false) - .vref_ext_en_lower(true) - .vref_ext_en_upper(false) - .refio_en(true) - ); }); } @@ -242,6 +246,13 @@ impl DdrRam { .t_rfc_min(0x9e) .post_selfref_gap_x32(0x10) ); + #[cfg(feature = "target_ebaz4205")] + self.regs.dram_param0.write( + regs::DramParam0::zeroed() + .t_rc(0x1a) // 48.75 ns / 1.875 ns = 26 clock cycles + .t_rfc_min(0x56) // 160 ns / 1.875 ns = 85.333 --> 86 clock cycles + .post_selfref_gap_x32(0x10) // Default value + ); #[cfg(feature = "target_redpitaya")] self.regs.dram_param0.write( regs::DramParam0::zeroed() @@ -256,6 +267,12 @@ impl DdrRam { .t_rfc_min(0x56) .post_selfref_gap_x32(0x10) ); + #[cfg(feature = "target_ebaz4205")] + self.regs.dram_param1.modify( + |_, w| w + .t_faw(0x16) // 40 ns / 1.875 ns = 21.33 --> 22 clock cycles + .t_ras_min(0x13) // 35 ns / 1.875 ns = 18.66 --> 19 clock cycles + ); #[cfg(feature = "target_redpitaya")] self.regs.dram_param1.modify( |_, w| w @@ -277,6 +294,11 @@ impl DdrRam { .rd2pre(0x4) .t_rcd(0x7) ); + #[cfg(feature = "target_ebaz4205")] + self.regs.dram_param3.modify( + |_, w| w + .t_rp(7) + ); #[cfg(feature = "target_redpitaya")] self.regs.dram_param3.modify( |_, w| w @@ -298,19 +320,21 @@ impl DdrRam { .emr(0x4) ); - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_redpitaya", + feature = "target_kasli_soc", + ))] self.regs.phy_configs[2].modify( |_, w| w.data_slice_in_use(false) ); - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] - self.regs.phy_configs[3].modify( - |_, w| w.data_slice_in_use(false) - ); - #[cfg(feature = "target_redpitaya")] - self.regs.phy_configs[2].modify( - |_, w| w.data_slice_in_use(false) - ); - #[cfg(feature = "target_redpitaya")] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_redpitaya", + feature = "target_kasli_soc", + ))] self.regs.phy_configs[3].modify( |_, w| w.data_slice_in_use(false) ); @@ -354,7 +378,11 @@ impl DdrRam { .gatelvl_init_ratio(0xee) ); - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_kasli_soc"), + )] self.regs.reg_64.modify( |_, w| w .phy_ctrl_slave_ratio(0x100) @@ -390,9 +418,12 @@ impl DdrRam { fn reset_ddrc(&mut self, mut f: F) { #[cfg(feature = "target_zc706")] let width = regs::DataBusWidth::Width32bit; - #[cfg(any(feature = "target_coraz7", feature = "target_kasli_soc"))] - let width = regs::DataBusWidth::Width16bit; - #[cfg(feature = "target_redpitaya")] + #[cfg(any( + feature = "target_coraz7", + feature = "target_ebaz4205", + feature = "target_redpitaya", + feature = "target_kasli_soc", + ))] let width = regs::DataBusWidth::Width16bit; self.regs.ddrc_ctrl.modify(|_, w| w .soft_rstb(false) @@ -410,6 +441,7 @@ impl DdrRam { } #[cfg(any( feature = "target_coraz7", + feature = "target_ebaz4205", feature = "target_redpitaya", feature = "target_kasli_soc", ))] @@ -446,6 +478,7 @@ impl DdrRam { let megabytes = 1023; #[cfg(any( feature = "target_coraz7", + feature = "target_ebaz4205", feature = "target_redpitaya", feature = "target_kasli_soc", ))] diff --git a/libboard_zynq/src/eth/phy/mod.rs b/libboard_zynq/src/eth/phy/mod.rs index 84cd06f..5161609 100644 --- a/libboard_zynq/src/eth/phy/mod.rs +++ b/libboard_zynq/src/eth/phy/mod.rs @@ -83,6 +83,7 @@ pub struct Phy { const OUI_MARVELL: u32 = 0x005043; const OUI_REALTEK: u32 = 0x000732; const OUI_LANTIQ : u32 = 0x355969; +const OUI_ICPLUS : u32 = 0x02430c; //only change pages on Kasli-SoC's Marvel 88E11xx #[cfg(feature="target_kasli_soc")] @@ -117,6 +118,13 @@ impl Phy { model: 0, .. }) => true, + Some(PhyIdentifier { + oui: OUI_ICPLUS, + // IP101G-DS-R01 + model: 5, + rev: 4, + .. + }) => true, _ => false, } }).map(|addr| Phy { addr }) @@ -141,7 +149,7 @@ impl Phy { { #[cfg(feature="target_kasli_soc")] pa.write_phy(self.addr, PAGE_REGISTER, PR::page().into()); - + let reg = pa.read_phy(self.addr, PR::addr()).into(); let reg = f(reg); pa.write_phy(self.addr, PR::addr(), reg.into()) @@ -160,7 +168,7 @@ impl Phy { PA: PhyAccess, F: FnMut(Leds) -> Leds, { - self.modify_reg(pa, f) + self.modify_reg(pa, f) } pub fn get_control(&self, pa: &mut PA) -> Control { diff --git a/libboard_zynq/src/sdio/mod.rs b/libboard_zynq/src/sdio/mod.rs index 6e3cb4b..f0025dc 100644 --- a/libboard_zynq/src/sdio/mod.rs +++ b/libboard_zynq/src/sdio/mod.rs @@ -116,8 +116,8 @@ impl Sdio { .speed(true), ); } - // redpitaya card detect pin - #[cfg(any(feature = "target_redpitaya", feature = "target_kasli_soc"))] + // kasli_soc and redpitaya card detect pin + #[cfg(any(feature = "target_kasli_soc", feature = "target_redpitaya"))] { unsafe { slcr.sd0_wp_cd_sel.write(46 << 16); @@ -128,6 +128,20 @@ impl Sdio { .speed(true), ); } + // ebaz4205 card detect pin + #[cfg(feature = "target_ebaz4205")] + { + unsafe { + slcr.sd0_wp_cd_sel.write(34 << 16); + } + slcr.mio_pin_34.write( + slcr::MioPin34::zeroed() + .io_type(slcr::IoBufferType::Lvcmos33) + .pullup(true) + .speed(true), + ); + } + slcr.sdio_rst_ctrl.reset_sdio0(); slcr.aper_clk_ctrl.enable_sdio0(); slcr.sdio_clk_ctrl.enable_sdio0(); diff --git a/libboard_zynq/src/stdio.rs b/libboard_zynq/src/stdio.rs index 3a2c275..ffda0e3 100644 --- a/libboard_zynq/src/stdio.rs +++ b/libboard_zynq/src/stdio.rs @@ -47,7 +47,11 @@ impl DerefMut for LazyUart { LazyUart::Uninitialized => { #[cfg(any(feature = "target_coraz7", feature = "target_redpitaya"))] let uart = Uart::uart0(UART_RATE); - #[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))] + #[cfg(any( + feature = "target_zc706", + feature = "target_ebaz4205", + feature = "target_kasli_soc", + ))] let uart = Uart::uart1(UART_RATE); *self = LazyUart::Initialized(uart); self diff --git a/libboard_zynq/src/uart/mod.rs b/libboard_zynq/src/uart/mod.rs index 391a0f2..3da07ea 100644 --- a/libboard_zynq/src/uart/mod.rs +++ b/libboard_zynq/src/uart/mod.rs @@ -79,6 +79,39 @@ impl Uart { self_ } + #[cfg(feature = "target_ebaz4205")] + pub fn uart1(baudrate: u32) -> Self { + slcr::RegisterBlock::unlocked(|slcr| { + // Route UART 1 RxD/TxD Signals to MIO Pins + // TX pin + slcr.mio_pin_24.write( + slcr::MioPin24::zeroed() + .l3_sel(0b111) + .io_type(slcr::IoBufferType::Lvcmos33) + .pullup(true) + ); + // RX pin + slcr.mio_pin_25.write( + slcr::MioPin25::zeroed() + .tri_enable(true) + .l3_sel(0b111) + .io_type(slcr::IoBufferType::Lvcmos33) + .pullup(true) + ); + }); + + slcr::RegisterBlock::unlocked(|slcr| { + slcr.uart_rst_ctrl.reset_uart1(); + slcr.aper_clk_ctrl.enable_uart1(); + slcr.uart_clk_ctrl.enable_uart1(); + }); + let mut self_ = Uart { + regs: regs::RegisterBlock::uart1(), + }; + self_.configure(baudrate); + self_ + } + pub fn write_byte(&mut self, value: u8) { while self.tx_fifo_full() {} diff --git a/libconfig/Cargo.toml b/libconfig/Cargo.toml index 43ea995..35265c5 100644 --- a/libconfig/Cargo.toml +++ b/libconfig/Cargo.toml @@ -13,6 +13,7 @@ log = "0.4" [features] target_zc706 = [] target_coraz7 = [] +target_ebaz4205 = [] target_redpitaya = [] target_kasli_soc = [] ipv6 = [] diff --git a/libconfig/src/net_settings.rs b/libconfig/src/net_settings.rs index fa3079f..03289c9 100644 --- a/libconfig/src/net_settings.rs +++ b/libconfig/src/net_settings.rs @@ -55,6 +55,10 @@ pub fn get_addresses(cfg: &Config) -> NetAddresses { let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x55]); #[cfg(feature = "target_redpitaya")] let mut ipv4_addr = IpAddress::v4(192, 168, 1, 55); + #[cfg(feature = "target_ebaz4205")] + let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x56]); + #[cfg(feature = "target_ebaz4205")] + let mut ipv4_addr = IpAddress::v4(192, 168, 1, 56); #[cfg(feature = "target_kasli_soc")] let mut hardware_addr = get_address_from_eeprom(); #[cfg(feature = "target_kasli_soc")] diff --git a/libsupport_zynq/Cargo.toml b/libsupport_zynq/Cargo.toml index 9adf2f9..18265ea 100644 --- a/libsupport_zynq/Cargo.toml +++ b/libsupport_zynq/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [features] target_zc706 = ["libboard_zynq/target_zc706"] target_coraz7 = ["libboard_zynq/target_coraz7"] +target_ebaz4205 = ["libboard_zynq/target_ebaz4205"] target_redpitaya = ["libboard_zynq/target_redpitaya"] target_kasli_soc = ["libboard_zynq/target_kasli_soc"] panic_handler = [] diff --git a/openocd/ebaz4205.cfg b/openocd/ebaz4205.cfg new file mode 100644 index 0000000..c1c0f08 --- /dev/null +++ b/openocd/ebaz4205.cfg @@ -0,0 +1,33 @@ +# The contents of this file are partially dependend on +# the adapter that you have. Please modify accordingly. +adapter driver ftdi +ftdi vid_pid 0x0403 0x6010 +ftdi channel 0 +# Every pin set as high impedance except TCK, TDI, TDO and TMS +ftdi layout_init 0x0008 0x000b + +# nSRST defined on pin CN2-13 of the MiniModule (pin ADBUS5 [AD5] on the FT2232H chip) +# This choice is arbitrary. Use other GPIO pin if desired. +ftdi layout_signal nSRST -data 0x0020 -oe 0x0020 + +transport select jtag +adapter speed 10000 + +set PL_TAPID 0x13722093 +set SMP 1 + +source ./zynq-7000.cfg + +reset_config srst_only srst_open_drain +adapter srst pulse_width 250 +adapter srst delay 400 + +source ./common.cfg + +reset halt + +# Disable MMU +targets $_TARGETNAME_1 +arm mcr 15 0 1 0 0 [expr { [arm mrc 15 0 1 0 0] & ~0xd }] +targets $_TARGETNAME_0 +arm mcr 15 0 1 0 0 [expr { [arm mrc 15 0 1 0 0] & ~0xd }] diff --git a/szl/Cargo.toml b/szl/Cargo.toml index b1a33ae..ac16fb0 100644 --- a/szl/Cargo.toml +++ b/szl/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [features] target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706", "libconfig/target_zc706"] target_coraz7 = ["libboard_zynq/target_coraz7", "libsupport_zynq/target_coraz7", "libconfig/target_coraz7"] +target_ebaz4205 = ["libboard_zynq/target_ebaz4205", "libsupport_zynq/target_ebaz4205", "libconfig/target_ebaz4205"] target_redpitaya = ["libboard_zynq/target_redpitaya", "libsupport_zynq/target_redpitaya", "libconfig/target_redpitaya"] target_kasli_soc = ["libboard_zynq/target_kasli_soc", "libsupport_zynq/target_kasli_soc", "libconfig/target_kasli_soc"] default = ["target_zc706"] -- 2.44.2 From eae21579bc350d252e93c7f40f3b57851f126ce7 Mon Sep 17 00:00:00 2001 From: newell Date: Wed, 4 Sep 2024 16:05:55 -0700 Subject: [PATCH 02/10] More updates. Fixed openocd. --- libboard_zynq/src/ddr/mod.rs | 3 ++- libboard_zynq/src/eth/mod.rs | 6 ++++-- openocd/ebaz4205.cfg | 2 +- szl/src/main.rs | 5 ++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libboard_zynq/src/ddr/mod.rs b/libboard_zynq/src/ddr/mod.rs index 3ae588e..9f57c37 100644 --- a/libboard_zynq/src/ddr/mod.rs +++ b/libboard_zynq/src/ddr/mod.rs @@ -478,11 +478,12 @@ impl DdrRam { let megabytes = 1023; #[cfg(any( feature = "target_coraz7", - feature = "target_ebaz4205", feature = "target_redpitaya", feature = "target_kasli_soc", ))] let megabytes = 512; + #[cfg(feature = "target_ebaz4205")] + let megabytes = 256; megabytes * 1024 * 1024 } diff --git a/libboard_zynq/src/eth/mod.rs b/libboard_zynq/src/eth/mod.rs index 8667533..9d0c0d6 100644 --- a/libboard_zynq/src/eth/mod.rs +++ b/libboard_zynq/src/eth/mod.rs @@ -154,6 +154,8 @@ pub struct Eth { impl Eth { pub fn eth0(macaddr: [u8; 6]) -> Self { + // EBAZ4205 ETH uses EMIO + #[cfg(not(feature = "target_ebaz4205"))] slcr::RegisterBlock::unlocked(|slcr| { // Manual example: 0x0000_1280 // MDIO @@ -511,7 +513,7 @@ impl PhyRst { }); Self::eth_reset_common(0xFFFF - 0x8000) } - + fn delay_ms(&mut self, ms: u64) { self.count_down.start(Milliseconds(ms)); nb::block!(self.count_down.wait()).unwrap(); @@ -531,7 +533,7 @@ impl PhyRst { self_.regs.gpio_direction.modify(|_, w| { w.phy_rst(true) }); - + self_ } diff --git a/openocd/ebaz4205.cfg b/openocd/ebaz4205.cfg index c1c0f08..db541f5 100644 --- a/openocd/ebaz4205.cfg +++ b/openocd/ebaz4205.cfg @@ -4,7 +4,7 @@ adapter driver ftdi ftdi vid_pid 0x0403 0x6010 ftdi channel 0 # Every pin set as high impedance except TCK, TDI, TDO and TMS -ftdi layout_init 0x0008 0x000b +ftdi layout_init 0x0088 0x008b # nSRST defined on pin CN2-13 of the MiniModule (pin ADBUS5 [AD5] on the FT2232H chip) # This choice is arbitrary. Use other GPIO pin if desired. diff --git a/szl/src/main.rs b/szl/src/main.rs index aafda8b..fc91b7e 100644 --- a/szl/src/main.rs +++ b/szl/src/main.rs @@ -80,12 +80,15 @@ pub fn main_core0() { ); info!("Simple Zynq Loader starting..."); - #[cfg(not(feature = "target_kasli_soc"))] + #[cfg(not(any(feature = "target_kasli_soc", feature = "target_ebaz4205")))] const CPU_FREQ: u32 = 800_000_000; #[cfg(feature = "target_kasli_soc")] const CPU_FREQ: u32 = 1_000_000_000; + #[cfg(feature = "target_ebaz4205")] + const CPU_FREQ: u32 = 666_666_666; + ArmPll::setup(2 * CPU_FREQ); Clocks::set_cpu_freq(CPU_FREQ); IoPll::setup(1_000_000_000); -- 2.44.2 From bb76c13ee01c8e5701ae48753e4e211522aaab1a Mon Sep 17 00:00:00 2001 From: newell Date: Thu, 5 Sep 2024 22:31:42 -0700 Subject: [PATCH 03/10] Remove cfg for eth --- libboard_zynq/src/eth/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/libboard_zynq/src/eth/mod.rs b/libboard_zynq/src/eth/mod.rs index 9d0c0d6..59e1d43 100644 --- a/libboard_zynq/src/eth/mod.rs +++ b/libboard_zynq/src/eth/mod.rs @@ -154,8 +154,6 @@ pub struct Eth { impl Eth { pub fn eth0(macaddr: [u8; 6]) -> Self { - // EBAZ4205 ETH uses EMIO - #[cfg(not(feature = "target_ebaz4205"))] slcr::RegisterBlock::unlocked(|slcr| { // Manual example: 0x0000_1280 // MDIO -- 2.44.2 From 6c3d901f0039e82c90a78087789842af275b12df Mon Sep 17 00:00:00 2001 From: newell Date: Fri, 20 Sep 2024 15:23:46 -0700 Subject: [PATCH 04/10] Create EMIO PLLSource --- libboard_zynq/src/clocks/mod.rs | 6 +++++ libboard_zynq/src/eth/mod.rs | 39 ++++++++++++++++++++++++++++++++ libboard_zynq/src/eth/phy/mod.rs | 4 ++-- libboard_zynq/src/slcr.rs | 8 ++++--- libconfig/src/net_settings.rs | 8 +++---- 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/libboard_zynq/src/clocks/mod.rs b/libboard_zynq/src/clocks/mod.rs index ee9cebd..24b9a56 100644 --- a/libboard_zynq/src/clocks/mod.rs +++ b/libboard_zynq/src/clocks/mod.rs @@ -1,3 +1,5 @@ +use core::unimplemented; + use libregister::{RegisterR, RegisterRW}; use super::slcr; pub use slcr::ArmPllSource; @@ -101,6 +103,8 @@ impl Clocks { self.ddr, slcr::PllSource::IoPll => self.io, + slcr::PllSource::EMIO => + unimplemented!(), }; pll / u32::from(uart_clk_ctrl.divisor()) } @@ -115,6 +119,8 @@ impl Clocks { self.ddr, slcr::PllSource::IoPll => self.io, + slcr::PllSource::EMIO => + unimplemented!(), }; pll / u32::from(sdio_clk_ctrl.divisor()) } diff --git a/libboard_zynq/src/eth/mod.rs b/libboard_zynq/src/eth/mod.rs index 59e1d43..3d6e312 100644 --- a/libboard_zynq/src/eth/mod.rs +++ b/libboard_zynq/src/eth/mod.rs @@ -16,6 +16,8 @@ pub mod tx; use super::time::Milliseconds; use embedded_hal::timer::CountDown; +use libcortex_a9::asm; + /// Size of all the buffers pub const MTU: usize = 1536; /// Maximum MDC clock @@ -65,17 +67,31 @@ impl Gem for Gem0 { slcr.gem0_clk_ctrl.write( // 0x0050_0801: 8, 5: 100 Mb/s // ...: 8, 1: 1000 Mb/s + #[cfg(not(feature = "target_ebaz4205"))] slcr::GemClkCtrl::zeroed() .clkact(true) .srcsel(slcr::PllSource::IoPll) .divisor(divisor0 as u8) + .divisor1(divisor1 as u8), + // ebaz4205 -- EMIO + #[cfg(feature = "target_ebaz4205")] + slcr::GemClkCtrl::zeroed() + .clkact(true) + .srcsel(slcr::PllSource::EMIO) + .divisor(divisor0 as u8) .divisor1(divisor1 as u8) ); // Enable gem0 recv clock slcr.gem0_rclk_ctrl.write( // 0x0000_0801 + #[cfg(not(feature = "target_ebaz4205"))] + slcr::RclkCtrl::zeroed() + .clkact(true), + // ebaz4205 -- EMIO + #[cfg(feature = "target_ebaz4205")] slcr::RclkCtrl::zeroed() .clkact(true) + .srcsel(true) ); }); } @@ -154,6 +170,7 @@ pub struct Eth { impl Eth { pub fn eth0(macaddr: [u8; 6]) -> Self { + #[cfg(not(feature = "target_ebaz4205"))] slcr::RegisterBlock::unlocked(|slcr| { // Manual example: 0x0000_1280 // MDIO @@ -281,6 +298,16 @@ impl Eth { ); }); + // This didn't help, might not need, keep for now, and remove later to test. + #[cfg(feature = "target_ebaz4205")] + slcr::RegisterBlock::unlocked(|slcr| { + // VREF internal generator + slcr.gpiob_ctrl.write( + slcr::GpiobCtrl::zeroed() + .vref_en(true) + ); + }); + Self::gem0(macaddr) } @@ -301,8 +328,12 @@ impl Eth { impl Eth { fn gem_common(macaddr: [u8; 6]) -> Self { + #[cfg(not(feature = "target_ebaz4205"))] GEM::setup_clock(TX_1000); + #[cfg(feature = "target_ebaz4205")] + GEM::setup_clock(TX_100); + #[cfg(feature="target_kasli_soc")] { let mut eth_reset_pin = PhyRst::rst_pin(); @@ -317,6 +348,14 @@ impl Eth { inner.configure(macaddr); + + // Used for debugging MDIO + // loop { + // let _phy = Phy::find(&mut inner); + // for _ in 0..100_000_000 { + // asm::nop(); + // } + // } let phy = Phy::find(&mut inner).expect("phy"); phy.reset(&mut inner); phy.restart_autoneg(&mut inner); diff --git a/libboard_zynq/src/eth/phy/mod.rs b/libboard_zynq/src/eth/phy/mod.rs index 5161609..a19c328 100644 --- a/libboard_zynq/src/eth/phy/mod.rs +++ b/libboard_zynq/src/eth/phy/mod.rs @@ -83,7 +83,8 @@ pub struct Phy { const OUI_MARVELL: u32 = 0x005043; const OUI_REALTEK: u32 = 0x000732; const OUI_LANTIQ : u32 = 0x355969; -const OUI_ICPLUS : u32 = 0x02430c; +const OUI_ICPLUS : u32 = 0x0090c3; +// const OUI_ICPLUS : u32 = 0x02430c; //only change pages on Kasli-SoC's Marvel 88E11xx #[cfg(feature="target_kasli_soc")] @@ -123,7 +124,6 @@ impl Phy { // IP101G-DS-R01 model: 5, rev: 4, - .. }) => true, _ => false, } diff --git a/libboard_zynq/src/slcr.rs b/libboard_zynq/src/slcr.rs index f887867..6b2d162 100644 --- a/libboard_zynq/src/slcr.rs +++ b/libboard_zynq/src/slcr.rs @@ -9,9 +9,11 @@ use libregister::{ #[repr(u8)] pub enum PllSource { - IoPll = 0b00, - ArmPll = 0b10, - DdrPll = 0b11, + IoPll = 0b000, + ArmPll = 0b010, + DdrPll = 0b011, + // Ethernet controller via EMIO + EMIO = 0b100, } #[repr(u8)] diff --git a/libconfig/src/net_settings.rs b/libconfig/src/net_settings.rs index 03289c9..d3ffc31 100644 --- a/libconfig/src/net_settings.rs +++ b/libconfig/src/net_settings.rs @@ -55,14 +55,14 @@ pub fn get_addresses(cfg: &Config) -> NetAddresses { let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x55]); #[cfg(feature = "target_redpitaya")] let mut ipv4_addr = IpAddress::v4(192, 168, 1, 55); - #[cfg(feature = "target_ebaz4205")] - let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x56]); - #[cfg(feature = "target_ebaz4205")] - let mut ipv4_addr = IpAddress::v4(192, 168, 1, 56); #[cfg(feature = "target_kasli_soc")] let mut hardware_addr = get_address_from_eeprom(); #[cfg(feature = "target_kasli_soc")] let mut ipv4_addr = IpAddress::v4(192, 168, 1, 56); + #[cfg(feature = "target_ebaz4205")] + let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x57]); + #[cfg(feature = "target_ebaz4205")] + let mut ipv4_addr = IpAddress::v4(192, 168, 1, 57); if let Ok(Ok(addr)) = cfg.read_str("mac").map(|s| s.parse()) { hardware_addr = addr; -- 2.44.2 From c3d92abe999e7293cf18d31b9b611c773ba80e06 Mon Sep 17 00:00:00 2001 From: newell Date: Mon, 23 Sep 2024 11:25:41 -0700 Subject: [PATCH 05/10] Update eth/mod.rs --- libboard_zynq/src/eth/mod.rs | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/libboard_zynq/src/eth/mod.rs b/libboard_zynq/src/eth/mod.rs index 3d6e312..159be13 100644 --- a/libboard_zynq/src/eth/mod.rs +++ b/libboard_zynq/src/eth/mod.rs @@ -298,16 +298,6 @@ impl Eth { ); }); - // This didn't help, might not need, keep for now, and remove later to test. - #[cfg(feature = "target_ebaz4205")] - slcr::RegisterBlock::unlocked(|slcr| { - // VREF internal generator - slcr.gpiob_ctrl.write( - slcr::GpiobCtrl::zeroed() - .vref_en(true) - ); - }); - Self::gem0(macaddr) } @@ -328,12 +318,8 @@ impl Eth { impl Eth { fn gem_common(macaddr: [u8; 6]) -> Self { - #[cfg(not(feature = "target_ebaz4205"))] GEM::setup_clock(TX_1000); - #[cfg(feature = "target_ebaz4205")] - GEM::setup_clock(TX_100); - #[cfg(feature="target_kasli_soc")] { let mut eth_reset_pin = PhyRst::rst_pin(); @@ -348,14 +334,6 @@ impl Eth { inner.configure(macaddr); - - // Used for debugging MDIO - // loop { - // let _phy = Phy::find(&mut inner); - // for _ in 0..100_000_000 { - // asm::nop(); - // } - // } let phy = Phy::find(&mut inner).expect("phy"); phy.reset(&mut inner); phy.restart_autoneg(&mut inner); -- 2.44.2 From 41f780e118a250c76435a24ea1172b783297ae8c Mon Sep 17 00:00:00 2001 From: newell Date: Mon, 23 Sep 2024 13:39:11 -0700 Subject: [PATCH 06/10] Clean up branch --- libboard_zynq/src/ddr/mod.rs | 10 +++++----- libboard_zynq/src/eth/mod.rs | 2 -- libboard_zynq/src/eth/phy/mod.rs | 1 - libboard_zynq/src/slcr.rs | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/libboard_zynq/src/ddr/mod.rs b/libboard_zynq/src/ddr/mod.rs index 9f57c37..b6ef3e7 100644 --- a/libboard_zynq/src/ddr/mod.rs +++ b/libboard_zynq/src/ddr/mod.rs @@ -249,9 +249,9 @@ impl DdrRam { #[cfg(feature = "target_ebaz4205")] self.regs.dram_param0.write( regs::DramParam0::zeroed() - .t_rc(0x1a) // 48.75 ns / 1.875 ns = 26 clock cycles - .t_rfc_min(0x56) // 160 ns / 1.875 ns = 85.333 --> 86 clock cycles - .post_selfref_gap_x32(0x10) // Default value + .t_rc(0x1a) + .t_rfc_min(0x56) + .post_selfref_gap_x32(0x10) ); #[cfg(feature = "target_redpitaya")] self.regs.dram_param0.write( @@ -270,8 +270,8 @@ impl DdrRam { #[cfg(feature = "target_ebaz4205")] self.regs.dram_param1.modify( |_, w| w - .t_faw(0x16) // 40 ns / 1.875 ns = 21.33 --> 22 clock cycles - .t_ras_min(0x13) // 35 ns / 1.875 ns = 18.66 --> 19 clock cycles + .t_faw(0x16) + .t_ras_min(0x13) ); #[cfg(feature = "target_redpitaya")] self.regs.dram_param1.modify( diff --git a/libboard_zynq/src/eth/mod.rs b/libboard_zynq/src/eth/mod.rs index 159be13..4bc06a0 100644 --- a/libboard_zynq/src/eth/mod.rs +++ b/libboard_zynq/src/eth/mod.rs @@ -16,8 +16,6 @@ pub mod tx; use super::time::Milliseconds; use embedded_hal::timer::CountDown; -use libcortex_a9::asm; - /// Size of all the buffers pub const MTU: usize = 1536; /// Maximum MDC clock diff --git a/libboard_zynq/src/eth/phy/mod.rs b/libboard_zynq/src/eth/phy/mod.rs index a19c328..1de8aae 100644 --- a/libboard_zynq/src/eth/phy/mod.rs +++ b/libboard_zynq/src/eth/phy/mod.rs @@ -84,7 +84,6 @@ const OUI_MARVELL: u32 = 0x005043; const OUI_REALTEK: u32 = 0x000732; const OUI_LANTIQ : u32 = 0x355969; const OUI_ICPLUS : u32 = 0x0090c3; -// const OUI_ICPLUS : u32 = 0x02430c; //only change pages on Kasli-SoC's Marvel 88E11xx #[cfg(feature="target_kasli_soc")] diff --git a/libboard_zynq/src/slcr.rs b/libboard_zynq/src/slcr.rs index 6b2d162..9a60940 100644 --- a/libboard_zynq/src/slcr.rs +++ b/libboard_zynq/src/slcr.rs @@ -12,7 +12,7 @@ pub enum PllSource { IoPll = 0b000, ArmPll = 0b010, DdrPll = 0b011, - // Ethernet controller via EMIO + // Ethernet controller 0 EMIO clock EMIO = 0b100, } -- 2.44.2 From 7453a2042015d56dfa78421415e1c8c6787cc4ae Mon Sep 17 00:00:00 2001 From: newell Date: Mon, 23 Sep 2024 19:46:10 -0700 Subject: [PATCH 07/10] Add ebaz4205 to build targets --- flake.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index d5b7144..13b0f67 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,7 @@ outputs = { self, nixpkgs, mozilla-overlay }: let pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) crosspkgs-overlay ]; }; - + rustManifest = pkgs.fetchurl { url = "https://static.rust-lang.org/dist/2021-01-29/channel-rust-nightly.toml"; sha256 = "sha256-EZKgw89AH4vxaJpUHmIMzMW/80wAFQlfcxRoBD9nz0c="; @@ -25,7 +25,7 @@ rustc = rust; cargo = rust; }); - + # https://doc.rust-lang.org/rustc/linker-plugin-lto.html#toolchain-compatibility llvmPackages_11 = pkgs.recurseIntoAttrs (pkgs.callPackage (import ./llvm/11) ({ inherit (pkgs.stdenvAdapters) overrideCC; @@ -142,11 +142,11 @@ "${target}-experiments" = build-crate "${target}-experiments" "experiments" "target_${target}"; "${target}-szl" = build-crate "${target}-szl" "szl" "target_${target}"; }; - targets = ["zc706" "coraz7" "redpitaya" "kasli_soc"]; + targets = ["zc706" "coraz7" "redpitaya" "kasli_soc" "ebaz4205"]; allTargetCrates = (builtins.foldl' (results: target: results // targetCrates target ) {} targets); - + szl = pkgs.runCommand "szl" {} (builtins.foldl' (commands: target: let szlResult = builtins.getAttr "${target}-szl" allTargetCrates; @@ -154,7 +154,7 @@ commands + "ln -s ${szlResult}/szl.elf $out/szl-${target}.elf\n" ) "mkdir $out\n" targets); in rec { - packages.x86_64-linux = { + packages.x86_64-linux = { inherit cargo-xbuild szl mkbootimage; zc706-fsbl = fsbl { board = "zc706"; }; } // allTargetCrates ; -- 2.44.2 From f2eebf44e9733ff7a2993fcdf763fe71b41c6fd9 Mon Sep 17 00:00:00 2001 From: newell Date: Tue, 24 Sep 2024 23:14:34 -0700 Subject: [PATCH 08/10] Review update --- libboard_zynq/src/slcr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libboard_zynq/src/slcr.rs b/libboard_zynq/src/slcr.rs index 9a60940..2a0b71e 100644 --- a/libboard_zynq/src/slcr.rs +++ b/libboard_zynq/src/slcr.rs @@ -13,7 +13,7 @@ pub enum PllSource { ArmPll = 0b010, DdrPll = 0b011, // Ethernet controller 0 EMIO clock - EMIO = 0b100, + Emio = 0b100, } #[repr(u8)] -- 2.44.2 From 8f2dc94cf828edb9547007d76f7cb3dbeee1f7f6 Mon Sep 17 00:00:00 2001 From: newell Date: Wed, 25 Sep 2024 19:28:47 -0700 Subject: [PATCH 09/10] Re-introduce deleted whitespace --- experiments/src/main.rs | 2 +- flake.nix | 8 ++++---- libboard_zynq/src/eth/mod.rs | 4 ++-- libboard_zynq/src/eth/phy/mod.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/experiments/src/main.rs b/experiments/src/main.rs index 14b0379..0f62d2f 100644 --- a/experiments/src/main.rs +++ b/experiments/src/main.rs @@ -204,7 +204,7 @@ pub fn main_core0() { let mut err_cdwn = timer.countdown(); let mut err_state = true; let mut led = zynq::error_led::ErrorLED::error_led(); - task::spawn( async move { + task::spawn( async move { loop { led.toggle(err_state); err_state = !err_state; diff --git a/flake.nix b/flake.nix index 13b0f67..869822f 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,7 @@ outputs = { self, nixpkgs, mozilla-overlay }: let pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) crosspkgs-overlay ]; }; - + rustManifest = pkgs.fetchurl { url = "https://static.rust-lang.org/dist/2021-01-29/channel-rust-nightly.toml"; sha256 = "sha256-EZKgw89AH4vxaJpUHmIMzMW/80wAFQlfcxRoBD9nz0c="; @@ -25,7 +25,7 @@ rustc = rust; cargo = rust; }); - + # https://doc.rust-lang.org/rustc/linker-plugin-lto.html#toolchain-compatibility llvmPackages_11 = pkgs.recurseIntoAttrs (pkgs.callPackage (import ./llvm/11) ({ inherit (pkgs.stdenvAdapters) overrideCC; @@ -146,7 +146,7 @@ allTargetCrates = (builtins.foldl' (results: target: results // targetCrates target ) {} targets); - + szl = pkgs.runCommand "szl" {} (builtins.foldl' (commands: target: let szlResult = builtins.getAttr "${target}-szl" allTargetCrates; @@ -154,7 +154,7 @@ commands + "ln -s ${szlResult}/szl.elf $out/szl-${target}.elf\n" ) "mkdir $out\n" targets); in rec { - packages.x86_64-linux = { + packages.x86_64-linux = { inherit cargo-xbuild szl mkbootimage; zc706-fsbl = fsbl { board = "zc706"; }; } // allTargetCrates ; diff --git a/libboard_zynq/src/eth/mod.rs b/libboard_zynq/src/eth/mod.rs index 4bc06a0..0f6fa45 100644 --- a/libboard_zynq/src/eth/mod.rs +++ b/libboard_zynq/src/eth/mod.rs @@ -526,7 +526,7 @@ impl PhyRst { }); Self::eth_reset_common(0xFFFF - 0x8000) } - + fn delay_ms(&mut self, ms: u64) { self.count_down.start(Milliseconds(ms)); nb::block!(self.count_down.wait()).unwrap(); @@ -546,7 +546,7 @@ impl PhyRst { self_.regs.gpio_direction.modify(|_, w| { w.phy_rst(true) }); - + self_ } diff --git a/libboard_zynq/src/eth/phy/mod.rs b/libboard_zynq/src/eth/phy/mod.rs index 1de8aae..9e85392 100644 --- a/libboard_zynq/src/eth/phy/mod.rs +++ b/libboard_zynq/src/eth/phy/mod.rs @@ -148,7 +148,7 @@ impl Phy { { #[cfg(feature="target_kasli_soc")] pa.write_phy(self.addr, PAGE_REGISTER, PR::page().into()); - + let reg = pa.read_phy(self.addr, PR::addr()).into(); let reg = f(reg); pa.write_phy(self.addr, PR::addr(), reg.into()) @@ -167,7 +167,7 @@ impl Phy { PA: PhyAccess, F: FnMut(Leds) -> Leds, { - self.modify_reg(pa, f) + self.modify_reg(pa, f) } pub fn get_control(&self, pa: &mut PA) -> Control { -- 2.44.2 From db22dafe28ada15a4147d11a44ec6504d02ed4b3 Mon Sep 17 00:00:00 2001 From: newell Date: Fri, 27 Sep 2024 18:55:32 -0700 Subject: [PATCH 10/10] Update EMIO to Emio --- libboard_zynq/src/clocks/mod.rs | 4 ++-- libboard_zynq/src/eth/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libboard_zynq/src/clocks/mod.rs b/libboard_zynq/src/clocks/mod.rs index 24b9a56..bc507c4 100644 --- a/libboard_zynq/src/clocks/mod.rs +++ b/libboard_zynq/src/clocks/mod.rs @@ -103,7 +103,7 @@ impl Clocks { self.ddr, slcr::PllSource::IoPll => self.io, - slcr::PllSource::EMIO => + slcr::PllSource::Emio => unimplemented!(), }; pll / u32::from(uart_clk_ctrl.divisor()) @@ -119,7 +119,7 @@ impl Clocks { self.ddr, slcr::PllSource::IoPll => self.io, - slcr::PllSource::EMIO => + slcr::PllSource::Emio => unimplemented!(), }; pll / u32::from(sdio_clk_ctrl.divisor()) diff --git a/libboard_zynq/src/eth/mod.rs b/libboard_zynq/src/eth/mod.rs index 0f6fa45..8dc0f62 100644 --- a/libboard_zynq/src/eth/mod.rs +++ b/libboard_zynq/src/eth/mod.rs @@ -75,7 +75,7 @@ impl Gem for Gem0 { #[cfg(feature = "target_ebaz4205")] slcr::GemClkCtrl::zeroed() .clkact(true) - .srcsel(slcr::PllSource::EMIO) + .srcsel(slcr::PllSource::Emio) .divisor(divisor0 as u8) .divisor1(divisor1 as u8) ); -- 2.44.2