Skip to content

Commit

Permalink
Connect MicroSD card slot to an SPI controller
Browse files Browse the repository at this point in the history
Wire up the on-board MicroSD card slot to an existing SPI controller
via pinmux.
CS line is connected at top-level.
Card detection is connected to fixed GPI.
  • Loading branch information
elliotb-lowrisc committed Oct 18, 2024
1 parent 8fcdbca commit f1d91d8
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 31 deletions.
9 changes: 9 additions & 0 deletions data/pins_sonata.xdc
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ set_property -dict { PACKAGE_PIN H6 IOSTANDARD LVCMOS18 } [get_ports ethmac_int
set_property PULLTYPE PULLUP [get_ports ethmac_intr]
set_property -dict { PACKAGE_PIN H5 IOSTANDARD LVCMOS18 } [get_ports ethmac_cs]

## MicroSD card slot
set_property -dict { PACKAGE_PIN U6 IOSTANDARD LVCMOS33 } [get_ports microsd_clk]
set_property -dict { PACKAGE_PIN V4 IOSTANDARD LVCMOS33 } [get_ports microsd_dat0]
# set_property -dict { PACKAGE_PIN R7 IOSTANDARD LVCMOS33 } [get_ports microsd_dat1] // unused
# set_property -dict { PACKAGE_PIN V5 IOSTANDARD LVCMOS33 } [get_ports microsd_dat2] // unused
set_property -dict { PACKAGE_PIN T8 IOSTANDARD LVCMOS33 } [get_ports microsd_dat3]
set_property -dict { PACKAGE_PIN R8 IOSTANDARD LVCMOS33 } [get_ports microsd_cmd]
set_property -dict { PACKAGE_PIN B3 IOSTANDARD LVCMOS18 } [get_ports microsd_det]

# HyperRAM
set_property -dict { PACKAGE_PIN B1 IOSTANDARD LVCMOS18 } [get_ports { hyperram_dq[0] }]
set_property -dict { PACKAGE_PIN E2 IOSTANDARD LVCMOS18 } [get_ports { hyperram_dq[1] }]
Expand Down
13 changes: 13 additions & 0 deletions data/top_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,16 @@ block_ios = [{block = "gpio", instance = 2, io = 0}]
name = "pmod1"
length = 8
block_ios = [{block = "gpio", instance = 2, io = 8}]

## MicroSD card slot
[[pins]]
name = "microsd_clk"
block_ios = [{block = "spi", instance = 3, io = "sck"}]

[[pins]]
name = "microsd_dat0"
block_ios = [{block = "spi", instance = 3, io = "rx"}]

[[pins]]
name = "microsd_cmd"
block_ios = [{block = "spi", instance = 3, io = "tx"}]
1 change: 1 addition & 0 deletions doc/ip/gpio.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The only difference between the registers is that the latter has debounced signa

| Bit offset | Description |
|------------|-------------|
| 17 | MicroSD card detection (0: present, 1: absent) |
| 16-14 | Software select switches (1, 2, 3) |
| 13 | mikroBUS interrupt |
| 12-5 | DIP switches |
Expand Down
4 changes: 3 additions & 1 deletion doc/ip/pinmux.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 17 additions & 12 deletions dv/verilator/top_verilator.sv
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ module top_verilator (input logic clk_i, rst_ni);
wire ethmac_rst, ethmac_cs;
// User LEDs.
wire [7:0] usrLed;
// MicroSD card slot
wire microsd_dat3;
// None of these signals is used presently.
wire unused_io_ = ^{mb0, mb1, ah_tmpio10, rph_g18, rph_g17,
rph_g16_ce2, rph_g8_ce0, rph_g7_ce1, ethmac_rst, ethmac_cs,
usrLed};
usrLed, microsd_dat3};

// Reporting of CHERI enable/disable and any exceptions that occur.
wire [CheriErrWidth-1:0] cheri_err;
Expand Down Expand Up @@ -260,7 +262,9 @@ module top_verilator (input logic clk_i, rst_ni);
.mb8(),
.pmod0(),
.pmod1(),

.microsd_clk(),
.microsd_dat0(),
.microsd_cmd(),
.tl_i(tlul_pkg::TL_H2D_DEFAULT),
.tl_o()
);
Expand All @@ -273,16 +277,17 @@ module top_verilator (input logic clk_i, rst_ni);
logic gp_ah_tmpio10, gp_mb1;

// CS outputs to SPI peripherals from controllers.
assign appspi_cs = spi_cs[0][0];
assign lcd_cs = spi_cs[1][0];
assign ethmac_cs = spi_cs[2][0];
assign rph_g8_ce0 = spi_cs[3][0];
assign rph_g7_ce1 = spi_cs[3][1];
assign ah_tmpio10 = spi_cs[3][2];
assign rph_g18 = spi_cs[4][0];
assign rph_g17 = spi_cs[4][1];
assign rph_g16_ce2 = spi_cs[4][2];
assign mb1 = spi_cs[4][3];
assign appspi_cs = spi_cs[0][0];
assign lcd_cs = spi_cs[1][0];
assign ethmac_cs = spi_cs[2][0];
assign rph_g8_ce0 = spi_cs[3][0];
assign rph_g7_ce1 = spi_cs[3][1];
assign ah_tmpio10 = spi_cs[3][2];
assign microsd_dat3 = spi_cs[3][3];
assign rph_g18 = spi_cs[4][0];
assign rph_g17 = spi_cs[4][1];
assign rph_g16_ce2 = spi_cs[4][2];
assign mb1 = spi_cs[4][3];

wire unused_gp_spi_cs_ = ^{gp_lcd_cs, gp_appspi_cs, gp_ethmac_cs,
gp_rph_g8_ce0, gp_rph_g7_ce1, gp_rph_g18, gp_rph_g17, gp_rph_g16_ce2,
Expand Down
40 changes: 27 additions & 13 deletions rtl/fpga/top_sonata.sv
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ module top_sonata (
output logic appspi_d3, // HOLD_N or RESET_N
output logic appspi_cs, // Chip select negated

// MicroSD card slot
output logic microsd_clk, // SPI mode: SCLK
input logic microsd_dat0, // SPI mode: CIPO
//input logic microsd_dat1, // SPI mode: NC
//input logic microsd_dat2, // SPI mode: NC
output logic microsd_dat3, // SPI mode: CS_N
output logic microsd_cmd, // SPI mode: COPI
input logic microsd_det, // Card insertion detection

inout wire [7:0] hyperram_dq,
inout wire hyperram_rwds,
output wire hyperram_ckp,
Expand Down Expand Up @@ -342,6 +351,9 @@ module top_sonata (
.mb8,
.pmod0,
.pmod1,
.microsd_clk,
.microsd_dat0,
.microsd_cmd,
.tl_i(tl_pinmux_h2d),
.tl_o(tl_pinmux_d2h)
);
Expand All @@ -354,16 +366,17 @@ module top_sonata (
logic gp_ah_tmpio10, gp_mb1;

// CS outputs to SPI peripherals from controllers.
assign appspi_cs = spi_cs[0][0];
assign lcd_cs = spi_cs[1][0];
assign ethmac_cs = spi_cs[2][0];
assign rph_g8_ce0 = spi_cs[3][0];
assign rph_g7_ce1 = spi_cs[3][1];
assign ah_tmpio10 = spi_cs[3][2];
assign rph_g18 = spi_cs[4][0];
assign rph_g17 = spi_cs[4][1];
assign rph_g16_ce2 = spi_cs[4][2];
assign mb1 = spi_cs[4][3];
assign appspi_cs = spi_cs[0][0];
assign lcd_cs = spi_cs[1][0];
assign ethmac_cs = spi_cs[2][0];
assign rph_g8_ce0 = spi_cs[3][0];
assign rph_g7_ce1 = spi_cs[3][1];
assign ah_tmpio10 = spi_cs[3][2];
assign microsd_dat3 = spi_cs[3][3];
assign rph_g18 = spi_cs[4][0];
assign rph_g17 = spi_cs[4][1];
assign rph_g16_ce2 = spi_cs[4][2];
assign mb1 = spi_cs[4][3];

wire unused_gp_spi_cs_ = ^{gp_lcd_cs, gp_appspi_cs, gp_ethmac_cs,
gp_rph_g8_ce0, gp_rph_g7_ce1,
Expand All @@ -373,8 +386,7 @@ module top_sonata (
// Collect the unused CS lines.
wire unused_spi_cs_ = ^{spi_cs[0][SPI_CS_NUM-1:1],
spi_cs[1][SPI_CS_NUM-1:1],
spi_cs[2][SPI_CS_NUM-1:1],
spi_cs[3][SPI_CS_NUM-1]};
spi_cs[2][SPI_CS_NUM-1:1]};

// Enable CHERI by default.
logic enable_cheri;
Expand Down Expand Up @@ -407,7 +419,8 @@ module top_sonata (

// GPIO
.gp_i ({
15'b0,
14'b0,
microsd_det, // MicroSD card insertion detection
sel_sw_n, // Software selection switches
mb9, // mikroBUS Click interrupt
user_sw_n, // user switches
Expand Down Expand Up @@ -458,6 +471,7 @@ module top_sonata (
// - 2x Raspberry Pi HAT
// - Arduino Shield
// - mikroBUS Click
// - MicroSD card slot
.spi_rx_i (spi_rx),
.spi_tx_o (spi_tx),
.spi_cs_o (spi_cs),
Expand Down
118 changes: 113 additions & 5 deletions rtl/system/pinmux.sv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f1d91d8

Please sign in to comment.